From bd4ada0af0912cd9a1ebe196d6e0e7070f241145 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Wed, 11 Jan 2023 11:39:06 +0530 Subject: [PATCH 01/36] Update SDK to v0.4.0. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 4170998..9d2e29f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module steampipe-plugin-steampipecloud go 1.19 require ( - github.com/turbot/steampipe-cloud-sdk-go v0.3.0 + github.com/turbot/steampipe-cloud-sdk-go v0.4.0 github.com/turbot/steampipe-plugin-sdk/v4 v4.1.8 ) diff --git a/go.sum b/go.sum index 387e9fb..c0dc16a 100644 --- a/go.sum +++ b/go.sum @@ -418,8 +418,8 @@ github.com/tkrajina/go-reflector v0.5.4 h1:dS9aJEa/eYNQU/fwsb5CSiATOxcNyA/gG/A7a github.com/tkrajina/go-reflector v0.5.4/go.mod h1:9PyLgEOzc78ey/JmQQHbW8cQJ1oucLlNQsg8yFvkVk8= github.com/turbot/go-kit v0.4.0 h1:EdD7Bf2EGAjvHRGQxRiWpDawzZSk3T+eghqbj74qiSc= github.com/turbot/go-kit v0.4.0/go.mod h1:SBdPRngbEfYubiR81iAVtO43oPkg1+ASr+XxvgbH7/k= -github.com/turbot/steampipe-cloud-sdk-go v0.3.0 h1:2x0VlzAYoRZBWfYxZ3Z0kkMmERtZF8alfY3uctqWhGA= -github.com/turbot/steampipe-cloud-sdk-go v0.3.0/go.mod h1:8M2CspUHgCGqDCJV+FNn+boBPyLRHyzDinYnoZ/kZYw= +github.com/turbot/steampipe-cloud-sdk-go v0.4.0 h1:ewDymSmTZSHwlqOBBMHS0kS2GzEtHaHD8DCYYXOEKMU= +github.com/turbot/steampipe-cloud-sdk-go v0.4.0/go.mod h1:8M2CspUHgCGqDCJV+FNn+boBPyLRHyzDinYnoZ/kZYw= github.com/turbot/steampipe-plugin-sdk/v4 v4.1.8 h1:4/fEpsrWNSKA/p2otsibzijBCf4f35Y8jIgUcJgd0Ng= github.com/turbot/steampipe-plugin-sdk/v4 v4.1.8/go.mod h1:t1uwq6KylUr2CzIinxeTafoktJvX8yWmhaoWCJJc4YI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= From 6cc55d2c3f89917fd88bca7fc4a30d94c19bcd53 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Wed, 11 Jan 2023 13:33:26 +0530 Subject: [PATCH 02/36] Add table for workspace pipelines. --- steampipecloud/plugin.go | 1 + ...table_steampipecloud_workspace_pipeline.go | 470 ++++++++++++++++++ 2 files changed, 471 insertions(+) create mode 100644 steampipecloud/table_steampipecloud_workspace_pipeline.go diff --git a/steampipecloud/plugin.go b/steampipecloud/plugin.go index fe753e8..4565524 100644 --- a/steampipecloud/plugin.go +++ b/steampipecloud/plugin.go @@ -33,6 +33,7 @@ func Plugin(ctx context.Context) *plugin.Plugin { "steampipecloud_workspace_mod": tableSteampipeCloudWorkspaceMod(ctx), "steampipecloud_workspace_mod_variable": tableSteampipeCloudWorkspaceModVariable(ctx), "steampipecloud_workspace_db_log": tableSteampipeCloudWorkspaceDBLog(ctx), + "steampipecloud_workspace_pipeline": tableSteampipeCloudWorkspacePipeline(ctx), "steampipecloud_workspace_snapshot": tableSteampipeCloudWorkspaceSnapshot(ctx), }, } diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go new file mode 100644 index 0000000..17c7a02 --- /dev/null +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -0,0 +1,470 @@ +package steampipecloud + +import ( + "context" + "strings" + + openapi "github.com/turbot/steampipe-cloud-sdk-go" + + "github.com/turbot/steampipe-plugin-sdk/v4/grpc/proto" + "github.com/turbot/steampipe-plugin-sdk/v4/plugin" + "github.com/turbot/steampipe-plugin-sdk/v4/plugin/transform" +) + +type IdentityWorkspaceDetailsForPipeline struct { + IdentityId string `json:"identity_id"` + IdentityHandle string `json:"identity_handle"` + IdentityType string `json:"identity_type"` + WorkspaceHandle string `json:"workspace_handle"` +} + +//// TABLE DEFINITION + +func tableSteampipeCloudWorkspacePipeline(_ context.Context) *plugin.Table { + return &plugin.Table{ + Name: "steampipecloud_workspace_pipeline", + Description: "Pipelines allow users to run different kinds of activities in steampipe cloud on a schedule.", + List: &plugin.ListConfig{ + ParentHydrate: listWorkspaces, + Hydrate: listWorkspacePipelines, + KeyColumns: []*plugin.KeyColumn{ + { + Name: "identity_handle", + Require: plugin.Optional, + }, + { + Name: "identity_id", + Require: plugin.Optional, + }, + { + Name: "workspace_handle", + Require: plugin.Optional, + }, + { + Name: "workspace_id", + Require: plugin.Optional, + }, + }, + }, + Get: &plugin.GetConfig{ + KeyColumns: plugin.AllColumns([]string{"identity_handle", "workspace_handle", "id"}), + Hydrate: getWorkspacePipeline, + }, + Columns: []*plugin.Column{ + { + Name: "id", + Description: "The unique identifier for the pipeline.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "identity_id", + Description: "The unique identifier of the identity to which the pipeline belongs to.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityWorkspaceDetailsForPipeline, + }, + { + Name: "identity_handle", + Description: "The handle of the identity.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityWorkspaceDetailsForPipeline, + }, + { + Name: "identity_type", + Description: "The type of identity, can be org/user.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityWorkspaceDetailsForPipeline, + }, + { + Name: "workspace_id", + Description: "The unique identifier for the workspace.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "workspace_handle", + Description: "The handle of the workspace.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityWorkspaceDetailsForPipeline, + }, + { + Name: "title", + Description: "The title of the pipeline.", + Type: proto.ColumnType_STRING, + }, + { + Name: "frequency", + Description: "The frequency at which the pipeline will be executed.", + Type: proto.ColumnType_JSON, + }, + { + Name: "pipeline", + Description: "The name of the pipeline to be executed.", + Type: proto.ColumnType_STRING, + }, + { + Name: "args", + Description: "Arguments to be passed to the pipeline.", + Type: proto.ColumnType_JSON, + }, + { + Name: "tags", + Description: "The tags for the pipeline.", + Type: proto.ColumnType_JSON, + }, + { + Name: "created_at", + Description: "The time when the pipeline was created.", + Type: proto.ColumnType_TIMESTAMP, + }, + { + Name: "created_by_id", + Description: "The unique identifier of the user who created the pipeline.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "created_by", + Description: "Information about the user who created the pipeline.", + Type: proto.ColumnType_JSON, + }, + { + Name: "updated_at", + Description: "The time when the pipeline was last updated.", + Type: proto.ColumnType_TIMESTAMP, + }, + { + Name: "updated_by_id", + Description: "The unique identifier of the user who last updated the pipeline.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "updated_by", + Description: "Information about the user who last updated the pipeline.", + Type: proto.ColumnType_JSON, + }, + { + Name: "version_id", + Description: "The current version ID for the pipeline.", + Type: proto.ColumnType_INT, + Transform: transform.FromCamel(), + }, + }, + } +} + +//// LIST FUNCTION + +func listWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + var workspace *openapi.Workspace + switch w := h.Item.(type) { + case openapi.Workspace: + wo := h.Item.(openapi.Workspace) + workspace = &wo + case *openapi.Workspace: + workspace = h.Item.(*openapi.Workspace) + default: + plugin.Logger(ctx).Error("listWorkspacePipelines", "unknown response type for workspace list parent hydrate call", w) + } + + // If the requested number of items is less than the paging max limit + // set the limit to that instead + maxResults := int32(100) + limit := d.QueryContext.Limit + if d.QueryContext.Limit != nil { + if *limit < int64(maxResults) { + if *limit < 1 { + maxResults = int32(1) + } else { + maxResults = int32(*limit) + } + } + } + + workspaceHandle := d.KeyColumnQuals["workspace_handle"].GetStringValue() + workspaceId := d.KeyColumnQuals["workspace_id"].GetStringValue() + var workspaceToPass string + + // Error out if both workspace_handle and workspace_id is passed + if workspaceHandle != "" && workspaceId != "" { + plugin.Logger(ctx).Error("listWorkspacePipelines", "please pass any one of workspace_id or workspace_handle") + } + // If either one has been passed, check whether either of the handle or the id matches with the workspace in context + if workspaceHandle != "" || workspaceId != "" { + if workspaceHandle == workspace.Handle { + workspaceToPass = workspaceHandle + } else if workspaceId == workspace.Id { + workspaceToPass = workspaceId + } else { + return nil, nil + } + } else { + // If neither is passed, we pass the context over to the call + workspaceToPass = workspace.Id + } + + var err error + if strings.HasPrefix(workspace.IdentityId, "u_") { + err = listUserWorkspacePipelines(ctx, d, h, workspace.IdentityId, workspaceToPass, maxResults) + } else { + err = listOrgWorkspacePipelines(ctx, d, h, workspace.IdentityId, workspaceToPass, maxResults) + } + + if err != nil { + plugin.Logger(ctx).Error("listWorkspacePipelines", "error", err) + return nil, err + } + + return nil, nil +} + +func listUserWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, userHandle string, workspaceHandle string, maxResults int32) error { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("listUserWorkspacePipelines", "connection_error", err) + return err + } + + pagesLeft := true + var resp openapi.ListPipelinesResponse + var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) + + for pagesLeft { + if resp.NextToken != nil { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.UserWorkspacePipelines.List(ctx, userHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + return resp, err + } + } else { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.UserWorkspacePipelines.List(ctx, userHandle, workspaceHandle).Limit(maxResults).Execute() + return resp, err + } + } + + response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + + if err != nil { + plugin.Logger(ctx).Error("listUserWorkspacePipelines", "list", err) + return err + } + + result := response.(openapi.ListPipelinesResponse) + + if result.HasItems() { + for _, pipeline := range *result.Items { + d.StreamListItem(ctx, pipeline) + + // Context can be cancelled due to manual cancellation or the limit has been hit + if d.QueryStatus.RowsRemaining(ctx) == 0 { + return nil + } + } + } + if result.NextToken == nil { + pagesLeft = false + } else { + resp.NextToken = result.NextToken + } + } + + return nil +} + +func listOrgWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, orgHandle string, workspaceHandle string, maxResults int32) error { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("listOrgWorkspacePipelines", "connection_error", err) + return err + } + + pagesLeft := true + var resp openapi.ListPipelinesResponse + var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) + + for pagesLeft { + if resp.NextToken != nil { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.OrgWorkspacePipelines.List(ctx, orgHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + return resp, err + } + } else { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.OrgWorkspacePipelines.List(ctx, orgHandle, workspaceHandle).Limit(maxResults).Execute() + return resp, err + } + } + + response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + + if err != nil { + plugin.Logger(ctx).Error("listOrgWorkspacePipelines", "list", err) + return err + } + + result := response.(openapi.ListPipelinesResponse) + + if result.HasItems() { + for _, pipeline := range *result.Items { + d.StreamListItem(ctx, pipeline) + + // Context can be cancelled due to manual cancellation or the limit has been hit + if d.QueryStatus.RowsRemaining(ctx) == 0 { + return nil + } + } + } + if result.NextToken == nil { + pagesLeft = false + } else { + resp.NextToken = result.NextToken + } + } + + return nil +} + +func getWorkspacePipeline(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + identityHandle := d.KeyColumnQuals["identity_handle"].GetStringValue() + workspaceHandle := d.KeyColumnQuals["workspace_handle"].GetStringValue() + pipelineId := d.KeyColumnQuals["id"].GetStringValue() + + // check if identityHandle or workspaceHandle or pipeline id is empty + if identityHandle == "" || workspaceHandle == "" || pipelineId == "" { + return nil, nil + } + + getUserIdentityCached := plugin.HydrateFunc(getUserIdentity).WithCache() + commonData, err := getUserIdentityCached(ctx, d, h) + if err != nil { + plugin.Logger(ctx).Error("getWorkspacePipeline", "getUserIdentityCached", err) + return nil, err + } + + user := commonData.(openapi.User) + var response interface{} + if identityHandle == user.Handle { + response, err = getUserWorkspacePipeline(ctx, d, h, identityHandle, workspaceHandle, pipelineId) + } else { + response, err = getOrgWorkspacePipeline(ctx, d, h, identityHandle, workspaceHandle, pipelineId) + } + + if err != nil { + plugin.Logger(ctx).Error("getWorkspacePipeline", "error", err) + return nil, err + } + + return response.(openapi.Pipeline), nil +} + +func getUserWorkspacePipeline(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, userHandle, workspaceHandle, pipelineId string) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getUserWorkspacePipeline", "connection_error", err) + return nil, err + } + + var pipeline openapi.Pipeline + + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + pipeline, _, err = svc.UserWorkspacePipelines.Get(ctx, userHandle, workspaceHandle, pipelineId).Execute() + return pipeline, err + } + + response, err := plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + if err != nil { + plugin.Logger(ctx).Error("getUserWorkspacePipeline", "get", err) + return nil, err + } + + return response, nil +} + +func getOrgWorkspacePipeline(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, orgHandle, workspaceHandle, pipelineId string) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getOrgWorkspacePipeline", "connection_error", err) + return nil, err + } + + var pipeline openapi.Pipeline + + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + pipeline, _, err = svc.OrgWorkspacePipelines.Get(ctx, orgHandle, workspaceHandle, pipelineId).Execute() + return pipeline, err + } + + response, err := plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + if err != nil { + plugin.Logger(ctx).Error("getOrgWorkspacePipeline", "get", err) + return nil, err + } + + return response, nil +} + +func getIdentityWorkspaceDetailsForPipeline(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getIdentityWorkspaceDetails", "connection_error", err) + return nil, err + } + + var identityWorkspaceDetails IdentityWorkspaceDetailsForPipeline + // get workspace details from hydrate data + // workspace details reside in the parent item in this case + switch w := h.ParentItem.(type) { + case openapi.Workspace: + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetails", "openapi.Workspace") + identityId := h.ParentItem.(openapi.Workspace).IdentityId + identityWorkspaceDetails.WorkspaceHandle = h.ParentItem.(openapi.Workspace).Handle + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + if strings.HasPrefix(identityId, "u_") { + resp, _, err := svc.Users.Get(ctx, identityId).Execute() + identityWorkspaceDetails.IdentityId = resp.Id + identityWorkspaceDetails.IdentityType = "user" + identityWorkspaceDetails.IdentityHandle = resp.Handle + return nil, err + } else { + resp, _, err := svc.Orgs.Get(ctx, identityId).Execute() + identityWorkspaceDetails.IdentityId = resp.Id + identityWorkspaceDetails.IdentityType = "org" + identityWorkspaceDetails.IdentityHandle = resp.Handle + return nil, err + } + } + _, _ = plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + return identityWorkspaceDetails, nil + case *openapi.Workspace: + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetails", "*openapi.Workspace") + identityId := h.ParentItem.(*openapi.Workspace).IdentityId + identityWorkspaceDetails.WorkspaceHandle = h.ParentItem.(*openapi.Workspace).Handle + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + if strings.HasPrefix(identityId, "u_") { + resp, _, err := svc.Users.Get(ctx, identityId).Execute() + identityWorkspaceDetails.IdentityId = resp.Id + identityWorkspaceDetails.IdentityType = "user" + identityWorkspaceDetails.IdentityHandle = resp.Handle + return nil, err + } else { + resp, _, err := svc.Orgs.Get(ctx, identityId).Execute() + identityWorkspaceDetails.IdentityId = resp.Id + identityWorkspaceDetails.IdentityType = "org" + identityWorkspaceDetails.IdentityHandle = resp.Handle + return nil, err + } + } + _, _ = plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetails", "identityWorkspaceDetails", identityWorkspaceDetails) + return identityWorkspaceDetails, nil + default: + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetails", "Unknown Type", w) + } + return identityWorkspaceDetails, nil +} From 41b758708ccc0ec53b2ac21205f6b8ca19085c61 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Tue, 31 Jan 2023 12:22:43 +0530 Subject: [PATCH 03/36] Add last_process_id and last_process to the pipeline table. --- .../table_steampipecloud_workspace_pipeline.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index 17c7a02..a2da068 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -112,6 +112,17 @@ func tableSteampipeCloudWorkspacePipeline(_ context.Context) *plugin.Table { Description: "The tags for the pipeline.", Type: proto.ColumnType_JSON, }, + { + Name: "last_process_id", + Description: "The unique identifier of the last process that was executed for the pipeline.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "last_process", + Description: "Information about the process that was last executed for the pipeline.", + Type: proto.ColumnType_JSON, + }, { Name: "created_at", Description: "The time when the pipeline was created.", From 4f696b49dd89dae83b16c5c9b5d1c4883d92c97e Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Tue, 31 Jan 2023 17:32:06 +0530 Subject: [PATCH 04/36] Add process and workspace process table. --- steampipecloud/plugin.go | 2 + .../table_steampipecloud_process.go | 409 ++++++++++++++++ ...table_steampipecloud_workspace_pipeline.go | 16 +- .../table_steampipecloud_workspace_process.go | 463 ++++++++++++++++++ 4 files changed, 883 insertions(+), 7 deletions(-) create mode 100644 steampipecloud/table_steampipecloud_process.go create mode 100644 steampipecloud/table_steampipecloud_workspace_process.go diff --git a/steampipecloud/plugin.go b/steampipecloud/plugin.go index 4565524..23506c0 100644 --- a/steampipecloud/plugin.go +++ b/steampipecloud/plugin.go @@ -23,6 +23,7 @@ func Plugin(ctx context.Context) *plugin.Plugin { "steampipecloud_connection": tableSteampipeCloudConnection(ctx), "steampipecloud_organization_member": tableSteampipeCloudOrganizationMember(ctx), "steampipecloud_organization": tableSteampipeCloudOrganization(ctx), + "steampipecloud_process": tableSteampipeCloudProcess(ctx), "steampipecloud_organization_workspace_member": tableSteampipeCloudOrganizationWorkspaceMember(ctx), "steampipecloud_token": tableSteampipeCloudToken(ctx), "steampipecloud_user": tableSteampipeCloudUser(ctx), @@ -34,6 +35,7 @@ func Plugin(ctx context.Context) *plugin.Plugin { "steampipecloud_workspace_mod_variable": tableSteampipeCloudWorkspaceModVariable(ctx), "steampipecloud_workspace_db_log": tableSteampipeCloudWorkspaceDBLog(ctx), "steampipecloud_workspace_pipeline": tableSteampipeCloudWorkspacePipeline(ctx), + "steampipecloud_workspace_process": tableSteampipeCloudWorkspaceProcess(ctx), "steampipecloud_workspace_snapshot": tableSteampipeCloudWorkspaceSnapshot(ctx), }, } diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go new file mode 100644 index 0000000..7e94574 --- /dev/null +++ b/steampipecloud/table_steampipecloud_process.go @@ -0,0 +1,409 @@ +package steampipecloud + +import ( + "context" + "fmt" + "strings" + + openapi "github.com/turbot/steampipe-cloud-sdk-go" + + "github.com/turbot/steampipe-plugin-sdk/v4/grpc/proto" + "github.com/turbot/steampipe-plugin-sdk/v4/plugin" + "github.com/turbot/steampipe-plugin-sdk/v4/plugin/transform" +) + +type IdentityDetailsForProcess struct { + IdentityHandle string `json:"identity_handle"` + IdentityType string `json:"identity_type"` +} + +//// TABLE DEFINITION + +func tableSteampipeCloudProcess(_ context.Context) *plugin.Table { + return &plugin.Table{ + Name: "steampipecloud_process", + Description: "Processes allow to track various activities in steampipe cloud.", + List: &plugin.ListConfig{ + Hydrate: listIdentityProcesses, + KeyColumns: []*plugin.KeyColumn{ + { + Name: "identity_handle", + Require: plugin.Optional, + }, + { + Name: "identity_id", + Require: plugin.Optional, + }, + }, + }, + Get: &plugin.GetConfig{ + KeyColumns: plugin.AllColumns([]string{"identity_handle", "id"}), + Hydrate: getIdentityProcess, + }, + Columns: []*plugin.Column{ + { + Name: "id", + Description: "The unique identifier for the process.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "identity_id", + Description: "The unique identifier of the identity to which the process belongs to.", + Type: proto.ColumnType_STRING, + }, + { + Name: "identity_handle", + Description: "The handle of the identity.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityDetailsForProcess, + }, + { + Name: "identity_type", + Description: "The type of identity, can be org/user.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityDetailsForProcess, + }, + { + Name: "pipeline_id", + Description: "The unique identifier for the pipeline if a process is for a pipeline run/execution.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "type", + Description: "The type of action executed by the process.", + Type: proto.ColumnType_STRING, + }, + { + Name: "state", + Description: "The current state of the process.", + Type: proto.ColumnType_STRING, + }, + { + Name: "data_state", + Description: "The current state of the process and its log data.", + Type: proto.ColumnType_STRING, + }, + { + Name: "created_at", + Description: "The time when the process was created.", + Type: proto.ColumnType_TIMESTAMP, + }, + { + Name: "created_by_id", + Description: "The unique identifier of the user who created the process.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "created_by", + Description: "Information about the user who created the process.", + Type: proto.ColumnType_JSON, + }, + { + Name: "updated_at", + Description: "The time when the process was last updated.", + Type: proto.ColumnType_TIMESTAMP, + }, + { + Name: "updated_by_id", + Description: "The unique identifier of the user who last updated the process.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "updated_by", + Description: "Information about the user who last updated the process.", + Type: proto.ColumnType_JSON, + }, + { + Name: "version_id", + Description: "The current version ID for the process.", + Type: proto.ColumnType_INT, + Transform: transform.FromCamel(), + }, + }, + } +} + +//// LIST FUNCTION + +func listIdentityProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + var user openapi.User + // If the requested number of items is less than the paging max limit + // set the limit to that instead + maxResults := int32(100) + limit := d.QueryContext.Limit + if d.QueryContext.Limit != nil { + if *limit < int64(maxResults) { + if *limit < 1 { + maxResults = int32(1) + } else { + maxResults = int32(*limit) + } + } + } + + identityHandle := d.KeyColumnQuals["identity_handle"].GetStringValue() + identityId := d.KeyColumnQuals["identity_id"].GetStringValue() + var identityToPass string + + getUserIdentityCached := plugin.HydrateFunc(getUserIdentity).WithCache() + commonData, err := getUserIdentityCached(ctx, d, h) + if err != nil { + plugin.Logger(ctx).Error("listIdentityProcesses", "getUserIdentityCached", err) + return nil, err + } + + user = commonData.(openapi.User) + + // Error out if both workspace_handle and workspace_id is passed + if identityHandle != "" && identityId != "" { + plugin.Logger(ctx).Error("listIdentityProcesses", "please pass any one of identity_handle or identity_id") + return nil, fmt.Errorf("please pass any one of identity_handle or identity_id") + } + if identityHandle != "" { + identityToPass = identityHandle + } else if identityId != "" { + identityToPass = identityId + } else { + identityToPass = user.Id + } + + if strings.HasPrefix(identityToPass, "u_") || identityToPass == user.Handle { + err = listUserProcesses(ctx, d, h, identityToPass, maxResults) + } else if strings.HasPrefix(identityToPass, "o_") || identityToPass != user.Handle { + err = listOrgProcesses(ctx, d, h, identityToPass, maxResults) + } + + if err != nil { + plugin.Logger(ctx).Error("listIdentityProcesses", "error", err) + return nil, err + } + + return nil, nil +} + +func listUserProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, userHandle string, maxResults int32) error { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("listUserProcesses", "connection_error", err) + return err + } + + pagesLeft := true + var resp openapi.ListProcessesResponse + var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) + + for pagesLeft { + if resp.NextToken != nil { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.UserProcesses.List(ctx, userHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + return resp, err + } + } else { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.UserProcesses.List(ctx, userHandle).Limit(maxResults).Execute() + return resp, err + } + } + + response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + + if err != nil { + plugin.Logger(ctx).Error("listUserProcesses", "list", err) + return err + } + + result := response.(openapi.ListProcessesResponse) + + if result.HasItems() { + for _, process := range *result.Items { + d.StreamListItem(ctx, process) + + // Context can be cancelled due to manual cancellation or the limit has been hit + if d.QueryStatus.RowsRemaining(ctx) == 0 { + return nil + } + } + } + if result.NextToken == nil { + pagesLeft = false + } else { + resp.NextToken = result.NextToken + } + } + + return nil +} + +func listOrgProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, orgHandle string, maxResults int32) error { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("listOrgProcesses", "connection_error", err) + return err + } + + pagesLeft := true + var resp openapi.ListProcessesResponse + var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) + + for pagesLeft { + if resp.NextToken != nil { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.OrgProcesses.List(ctx, orgHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + return resp, err + } + } else { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.OrgProcesses.List(ctx, orgHandle).Limit(maxResults).Execute() + return resp, err + } + } + + response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + + if err != nil { + plugin.Logger(ctx).Error("listOrgProcesses", "list", err) + return err + } + + result := response.(openapi.ListProcessesResponse) + + if result.HasItems() { + for _, process := range *result.Items { + d.StreamListItem(ctx, process) + + // Context can be cancelled due to manual cancellation or the limit has been hit + if d.QueryStatus.RowsRemaining(ctx) == 0 { + return nil + } + } + } + if result.NextToken == nil { + pagesLeft = false + } else { + resp.NextToken = result.NextToken + } + } + + return nil +} + +func getIdentityProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + identityHandle := d.KeyColumnQuals["identity_handle"].GetStringValue() + processId := d.KeyColumnQuals["id"].GetStringValue() + + // check if identityHandle or workspaceHandle or process id is empty + if identityHandle == "" || processId == "" { + return nil, nil + } + + getUserIdentityCached := plugin.HydrateFunc(getUserIdentity).WithCache() + commonData, err := getUserIdentityCached(ctx, d, h) + if err != nil { + plugin.Logger(ctx).Error("getIdentityProcess", "getUserIdentityCached", err) + return nil, err + } + + user := commonData.(openapi.User) + var response interface{} + if identityHandle == user.Handle { + response, err = getUserProcess(ctx, d, h, identityHandle, processId) + } else { + response, err = getOrgProcess(ctx, d, h, identityHandle, processId) + } + + if err != nil { + plugin.Logger(ctx).Error("getIdentityProcess", "error", err) + return nil, err + } + + return response.(openapi.SpProcess), nil +} + +func getUserProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, userHandle, processId string) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getUserProcess", "connection_error", err) + return nil, err + } + + var process openapi.SpProcess + + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + process, _, err = svc.UserProcesses.Get(ctx, userHandle, processId).Execute() + return process, err + } + + response, err := plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + if err != nil { + plugin.Logger(ctx).Error("getUserProcess", "get", err) + return nil, err + } + + return response, nil +} + +func getOrgProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, orgHandle, processId string) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getOrgProcess", "connection_error", err) + return nil, err + } + + var process openapi.SpProcess + + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + process, _, err = svc.OrgProcesses.Get(ctx, orgHandle, processId).Execute() + return process, err + } + + response, err := plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + if err != nil { + plugin.Logger(ctx).Error("getOrgProcess", "get", err) + return nil, err + } + + return response, nil +} + +func getIdentityDetailsForProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getIdentityDetailsForProcess", "connection_error", err) + return nil, err + } + + getUserIdentityCached := plugin.HydrateFunc(getUserIdentity).WithCache() + commonData, err := getUserIdentityCached(ctx, d, h) + if err != nil { + plugin.Logger(ctx).Error("getIdentityDetailsForProcess", "getUserIdentityCached", err) + return nil, err + } + + user := commonData.(openapi.User) + + var identityDetails IdentityDetailsForProcess + process := h.Item.(openapi.SpProcess) + plugin.Logger(ctx).Info("getIdentityDetailsForProcess", "process Item", process) + if *process.IdentityId == user.Id { + identityDetails.IdentityHandle = user.Handle + identityDetails.IdentityType = "user" + } else { + org, _, err := svc.Orgs.Get(ctx, *process.IdentityId).Execute() + if err != nil { + plugin.Logger(ctx).Error("getIdentityDetailsForProcess", "getOrg", err) + return nil, err + } + identityDetails.IdentityHandle = org.Handle + identityDetails.IdentityType = "org" + } + return identityDetails, nil +} diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index a2da068..1316b90 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -2,6 +2,7 @@ package steampipecloud import ( "context" + "fmt" "strings" openapi "github.com/turbot/steampipe-cloud-sdk-go" @@ -200,6 +201,7 @@ func listWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plugin. // Error out if both workspace_handle and workspace_id is passed if workspaceHandle != "" && workspaceId != "" { plugin.Logger(ctx).Error("listWorkspacePipelines", "please pass any one of workspace_id or workspace_handle") + return nil, fmt.Errorf("please pass any one of workspace_id or workspace_handle") } // If either one has been passed, check whether either of the handle or the id matches with the workspace in context if workspaceHandle != "" || workspaceId != "" { @@ -423,7 +425,7 @@ func getIdentityWorkspaceDetailsForPipeline(ctx context.Context, d *plugin.Query // Create Session svc, err := connect(ctx, d) if err != nil { - plugin.Logger(ctx).Error("getIdentityWorkspaceDetails", "connection_error", err) + plugin.Logger(ctx).Error("getIdentityWorkspaceDetailsForPipeline", "connection_error", err) return nil, err } @@ -432,7 +434,7 @@ func getIdentityWorkspaceDetailsForPipeline(ctx context.Context, d *plugin.Query // workspace details reside in the parent item in this case switch w := h.ParentItem.(type) { case openapi.Workspace: - plugin.Logger(ctx).Debug("getIdentityWorkspaceDetails", "openapi.Workspace") + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetailsForPipeline", "openapi.Workspace") identityId := h.ParentItem.(openapi.Workspace).IdentityId identityWorkspaceDetails.WorkspaceHandle = h.ParentItem.(openapi.Workspace).Handle getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { @@ -453,7 +455,7 @@ func getIdentityWorkspaceDetailsForPipeline(ctx context.Context, d *plugin.Query _, _ = plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) return identityWorkspaceDetails, nil case *openapi.Workspace: - plugin.Logger(ctx).Debug("getIdentityWorkspaceDetails", "*openapi.Workspace") + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetailsForPipeline", "*openapi.Workspace") identityId := h.ParentItem.(*openapi.Workspace).IdentityId identityWorkspaceDetails.WorkspaceHandle = h.ParentItem.(*openapi.Workspace).Handle getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { @@ -472,10 +474,10 @@ func getIdentityWorkspaceDetailsForPipeline(ctx context.Context, d *plugin.Query } } _, _ = plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) - plugin.Logger(ctx).Debug("getIdentityWorkspaceDetails", "identityWorkspaceDetails", identityWorkspaceDetails) - return identityWorkspaceDetails, nil + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetailsForPipeline", "identityWorkspaceDetails", identityWorkspaceDetails) + return &identityWorkspaceDetails, nil default: - plugin.Logger(ctx).Debug("getIdentityWorkspaceDetails", "Unknown Type", w) + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetailsForPipeline", "Unknown Type", w) } - return identityWorkspaceDetails, nil + return &identityWorkspaceDetails, nil } diff --git a/steampipecloud/table_steampipecloud_workspace_process.go b/steampipecloud/table_steampipecloud_workspace_process.go new file mode 100644 index 0000000..02b2563 --- /dev/null +++ b/steampipecloud/table_steampipecloud_workspace_process.go @@ -0,0 +1,463 @@ +package steampipecloud + +import ( + "context" + "fmt" + "strings" + + openapi "github.com/turbot/steampipe-cloud-sdk-go" + + "github.com/turbot/steampipe-plugin-sdk/v4/grpc/proto" + "github.com/turbot/steampipe-plugin-sdk/v4/plugin" + "github.com/turbot/steampipe-plugin-sdk/v4/plugin/transform" +) + +type IdentityWorkspaceDetailsForProcess struct { + IdentityHandle string `json:"identity_handle"` + IdentityType string `json:"identity_type"` + WorkspaceHandle string `json:"workspace_handle"` +} + +//// TABLE DEFINITION + +func tableSteampipeCloudWorkspaceProcess(_ context.Context) *plugin.Table { + return &plugin.Table{ + Name: "steampipecloud_workspace_process", + Description: "Processes allow to track various activities in steampipe cloud.", + List: &plugin.ListConfig{ + ParentHydrate: listWorkspaces, + Hydrate: listWorkspaceProcesses, + KeyColumns: []*plugin.KeyColumn{ + { + Name: "identity_handle", + Require: plugin.Optional, + }, + { + Name: "identity_id", + Require: plugin.Optional, + }, + { + Name: "workspace_handle", + Require: plugin.Optional, + }, + { + Name: "workspace_id", + Require: plugin.Optional, + }, + }, + }, + Get: &plugin.GetConfig{ + KeyColumns: plugin.AllColumns([]string{"identity_handle", "workspace_handle", "id"}), + Hydrate: getWorkspaceProcess, + }, + Columns: []*plugin.Column{ + { + Name: "id", + Description: "The unique identifier for the process.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "identity_id", + Description: "The unique identifier of the identity to which the process belongs to.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "identity_handle", + Description: "The handle of the identity.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityWorkspaceDetailsForWorkspaceProcess, + }, + { + Name: "identity_type", + Description: "The type of identity, can be org/user.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityWorkspaceDetailsForWorkspaceProcess, + }, + { + Name: "workspace_id", + Description: "The unique identifier of the workspace to which the process belongs to.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "workspace_handle", + Description: "The handle of the workspace.", + Type: proto.ColumnType_STRING, + Hydrate: getIdentityWorkspaceDetailsForWorkspaceProcess, + }, + { + Name: "pipeline_id", + Description: "The unique identifier for the pipeline if a process is for a pipeline run/execution.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "type", + Description: "The type of action executed by the process.", + Type: proto.ColumnType_STRING, + }, + { + Name: "state", + Description: "The current state of the process.", + Type: proto.ColumnType_STRING, + }, + { + Name: "data_state", + Description: "The current state of the process and its log data.", + Type: proto.ColumnType_STRING, + }, + { + Name: "created_at", + Description: "The time when the process was created.", + Type: proto.ColumnType_TIMESTAMP, + }, + { + Name: "created_by_id", + Description: "The unique identifier of the user who created the process.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "created_by", + Description: "Information about the user who created the process.", + Type: proto.ColumnType_JSON, + }, + { + Name: "updated_at", + Description: "The time when the process was last updated.", + Type: proto.ColumnType_TIMESTAMP, + }, + { + Name: "updated_by_id", + Description: "The unique identifier of the user who last updated the process.", + Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), + }, + { + Name: "updated_by", + Description: "Information about the user who last updated the process.", + Type: proto.ColumnType_JSON, + }, + { + Name: "version_id", + Description: "The current version ID for the process.", + Type: proto.ColumnType_INT, + Transform: transform.FromCamel(), + }, + }, + } +} + +//// LIST FUNCTION + +func listWorkspaceProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + var workspace *openapi.Workspace + switch w := h.Item.(type) { + case openapi.Workspace: + wo := h.Item.(openapi.Workspace) + workspace = &wo + case *openapi.Workspace: + workspace = h.Item.(*openapi.Workspace) + default: + plugin.Logger(ctx).Error("listWorkspaceProcesses", "unknown response type for workspace list parent hydrate call", w) + } + + // If the requested number of items is less than the paging max limit + // set the limit to that instead + maxResults := int32(100) + limit := d.QueryContext.Limit + if d.QueryContext.Limit != nil { + if *limit < int64(maxResults) { + if *limit < 1 { + maxResults = int32(1) + } else { + maxResults = int32(*limit) + } + } + } + + workspaceHandle := d.KeyColumnQuals["workspace_handle"].GetStringValue() + workspaceId := d.KeyColumnQuals["workspace_id"].GetStringValue() + var workspaceToPass string + + // Error out if both workspace_handle and workspace_id is passed + if workspaceHandle != "" && workspaceId != "" { + plugin.Logger(ctx).Error("listWorkspaceProcesses", "please pass any one of workspace_id or workspace_handle") + return nil, fmt.Errorf("please pass any one of workspace_id or workspace_handle") + } + // If either one has been passed, check whether either of the handle or the id matches with the workspace in context + if workspaceHandle != "" || workspaceId != "" { + if workspaceHandle == workspace.Handle { + workspaceToPass = workspaceHandle + } else if workspaceId == workspace.Id { + workspaceToPass = workspaceId + } else { + return nil, nil + } + } else { + // If neither is passed, we pass the context over to the call + workspaceToPass = workspace.Id + } + + var err error + if strings.HasPrefix(workspace.IdentityId, "u_") { + err = listUserWorkspaceProcesses(ctx, d, h, workspace.IdentityId, workspaceToPass, maxResults) + } else { + err = listOrgWorkspaceProcesses(ctx, d, h, workspace.IdentityId, workspaceToPass, maxResults) + } + + if err != nil { + plugin.Logger(ctx).Error("listWorkspaceProcesses", "error", err) + return nil, err + } + + return nil, nil +} + +func listUserWorkspaceProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, userHandle, workspaceHandle string, maxResults int32) error { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("listUserWorkspaceProcesses", "connection_error", err) + return err + } + + pagesLeft := true + var resp openapi.ListProcessesResponse + var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) + + for pagesLeft { + if resp.NextToken != nil { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.UserWorkspaceProcesses.List(ctx, userHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + return resp, err + } + } else { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.UserWorkspaceProcesses.List(ctx, userHandle, workspaceHandle).Limit(maxResults).Execute() + return resp, err + } + } + + response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + + if err != nil { + plugin.Logger(ctx).Error("listUserWorkspaceProcesses", "list", err) + return err + } + + result := response.(openapi.ListProcessesResponse) + + if result.HasItems() { + for _, process := range *result.Items { + d.StreamListItem(ctx, process) + + // Context can be cancelled due to manual cancellation or the limit has been hit + if d.QueryStatus.RowsRemaining(ctx) == 0 { + return nil + } + } + } + if result.NextToken == nil { + pagesLeft = false + } else { + resp.NextToken = result.NextToken + } + } + + return nil +} + +func listOrgWorkspaceProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, orgHandle, workspaceHandle string, maxResults int32) error { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("listOrgWorkspaceProcesses", "connection_error", err) + return err + } + + pagesLeft := true + var resp openapi.ListProcessesResponse + var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) + + for pagesLeft { + if resp.NextToken != nil { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.OrgWorkspaceProcesses.List(ctx, orgHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + return resp, err + } + } else { + listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + resp, _, err = svc.OrgWorkspaceProcesses.List(ctx, orgHandle, workspaceHandle).Limit(maxResults).Execute() + return resp, err + } + } + + response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + + if err != nil { + plugin.Logger(ctx).Error("listOrgWorkspaceProcesses", "list", err) + return err + } + + result := response.(openapi.ListProcessesResponse) + + if result.HasItems() { + for _, process := range *result.Items { + d.StreamListItem(ctx, process) + + // Context can be cancelled due to manual cancellation or the limit has been hit + if d.QueryStatus.RowsRemaining(ctx) == 0 { + return nil + } + } + } + if result.NextToken == nil { + pagesLeft = false + } else { + resp.NextToken = result.NextToken + } + } + + return nil +} + +func getWorkspaceProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + identityHandle := d.KeyColumnQuals["identity_handle"].GetStringValue() + workspaceHandle := d.KeyColumnQuals["workspace_handle"].GetStringValue() + processId := d.KeyColumnQuals["id"].GetStringValue() + + // check if identityHandle or workspaceHandle or pipeline id is empty + if identityHandle == "" || workspaceHandle == "" || processId == "" { + return nil, nil + } + + getUserIdentityCached := plugin.HydrateFunc(getUserIdentity).WithCache() + commonData, err := getUserIdentityCached(ctx, d, h) + if err != nil { + plugin.Logger(ctx).Error("getWorkspaceProcess", "getUserIdentityCached", err) + return nil, err + } + + user := commonData.(openapi.User) + var response interface{} + if identityHandle == user.Handle { + response, err = getUserWorkspaceProcess(ctx, d, h, identityHandle, workspaceHandle, processId) + } else { + response, err = getOrgWorkspaceProcess(ctx, d, h, identityHandle, workspaceHandle, processId) + } + + if err != nil { + plugin.Logger(ctx).Error("getWorkspaceProcess", "error", err) + return nil, err + } + + return response.(openapi.SpProcess), nil +} + +func getUserWorkspaceProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, userHandle, workspaceHandle, processId string) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getUserWorkspaceProcess", "connection_error", err) + return nil, err + } + + var process openapi.SpProcess + + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + process, _, err = svc.UserWorkspaceProcesses.Get(ctx, userHandle, workspaceHandle, processId).Execute() + return process, err + } + + response, err := plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + if err != nil { + plugin.Logger(ctx).Error("getUserWorkspaceProcess", "get", err) + return nil, err + } + + return response, nil +} + +func getOrgWorkspaceProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, orgHandle, workspaceHandle, processId string) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getOrgWorkspaceProcess", "connection_error", err) + return nil, err + } + + var process openapi.SpProcess + + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + process, _, err = svc.OrgWorkspaceProcesses.Get(ctx, orgHandle, workspaceHandle, processId).Execute() + return process, err + } + + response, err := plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + if err != nil { + plugin.Logger(ctx).Error("getOrgWorkspaceProcess", "get", err) + return nil, err + } + + return response, nil +} + +func getIdentityWorkspaceDetailsForWorkspaceProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + // Create Session + svc, err := connect(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("getIdentityWorkspaceDetailsForWorkspaceProcess", "connection_error", err) + return nil, err + } + + var identityWorkspaceDetails IdentityWorkspaceDetailsForProcess + // get workspace details from hydrate data + // workspace details reside in the parent item in this case + switch w := h.ParentItem.(type) { + case openapi.Workspace: + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetailsForWorkspaceProcess", "openapi.Workspace") + identityId := h.ParentItem.(openapi.Workspace).IdentityId + identityWorkspaceDetails.WorkspaceHandle = h.ParentItem.(openapi.Workspace).Handle + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + if strings.HasPrefix(identityId, "u_") { + resp, _, err := svc.Users.Get(ctx, identityId).Execute() + identityWorkspaceDetails.IdentityType = "user" + identityWorkspaceDetails.IdentityHandle = resp.Handle + return nil, err + } else { + resp, _, err := svc.Orgs.Get(ctx, identityId).Execute() + identityWorkspaceDetails.IdentityType = "org" + identityWorkspaceDetails.IdentityHandle = resp.Handle + return nil, err + } + } + _, _ = plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + return identityWorkspaceDetails, nil + case *openapi.Workspace: + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetailsForWorkspaceProcess", "*openapi.Workspace") + identityId := h.ParentItem.(*openapi.Workspace).IdentityId + identityWorkspaceDetails.WorkspaceHandle = h.ParentItem.(*openapi.Workspace).Handle + getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + if strings.HasPrefix(identityId, "u_") { + resp, _, err := svc.Users.Get(ctx, identityId).Execute() + identityWorkspaceDetails.IdentityType = "user" + identityWorkspaceDetails.IdentityHandle = resp.Handle + return nil, err + } else { + resp, _, err := svc.Orgs.Get(ctx, identityId).Execute() + identityWorkspaceDetails.IdentityType = "org" + identityWorkspaceDetails.IdentityHandle = resp.Handle + return nil, err + } + } + _, _ = plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetailsForWorkspaceProcess", "identityWorkspaceDetails", identityWorkspaceDetails) + return &identityWorkspaceDetails, nil + default: + plugin.Logger(ctx).Debug("getIdentityWorkspaceDetailsForWorkspaceProcess", "Unknown Type", w) + } + return &identityWorkspaceDetails, nil +} From 3dfde6b7f66a4f04754699ce9d449860722d3ae7 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 11:43:43 +0530 Subject: [PATCH 05/36] Remove `data_state` column from identity and workspace process. --- steampipecloud/table_steampipecloud_process.go | 5 ----- steampipecloud/table_steampipecloud_workspace_process.go | 5 ----- 2 files changed, 10 deletions(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 7e94574..1ea375f 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -80,11 +80,6 @@ func tableSteampipeCloudProcess(_ context.Context) *plugin.Table { Description: "The current state of the process.", Type: proto.ColumnType_STRING, }, - { - Name: "data_state", - Description: "The current state of the process and its log data.", - Type: proto.ColumnType_STRING, - }, { Name: "created_at", Description: "The time when the process was created.", diff --git a/steampipecloud/table_steampipecloud_workspace_process.go b/steampipecloud/table_steampipecloud_workspace_process.go index 02b2563..f191d0c 100644 --- a/steampipecloud/table_steampipecloud_workspace_process.go +++ b/steampipecloud/table_steampipecloud_workspace_process.go @@ -103,11 +103,6 @@ func tableSteampipeCloudWorkspaceProcess(_ context.Context) *plugin.Table { Description: "The current state of the process.", Type: proto.ColumnType_STRING, }, - { - Name: "data_state", - Description: "The current state of the process and its log data.", - Type: proto.ColumnType_STRING, - }, { Name: "created_at", Description: "The time when the process was created.", From 7be8ac3d03ea29149a039c73fe750621b9056391 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 11:49:38 +0530 Subject: [PATCH 06/36] Update process table descriptions. --- steampipecloud/table_steampipecloud_process.go | 2 +- steampipecloud/table_steampipecloud_workspace_process.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 1ea375f..eb0f727 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -22,7 +22,7 @@ type IdentityDetailsForProcess struct { func tableSteampipeCloudProcess(_ context.Context) *plugin.Table { return &plugin.Table{ Name: "steampipecloud_process", - Description: "Processes allow to track various activities in steampipe cloud.", + Description: "Allows to track various processes for an identity in Steampipe Cloud.", List: &plugin.ListConfig{ Hydrate: listIdentityProcesses, KeyColumns: []*plugin.KeyColumn{ diff --git a/steampipecloud/table_steampipecloud_workspace_process.go b/steampipecloud/table_steampipecloud_workspace_process.go index f191d0c..631e888 100644 --- a/steampipecloud/table_steampipecloud_workspace_process.go +++ b/steampipecloud/table_steampipecloud_workspace_process.go @@ -23,7 +23,7 @@ type IdentityWorkspaceDetailsForProcess struct { func tableSteampipeCloudWorkspaceProcess(_ context.Context) *plugin.Table { return &plugin.Table{ Name: "steampipecloud_workspace_process", - Description: "Processes allow to track various activities in steampipe cloud.", + Description: "Allows to track various processes for a workspace of an identity in Steampipe Cloud.", List: &plugin.ListConfig{ ParentHydrate: listWorkspaces, Hydrate: listWorkspaceProcesses, From f3cb6d7ea67e2cde38203509fc09eefe6a5d2fa9 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 11:57:29 +0530 Subject: [PATCH 07/36] Add a fromcamel transform for identity_id in process for it to be populated. --- steampipecloud/table_steampipecloud_process.go | 1 + 1 file changed, 1 insertion(+) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index eb0f727..9ce8fe1 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -51,6 +51,7 @@ func tableSteampipeCloudProcess(_ context.Context) *plugin.Table { Name: "identity_id", Description: "The unique identifier of the identity to which the process belongs to.", Type: proto.ColumnType_STRING, + Transform: transform.FromCamel(), }, { Name: "identity_handle", From 3f4671ec26537cc68b1963f6bc174e179b49e798 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 12:57:11 +0530 Subject: [PATCH 08/36] Add ability to filter org workspace snapshot records by query quals. --- ...table_steampipecloud_workspace_snapshot.go | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/steampipecloud/table_steampipecloud_workspace_snapshot.go b/steampipecloud/table_steampipecloud_workspace_snapshot.go index 5dc5ee5..da64ed2 100644 --- a/steampipecloud/table_steampipecloud_workspace_snapshot.go +++ b/steampipecloud/table_steampipecloud_workspace_snapshot.go @@ -354,6 +354,53 @@ func listOrgWorkspaceSnapshots(ctx context.Context, d *plugin.QueryData, h *plug return err } + var filter string + // collect all clauses passed as quals except for "query_where" + var clauses []string + for _, keyQual := range d.Table.List.KeyColumns { + filterQual := d.Quals[keyQual.Name] + if filterQual == nil || keyQual.Name == "query_where" { + continue + } + for _, qual := range filterQual.Quals { + if qual.Value != nil { + var value string + if keyQual.Name == "created_at" { + t := time.Unix(qual.Value.GetTimestampValue().Seconds, int64(qual.Value.GetTimestampValue().Nanos)).UTC() + value = t.Format("2006-01-02 15:04:05.00000") + } else { + value = qual.Value.GetStringValue() + } + switch qual.Operator { + case "=": + clauses = append(clauses, fmt.Sprintf(`%s = '%s'`, keyQual.Name, value)) + case "<>": + clauses = append(clauses, fmt.Sprintf(`%s <> '%s'`, keyQual.Name, value)) + case ">": + clauses = append(clauses, fmt.Sprintf(`%s > '%s'`, keyQual.Name, value)) + case ">=": + clauses = append(clauses, fmt.Sprintf(`%s >= '%s'`, keyQual.Name, value)) + case "<": + clauses = append(clauses, fmt.Sprintf(`%s < '%s'`, keyQual.Name, value)) + case "<=": + clauses = append(clauses, fmt.Sprintf(`%s <= '%s'`, keyQual.Name, value)) + } + } + } + } + + // Frame the filter string by joining the collected quals by "and" + filter = strings.Join(clauses, " and ") + + // Check if a query_where qual has been passed and add it to the filter string if yes + if d.KeyColumnQuals["query_where"] != nil { + if len(filter) >= 1 { + filter = filter + " and " + d.KeyColumnQuals["query_where"].GetStringValue() + } else { + filter = d.KeyColumnQuals["query_where"].GetStringValue() + } + } + pagesLeft := true var resp openapi.ListWorkspaceSnapshotsResponse var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) @@ -361,12 +408,12 @@ func listOrgWorkspaceSnapshots(ctx context.Context, d *plugin.QueryData, h *plug for pagesLeft { if resp.NextToken != nil { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.OrgWorkspaceSnapshots.List(ctx, orgHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + resp, _, err = svc.OrgWorkspaceSnapshots.List(ctx, orgHandle, workspaceHandle).Where(filter).NextToken(*resp.NextToken).Limit(maxResults).Execute() return resp, err } } else { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.OrgWorkspaceSnapshots.List(ctx, orgHandle, workspaceHandle).Limit(maxResults).Execute() + resp, _, err = svc.OrgWorkspaceSnapshots.List(ctx, orgHandle, workspaceHandle).Where(filter).Limit(maxResults).Execute() return resp, err } } From 50dd256e8cbf44a79046c9cadbeab4f9f7be2bc7 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 13:54:06 +0530 Subject: [PATCH 09/36] Add filter quals and query_where for pipelines and processes. --- ...table_steampipecloud_workspace_pipeline.go | 139 ++++++++++++++++- .../table_steampipecloud_workspace_process.go | 144 +++++++++++++++++- 2 files changed, 275 insertions(+), 8 deletions(-) diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index 1316b90..c70dd5e 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "strings" + "time" openapi "github.com/turbot/steampipe-cloud-sdk-go" @@ -29,6 +30,16 @@ func tableSteampipeCloudWorkspacePipeline(_ context.Context) *plugin.Table { ParentHydrate: listWorkspaces, Hydrate: listWorkspacePipelines, KeyColumns: []*plugin.KeyColumn{ + { + Name: "created_at", + Require: plugin.Optional, + Operators: []string{">", ">=", "=", "<", "<="}, + }, + { + Name: "id", + Require: plugin.Optional, + Operators: []string{"=", "<>"}, + }, { Name: "identity_handle", Require: plugin.Optional, @@ -37,6 +48,26 @@ func tableSteampipeCloudWorkspacePipeline(_ context.Context) *plugin.Table { Name: "identity_id", Require: plugin.Optional, }, + { + Name: "pipeline", + Require: plugin.Optional, + Operators: []string{"=", "<>"}, + }, + { + Name: "query_where", + Require: plugin.Optional, + CacheMatch: "exact", + }, + { + Name: "title", + Require: plugin.Optional, + Operators: []string{"=", "<>"}, + }, + { + Name: "updated_at", + Require: plugin.Optional, + Operators: []string{">", ">=", "=", "<", "<="}, + }, { Name: "workspace_handle", Require: plugin.Optional, @@ -124,6 +155,12 @@ func tableSteampipeCloudWorkspacePipeline(_ context.Context) *plugin.Table { Description: "Information about the process that was last executed for the pipeline.", Type: proto.ColumnType_JSON, }, + { + Name: "query_where", + Description: "The query where expression to filter pipelines.", + Type: proto.ColumnType_STRING, + Transform: transform.FromQual("query_where"), + }, { Name: "created_at", Description: "The time when the pipeline was created.", @@ -240,6 +277,53 @@ func listUserWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plu return err } + var filter string + // collect all clauses passed as quals except for "query_where", "identity_id", "identity_handle", "workspace_id", "workspace_handle" + var clauses []string + for _, keyQual := range d.Table.List.KeyColumns { + filterQual := d.Quals[keyQual.Name] + if filterQual == nil || keyQual.Name == "query_where" || keyQual.Name == "identity_id" || keyQual.Name == "identity_handle" || keyQual.Name == "workspace_id" || keyQual.Name == "workspace_handle" { + continue + } + for _, qual := range filterQual.Quals { + if qual.Value != nil { + var value string + if keyQual.Name == "created_at" || keyQual.Name == "updated_at" { + t := time.Unix(qual.Value.GetTimestampValue().Seconds, int64(qual.Value.GetTimestampValue().Nanos)).UTC() + value = t.Format("2006-01-02 15:04:05.00000") + } else { + value = qual.Value.GetStringValue() + } + switch qual.Operator { + case "=": + clauses = append(clauses, fmt.Sprintf(`%s = '%s'`, keyQual.Name, value)) + case "<>": + clauses = append(clauses, fmt.Sprintf(`%s <> '%s'`, keyQual.Name, value)) + case ">": + clauses = append(clauses, fmt.Sprintf(`%s > '%s'`, keyQual.Name, value)) + case ">=": + clauses = append(clauses, fmt.Sprintf(`%s >= '%s'`, keyQual.Name, value)) + case "<": + clauses = append(clauses, fmt.Sprintf(`%s < '%s'`, keyQual.Name, value)) + case "<=": + clauses = append(clauses, fmt.Sprintf(`%s <= '%s'`, keyQual.Name, value)) + } + } + } + } + + // Frame the filter string by joining the collected quals by "and" + filter = strings.Join(clauses, " and ") + + // Check if a query_where qual has been passed and add it to the filter string if yes + if d.KeyColumnQuals["query_where"] != nil { + if len(filter) >= 1 { + filter = filter + " and " + d.KeyColumnQuals["query_where"].GetStringValue() + } else { + filter = d.KeyColumnQuals["query_where"].GetStringValue() + } + } + pagesLeft := true var resp openapi.ListPipelinesResponse var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) @@ -247,12 +331,12 @@ func listUserWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plu for pagesLeft { if resp.NextToken != nil { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.UserWorkspacePipelines.List(ctx, userHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + resp, _, err = svc.UserWorkspacePipelines.List(ctx, userHandle, workspaceHandle).Where(filter).NextToken(*resp.NextToken).Limit(maxResults).Execute() return resp, err } } else { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.UserWorkspacePipelines.List(ctx, userHandle, workspaceHandle).Limit(maxResults).Execute() + resp, _, err = svc.UserWorkspacePipelines.List(ctx, userHandle, workspaceHandle).Where(filter).Limit(maxResults).Execute() return resp, err } } @@ -294,6 +378,53 @@ func listOrgWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plug return err } + var filter string + // collect all clauses passed as quals except for "query_where", "identity_id", "identity_handle", "workspace_id", "workspace_handle" + var clauses []string + for _, keyQual := range d.Table.List.KeyColumns { + filterQual := d.Quals[keyQual.Name] + if filterQual == nil || keyQual.Name == "query_where" || keyQual.Name == "identity_id" || keyQual.Name == "identity_handle" || keyQual.Name == "workspace_id" || keyQual.Name == "workspace_handle" { + continue + } + for _, qual := range filterQual.Quals { + if qual.Value != nil { + var value string + if keyQual.Name == "created_at" || keyQual.Name == "updated_at" { + t := time.Unix(qual.Value.GetTimestampValue().Seconds, int64(qual.Value.GetTimestampValue().Nanos)).UTC() + value = t.Format("2006-01-02 15:04:05.00000") + } else { + value = qual.Value.GetStringValue() + } + switch qual.Operator { + case "=": + clauses = append(clauses, fmt.Sprintf(`%s = '%s'`, keyQual.Name, value)) + case "<>": + clauses = append(clauses, fmt.Sprintf(`%s <> '%s'`, keyQual.Name, value)) + case ">": + clauses = append(clauses, fmt.Sprintf(`%s > '%s'`, keyQual.Name, value)) + case ">=": + clauses = append(clauses, fmt.Sprintf(`%s >= '%s'`, keyQual.Name, value)) + case "<": + clauses = append(clauses, fmt.Sprintf(`%s < '%s'`, keyQual.Name, value)) + case "<=": + clauses = append(clauses, fmt.Sprintf(`%s <= '%s'`, keyQual.Name, value)) + } + } + } + } + + // Frame the filter string by joining the collected quals by "and" + filter = strings.Join(clauses, " and ") + + // Check if a query_where qual has been passed and add it to the filter string if yes + if d.KeyColumnQuals["query_where"] != nil { + if len(filter) >= 1 { + filter = filter + " and " + d.KeyColumnQuals["query_where"].GetStringValue() + } else { + filter = d.KeyColumnQuals["query_where"].GetStringValue() + } + } + pagesLeft := true var resp openapi.ListPipelinesResponse var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) @@ -301,12 +432,12 @@ func listOrgWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plug for pagesLeft { if resp.NextToken != nil { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.OrgWorkspacePipelines.List(ctx, orgHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + resp, _, err = svc.OrgWorkspacePipelines.List(ctx, orgHandle, workspaceHandle).Where(filter).NextToken(*resp.NextToken).Limit(maxResults).Execute() return resp, err } } else { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.OrgWorkspacePipelines.List(ctx, orgHandle, workspaceHandle).Limit(maxResults).Execute() + resp, _, err = svc.OrgWorkspacePipelines.List(ctx, orgHandle, workspaceHandle).Where(filter).Limit(maxResults).Execute() return resp, err } } diff --git a/steampipecloud/table_steampipecloud_workspace_process.go b/steampipecloud/table_steampipecloud_workspace_process.go index 631e888..5ffe5c7 100644 --- a/steampipecloud/table_steampipecloud_workspace_process.go +++ b/steampipecloud/table_steampipecloud_workspace_process.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "strings" + "time" openapi "github.com/turbot/steampipe-cloud-sdk-go" @@ -28,6 +29,16 @@ func tableSteampipeCloudWorkspaceProcess(_ context.Context) *plugin.Table { ParentHydrate: listWorkspaces, Hydrate: listWorkspaceProcesses, KeyColumns: []*plugin.KeyColumn{ + { + Name: "created_at", + Require: plugin.Optional, + Operators: []string{">", ">=", "=", "<", "<="}, + }, + { + Name: "id", + Require: plugin.Optional, + Operators: []string{"=", "<>"}, + }, { Name: "identity_handle", Require: plugin.Optional, @@ -36,6 +47,31 @@ func tableSteampipeCloudWorkspaceProcess(_ context.Context) *plugin.Table { Name: "identity_id", Require: plugin.Optional, }, + { + Name: "pipeline_id", + Require: plugin.Optional, + Operators: []string{"=", "<>"}, + }, + { + Name: "query_where", + Require: plugin.Optional, + CacheMatch: "exact", + }, + { + Name: "state", + Require: plugin.Optional, + Operators: []string{"=", "<>"}, + }, + { + Name: "type", + Require: plugin.Optional, + Operators: []string{"=", "<>"}, + }, + { + Name: "updated_at", + Require: plugin.Optional, + Operators: []string{">", ">=", "=", "<", "<="}, + }, { Name: "workspace_handle", Require: plugin.Optional, @@ -103,6 +139,12 @@ func tableSteampipeCloudWorkspaceProcess(_ context.Context) *plugin.Table { Description: "The current state of the process.", Type: proto.ColumnType_STRING, }, + { + Name: "query_where", + Description: "The query where expression to filter workspace processes.", + Type: proto.ColumnType_STRING, + Transform: transform.FromQual("query_where"), + }, { Name: "created_at", Description: "The time when the process was created.", @@ -219,6 +261,53 @@ func listUserWorkspaceProcesses(ctx context.Context, d *plugin.QueryData, h *plu return err } + var filter string + // collect all clauses passed as quals except for "query_where", "identity_id", "identity_handle", "workspace_id", "workspace_handle" + var clauses []string + for _, keyQual := range d.Table.List.KeyColumns { + filterQual := d.Quals[keyQual.Name] + if filterQual == nil || keyQual.Name == "query_where" || keyQual.Name == "identity_id" || keyQual.Name == "identity_handle" || keyQual.Name == "workspace_id" || keyQual.Name == "workspace_handle" { + continue + } + for _, qual := range filterQual.Quals { + if qual.Value != nil { + var value string + if keyQual.Name == "created_at" || keyQual.Name == "updated_at" { + t := time.Unix(qual.Value.GetTimestampValue().Seconds, int64(qual.Value.GetTimestampValue().Nanos)).UTC() + value = t.Format("2006-01-02 15:04:05.00000") + } else { + value = qual.Value.GetStringValue() + } + switch qual.Operator { + case "=": + clauses = append(clauses, fmt.Sprintf(`%s = '%s'`, keyQual.Name, value)) + case "<>": + clauses = append(clauses, fmt.Sprintf(`%s <> '%s'`, keyQual.Name, value)) + case ">": + clauses = append(clauses, fmt.Sprintf(`%s > '%s'`, keyQual.Name, value)) + case ">=": + clauses = append(clauses, fmt.Sprintf(`%s >= '%s'`, keyQual.Name, value)) + case "<": + clauses = append(clauses, fmt.Sprintf(`%s < '%s'`, keyQual.Name, value)) + case "<=": + clauses = append(clauses, fmt.Sprintf(`%s <= '%s'`, keyQual.Name, value)) + } + } + } + } + + // Frame the filter string by joining the collected quals by "and" + filter = strings.Join(clauses, " and ") + + // Check if a query_where qual has been passed and add it to the filter string if yes + if d.KeyColumnQuals["query_where"] != nil { + if len(filter) >= 1 { + filter = filter + " and " + d.KeyColumnQuals["query_where"].GetStringValue() + } else { + filter = d.KeyColumnQuals["query_where"].GetStringValue() + } + } + pagesLeft := true var resp openapi.ListProcessesResponse var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) @@ -226,12 +315,12 @@ func listUserWorkspaceProcesses(ctx context.Context, d *plugin.QueryData, h *plu for pagesLeft { if resp.NextToken != nil { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.UserWorkspaceProcesses.List(ctx, userHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + resp, _, err = svc.UserWorkspaceProcesses.List(ctx, userHandle, workspaceHandle).Where(filter).NextToken(*resp.NextToken).Limit(maxResults).Execute() return resp, err } } else { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.UserWorkspaceProcesses.List(ctx, userHandle, workspaceHandle).Limit(maxResults).Execute() + resp, _, err = svc.UserWorkspaceProcesses.List(ctx, userHandle, workspaceHandle).Where(filter).Limit(maxResults).Execute() return resp, err } } @@ -273,6 +362,53 @@ func listOrgWorkspaceProcesses(ctx context.Context, d *plugin.QueryData, h *plug return err } + var filter string + // collect all clauses passed as quals except for "query_where", "identity_id", "identity_handle", "workspace_id", "workspace_handle" + var clauses []string + for _, keyQual := range d.Table.List.KeyColumns { + filterQual := d.Quals[keyQual.Name] + if filterQual == nil || keyQual.Name == "query_where" || keyQual.Name == "identity_id" || keyQual.Name == "identity_handle" || keyQual.Name == "workspace_id" || keyQual.Name == "workspace_handle" { + continue + } + for _, qual := range filterQual.Quals { + if qual.Value != nil { + var value string + if keyQual.Name == "created_at" || keyQual.Name == "updated_at" { + t := time.Unix(qual.Value.GetTimestampValue().Seconds, int64(qual.Value.GetTimestampValue().Nanos)).UTC() + value = t.Format("2006-01-02 15:04:05.00000") + } else { + value = qual.Value.GetStringValue() + } + switch qual.Operator { + case "=": + clauses = append(clauses, fmt.Sprintf(`%s = '%s'`, keyQual.Name, value)) + case "<>": + clauses = append(clauses, fmt.Sprintf(`%s <> '%s'`, keyQual.Name, value)) + case ">": + clauses = append(clauses, fmt.Sprintf(`%s > '%s'`, keyQual.Name, value)) + case ">=": + clauses = append(clauses, fmt.Sprintf(`%s >= '%s'`, keyQual.Name, value)) + case "<": + clauses = append(clauses, fmt.Sprintf(`%s < '%s'`, keyQual.Name, value)) + case "<=": + clauses = append(clauses, fmt.Sprintf(`%s <= '%s'`, keyQual.Name, value)) + } + } + } + } + + // Frame the filter string by joining the collected quals by "and" + filter = strings.Join(clauses, " and ") + + // Check if a query_where qual has been passed and add it to the filter string if yes + if d.KeyColumnQuals["query_where"] != nil { + if len(filter) >= 1 { + filter = filter + " and " + d.KeyColumnQuals["query_where"].GetStringValue() + } else { + filter = d.KeyColumnQuals["query_where"].GetStringValue() + } + } + pagesLeft := true var resp openapi.ListProcessesResponse var listDetails func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) @@ -280,12 +416,12 @@ func listOrgWorkspaceProcesses(ctx context.Context, d *plugin.QueryData, h *plug for pagesLeft { if resp.NextToken != nil { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.OrgWorkspaceProcesses.List(ctx, orgHandle, workspaceHandle).NextToken(*resp.NextToken).Limit(maxResults).Execute() + resp, _, err = svc.OrgWorkspaceProcesses.List(ctx, orgHandle, workspaceHandle).Where(filter).NextToken(*resp.NextToken).Limit(maxResults).Execute() return resp, err } } else { listDetails = func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - resp, _, err = svc.OrgWorkspaceProcesses.List(ctx, orgHandle, workspaceHandle).Limit(maxResults).Execute() + resp, _, err = svc.OrgWorkspaceProcesses.List(ctx, orgHandle, workspaceHandle).Where(filter).Limit(maxResults).Execute() return resp, err } } From 54acc3118e86da68a6b558766e88a5d271841443 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 14:25:28 +0530 Subject: [PATCH 10/36] Various doc updates. --- .../steampipecloud_workspace_pipeline.md | 117 ++++++++++++++++++ .../steampipecloud_workspace_snapshot.md | 2 - ...table_steampipecloud_workspace_pipeline.go | 2 +- 3 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 docs/tables/steampipecloud_workspace_pipeline.md diff --git a/docs/tables/steampipecloud_workspace_pipeline.md b/docs/tables/steampipecloud_workspace_pipeline.md new file mode 100644 index 0000000..c72068e --- /dev/null +++ b/docs/tables/steampipecloud_workspace_pipeline.md @@ -0,0 +1,117 @@ +# Table: steampipecloud_workspace_pipeline + +Pipelines allow users to run different kinds of activities in Steampipe Cloud on a schedule. + +**Important notes:** + +This table supports optional quals. Queries with optional quals in the `where` clause are optimised to use Steampipe Cloud filters. + +Optional quals are supported for the following columns: + +- `created_at` +- `id` +- `identity_handle` +- `identity_id` +- `pipeline` +- `query_where` - Allows use of [query filters](https://steampipe.io/docs/cloud/reference/query-filter). Please note that any query filter passed into the `query_where` qual will be combined with other optional quals. +- `title` +- `updated_at` +- `workspace_handle` +- `workspace_id` + +## Examples + +### Basic info + +```sql +select + id, + identity_handle, + workspace_handle, + title, + frequency, + pipeline, + args, + tags, + last_process_id +from + steampipecloud_workspace_pipeline; +``` + +### List pipelines for a specific workspace + +```sql +select + id, + identity_handle, + workspace_handle, + title, + frequency, + pipeline, + args, + tags, + last_process_id +from + steampipecloud_workspace_pipeline +where + workspace_handle = 'dev'; +``` + +### List pipelines of frequency type `interval` for a specific workspace + +```sql +select + id, + identity_handle, + workspace_handle, + title, + frequency, + pipeline, + args, + tags, + last_process_id +from + steampipecloud_workspace_pipeline +where + workspace_handle = 'dev' + and frequency->>'type' = 'interval'; +``` + +### List pipelines for the `AWS Compliance CIS v1.4.0` dashboard created in the last 7 days + +```sql +select + id, + identity_handle, + workspace_handle, + title, + frequency, + pipeline, + args, + tags, + last_process_id +from + steampipecloud_workspace_pipeline +where + args->>'resource' = 'aws_compliance.benchmark.cis_v140' + and created_at >= now() - interval '7 days'; +``` + +### List pipelines for the `AWS Compliance CIS v1.4.0` dashboard created in the last 7 days using [query filter](https://steampipe.io/docs/cloud/reference/query-filter) + +```sql +select + id, + identity_handle, + workspace_handle, + title, + frequency, + pipeline, + args, + tags, + last_process_id +from + steampipecloud_workspace_pipeline +where + query_where = 'title = ''Scheduled snapshot: CIS v1.4.0'' and created_at >= now() - interval ''7 days'''; +``` diff --git a/docs/tables/steampipecloud_workspace_snapshot.md b/docs/tables/steampipecloud_workspace_snapshot.md index 0068c82..affb855 100644 --- a/docs/tables/steampipecloud_workspace_snapshot.md +++ b/docs/tables/steampipecloud_workspace_snapshot.md @@ -12,9 +12,7 @@ Optional quals are supported for the following columns: - `dashboard_name` - `dashboard_title` - `id` -- `inputs` - `query_where` - Allows use of [query filters](https://steampipe.io/docs/cloud/reference/query-filter). For a list of supported columns for snapshots, please see [Supported APIs and Columns](https://steampipe.io/docs/cloud/reference/query-filter#supported-apis--columns). Please note that any query filter passed into the `query_where` qual will be combined with other optional quals. -- `tags` - `visibility` ## Examples diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index c70dd5e..f29c5a7 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -25,7 +25,7 @@ type IdentityWorkspaceDetailsForPipeline struct { func tableSteampipeCloudWorkspacePipeline(_ context.Context) *plugin.Table { return &plugin.Table{ Name: "steampipecloud_workspace_pipeline", - Description: "Pipelines allow users to run different kinds of activities in steampipe cloud on a schedule.", + Description: "Pipelines allow users to run different kinds of activities in Steampipe Cloud on a schedule.", List: &plugin.ListConfig{ ParentHydrate: listWorkspaces, Hydrate: listWorkspacePipelines, From df60a0a66582c3bc7bc7e52daacad75250187dbc Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 14:40:53 +0530 Subject: [PATCH 11/36] Add documentation for process tables. --- docs/tables/steampipecloud_process.md | 71 +++++++++++++++ .../steampipecloud_workspace_process.md | 90 +++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 docs/tables/steampipecloud_process.md create mode 100644 docs/tables/steampipecloud_workspace_process.md diff --git a/docs/tables/steampipecloud_process.md b/docs/tables/steampipecloud_process.md new file mode 100644 index 0000000..0915523 --- /dev/null +++ b/docs/tables/steampipecloud_process.md @@ -0,0 +1,71 @@ +# Table: steampipecloud_process + +Allows to track various activities performed on an identity in Steampipe Cloud. + +## Examples + +### Basic info + +```sql +select + id, + identity_handle, + identity_type, + pipeline_id, + type, + state, + created_at +from + steampipecloud_process; +``` + +### List processes that are being run by an identity pipeline + +```sql +select + id, + identity_handle, + identity_type, + pipeline_id, + type, + state, + created_at +from + steampipecloud_process +where + pipeline_id is not null; +``` + +### List user processes + +```sql +select + id, + identity_handle, + identity_type, + pipeline_id, + type, + state, + created_at +from + steampipecloud_process +where + identity_type = 'user'; +``` + +### List running processes + +```sql +select + id, + identity_handle, + identity_type, + pipeline_id, + type, + state, + created_at +from + steampipecloud_process +where + state = 'running'; +``` diff --git a/docs/tables/steampipecloud_workspace_process.md b/docs/tables/steampipecloud_workspace_process.md new file mode 100644 index 0000000..8347487 --- /dev/null +++ b/docs/tables/steampipecloud_workspace_process.md @@ -0,0 +1,90 @@ +# Table: steampipecloud_workspace_process + +Allows to track various activities performed on a workspace of an identity in Steampipe Cloud. + +**Important notes:** + +This table supports optional quals. Queries with optional quals in the `where` clause are optimised to use Steampipe Cloud filters. + +Optional quals are supported for the following columns: + +- `created_at` +- `id` +- `identity_handle` +- `identity_id` +- `pipeline_id` +- `query_where` - Allows use of [query filters](https://steampipe.io/docs/cloud/reference/query-filter). Please note that any query filter passed into the `query_where` qual will be combined with other optional quals. +- `state` +- `type` +- `updated_at` +- `workspace_handle` +- `workspace_id` + +## Examples + +### Basic info + +```sql +select + id, + identity_handle, + workspace_handle, + pipeline_id, + type, + state, + created_at +from + steampipecloud_workspace_process; +``` + +### List processes for a pipeline + +```sql +select + id, + identity_handle, + workspace_handle, + pipeline_id, + type, + state, + created_at +from + steampipecloud_workspace_process +where + pipeline_id = 'pipe_cfcgiefm1tumv1dis7lg'; +``` + +### List running processes for a pipeline + +```sql +select + id, + identity_handle, + workspace_handle, + pipeline_id, + type, + state, + created_at +from + steampipecloud_workspace_process +where + pipeline_id = 'pipe_cfcgiefm1tumv1dis7lg' + and state = 'running'; +``` + +### List running processes for a pipeline using [query filter](https://steampipe.io/docs/cloud/reference/query-filter) + +```sql +select + id, + identity_handle, + workspace_handle, + pipeline_id, + type, + state, + created_at +from + steampipecloud_workspace_process +where + query_where = 'pipeline_id = ''pipe_cfcgiefm1tumv1dis7lg'' and state = ''running'''; +``` From cf083cf2501720708726854ce3be32423ae4b8d4 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 17:27:54 +0530 Subject: [PATCH 12/36] Upgrade SDK to v0.5.0. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9d2e29f..517beaf 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module steampipe-plugin-steampipecloud go 1.19 require ( - github.com/turbot/steampipe-cloud-sdk-go v0.4.0 + github.com/turbot/steampipe-cloud-sdk-go v0.5.0 github.com/turbot/steampipe-plugin-sdk/v4 v4.1.8 ) diff --git a/go.sum b/go.sum index c0dc16a..27ac257 100644 --- a/go.sum +++ b/go.sum @@ -418,8 +418,8 @@ github.com/tkrajina/go-reflector v0.5.4 h1:dS9aJEa/eYNQU/fwsb5CSiATOxcNyA/gG/A7a github.com/tkrajina/go-reflector v0.5.4/go.mod h1:9PyLgEOzc78ey/JmQQHbW8cQJ1oucLlNQsg8yFvkVk8= github.com/turbot/go-kit v0.4.0 h1:EdD7Bf2EGAjvHRGQxRiWpDawzZSk3T+eghqbj74qiSc= github.com/turbot/go-kit v0.4.0/go.mod h1:SBdPRngbEfYubiR81iAVtO43oPkg1+ASr+XxvgbH7/k= -github.com/turbot/steampipe-cloud-sdk-go v0.4.0 h1:ewDymSmTZSHwlqOBBMHS0kS2GzEtHaHD8DCYYXOEKMU= -github.com/turbot/steampipe-cloud-sdk-go v0.4.0/go.mod h1:8M2CspUHgCGqDCJV+FNn+boBPyLRHyzDinYnoZ/kZYw= +github.com/turbot/steampipe-cloud-sdk-go v0.5.0 h1:sgMpUL/gLnT5/9v6LaUDITo40npvSn+RQD5maT03wRQ= +github.com/turbot/steampipe-cloud-sdk-go v0.5.0/go.mod h1:8M2CspUHgCGqDCJV+FNn+boBPyLRHyzDinYnoZ/kZYw= github.com/turbot/steampipe-plugin-sdk/v4 v4.1.8 h1:4/fEpsrWNSKA/p2otsibzijBCf4f35Y8jIgUcJgd0Ng= github.com/turbot/steampipe-plugin-sdk/v4 v4.1.8/go.mod h1:t1uwq6KylUr2CzIinxeTafoktJvX8yWmhaoWCJJc4YI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= From 6b833d73ac9fe155a69fe81d497bc33b94577b27 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Mon, 6 Feb 2023 17:28:45 +0530 Subject: [PATCH 13/36] Add links to look up supported APIs and columns for query filter. --- docs/tables/steampipecloud_workspace_pipeline.md | 2 +- docs/tables/steampipecloud_workspace_process.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tables/steampipecloud_workspace_pipeline.md b/docs/tables/steampipecloud_workspace_pipeline.md index c72068e..60a01b8 100644 --- a/docs/tables/steampipecloud_workspace_pipeline.md +++ b/docs/tables/steampipecloud_workspace_pipeline.md @@ -13,7 +13,7 @@ Optional quals are supported for the following columns: - `identity_handle` - `identity_id` - `pipeline` -- `query_where` - Allows use of [query filters](https://steampipe.io/docs/cloud/reference/query-filter). Please note that any query filter passed into the `query_where` qual will be combined with other optional quals. +- `query_where` - Allows use of [query filters](https://steampipe.io/docs/cloud/reference/query-filter). For a list of supported columns for pipelines, please see [Supported APIs and Columns](https://steampipe.io/docs/cloud/reference/query-filter#supported-apis--columns). Please note that any query filter passed into the `query_where` qual will be combined with other optional quals. - `title` - `updated_at` - `workspace_handle` diff --git a/docs/tables/steampipecloud_workspace_process.md b/docs/tables/steampipecloud_workspace_process.md index 8347487..748b8b9 100644 --- a/docs/tables/steampipecloud_workspace_process.md +++ b/docs/tables/steampipecloud_workspace_process.md @@ -13,7 +13,7 @@ Optional quals are supported for the following columns: - `identity_handle` - `identity_id` - `pipeline_id` -- `query_where` - Allows use of [query filters](https://steampipe.io/docs/cloud/reference/query-filter). Please note that any query filter passed into the `query_where` qual will be combined with other optional quals. +- `query_where` - Allows use of [query filters](https://steampipe.io/docs/cloud/reference/query-filter). For a list of supported columns for workspace proceses, please see [Supported APIs and Columns](https://steampipe.io/docs/cloud/reference/query-filter#supported-apis--columns). Please note that any query filter passed into the `query_where` qual will be combined with other optional quals. - `state` - `type` - `updated_at` From 758449e2d348c8d02c29b88ece165b6fc6d4ea78 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:17:52 +0530 Subject: [PATCH 14/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 9ce8fe1..b268c7e 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -148,7 +148,7 @@ func listIdentityProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.H getUserIdentityCached := plugin.HydrateFunc(getUserIdentity).WithCache() commonData, err := getUserIdentityCached(ctx, d, h) if err != nil { - plugin.Logger(ctx).Error("listIdentityProcesses", "getUserIdentityCached", err) + plugin.Logger(ctx).Error("steampipecloud_process.listIdentityProcesses", "getUserIdentityCached", err) return nil, err } From 3efa29f943aad6331af4ff15aa7d393bcf8037a2 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:18:37 +0530 Subject: [PATCH 15/36] Update steampipecloud/table_steampipecloud_workspace_pipeline.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_workspace_pipeline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index f29c5a7..f33f4ec 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -262,7 +262,7 @@ func listWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plugin. } if err != nil { - plugin.Logger(ctx).Error("listWorkspacePipelines", "error", err) + plugin.Logger(ctx).Error("steampipecloud_workspace_pipeline.listWorkspacePipelines", "query_error", err) return nil, err } From 2064d704af34564fc11dc9b17fc7469021e8ee94 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:19:06 +0530 Subject: [PATCH 16/36] Update steampipecloud/table_steampipecloud_workspace_pipeline.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_workspace_pipeline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index f33f4ec..8a67fd8 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -344,7 +344,7 @@ func listUserWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plu response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) if err != nil { - plugin.Logger(ctx).Error("listUserWorkspacePipelines", "list", err) + plugin.Logger(ctx).Error("steampipecloud_workspace_pipeline.listUserWorkspacePipelines", "query_error", err) return err } From eaa4612c8db5215e9422646adf248fe7ffcf11da Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:19:17 +0530 Subject: [PATCH 17/36] Update steampipecloud/table_steampipecloud_workspace_pipeline.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_workspace_pipeline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index 8a67fd8..fe5dc90 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -374,7 +374,7 @@ func listOrgWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plug // Create Session svc, err := connect(ctx, d) if err != nil { - plugin.Logger(ctx).Error("listOrgWorkspacePipelines", "connection_error", err) + plugin.Logger(ctx).Error("steampipecloud_workspace_pipeline.listOrgWorkspacePipelines", "connection_error", err) return err } From 6909084eb7098d766f0f90617a59998a13ec628b Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:19:29 +0530 Subject: [PATCH 18/36] Update steampipecloud/table_steampipecloud_workspace_pipeline.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_workspace_pipeline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index fe5dc90..f5d97b8 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -445,7 +445,7 @@ func listOrgWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plug response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) if err != nil { - plugin.Logger(ctx).Error("listOrgWorkspacePipelines", "list", err) + plugin.Logger(ctx).Error("steampipecloud_workspace_pipeline.listOrgWorkspacePipelines", "query_error", err) return err } From ba13198d73cd1ac5f26850caf3893e287254b368 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:19:55 +0530 Subject: [PATCH 19/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index b268c7e..595b57e 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -174,7 +174,7 @@ func listIdentityProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.H } if err != nil { - plugin.Logger(ctx).Error("listIdentityProcesses", "error", err) + plugin.Logger(ctx).Error("steampipecloud_process.listIdentityProcesses", "query_error", err) return nil, err } From de3b188031fdb1ee91b16777011f6524d59a7bf6 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:20:14 +0530 Subject: [PATCH 20/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 595b57e..3182e81 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -185,7 +185,7 @@ func listUserProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.Hydra // Create Session svc, err := connect(ctx, d) if err != nil { - plugin.Logger(ctx).Error("listUserProcesses", "connection_error", err) + plugin.Logger(ctx).Error("steampipecloud_process.listUserProcesses", "connection_error", err) return err } From 3dfeca28208e264f6de066952708aad0909dd335 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:20:28 +0530 Subject: [PATCH 21/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 3182e81..0129d37 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -209,7 +209,7 @@ func listUserProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.Hydra response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) if err != nil { - plugin.Logger(ctx).Error("listUserProcesses", "list", err) + plugin.Logger(ctx).Error("steampipecloud_process.listUserProcesses", "query_error", err) return err } From daad29fa98995d0aabdbcc22cf17d7776514eba1 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:20:48 +0530 Subject: [PATCH 22/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 0129d37..b0656b6 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -239,7 +239,7 @@ func listOrgProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrat // Create Session svc, err := connect(ctx, d) if err != nil { - plugin.Logger(ctx).Error("listOrgProcesses", "connection_error", err) + plugin.Logger(ctx).Error("steampipecloud_process.listOrgProcesses", "connection_error", err) return err } From 1ee851a66b2475d4303e3d19685f3972a20bf06c Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Tue, 21 Feb 2023 18:22:51 +0530 Subject: [PATCH 23/36] Update faulty comment. --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index b0656b6..22181e8 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -154,7 +154,7 @@ func listIdentityProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.H user = commonData.(openapi.User) - // Error out if both workspace_handle and workspace_id is passed + // Error out if both identity_handle and identity_id is passed if identityHandle != "" && identityId != "" { plugin.Logger(ctx).Error("listIdentityProcesses", "please pass any one of identity_handle or identity_id") return nil, fmt.Errorf("please pass any one of identity_handle or identity_id") From 9d3af2786ea9743eaf251d6f5682f3ac1f464b09 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Tue, 21 Feb 2023 18:25:10 +0530 Subject: [PATCH 24/36] Remove logger entries. --- steampipecloud/table_steampipecloud_process.go | 1 - steampipecloud/table_steampipecloud_workspace_pipeline.go | 1 - 2 files changed, 2 deletions(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 22181e8..8a0d95d 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -156,7 +156,6 @@ func listIdentityProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.H // Error out if both identity_handle and identity_id is passed if identityHandle != "" && identityId != "" { - plugin.Logger(ctx).Error("listIdentityProcesses", "please pass any one of identity_handle or identity_id") return nil, fmt.Errorf("please pass any one of identity_handle or identity_id") } if identityHandle != "" { diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index f5d97b8..aa07936 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -237,7 +237,6 @@ func listWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plugin. // Error out if both workspace_handle and workspace_id is passed if workspaceHandle != "" && workspaceId != "" { - plugin.Logger(ctx).Error("listWorkspacePipelines", "please pass any one of workspace_id or workspace_handle") return nil, fmt.Errorf("please pass any one of workspace_id or workspace_handle") } // If either one has been passed, check whether either of the handle or the id matches with the workspace in context From 82a7c0e3c80f56cd07f3059d55f52f0a50d30565 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:26:05 +0530 Subject: [PATCH 25/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 8a0d95d..0ce026c 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -262,7 +262,7 @@ func listOrgProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrat response, err := plugin.RetryHydrate(ctx, d, h, listDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) if err != nil { - plugin.Logger(ctx).Error("listOrgProcesses", "list", err) + plugin.Logger(ctx).Error("steampipecloud_process.listOrgProcesses", "query_error", err) return err } From 3631604fc8846eca53c1b529f80205fdb7e0a797 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:26:26 +0530 Subject: [PATCH 26/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 0ce026c..9afcd85 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -300,7 +300,7 @@ func getIdentityProcess(ctx context.Context, d *plugin.QueryData, h *plugin.Hydr getUserIdentityCached := plugin.HydrateFunc(getUserIdentity).WithCache() commonData, err := getUserIdentityCached(ctx, d, h) if err != nil { - plugin.Logger(ctx).Error("getIdentityProcess", "getUserIdentityCached", err) + plugin.Logger(ctx).Error("steampipecloud_process.getIdentityProcess", "connection_error", err) return nil, err } From 26e5c975613a46e5db2bd19835d4ea98ecc24fa8 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:26:40 +0530 Subject: [PATCH 27/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 9afcd85..e0e44fb 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -313,7 +313,7 @@ func getIdentityProcess(ctx context.Context, d *plugin.QueryData, h *plugin.Hydr } if err != nil { - plugin.Logger(ctx).Error("getIdentityProcess", "error", err) + plugin.Logger(ctx).Error("steampipecloud_process.getIdentityProcess", "query_error", err) return nil, err } From 880b02c0e427eef501964b609cdd09c17a8fe9e7 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:26:53 +0530 Subject: [PATCH 28/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index e0e44fb..add57e2 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -324,7 +324,7 @@ func getUserProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateD // Create Session svc, err := connect(ctx, d) if err != nil { - plugin.Logger(ctx).Error("getUserProcess", "connection_error", err) + plugin.Logger(ctx).Error("steampipecloud_process.getUserProcess", "connection_error", err) return nil, err } From cc0e60b4cc4ab594d7e759feb13a9c6f2f4d7ffb Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:27:18 +0530 Subject: [PATCH 29/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index add57e2..093c8ee 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -337,7 +337,7 @@ func getUserProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateD response, err := plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) if err != nil { - plugin.Logger(ctx).Error("getUserProcess", "get", err) + plugin.Logger(ctx).Error("steampipecloud_process.getUserProcess", "query_error", err) return nil, err } From d98aacb296f28357d9dd03de3a1c5c9da94c0d96 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:27:31 +0530 Subject: [PATCH 30/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 093c8ee..1378fc4 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -348,7 +348,7 @@ func getOrgProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateDa // Create Session svc, err := connect(ctx, d) if err != nil { - plugin.Logger(ctx).Error("getOrgProcess", "connection_error", err) + plugin.Logger(ctx).Error("steampipecloud_process.getOrgProcess", "connection_error", err) return nil, err } From ce5d37a7dafd4d2a5e2a85ba16c19f4aaf645c53 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:27:42 +0530 Subject: [PATCH 31/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 1378fc4..0560059 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -361,7 +361,7 @@ func getOrgProcess(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateDa response, err := plugin.RetryHydrate(ctx, d, h, getDetails, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) if err != nil { - plugin.Logger(ctx).Error("getOrgProcess", "get", err) + plugin.Logger(ctx).Error("steampipecloud_process.getOrgProcess", "query_error", err) return nil, err } From 5d53bdad6933df8d16e88a873992edd66dee2d7d Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:28:01 +0530 Subject: [PATCH 32/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 0560059..5247316 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -372,7 +372,7 @@ func getIdentityDetailsForProcess(ctx context.Context, d *plugin.QueryData, h *p // Create Session svc, err := connect(ctx, d) if err != nil { - plugin.Logger(ctx).Error("getIdentityDetailsForProcess", "connection_error", err) + plugin.Logger(ctx).Error("steampipecloud_process.getIdentityDetailsForProcess", "connection_error", err) return nil, err } From b73be52a33ac4bc2ac4f5b3c0ade19056a1a56a7 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:28:13 +0530 Subject: [PATCH 33/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index 5247316..bf2cc71 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -379,7 +379,7 @@ func getIdentityDetailsForProcess(ctx context.Context, d *plugin.QueryData, h *p getUserIdentityCached := plugin.HydrateFunc(getUserIdentity).WithCache() commonData, err := getUserIdentityCached(ctx, d, h) if err != nil { - plugin.Logger(ctx).Error("getIdentityDetailsForProcess", "getUserIdentityCached", err) + plugin.Logger(ctx).Error("steampipecloud_process.getIdentityDetailsForProcess", "getUserIdentityCached", err) return nil, err } From 4aaf3941db9617af61823b7598ebdde9676bd674 Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:28:24 +0530 Subject: [PATCH 34/36] Update steampipecloud/table_steampipecloud_process.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_process.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index bf2cc71..efa5b25 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -394,7 +394,7 @@ func getIdentityDetailsForProcess(ctx context.Context, d *plugin.QueryData, h *p } else { org, _, err := svc.Orgs.Get(ctx, *process.IdentityId).Execute() if err != nil { - plugin.Logger(ctx).Error("getIdentityDetailsForProcess", "getOrg", err) + plugin.Logger(ctx).Error("steampipecloud_process.getIdentityDetailsForProcess", "query_error", err) return nil, err } identityDetails.IdentityHandle = org.Handle From ac4c90579b0b0ce51f94b4da6f3bf0641fea574c Mon Sep 17 00:00:00 2001 From: Siddhartha Das Date: Tue, 21 Feb 2023 18:33:39 +0530 Subject: [PATCH 35/36] Update steampipecloud/table_steampipecloud_workspace_pipeline.go Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com> --- steampipecloud/table_steampipecloud_workspace_pipeline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index aa07936..91365d6 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -29,7 +29,7 @@ func tableSteampipeCloudWorkspacePipeline(_ context.Context) *plugin.Table { List: &plugin.ListConfig{ ParentHydrate: listWorkspaces, Hydrate: listWorkspacePipelines, - KeyColumns: []*plugin.KeyColumn{ + KeyColumns: []*plugin.KeyColumn{ { Name: "created_at", Require: plugin.Optional, From dad885d30324affd63d5c070e8080c37fa21f2b8 Mon Sep 17 00:00:00 2001 From: siddharthaturbot Date: Wed, 22 Feb 2023 13:39:00 +0530 Subject: [PATCH 36/36] Change limit logic. --- steampipecloud/table_steampipecloud_process.go | 8 ++------ .../table_steampipecloud_workspace_pipeline.go | 10 +++------- .../table_steampipecloud_workspace_process.go | 8 ++------ 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/steampipecloud/table_steampipecloud_process.go b/steampipecloud/table_steampipecloud_process.go index efa5b25..290b9ed 100644 --- a/steampipecloud/table_steampipecloud_process.go +++ b/steampipecloud/table_steampipecloud_process.go @@ -131,13 +131,9 @@ func listIdentityProcesses(ctx context.Context, d *plugin.QueryData, h *plugin.H // set the limit to that instead maxResults := int32(100) limit := d.QueryContext.Limit - if d.QueryContext.Limit != nil { + if limit != nil { if *limit < int64(maxResults) { - if *limit < 1 { - maxResults = int32(1) - } else { - maxResults = int32(*limit) - } + maxResults = int32(*limit) } } diff --git a/steampipecloud/table_steampipecloud_workspace_pipeline.go b/steampipecloud/table_steampipecloud_workspace_pipeline.go index 91365d6..be3fc74 100644 --- a/steampipecloud/table_steampipecloud_workspace_pipeline.go +++ b/steampipecloud/table_steampipecloud_workspace_pipeline.go @@ -29,7 +29,7 @@ func tableSteampipeCloudWorkspacePipeline(_ context.Context) *plugin.Table { List: &plugin.ListConfig{ ParentHydrate: listWorkspaces, Hydrate: listWorkspacePipelines, - KeyColumns: []*plugin.KeyColumn{ + KeyColumns: []*plugin.KeyColumn{ { Name: "created_at", Require: plugin.Optional, @@ -221,13 +221,9 @@ func listWorkspacePipelines(ctx context.Context, d *plugin.QueryData, h *plugin. // set the limit to that instead maxResults := int32(100) limit := d.QueryContext.Limit - if d.QueryContext.Limit != nil { + if limit != nil { if *limit < int64(maxResults) { - if *limit < 1 { - maxResults = int32(1) - } else { - maxResults = int32(*limit) - } + maxResults = int32(*limit) } } diff --git a/steampipecloud/table_steampipecloud_workspace_process.go b/steampipecloud/table_steampipecloud_workspace_process.go index 5ffe5c7..4313594 100644 --- a/steampipecloud/table_steampipecloud_workspace_process.go +++ b/steampipecloud/table_steampipecloud_workspace_process.go @@ -205,13 +205,9 @@ func listWorkspaceProcesses(ctx context.Context, d *plugin.QueryData, h *plugin. // set the limit to that instead maxResults := int32(100) limit := d.QueryContext.Limit - if d.QueryContext.Limit != nil { + if limit != nil { if *limit < int64(maxResults) { - if *limit < 1 { - maxResults = int32(1) - } else { - maxResults = int32(*limit) - } + maxResults = int32(*limit) } }