Skip to content

Commit d65b6c2

Browse files
authored
Merge pull request #29 from opengovern/fix-folder-reorganization
fix: cycle imports
2 parents 1ad50d3 + 0b0595c commit d65b6c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+460
-173
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package models
2+
3+
4+
type IntegrationCredentials struct {
5+
PatToken string `json:"pat_token"`
6+
}

discovery/pkg/models/resource_type.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package models
22

33
import (
4-
"github.com/opengovern/og-describer-github/global"
54
"github.com/opengovern/og-util/pkg/describe/enums"
65
"github.com/opengovern/og-util/pkg/integration"
76
"golang.org/x/net/context"
87
)
98

109
// any types are used to load your provider configuration.
11-
type ResourceDescriber func(context.Context, global.IntegrationCredentials, enums.DescribeTriggerType, map[string]string, *StreamSender) ([]Resource, error)
12-
type SingleResourceDescriber func(context.Context, global.IntegrationCredentials, enums.DescribeTriggerType, map[string]string, string, *StreamSender) (*Resource, error)
10+
type ResourceDescriber func(context.Context, IntegrationCredentials, enums.DescribeTriggerType, map[string]string, *StreamSender) ([]Resource, error)
11+
type SingleResourceDescriber func(context.Context, IntegrationCredentials, enums.DescribeTriggerType, map[string]string, string, *StreamSender) (*Resource, error)
1312

