-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtable_github_actions_repository_secret.go
More file actions
116 lines (94 loc) · 3.73 KB
/
Copy pathtable_github_actions_repository_secret.go
File metadata and controls
116 lines (94 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package github
import (
"context"
"github.com/google/go-github/v55/github"
"github.com/turbot/steampipe-plugin-sdk/v6/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin"
"github.com/turbot/steampipe-plugin-sdk/v6/plugin/transform"
)
func tableGitHubActionsRepositorySecret() *plugin.Table {
return &plugin.Table{
Name: "github_actions_repository_secret",
Description: "Secrets are encrypted environment variables that you create in a repository",
List: &plugin.ListConfig{
KeyColumns: plugin.SingleColumn("repository_full_name"),
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubRepoSecretList,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"repository_full_name", "name"}),
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubRepoSecretGet,
},
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."},
{Name: "visibility", Type: proto.ColumnType_STRING, Description: "The visibility of the secret."},
{Name: "selected_repositories_url", Type: proto.ColumnType_STRING, Transform: transform.FromField("SelectedRepositoriesURL"), Description: "The GitHub URL of the repository."},
// 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."},
}),
}
}
func tableGitHubRepoSecretList(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
client := connect(ctx, d)
orgName := d.EqualsQuals["repository_full_name"].GetStringValue()
owner, repo := parseRepoFullName(orgName)
opts := &github.ListOptions{PerPage: 100}
limit := d.QueryContext.Limit
if limit != nil {
if *limit < int64(opts.PerPage) {
opts.PerPage = int(*limit)
}
}
for {
secrets, resp, err := client.Actions.ListRepoSecrets(ctx, owner, repo, opts)
if err != nil {
return nil, err
}
for _, i := range secrets.Secrets {
if i != nil {
d.StreamListItem(ctx, i)
}
// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return nil, nil
}
func tableGitHubRepoSecretGet(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
name := d.EqualsQuals["name"].GetStringValue()
orgName := d.EqualsQuals["repository_full_name"].GetStringValue()
// Empty check for the parameters
if name == "" || orgName == "" {
return nil, nil
}
owner, repo := parseRepoFullName(orgName)
plugin.Logger(ctx).Trace("tableGitHubRepoSecretGet", "owner", owner, "repo", repo, "name", name)
client := connect(ctx, d)
type GetResponse struct {
secret *github.Secret
resp *github.Response
}
getDetails := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
detail, resp, err := client.Actions.GetRepoSecret(ctx, owner, repo, name)
return GetResponse{
secret: detail,
resp: resp,
}, err
}
getResponse, err := plugin.RetryHydrate(ctx, d, h, getDetails, retryConfig())
if err != nil {
return nil, err
}
getResp := getResponse.(GetResponse)
return getResp.secret, nil
}