Skip to content

Commit

Permalink
Recompile plugin with steampipe-plugin-sdk v5.10.1 and add support fo…
Browse files Browse the repository at this point in the history
…r connection key columns (#422)

Co-authored-by: ParthaI <[email protected]>
  • Loading branch information
misraved and ParthaI authored May 17, 2024
1 parent 1dc44f2 commit 3b9337d
Show file tree
Hide file tree
Showing 61 changed files with 295 additions and 220 deletions.
57 changes: 57 additions & 0 deletions github/common_column.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package github

import (
"context"

"github.com/shurcooL/githubv4"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/memoize"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)

func commonColumns(c []*plugin.Column) []*plugin.Column {
return append([]*plugin.Column{
{
Name: "login_id",
Description: "Unique identifier for the user login.",
Type: proto.ColumnType_STRING,
Hydrate: getLoginId,
Transform: transform.FromValue(),
},
}, c...)
}

// if the caching is required other than per connection, build a cache key for the call and use it in Memoize.
var getLoginIdMemoized = plugin.HydrateFunc(getLoginIdUncached).Memoize(memoize.WithCacheKeyFunction(getLoginIdCacheKey))

// declare a wrapper hydrate function to call the memoized function
// - this is required when a memoized function is used for a column definition
func getLoginId(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
return getLoginIdMemoized(ctx, d, h)
}

// Build a cache key for the call to getLoginIdCacheKey.
func getLoginIdCacheKey(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
key := "getLoginId"
return key, nil
}

func getLoginIdUncached(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {

client := connectV4(ctx, d)

var query struct {
Viewer struct {
Login githubv4.String
ID githubv4.ID
}
}
err := client.Query(ctx, &query, nil)
if err != nil {
plugin.Logger(ctx).Error("getLoginIdUncached", "api_error", err)
return nil, err
}

return query.Viewer.ID, nil
}
6 changes: 6 additions & 0 deletions github/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ func Plugin(ctx context.Context) *plugin.Plugin {
ConnectionConfigSchema: &plugin.ConnectionConfigSchema{
NewInstance: ConfigInstance,
},
ConnectionKeyColumns: []plugin.ConnectionKeyColumn{
{
Name: "login_id",
Hydrate: getLoginId,
},
},
DefaultTransform: transform.FromGo(),
DefaultRetryConfig: retryConfig(),
TableMap: map[string]*plugin.Table{
Expand Down
4 changes: 2 additions & 2 deletions github/table_github_actions_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func tableGitHubActionsArtifact() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubArtifactGet,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository that contains the artifact."},
{Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the artifact."},
Expand All @@ -37,7 +37,7 @@ func tableGitHubActionsArtifact() *plugin.Table {
{Name: "expired", Type: proto.ColumnType_BOOL, Description: "It defines whether the artifact is expires or not."},
{Name: "expires_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("ExpiresAt").Transform(convertTimestamp), Description: "Time when the artifact expires."},
{Name: "node_id", Type: proto.ColumnType_STRING, Description: "Node where GitHub stores this data internally."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_actions_repository_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func tableGitHubActionsRepositoryRunner() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubRunnerGet,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository that contains the runners."},
{Name: "id", Type: proto.ColumnType_INT, Transform: transform.FromGo(), Description: "The unique identifier of the runner."},
Expand All @@ -33,7 +33,7 @@ func tableGitHubActionsRepositoryRunner() *plugin.Table {
{Name: "status", Type: proto.ColumnType_STRING, Description: "The status of the runner."},
{Name: "busy", Type: proto.ColumnType_BOOL, Description: "Indicates whether the runner is currently in use or not."},
{Name: "labels", Type: proto.ColumnType_JSON, Description: "Labels represents a collection of labels attached to each runner."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_actions_repository_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func tableGitHubActionsRepositorySecret() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubRepoSecretGet,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository that contains the secrets."},
{Name: "name", Type: proto.ColumnType_STRING, Description: "The name of the secret."},
Expand All @@ -34,7 +34,7 @@ func tableGitHubActionsRepositorySecret() *plugin.Table {
// Other columns
{Name: "created_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("CreatedAt").Transform(convertTimestamp), Description: "Time when the secret was created."},
{Name: "updated_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("UpdatedAt").Transform(convertTimestamp), Description: "Time when the secret was updated."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_actions_repository_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func tableGitHubActionsRepositoryWorkflowRun() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubRepoWorkflowRunGet,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository that specifies the workflow run."},
{Name: "id", Type: proto.ColumnType_INT, Description: "The unque identifier of the workflow run."},
Expand Down Expand Up @@ -64,7 +64,7 @@ func tableGitHubActionsRepositoryWorkflowRun() *plugin.Table {
{Name: "actor_login", Type: proto.ColumnType_STRING, Description: "The login of the user whom initiated the first instance of the workflow run.", Transform: transform.FromField("Actor.Login")},
{Name: "triggering_actor", Type: proto.ColumnType_JSON, Description: "The user whom initiated the latest instance of this workflow run."},
{Name: "triggering_actor_login", Type: proto.ColumnType_STRING, Description: "The login of the user whom initiated the latest instance of this workflow run.", Transform: transform.FromField("TriggeringActor.Login")},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func tableGitHubAuditLog() *plugin.Table {
},
Hydrate: tableGitHubAuditLogList,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
{Name: "organization", Type: proto.ColumnType_STRING, Transform: transform.FromQual("organization"), Description: "The GitHub organization."},
{Name: "phrase", Type: proto.ColumnType_STRING, Transform: transform.FromQual("phrase"), Description: "The search phrase for your audit events."},
{Name: "include", Type: proto.ColumnType_STRING, Transform: transform.FromQual("include"), Description: "The event types to include: web, git, all."},
Expand All @@ -42,7 +42,7 @@ func tableGitHubAuditLog() *plugin.Table {
{Name: "user_login", Type: proto.ColumnType_STRING, Description: "The GitHub user, when the action relates to a user.", Transform: transform.FromField("User")},
{Name: "repo", Type: proto.ColumnType_STRING, Description: "The GitHub repository, when the action relates to a repository."},
{Name: "data", Type: proto.ColumnType_JSON, Description: "Additional data relating to the audit event."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func tableGitHubBranch() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubBranchList,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository that contains the branch."},
{Name: "name", Type: proto.ColumnType_STRING, Description: "Name of the branch."},
{Name: "commit", Type: proto.ColumnType_JSON, Transform: transform.FromField("Target.Commit"), Description: "Latest commit on the branch."},
{Name: "protected", Type: proto.ColumnType_BOOL, Hydrate: branchHydrateProtected, Transform: transform.FromValue().Transform(HasValue), Description: "If true, the branch is protected."},
{Name: "branch_protection_rule", Type: proto.ColumnType_JSON, Hydrate: branchHydrateBranchProtectionRule, Transform: transform.FromValue().NullIfZero(), Description: "Branch protection rule if protected."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func tableGitHubBranchProtection() *plugin.Table {
KeyColumns: plugin.SingleColumn("node_id"),
Hydrate: tableGitHubRepositoryBranchProtectionGet,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "The full name of the repository (login/repo-name)."},
{Name: "id", Type: proto.ColumnType_INT, Hydrate: branchProtectionRuleHydrateId, Transform: transform.FromValue(), Description: "The ID of the branch protection rule."},
{Name: "node_id", Type: proto.ColumnType_STRING, Description: "The Node ID of the branch protection rule."},
Expand Down Expand Up @@ -59,7 +59,7 @@ func tableGitHubBranchProtection() *plugin.Table {
{Name: "bypass_pull_request_allowance_apps", Type: proto.ColumnType_JSON, Description: "Applications can bypass pull requests to the branch only if in this list."},
{Name: "bypass_pull_request_allowance_teams", Type: proto.ColumnType_JSON, Description: "Teams can bypass pull requests to the branch only if in this list."},
{Name: "bypass_pull_request_allowance_users", Type: proto.ColumnType_JSON, Description: "Users can bypass pull requests to the branch only if in this list."},
},
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_code_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func tableGitHubCodeOwner() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
KeyColumns: plugin.SingleColumn("repository_full_name"),
},
Columns: gitHubCodeOwnerColumns(),
Columns: commonColumns(gitHubCodeOwnerColumns()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func tableGitHubCommit() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubCommitGet,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository that contains the commit."},
{Name: "sha", Type: proto.ColumnType_STRING, Description: "SHA of the commit."},
{Name: "short_sha", Type: proto.ColumnType_STRING, Hydrate: commitHydrateShortSha, Transform: transform.FromValue(), Description: "Short SHA of the commit."},
Expand All @@ -56,7 +56,7 @@ func tableGitHubCommit() *plugin.Table {
{Name: "url", Type: proto.ColumnType_STRING, Hydrate: commitHydrateUrl, Transform: transform.FromValue(), Description: "URL of the commit."},
{Name: "node_id", Type: proto.ColumnType_STRING, Hydrate: commitHydrateNodeId, Transform: transform.FromValue(), Description: "The node ID of the commit."},
{Name: "message_headline", Type: proto.ColumnType_STRING, Hydrate: commitHydrateMessageHeadline, Transform: transform.FromValue(), Description: "The Git commit message headline."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_community_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func tableGitHubCommunityProfile() *plugin.Table {
Hydrate: tableGitHubCommunityProfileList,
ShouldIgnoreError: isNotFoundError([]string{"404"}),
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository that contains the tag."},
{Name: "code_of_conduct", Type: proto.ColumnType_JSON, Transform: transform.FromValue().NullIfZero(), Hydrate: cpHydrateCodeOfConduct, Description: "Code of conduct for the repository."},
{Name: "contributing", Type: proto.ColumnType_JSON, Transform: transform.FromValue().NullIfZero(), Hydrate: cpHydrateContributing, Description: "Contributing guidelines for the repository."},
Expand All @@ -28,7 +28,7 @@ func tableGitHubCommunityProfile() *plugin.Table {
{Name: "license_info", Type: proto.ColumnType_JSON, Transform: transform.FromValue().NullIfZero(), Hydrate: cpHydrateLicense, Description: "License for the repository."},
{Name: "readme", Type: proto.ColumnType_JSON, Transform: transform.FromValue().NullIfZero(), Hydrate: cpHydrateReadme, Description: "README for the repository."},
{Name: "security", Type: proto.ColumnType_JSON, Transform: transform.FromValue().NullIfZero(), Hydrate: cpHydrateSecurity, Description: "Security for the repository."},
},
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_gist.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func tableGitHubGist() *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
ShouldIgnoreError: isNotFoundError([]string{"404"}),
},
Columns: gitHubGistColumns(),
Columns: commonColumns(gitHubGistColumns()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func tableGitHubGitignore() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubGitignoreGetData,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "name", Type: proto.ColumnType_STRING, Description: "Name of the gitignore template."},
{Name: "source", Type: proto.ColumnType_STRING, Hydrate: tableGitHubGitignoreGetData, Description: "Source code of the gitignore template."},
},
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func tableGitHubIssue() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubRepositoryIssueGet,
},
Columns: gitHubIssueColumns(),
Columns: commonColumns(gitHubIssueColumns()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func tableGitHubIssueComment() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubRepositoryIssueCommentList,
},
Columns: sharedCommentsColumns(),
Columns: commonColumns(sharedCommentsColumns()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func tableGitHubLicense() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubLicenseGetData,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
{Name: "spdx_id", Description: "The Software Package Data Exchange (SPDX) id of the license.", Type: proto.ColumnType_STRING, Transform: transform.FromValue(), Hydrate: licenseHydrateSpdxId},
{Name: "name", Description: "The name of the license.", Type: proto.ColumnType_STRING, Transform: transform.FromValue(), Hydrate: licenseHydrateName},
{Name: "url", Description: "The HTML URL of the license.", Type: proto.ColumnType_STRING, Transform: transform.FromValue(), Hydrate: licenseHydrateUrl},
Expand All @@ -40,7 +40,7 @@ func tableGitHubLicense() *plugin.Table {
{Name: "permissions", Description: "An array of permissions for the license (private-use, commercial-use,modifications, etc).", Type: proto.ColumnType_JSON, Transform: transform.FromValue(), Hydrate: licenseHydratePermissions},
{Name: "nickname", Description: "The customary short name of the license.", Type: proto.ColumnType_STRING, Transform: transform.FromValue(), Hydrate: licenseHydrateNickname},
{Name: "pseudo_license", Description: "Indicates if the license is a pseudo-license placeholder (e.g. other, no-license).", Type: proto.ColumnType_BOOL, Transform: transform.FromValue(), Hydrate: licenseHydratePseudoLicense},
},
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_my_gist.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func tableGitHubMyGist() *plugin.Table {
List: &plugin.ListConfig{
Hydrate: tableGitHubMyGistList,
},
Columns: gitHubGistColumns(),
Columns: commonColumns(gitHubGistColumns()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_my_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func tableGitHubMyIssue() *plugin.Table {
{Name: "updated_at", Require: plugin.Optional, Operators: []string{">", ">="}},
},
},
Columns: gitHubMyIssueColumns(),
Columns: commonColumns(gitHubMyIssueColumns()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_my_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func tableGitHubMyOrganization() *plugin.Table {
List: &plugin.ListConfig{
Hydrate: tableGitHubMyOrganizationList,
},
Columns: gitHubOrganizationColumns(),
Columns: commonColumns(gitHubOrganizationColumns()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_my_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func tableGitHubMyRepository() *plugin.Table {
Hydrate: tableGitHubMyRepositoryList,
ShouldIgnoreError: isNotFoundError([]string{"404"}),
},
Columns: sharedRepositoryColumns(),
Columns: commonColumns(sharedRepositoryColumns()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_my_star.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func tableGitHubMyStar() *plugin.Table {
Hydrate: tableGitHubMyStarredRepositoryList,
ShouldIgnoreError: isNotFoundError([]string{"404"}),
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Description: "The full name of the repository, including the owner and repo name.", Transform: transform.FromValue(), Hydrate: starHydrateNameWithOwner},
{Name: "starred_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromValue().Transform(convertTimestamp), Hydrate: starHydrateStarredAt, Description: "The timestamp when the repository was starred."},
{Name: "url", Type: proto.ColumnType_STRING, Transform: transform.FromValue(), Hydrate: starHydrateUrl, Description: "URL of the repository."},
},
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_my_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func tableGitHubMyTeam() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubTeamGet,
},
Columns: gitHubTeamColumns(),
Columns: commonColumns(gitHubTeamColumns()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func tableGitHubOrganization() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubOrganizationList,
},
Columns: gitHubOrganizationColumns(),
Columns: commonColumns(gitHubOrganizationColumns()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion github/table_github_organization_collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func tableGitHubOrganizationCollaborator() *plugin.Table {
},
Hydrate: listGitHubOrganizationCollaborators,
},
Columns: gitHubOrganizationCollaborators(),
Columns: commonColumns(gitHubOrganizationCollaborators()),
}
}

Expand Down
4 changes: 2 additions & 2 deletions github/table_github_organization_dependabot_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func tableGitHubOrganizationDependabotAlert() *plugin.Table {
ShouldIgnoreError: isNotFoundError([]string{"404", "403"}),
Hydrate: tableGitHubOrganizationDependabotAlertList,
},
Columns: append(
Columns: commonColumns(append(
gitHubDependabotAlertColumns(),
[]*plugin.Column{
{
Expand All @@ -203,7 +203,7 @@ func tableGitHubOrganizationDependabotAlert() *plugin.Table {
Transform: transform.FromQual("organization"),
},
}...,
),
)),
}
}

Expand Down
Loading

0 comments on commit 3b9337d

Please sign in to comment.