From 4d6687cba26e4a4f16c081b4b098f32655d72336 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 22 Dec 2024 23:25:01 +0330 Subject: [PATCH] fix: added common columns for render tables --- output.json | 2 +- .../render/common_column.go | 46 +++++++++++++++++++ .../render/table_render_blueprint.go | 4 +- .../render/table_render_deploy.go | 4 +- .../render/table_render_disk.go | 4 +- .../render/table_render_env_group.go | 4 +- .../render/table_render_environment.go | 4 +- .../render/table_render_header.go | 4 +- .../render/table_render_job.go | 4 +- .../render/table_render_postgres_instance.go | 4 +- .../render/table_render_project.go | 4 +- .../render/table_render_route.go | 4 +- .../render/table_render_service.go | 4 +- 13 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 steampipe-plugin-render/render/common_column.go diff --git a/output.json b/output.json index 224d54e6..d1a5c097 100644 --- a/output.json +++ b/output.json @@ -1 +1 @@ -{"es_id":"","es_index":"","platform_id":":::Render/EnvGroup:::evg-ctavhehopnds73ejl14g","resource_id":"evg-ctavhehopnds73ejl14g","resource_name":"harbor-prod","description":{"createdAt":"2024-12-08T19:51:22.426806Z","environmentId":"","id":"evg-ctavhehopnds73ejl14g","name":"harbor-prod","ownerId":"tea-csuhvt52ng1s739lbn5g","serviceLinks":[],"updatedAt":"2024-12-08T19:51:22.426806Z"},"integration_type":"RENDER_ACCOUNT","resource_type":"render/envgroup","integration_id":"","metadata":{},"canonical_tags":null,"described_by":"473050548","described_at":1733908008835}, +{"es_id":"","es_index":"","platform_id":":::Render/Project:::prj-ctavcqqj1k6c738qbuf0","resource_id":"prj-ctavcqqj1k6c738qbuf0","resource_name":"opencomply-platform","description":{"createdAt":"2024-12-08T19:41:31.164334Z","environmentIds":["evm-ctavcqqj1k6c738qbufg"],"id":"prj-ctavcqqj1k6c738qbuf0","name":"opencomply-platform","owner":{"email":"anil.gaddam@opencomply.io","id":"tea-csuhvt52ng1s739lbn5g","name":"My Workspace","twoFactorAuthEnabled":false,"type":"team"},"updatedAt":"2024-12-08T19:41:31.164334Z"},"integration_type":"RENDER_ACCOUNT","resource_type":"render/project","integration_id":"","metadata":{},"canonical_tags":null,"described_by":"3928438176","described_at":1734887045810}, diff --git a/steampipe-plugin-render/render/common_column.go b/steampipe-plugin-render/render/common_column.go new file mode 100644 index 00000000..9ff66261 --- /dev/null +++ b/steampipe-plugin-render/render/common_column.go @@ -0,0 +1,46 @@ +package render + +import ( + "context" + "encoding/json" + "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" +) + +func commonColumns(c []*plugin.Column) []*plugin.Column { + return append(c, []*plugin.Column{ + { + Name: "platform_account_id", + Type: proto.ColumnType_STRING, + Description: "The Platform Account ID in which the resource is located.", + Transform: transform.FromField("IntegrationID"), + }, + { + Name: "platform_resource_id", + Type: proto.ColumnType_STRING, + Description: "The unique ID of the resource in opengovernance.", + Transform: transform.FromField("PlatformID"), + }, + { + Name: "platform_metadata", + Type: proto.ColumnType_JSON, + Description: "The metadata of the resource", + Transform: transform.FromField("Metadata").Transform(marshalJSON), + }, + { + Name: "platform_resource_description", + Type: proto.ColumnType_JSON, + Description: "The full model description of the resource", + Transform: transform.FromField("Description").Transform(marshalJSON), + }, + }...) +} + +func marshalJSON(_ context.Context, d *transform.TransformData) (interface{}, error) { + b, err := json.Marshal(d.Value) + if err != nil { + return nil, err + } + return string(b), nil +} diff --git a/steampipe-plugin-render/render/table_render_blueprint.go b/steampipe-plugin-render/render/table_render_blueprint.go index 80daaef6..0d0715d7 100644 --- a/steampipe-plugin-render/render/table_render_blueprint.go +++ b/steampipe-plugin-render/render/table_render_blueprint.go @@ -19,7 +19,7 @@ func tableRenderBlueprint(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetBlueprint, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the blueprint.", Transform: transform.FromField("Description.ID")}, {Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the blueprint.", Transform: transform.FromField("Description.Name")}, @@ -28,6 +28,6 @@ func tableRenderBlueprint(ctx context.Context) *plugin.Table { {Name: "repo", Type: proto.ColumnType_STRING, Description: "The repository associated with the blueprint.", Transform: transform.FromField("Description.Repo")}, {Name: "branch", Type: proto.ColumnType_STRING, Description: "The branch in the repository for the blueprint.", Transform: transform.FromField("Description.Branch")}, {Name: "lastSync", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of the last sync for the blueprint.", Transform: transform.FromField("Description.LastSync")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_deploy.go b/steampipe-plugin-render/render/table_render_deploy.go index 2609b818..4ee93228 100644 --- a/steampipe-plugin-render/render/table_render_deploy.go +++ b/steampipe-plugin-render/render/table_render_deploy.go @@ -19,7 +19,7 @@ func tableRenderDeploy(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetDeploy, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the deployment.", Transform: transform.FromField("Description.ID")}, {Name: "commit", Type: proto.ColumnType_JSON, Description: "The commit details associated with the deployment.", Transform: transform.FromField("Description.Commit")}, @@ -29,6 +29,6 @@ func tableRenderDeploy(ctx context.Context) *plugin.Table { {Name: "finishedAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of when the deployment finished.", Transform: transform.FromField("Description.FinishedAt")}, {Name: "createdAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of when the deployment was created.", Transform: transform.FromField("Description.CreatedAt")}, {Name: "updatedAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of the last update to the deployment.", Transform: transform.FromField("Description.UpdatedAt")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_disk.go b/steampipe-plugin-render/render/table_render_disk.go index d7f91671..c778f812 100644 --- a/steampipe-plugin-render/render/table_render_disk.go +++ b/steampipe-plugin-render/render/table_render_disk.go @@ -19,7 +19,7 @@ func tableRenderDisk(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetDisk, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the disk.", Transform: transform.FromField("Description.ID")}, {Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the disk.", Transform: transform.FromField("Description.Name")}, @@ -28,6 +28,6 @@ func tableRenderDisk(ctx context.Context) *plugin.Table { {Name: "serviceId", Type: proto.ColumnType_STRING, Description: "The ID of the service associated with the disk.", Transform: transform.FromField("Description.ServiceID")}, {Name: "createdAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of when the disk was created.", Transform: transform.FromField("Description.CreatedAt")}, {Name: "updatedAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of the last update to the disk.", Transform: transform.FromField("Description.UpdatedAt")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_env_group.go b/steampipe-plugin-render/render/table_render_env_group.go index 469777bb..a7c432e2 100644 --- a/steampipe-plugin-render/render/table_render_env_group.go +++ b/steampipe-plugin-render/render/table_render_env_group.go @@ -19,7 +19,7 @@ func tableRenderEnvGroup(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetEnvGroup, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the environment group.", Transform: transform.FromField("Description.ID")}, {Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the environment group.", Transform: transform.FromField("Description.Name")}, @@ -28,6 +28,6 @@ func tableRenderEnvGroup(ctx context.Context) *plugin.Table { {Name: "updatedAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of the last update to the environment group.", Transform: transform.FromField("Description.UpdatedAt")}, {Name: "serviceLinks", Type: proto.ColumnType_JSON, Description: "A list of service links associated with the environment group.", Transform: transform.FromField("Description.ServiceLinks")}, {Name: "environmentId", Type: proto.ColumnType_STRING, Description: "The ID of the associated environment.", Transform: transform.FromField("Description.EnvironmentID")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_environment.go b/steampipe-plugin-render/render/table_render_environment.go index 188b906f..c542f024 100644 --- a/steampipe-plugin-render/render/table_render_environment.go +++ b/steampipe-plugin-render/render/table_render_environment.go @@ -19,7 +19,7 @@ func tableRenderEnvironment(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetEnvironment, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the environment.", Transform: transform.FromField("Description.ID")}, {Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the environment.", Transform: transform.FromField("Description.Name")}, @@ -29,6 +29,6 @@ func tableRenderEnvironment(ctx context.Context) *plugin.Table { {Name: "serviceIds", Type: proto.ColumnType_JSON, Description: "A list of service IDs associated with the environment.", Transform: transform.FromField("Description.ServiceIDs")}, {Name: "envGroupIds", Type: proto.ColumnType_JSON, Description: "A list of environment group IDs associated with the environment.", Transform: transform.FromField("Description.EnvGroupIDs")}, {Name: "protectedStatus", Type: proto.ColumnType_STRING, Description: "The protected status of the environment.", Transform: transform.FromField("Description.ProtectedStatus")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_header.go b/steampipe-plugin-render/render/table_render_header.go index ca96b993..4a964d5c 100644 --- a/steampipe-plugin-render/render/table_render_header.go +++ b/steampipe-plugin-render/render/table_render_header.go @@ -19,12 +19,12 @@ func tableRenderHeader(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetHeader, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the header.", Transform: transform.FromField("Description.ID")}, {Name: "path", Type: proto.ColumnType_STRING, Description: "The path of the header.", Transform: transform.FromField("Description.Path")}, {Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the header.", Transform: transform.FromField("Description.Name")}, {Name: "value", Type: proto.ColumnType_STRING, Description: "The value of the header.", Transform: transform.FromField("Description.Value")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_job.go b/steampipe-plugin-render/render/table_render_job.go index d846b7ca..bb5d6078 100644 --- a/steampipe-plugin-render/render/table_render_job.go +++ b/steampipe-plugin-render/render/table_render_job.go @@ -19,7 +19,7 @@ func tableRenderJob(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetJob, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the job.", Transform: transform.FromField("Description.ID")}, {Name: "serviceId", Type: proto.ColumnType_STRING, Description: "The ID of the service associated with the job.", Transform: transform.FromField("Description.ServiceID")}, @@ -29,6 +29,6 @@ func tableRenderJob(ctx context.Context) *plugin.Table { {Name: "createdAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of when the job was created.", Transform: transform.FromField("Description.CreatedAt")}, {Name: "startedAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of when the job started.", Transform: transform.FromField("Description.StartedAt")}, {Name: "finishedAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of when the job finished.", Transform: transform.FromField("Description.FinishedAt")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_postgres_instance.go b/steampipe-plugin-render/render/table_render_postgres_instance.go index 971e8d63..6dba2d54 100644 --- a/steampipe-plugin-render/render/table_render_postgres_instance.go +++ b/steampipe-plugin-render/render/table_render_postgres_instance.go @@ -19,7 +19,7 @@ func tableRenderPostgres(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetPostgres, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the PostgreSQL instance.", Transform: transform.FromField("Description.ID")}, {Name: "ipAllowList", Type: proto.ColumnType_JSON, Description: "A list of IP addresses allowed to access the PostgreSQL instance.", Transform: transform.FromField("Description.IPAllowList")}, @@ -43,6 +43,6 @@ func tableRenderPostgres(ctx context.Context) *plugin.Table { {Name: "suspended", Type: proto.ColumnType_STRING, Description: "Indicates whether the PostgreSQL instance is suspended.", Transform: transform.FromField("Description.Suspended")}, {Name: "suspenders", Type: proto.ColumnType_JSON, Description: "A list of suspenders associated with the PostgreSQL instance.", Transform: transform.FromField("Description.Suspenders")}, {Name: "dashboardUrl", Type: proto.ColumnType_STRING, Description: "The URL of the PostgreSQL instance's dashboard.", Transform: transform.FromField("Description.DashboardURL")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_project.go b/steampipe-plugin-render/render/table_render_project.go index 7118a6df..ec784d3b 100644 --- a/steampipe-plugin-render/render/table_render_project.go +++ b/steampipe-plugin-render/render/table_render_project.go @@ -19,7 +19,7 @@ func tableRenderProject(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetProject, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the project.", Transform: transform.FromField("Description.ID")}, {Name: "createdAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of when the project was created.", Transform: transform.FromField("Description.CreatedAt")}, @@ -27,6 +27,6 @@ func tableRenderProject(ctx context.Context) *plugin.Table { {Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the project.", Transform: transform.FromField("Description.Name")}, {Name: "owner", Type: proto.ColumnType_JSON, Description: "Information about the owner of the project.", Transform: transform.FromField("Description.Owner")}, {Name: "environmentIds", Type: proto.ColumnType_JSON, Description: "A list of environment IDs associated with the project.", Transform: transform.FromField("Description.EnvironmentIDs")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_route.go b/steampipe-plugin-render/render/table_render_route.go index a2c909b9..a1a3d25a 100644 --- a/steampipe-plugin-render/render/table_render_route.go +++ b/steampipe-plugin-render/render/table_render_route.go @@ -19,13 +19,13 @@ func tableRenderRoute(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetRoute, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the route.", Transform: transform.FromField("Description.ID")}, {Name: "type", Type: proto.ColumnType_STRING, Description: "The type of the route.", Transform: transform.FromField("Description.Type")}, {Name: "source", Type: proto.ColumnType_STRING, Description: "The source of the route.", Transform: transform.FromField("Description.Source")}, {Name: "destination", Type: proto.ColumnType_STRING, Description: "The destination of the route.", Transform: transform.FromField("Description.Destination")}, {Name: "priority", Type: proto.ColumnType_INT, Description: "The priority of the route.", Transform: transform.FromField("Description.Priority")}, - }, + }), } } diff --git a/steampipe-plugin-render/render/table_render_service.go b/steampipe-plugin-render/render/table_render_service.go index 7a2fe323..e70e5c76 100644 --- a/steampipe-plugin-render/render/table_render_service.go +++ b/steampipe-plugin-render/render/table_render_service.go @@ -19,7 +19,7 @@ func tableRenderService(ctx context.Context) *plugin.Table { KeyColumns: plugin.SingleColumn("id"), Hydrate: opengovernance.GetService, }, - Columns: []*plugin.Column{ + Columns: commonColumns([]*plugin.Column{ // Top columns {Name: "id", Type: proto.ColumnType_STRING, Description: "The unique identifier for the service.", Transform: transform.FromField("Description.ID")}, {Name: "autoDeploy", Type: proto.ColumnType_STRING, Description: "Indicates whether the service deploys automatically.", Transform: transform.FromField("Description.AutoDeploy")}, @@ -41,6 +41,6 @@ func tableRenderService(ctx context.Context) *plugin.Table { {Name: "type", Type: proto.ColumnType_STRING, Description: "The type of the service.", Transform: transform.FromField("Description.Type")}, {Name: "updatedAt", Type: proto.ColumnType_TIMESTAMP, Description: "The timestamp of the last update to the service.", Transform: transform.FromField("Description.UpdatedAt")}, {Name: "serviceDetails", Type: proto.ColumnType_JSON, Description: "The details of the service.", Transform: transform.FromField("Description.ServiceDetails")}, - }, + }), } }