Skip to content

Commit

Permalink
Converting columns to timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmaradiaga committed Dec 5, 2023
1 parent a63f6af commit 25728ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
5 changes: 3 additions & 2 deletions btp/table_btp_accounts_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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* <b>STARTED:</b> CRUD operation on an entity has started.\n* <b>CREATING:</b> Creating entity operation is in progress.\n* <b>UPDATING:</b> Updating entity operation is in progress.\n* <b>MOVING:</b> Moving entity operation is in progress.\n* <b>PROCESSING:</b> A series of operations related to the entity is in progress.\n* <b>DELETING:</b> Deleting entity operation is in progress.\n* <b>OK:</b> The CRUD operation or series of operations completed successfully.\n* <b>PENDING REVIEW:</b> The processing operation has been stopped for reviewing and can be restarted by the operator.\n* <b>CANCELLED:</b> The operation or processing was canceled by the operator.\n* <b>CREATION_FAILED:</b> The creation operation failed, and the entity was not created or was created but cannot be used.\n* <b>UPDATE_FAILED:</b> The update operation failed, and the entity was not updated.\n* <b>PROCESSING_FAILED:</b> The processing operations failed.\n* <b>DELETION_FAILED:</b> The delete operation failed, and the entity was not deleted.\n* <b>MOVE_FAILED:</b> Entity could not be moved to a different location.\n* <b>MIGRATING:</b> 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."},
Expand Down
5 changes: 3 additions & 2 deletions btp/table_btp_accounts_global_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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."},
Expand Down
5 changes: 3 additions & 2 deletions btp/table_btp_accounts_subaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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."},
},
}
Expand Down
16 changes: 16 additions & 0 deletions btp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 25728ca

Please sign in to comment.