@@ -2,19 +2,30 @@ package provider
22
33import (
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 }
0 commit comments