Skip to content

Commit

Permalink
Convert Unix Epoch time to seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnotoole committed Sep 20, 2024
1 parent d9c24c8 commit cd017eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion internal/cmp/morpheus_datasource_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package cmp

import (
"context"
"time"

"github.com/HewlettPackard/hpegl-vmaas-cmp-go-sdk/pkg/client"
"github.com/HewlettPackard/hpegl-vmaas-terraform-resources/internal/utils"
)
Expand All @@ -27,14 +29,17 @@ func (m *morpheusBroker) Read(ctx context.Context, d *utils.Data, meta interface
return err
}

// Convert the Unix timestamp to Duration in seconds
validSeconds := time.Until(time.Unix(morpheusDetails.ValidTill, 0)) / time.Second

// Set all of the details
d.SetId(morpheusDetails.ID)

if err = d.Set("access_token", morpheusDetails.AccessToken); err != nil {
return err
}

if err = d.Set("valid_till", morpheusDetails.ValidTill); err != nil {
if err = d.Set("valid_till", validSeconds); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions internal/resources/data_source_morpheus_token_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func MorpheusDetailsBroker() *schema.Resource {
"valid_till": {
Type: schema.TypeInt,
Computed: true,
Description: "Unix timestamp of when the access_token expires, in seconds",
Description: "time until the token expires, in seconds",
Sensitive: false,
},
"url": {
Expand All @@ -36,8 +36,8 @@ func MorpheusDetailsBroker() *schema.Resource {
},
ReadContext: MorpheusDetailsBrokerReadContext,
Description: `The ` + DSMorpheusDataSource + ` data source can be used to get a details of the Morpheus instance
used by VMaaS. The details that can be retrieved are the access_token, valid_till (the Unix timestamp of
access_token expiration) and the URL of the Morpheus instance.`,
used by VMaaS. The details that can be retrieved are the access_token, valid_till (time until the token expires,
in seconds), and the URL of the Morpheus instance.`,
SchemaVersion: 0,
StateUpgraders: nil,
Importer: &schema.ResourceImporter{
Expand Down

0 comments on commit cd017eb

Please sign in to comment.