From f285f85a33847ba92f2c070526597deb43c0e2bb Mon Sep 17 00:00:00 2001 From: Anil Chandra <120965339+acx1729@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:30:52 -0500 Subject: [PATCH] updating for github repository --- command/cmd/describer.go | 19 ++++++++++++++++--- provider/describer/repository.go | 19 +++++++++++++++++-- provider/resource_types.go | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/command/cmd/describer.go b/command/cmd/describer.go index c0252d7f..ff1a3a76 100644 --- a/command/cmd/describer.go +++ b/command/cmd/describer.go @@ -1,6 +1,8 @@ +// describer.go package cmd import ( + "context" "encoding/json" "fmt" "os" @@ -18,7 +20,6 @@ import ( "github.com/opengovern/og-util/pkg/es" "github.com/spf13/cobra" "go.uber.org/zap" - "golang.org/x/net/context" ) var ( @@ -31,6 +32,18 @@ var describerCmd = &cobra.Command{ Use: "describer", Short: "A brief description of your command", RunE: func(cmd *cobra.Command, args []string) error { + // Environment takes priority + orgEnv := os.Getenv("GITHUB_ORG") + patEnv := os.Getenv("GITHUB_PAT") + + if orgEnv != "" { + OrganizationName = orgEnv + } + + if patEnv != "" { + PatToken = patEnv + } + // Open the output file file, err := os.Create(outputFile) if err != nil { @@ -47,7 +60,7 @@ var describerCmd = &cobra.Command{ IntegrationType: configs.IntegrationTypeLower, CipherText: "", IntegrationLabels: map[string]string{ - "OrganizationName": "opengovern", + "OrganizationName": OrganizationName, }, IntegrationAnnotations: nil, } @@ -56,7 +69,7 @@ var describerCmd = &cobra.Command{ logger, _ := zap.NewProduction() creds, err := provider.AccountCredentialsFromMap(map[string]any{ - "pat_token": "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", + "pat_token": PatToken, }) if err != nil { return fmt.Errorf(" account credentials: %w", err) diff --git a/provider/describer/repository.go b/provider/describer/repository.go index 4fc085f5..6776550b 100644 --- a/provider/describer/repository.go +++ b/provider/describer/repository.go @@ -131,8 +131,15 @@ func GetRepositoryListWithOptions( return allResources, nil } -// GetRepositoryDetail returns details for a given repo -func GetRepositoryDetail(ctx context.Context, githubClient GitHubClient, organizationName, repositoryName string) (*models.Resource, error) { +// GetRepository returns details for a given repo +func GetRepository( + ctx context.Context, + githubClient GitHubClient, + organizationName string, + repositoryName string, + resourceID string, + stream *models.StreamSender, +) (*models.Resource, error) { sdk := resilientbridge.NewResilientBridge() sdk.RegisterProvider("github", adapters.NewGitHubAdapter(githubClient.Token), &resilientbridge.ProviderConfig{ UseProviderLimits: true, @@ -164,6 +171,14 @@ func GetRepositoryDetail(ctx context.Context, githubClient GitHubClient, organiz Value: finalDetail, }, } + + // If a stream is provided, send the resource through the stream + if stream != nil { + if err := (*stream)(value); err != nil { + return nil, err + } + } + return &value, nil } diff --git a/provider/resource_types.go b/provider/resource_types.go index e999b8f6..1772f30f 100644 --- a/provider/resource_types.go +++ b/provider/resource_types.go @@ -222,7 +222,7 @@ var ResourceTypes = map[string]model.ResourceType{ Annotations: map[string]string{}, ListDescriber: DescribeByGithub(describer.GetRepositoryList), - GetDescriber: DescribeSingleByRepo(describer.GetRepositoryDetail), + GetDescriber: DescribeSingleByRepo(describer.GetRepository), }, "Github/Repository/Collaborator": {