1413
type ResourceType struct {
1514
IntegrationType integration.Type

discovery/pkg/orchestrator/resources.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
model "github.com/opengovern/og-describer-github/discovery/pkg/models"
99
"github.com/opengovern/og-describer-github/discovery/provider/describers"
10-
"github.com/opengovern/og-describer-github/global"
1110
"github.com/opengovern/og-describer-github/global/maps"
1211
"github.com/opengovern/og-util/pkg/describe/enums"
1312
"go.uber.org/zap"
@@ -49,7 +48,7 @@ func GetResources(
4948
logger *zap.Logger,
5049
resourceType string,
5150
triggerType enums.DescribeTriggerType,
52-
cfg global.IntegrationCredentials,
51+
cfg model.IntegrationCredentials,
5352
additionalParameters map[string]string,
5453
stream *model.StreamSender,
5554
) error {
@@ -60,7 +59,7 @@ func GetResources(
6059
return nil
6160
}
6261

63-
func describe(ctx context.Context, logger *zap.Logger, accountCfg global.IntegrationCredentials, resourceType string, triggerType enums.DescribeTriggerType, additionalParameters map[string]string, stream *model.StreamSender) ([]model.Resource, error) {
62+
func describe(ctx context.Context, logger *zap.Logger, accountCfg model.IntegrationCredentials, resourceType string, triggerType enums.DescribeTriggerType, additionalParameters map[string]string, stream *model.StreamSender) ([]model.Resource, error) {
6463
resourceTypeObject, ok := maps.ResourceTypes[resourceType]
6564
if !ok {
6665
return nil, fmt.Errorf("unsupported resource type: %s", resourceType)
@@ -75,7 +74,7 @@ func GetSingleResource(
7574
logger *zap.Logger,
7675
resourceType string,
7776
triggerType enums.DescribeTriggerType,
78-
cfg global.IntegrationCredentials,
77+
cfg model.IntegrationCredentials,
7978
additionalParameters map[string]string,
8079
resourceId string,
8180
stream *model.StreamSender,
@@ -87,7 +86,7 @@ func GetSingleResource(
8786
return nil
8887
}
8988

90-
func describeSingle(ctx context.Context, logger *zap.Logger, accountCfg global.IntegrationCredentials, resourceType string, resourceID string, triggerType enums.DescribeTriggerType, additionalParameters map[string]string, stream *model.StreamSender) (*model.Resource, error) {
89+
func describeSingle(ctx context.Context, logger *zap.Logger, accountCfg model.IntegrationCredentials, resourceType string, resourceID string, triggerType enums.DescribeTriggerType, additionalParameters map[string]string, stream *model.StreamSender) (*model.Resource, error) {
9190
resourceTypeObject, ok := maps.ResourceTypes[resourceType]
9291
if !ok {
9392
return nil, fmt.Errorf("unsupported resource type: %s", resourceType)

discovery/provider/credentials.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ package provider
33
import (
44
"encoding/json"
55
model "github.com/opengovern/og-describer-github/discovery/pkg/models"
6-
"github.com/opengovern/og-describer-github/global"
76
"github.com/opengovern/og-util/pkg/describe"
87
)
98

109
// AccountCredentialsFromMap TODO: converts a map to a configs.IntegrationCredentials.
11-
func AccountCredentialsFromMap(m map[string]any) (global.IntegrationCredentials, error) {
10+
func AccountCredentialsFromMap(m map[string]any) (model.IntegrationCredentials, error) {
1211
mj, err := json.Marshal(m)
1312
if err != nil {
14-
return global.IntegrationCredentials{}, err
13+
return model.IntegrationCredentials{}, err
1514
}
1615

17-
var c global.IntegrationCredentials
16+
var c model.IntegrationCredentials
1817
err = json.Unmarshal(mj, &c)
1918
if err != nil {
20-
return global.IntegrationCredentials{}, err
19+
return model.IntegrationCredentials{}, err
2120
}
2221

2322
return c, nil

discovery/provider/describer_wrapper.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@ package provider
22

33
import (
44
"fmt"
5+
56
"github.com/google/go-github/v55/github"
67
model "github.com/opengovern/og-describer-github/discovery/pkg/models"
7-
"github.com/opengovern/og-describer-github/discovery/provider/describers"
8-
"github.com/opengovern/og-describer-github/global"
98
"github.com/opengovern/og-util/pkg/describe/enums"
109
"github.com/shurcooL/githubv4"
1110
"golang.org/x/net/context"
1211
"golang.org/x/oauth2"
1312
)
1413

15-
func DescribeByGithub(describe func(context.Context, describers.GitHubClient, string, *model.StreamSender) ([]model.Resource, error)) model.ResourceDescriber {
16-
return func(ctx context.Context, cfg global.IntegrationCredentials, triggerType enums.DescribeTriggerType, additionalParameters map[string]string, stream *model.StreamSender) ([]model.Resource, error) {
17-
ctx = describers.WithTriggerType(ctx, triggerType)
14+
15+
type GitHubClient struct {
16+
RestClient *github.Client
17+
GraphQLClient *githubv4.Client
18+
Token string
19+
}
20+
var (
21+
triggerTypeKey string = "trigger_type"
22+
)
23+
func WithTriggerType(ctx context.Context, tt enums.DescribeTriggerType) context.Context {
24+
return context.WithValue(ctx, triggerTypeKey, tt)
25+
}
26+
func DescribeByGithub(describe func(context.Context, GitHubClient, string, *model.StreamSender) ([]model.Resource, error)) model.ResourceDescriber {
27+
return func(ctx context.Context, cfg model.IntegrationCredentials, triggerType enums.DescribeTriggerType, additionalParameters map[string]string, stream *model.StreamSender) ([]model.Resource, error) {
28+
ctx = WithTriggerType(ctx, triggerType)
1829

1930
if cfg.PatToken == "" {
2031
return nil, fmt.Errorf("'token' must be set in the connection configuration. Edit your connection configuration file and then restart Steampipe")
@@ -32,7 +43,7 @@ func DescribeByGithub(describe func(context.Context, describers.GitHubClient, st
3243
restClient := github.NewClient(tc)
3344
graphQLClient := githubv4.NewClient(tc)
3445

35-
client := describers.GitHubClient{
46+
client := GitHubClient{
3647
RestClient: restClient,
3748
GraphQLClient: graphQLClient,
3849
Token: cfg.PatToken,
@@ -49,9 +60,9 @@ func DescribeByGithub(describe func(context.Context, describers.GitHubClient, st
4960
}
5061
}
5162

52-
func DescribeSingleByRepo(describe func(context.Context, describers.GitHubClient, string, string, string, *model.StreamSender) (*model.Resource, error)) model.SingleResourceDescriber {
53-
return func(ctx context.Context, cfg global.IntegrationCredentials, triggerType enums.DescribeTriggerType, additionalParameters map[string]string, resourceID string, stream *model.StreamSender) (*model.Resource, error) {
54-
ctx = describers.WithTriggerType(ctx, triggerType)
63+
func DescribeSingleByRepo(describe func(context.Context, GitHubClient, string, string, string, *model.StreamSender) (*model.Resource, error)) model.SingleResourceDescriber {
64+
return func(ctx context.Context, cfg model.IntegrationCredentials, triggerType enums.DescribeTriggerType, additionalParameters map[string]string, resourceID string, stream *model.StreamSender) (*model.Resource, error) {
65+
ctx = WithTriggerType(ctx, triggerType)
5566

5667
if cfg.PatToken == "" {
5768
return nil, fmt.Errorf("'token' must be set in the connection configuration. Edit your connection configuration file and then restart Steampipe")
@@ -69,7 +80,7 @@ func DescribeSingleByRepo(describe func(context.Context, describers.GitHubClient
6980
restClient := github.NewClient(tc)
7081
graphQLClient := githubv4.NewClient(tc)
7182

72-
client := describers.GitHubClient{
83+
client := GitHubClient{
7384
RestClient: restClient,
7485
GraphQLClient: graphQLClient,
7586
}

discovery/provider/describers/action_artifact.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package describers
22

33
import (
44
"context"
5+
"strconv"
6+
"time"
7+
58
"github.com/google/go-github/v55/github"
69
"github.com/opengovern/og-describer-github/discovery/pkg/models"
710
model "github.com/opengovern/og-describer-github/discovery/provider"
8-
"strconv"
9-
"time"
1011
)
1112

12-
func GetAllArtifacts(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
13+
func GetAllArtifacts(ctx context.Context, githubClient model.GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
1314
client := githubClient.RestClient
1415
owner := organizationName
1516
repositories, err := getRepositories(ctx, client, owner)
@@ -27,7 +28,7 @@ func GetAllArtifacts(ctx context.Context, githubClient GitHubClient, organizatio
2728
return values, nil
2829
}
2930

30-
func GetRepositoryArtifacts(ctx context.Context, githubClient GitHubClient, stream *models.StreamSender, owner, repo string) ([]models.Resource, error) {
31+
func GetRepositoryArtifacts(ctx context.Context, githubClient model.GitHubClient, stream *models.StreamSender, owner, repo string) ([]models.Resource, error) {
3132
client := githubClient.RestClient
3233
opts := &github.ListOptions{PerPage: maxPagesCount}
3334
repoFullName := formRepositoryFullName(owner, repo)
@@ -71,7 +72,7 @@ func GetRepositoryArtifacts(ctx context.Context, githubClient GitHubClient, stre
7172
return values, nil
7273
}
7374

74-
func GetArtifact(ctx context.Context, githubClient GitHubClient, organizationName string, repositoryName string, resourceID string, stream *models.StreamSender) (*models.Resource, error) {
75+
func GetArtifact(ctx context.Context, githubClient model.GitHubClient, organizationName string, repositoryName string, resourceID string, stream *models.StreamSender) (*models.Resource, error) {
7576
client := githubClient.RestClient
7677
artifactID, err := strconv.ParseInt(resourceID, 10, 64)
7778
if err != nil {

discovery/provider/describers/action_repository_runner.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package describers
22

33
import (
44
"context"
5+
"strconv"
6+
57
"github.com/google/go-github/v55/github"
68
"github.com/opengovern/og-describer-github/discovery/pkg/models"
79
model "github.com/opengovern/og-describer-github/discovery/provider"
8-
"strconv"
910
)
1011

11-
func GetAllRunners(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
12+
func GetAllRunners(ctx context.Context, githubClient model.GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
1213
client := githubClient.RestClient
1314
owner := organizationName
1415
repositories, err := getRepositories(ctx, client, owner)
@@ -26,7 +27,7 @@ func GetAllRunners(ctx context.Context, githubClient GitHubClient, organizationN
2627
return values, nil
2728
}
2829

29-
func GetRepositoryRunners(ctx context.Context, githubClient GitHubClient, stream *models.StreamSender, owner, repo string) ([]models.Resource, error) {
30+
func GetRepositoryRunners(ctx context.Context, githubClient model.GitHubClient, stream *models.StreamSender, owner, repo string) ([]models.Resource, error) {
3031
client := githubClient.RestClient
3132
opts := &github.ListOptions{PerPage: maxPagesCount}
3233
repoFullName := formRepositoryFullName(owner, repo)
@@ -74,7 +75,7 @@ func GetRepositoryRunners(ctx context.Context, githubClient GitHubClient, stream
7475
return values, nil
7576
}
7677

77-
func GetActionRunner(ctx context.Context, githubClient GitHubClient, organizationName string, repositoryName string, resourceID string, stream *models.StreamSender) (*models.Resource, error) {
78+
func GetActionRunner(ctx context.Context, githubClient model.GitHubClient, organizationName string, repositoryName string, resourceID string, stream *models.StreamSender) (*models.Resource, error) {
7879
client := githubClient.RestClient
7980
runnerID, err := strconv.ParseInt(resourceID, 10, 64)
8081
if err != nil {

discovery/provider/describers/action_repository_secret.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package describers
33
import (
44
"context"
55
"fmt"
6+
"time"
7+
68
"github.com/google/go-github/v55/github"
79
"github.com/opengovern/og-describer-github/discovery/pkg/models"
810
model "github.com/opengovern/og-describer-github/discovery/provider"
9-
"time"
1011
)
1112

12-
func GetAllSecrets(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
13+
func GetAllSecrets(ctx context.Context, githubClient model.GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
1314
client := githubClient.RestClient
1415
owner := organizationName
1516
repositories, err := getRepositories(ctx, client, owner)
@@ -27,7 +28,7 @@ func GetAllSecrets(ctx context.Context, githubClient GitHubClient, organizationN
2728
return values, nil
2829
}
2930

30-
func GetRepositorySecrets(ctx context.Context, githubClient GitHubClient, stream *models.StreamSender, owner, repo string) ([]models.Resource, error) {
31+
func GetRepositorySecrets(ctx context.Context, githubClient model.GitHubClient, stream *models.StreamSender, owner, repo string) ([]models.Resource, error) {
3132
client := githubClient.RestClient
3233
opts := &github.ListOptions{PerPage: maxPagesCount}
3334
repoFullName := formRepositoryFullName(owner, repo)
@@ -69,7 +70,7 @@ func GetRepositorySecrets(ctx context.Context, githubClient GitHubClient, stream
6970
return values, nil
7071
}
7172

72-
func GetRepoActionSecret(ctx context.Context, githubClient GitHubClient, organizationName string, repositoryName string, resourceID string, stream *models.StreamSender) (*models.Resource, error) {
73+
func GetRepoActionSecret(ctx context.Context, githubClient model.GitHubClient, organizationName string, repositoryName string, resourceID string, stream *models.StreamSender) (*models.Resource, error) {
7374
client := githubClient.RestClient
7475
repoFullName := formRepositoryFullName(organizationName, repositoryName)
7576
secret, _, err := client.Actions.GetRepoSecret(ctx, organizationName, repositoryName, resourceID)

discovery/provider/describers/action_workflow_run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
resilientbridge "github.com/opengovern/resilient-bridge"
1515
)
1616

17-
func GetAllWorkflowRuns(ctx context.Context, githubClient GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
17+
func GetAllWorkflowRuns(ctx context.Context, githubClient model.GitHubClient, organizationName string, stream *models.StreamSender) ([]models.Resource, error) {
1818
// Retrieve only active (non-archived, non-disabled) repositories
1919
repositories, err := GetRepositoryListWithOptions(ctx, githubClient, organizationName, nil, true, true)
2020
if err != nil {
@@ -204,7 +204,7 @@ func GetRepositoryWorkflowRuns(ctx context.Context, sdk *resilientbridge.Resilie
204204
return values, nil
205205
}
206206

207-
//func GetRepoWorkflowRun(ctx context.Context, client GitHubClient, organizationName string, repo string, resourceID string, stream *models.StreamSender) (*models.Resource, error) {
207+
//func GetRepoWorkflowRun(ctx context.Context, client model.GitHubClient, organizationName string, repo string, resourceID string, stream *models.StreamSender) (*models.Resource, error) {
208208
// owner := organizationName
209209
// workflowRunID, err := strconv.ParseInt(resourceID, 10, 64)
210210
// if err != nil {

discovery/provider/describers/artifact_dockerfile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const MAX_DOCKERFILE_LEN = 500
2929
// streamed immediately upon processing, and also added to the final slice.
3030
func ListArtifactDockerFiles(
3131
ctx context.Context,
32-
githubClient GitHubClient,
32+
githubClient model.GitHubClient,
3333
organizationName string,
3434
stream *models.StreamSender,
3535
) ([]models.Resource, error) {
@@ -136,7 +136,7 @@ func ListArtifactDockerFiles(
136136
// If parse fails, we store an empty Images slice.
137137
func GetDockerfile(
138138
ctx context.Context,
139-
githubClient GitHubClient,
139+
githubClient model.GitHubClient,
140140
organizationName, repoFullName, filePath string,
141141
stream *models.StreamSender,
142142
) (*models.Resource, error) {

0 commit comments

Comments
 (0)