From 25728caea9c22fe8c545e38416096bae4ded20e5 Mon Sep 17 00:00:00 2001 From: Antonio Maradiaga Date: Tue, 5 Dec 2023 12:29:25 +0100 Subject: [PATCH] Converting columns to timestamp --- btp/table_btp_accounts_directory.go | 5 +++-- btp/table_btp_accounts_global_account.go | 5 +++-- btp/table_btp_accounts_subaccount.go | 5 +++-- btp/utils.go | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/btp/table_btp_accounts_directory.go b/btp/table_btp_accounts_directory.go index ce912d7..6eec68a 100644 --- a/btp/table_btp_accounts_directory.go +++ b/btp/table_btp_accounts_directory.go @@ -7,6 +7,7 @@ import ( "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" "github.com/turbot/steampipe-plugin-sdk/v5/plugin" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" ) const ( @@ -26,9 +27,9 @@ func tableBTPAccountsDirectory() *plugin.Table { {Name: "parent_type", Type: proto.ColumnType_STRING, Description: "The Type of the directory parent entity."}, {Name: "global_account_guid", Type: proto.ColumnType_STRING, Description: "The GUID of the directory's global account entity."}, {Name: "display_name", Type: proto.ColumnType_STRING, Description: "The display name of the directory."}, - {Name: "created_date", Type: proto.ColumnType_INT, Description: "The date the directory was created. Dates and times are in UTC format."}, + {Name: "created_date", Type: proto.ColumnType_TIMESTAMP, Description: "The date the directory was created. Dates and times are in UTC format.", Transform: transform.FromField("createdDate").Transform(convertTimestamp)}, {Name: "created_by", Type: proto.ColumnType_STRING, Description: "Details of the user that created the directory."}, - {Name: "modified_date", Type: proto.ColumnType_INT, Description: "The date the directory was last modified. Dates and times are in UTC format."}, + {Name: "modified_date", Type: proto.ColumnType_TIMESTAMP, Description: "The date the directory was last modified. Dates and times are in UTC format.", Transform: transform.FromField("modifiedDate").Transform(convertTimestamp)}, {Name: "entity_state", Type: proto.ColumnType_STRING, Description: "The current state of the directory.\n* STARTED: CRUD operation on an entity has started.\n* CREATING: Creating entity operation is in progress.\n* UPDATING: Updating entity operation is in progress.\n* MOVING: Moving entity operation is in progress.\n* PROCESSING: A series of operations related to the entity is in progress.\n* DELETING: Deleting entity operation is in progress.\n* OK: The CRUD operation or series of operations completed successfully.\n* PENDING REVIEW: The processing operation has been stopped for reviewing and can be restarted by the operator.\n* CANCELLED: The operation or processing was canceled by the operator.\n* CREATION_FAILED: The creation operation failed, and the entity was not created or was created but cannot be used.\n* UPDATE_FAILED: The update operation failed, and the entity was not updated.\n* PROCESSING_FAILED: The processing operations failed.\n* DELETION_FAILED: The delete operation failed, and the entity was not deleted.\n* MOVE_FAILED: Entity could not be moved to a different location.\n* MIGRATING: Migrating entity from NEO to CF."}, {Name: "state_message", Type: proto.ColumnType_STRING, Description: "Information about the state."}, {Name: "directory_type", Type: proto.ColumnType_STRING, Description: "Type of directory."}, diff --git a/btp/table_btp_accounts_global_account.go b/btp/table_btp_accounts_global_account.go index 2226c68..d38ad6c 100644 --- a/btp/table_btp_accounts_global_account.go +++ b/btp/table_btp_accounts_global_account.go @@ -7,6 +7,7 @@ import ( "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" "github.com/turbot/steampipe-plugin-sdk/v5/plugin" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" ) const ( @@ -23,8 +24,8 @@ func tableBTPAccountsGlobalAccount() *plugin.Table { Columns: []*plugin.Column{ {Name: "guid", Type: proto.ColumnType_STRING, Description: "The unique ID of the global account."}, {Name: "display_name", Type: proto.ColumnType_STRING, Description: "The display name of the global account."}, - {Name: "created_date", Type: proto.ColumnType_INT, Description: "The date the global account was created. Dates and times are in UTC format."}, - {Name: "modified_date", Type: proto.ColumnType_INT, Description: "The date the global account was last modified. Dates and times are in UTC format."}, + {Name: "created_date", Type: proto.ColumnType_TIMESTAMP, Description: "The date the global account was created. Dates and times are in UTC format.", Transform: transform.FromField("createdDate").Transform(convertTimestamp)}, + {Name: "modified_date", Type: proto.ColumnType_TIMESTAMP, Description: "The date the global account was last modified. Dates and times are in UTC format.", Transform: transform.FromField("modifiedDate").Transform(convertTimestamp)}, {Name: "entity_state", Type: proto.ColumnType_STRING, Description: "The current state of the global account.\n* STARTED: CRUD operation on an entity has started.\n* CREATING: Creating entity operation is in progress.\n* UPDATING: Updating entity operation is in progress.\n* MOVING: Moving entity operation is in progress.\n* PROCESSING: A series of operations related to the entity is in progress.\n* DELETING: Deleting entity operation is in progress.\n* OK: The CRUD operation or series of operations completed successfully.\n* PENDING REVIEW: The processing operation has been stopped for reviewing and can be restarted by the operator.\n* CANCELLED: The operation or processing was canceled by the operator.\n* CREATION_FAILED: The creation operation failed, and the entity was not created or was created but cannot be used.\n* UPDATE_FAILED: The update operation failed, and the entity was not updated.\n* PROCESSING_FAILED: The processing operations failed.\n* DELETION_FAILED: The delete operation failed, and the entity was not deleted.\n* MOVE_FAILED: Entity could not be moved to a different location.\n* MIGRATING: Migrating entity from NEO to CF."}, {Name: "state_message", Type: proto.ColumnType_STRING, Description: "Information about the state."}, {Name: "subdomain", Type: proto.ColumnType_STRING, Description: "Relevant only for entities that require authorization (e.g. global account). The subdomain that becomes part of the path used to access the authorization tenant of the global account. Unique within the defined region."}, diff --git a/btp/table_btp_accounts_subaccount.go b/btp/table_btp_accounts_subaccount.go index fb980d3..d68aa77 100644 --- a/btp/table_btp_accounts_subaccount.go +++ b/btp/table_btp_accounts_subaccount.go @@ -7,6 +7,7 @@ import ( "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" "github.com/turbot/steampipe-plugin-sdk/v5/plugin" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" ) const ( @@ -39,9 +40,9 @@ func tableBTPAccountsSubaccount() *plugin.Table { {Name: "description", Type: proto.ColumnType_STRING, Description: "A description of the subaccount for customer-facing UIs."}, {Name: "state", Type: proto.ColumnType_STRING, Description: "The current state of the subaccount."}, {Name: "state_message", Type: proto.ColumnType_STRING, Description: "Information about the state of the subaccount."}, - {Name: "created_date", Type: proto.ColumnType_INT, Description: "The date the subaccount was created. Dates and times are in UTC format."}, + {Name: "created_date", Type: proto.ColumnType_TIMESTAMP, Description: "The date the subaccount was created. Dates and times are in UTC format.", Transform: transform.FromField("createdDate").Transform(convertTimestamp)}, {Name: "created_by", Type: proto.ColumnType_STRING, Description: "Details of the user that created the subaccount."}, - {Name: "modified_date", Type: proto.ColumnType_INT, Description: "The date the subaccount was last modified. Dates and times are in UTC format."}, + {Name: "modified_date", Type: proto.ColumnType_TIMESTAMP, Description: "The date the subaccount was last modified. Dates and times are in UTC format.", Transform: transform.FromField("modifiedDate").Transform(convertTimestamp)}, {Name: "custom_properties", Type: proto.ColumnType_JSON, Description: "The custom properties of the subaccount."}, }, } diff --git a/btp/utils.go b/btp/utils.go index 3664c48..c56cea6 100644 --- a/btp/utils.go +++ b/btp/utils.go @@ -4,10 +4,13 @@ import ( "context" "errors" "io" + "math" "net/http" "os" + "time" "github.com/turbot/steampipe-plugin-sdk/v5/plugin" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" ) type BTPService string @@ -191,3 +194,16 @@ func (b *BTPClient) Get(ctx context.Context, service BTPService, path string, he } return body, nil } + +// Source of this function: https://github.com/dboeke/steampipe-plugin-aws/blob/4a98b9c8b6172e6f4c70b2ee2b9fd269fd72198c/aws/utils.go#L44 +func convertTimestamp(ctx context.Context, d *transform.TransformData) (interface{}, error) { + epochTime := d.Value.(*int64) + + if epochTime != nil { + timeInSec := math.Floor(float64(*epochTime) / 1000) + unixTimestamp := time.Unix(int64(timeInSec), 0) + timestampRFC3339Format := unixTimestamp.Format(time.RFC3339) + return timestampRFC3339Format, nil + } + return nil, nil +}