From 9272a823707f1d7d22232bdb2c07538d6cd0a4e0 Mon Sep 17 00:00:00 2001 From: Adnan Gulegulzar Date: Tue, 17 Sep 2024 14:30:25 -0400 Subject: [PATCH] fix: add shorthand integration --- README.md | 12 ++++++++++++ cmd/get/compliance_summary_for_integration.go | 11 +++++++++-- cmd/run/compliance.go | 4 ++++ makefile | 6 +++++- pkg/config/config.go | 10 ++++++---- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f0cd75d..0067fcd 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,18 @@ Non-interactive mode: checktl configure --api-key <> --app-endpoint https://path.to.app.endpoint --output json ``` +--- +**_NOTE:_** Pre-defined integartions can be manually added to the configuration file, by updating the `integrations` field inside `$HOME/.checkctl/config.json`. + +config.json: +``` +{ + ... + "integrations": {"acc3":"id_name=account3"} +} +``` + +--- ## get ### benchmarks diff --git a/cmd/get/compliance_summary_for_integration.go b/cmd/get/compliance_summary_for_integration.go index b92b932..b663315 100644 --- a/cmd/get/compliance_summary_for_integration.go +++ b/cmd/get/compliance_summary_for_integration.go @@ -3,13 +3,14 @@ package get import ( "encoding/json" "fmt" + "io" + "net/http" + "github.com/adorigi/checkctl/pkg/config" "github.com/adorigi/checkctl/pkg/request" "github.com/adorigi/checkctl/pkg/types" "github.com/adorigi/checkctl/pkg/utils" "github.com/spf13/cobra" - "io" - "net/http" ) // complianceSummaryForIntegrationCmd represents the benchmarks command @@ -41,6 +42,12 @@ var complianceSummaryForIntegrationCmd = &cobra.Command{ Integration info in the form 'integration=AWS,id=123,id_name=name'`) return nil } + + if _, ok := configuration.Integrations[integrationStr]; ok { + fmt.Printf("Found stored integration %s", integrationStr) + integrationStr = configuration.Integrations[integrationStr] + } + integration := types.ParseIntegrationInfo(integrationStr) requestPayload := types.ComplianceSummaryOfIntegrationRequest{ diff --git a/cmd/run/compliance.go b/cmd/run/compliance.go index 3ebc939..2d79e8c 100644 --- a/cmd/run/compliance.go +++ b/cmd/run/compliance.go @@ -39,6 +39,10 @@ var complianceCmd = &cobra.Command{ var integrations []types.IntegrationFilterInfo for _, integrationStr := range integrationsStr { + if _, ok := configuration.Integrations[integrationStr]; ok { + fmt.Printf("Found stored integration %s", integrationStr) + integrationStr = configuration.Integrations[integrationStr] + } integrations = append(integrations, types.ParseIntegrationInfo(integrationStr)) } req := types.RunBenchmarkByIdRequest{ diff --git a/makefile b/makefile index 3139c18..21f197c 100644 --- a/makefile +++ b/makefile @@ -6,4 +6,8 @@ build: clean env GOOS=linux GOARCH=arm go build -o bin/checkctl-linux goreleaser: - REPOSITORY_OWNER=local REPOSITORY_NAME=local goreleaser build --snapshot \ No newline at end of file + REPOSITORY_OWNER=local REPOSITORY_NAME=local goreleaser build --snapshot + +install: + rm $(GOPATH)/bin/checkctl + go install \ No newline at end of file diff --git a/pkg/config/config.go b/pkg/config/config.go index fb5d9bb..c5e262b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,10 +1,11 @@ package config type Configuration struct { - OutputFormat string `json:"output_format"` - ApiEndpoint string `json:"api_endpoint"` - UtilizationAnalyzerEndpoint string `json:"utilization_analyzer_endpoint"` - ApiKey string `json:"api_key"` + OutputFormat string `json:"output_format"` + ApiEndpoint string `json:"api_endpoint"` + UtilizationAnalyzerEndpoint string `json:"utilization_analyzer_endpoint"` + ApiKey string `json:"api_key"` + Integrations map[string]string `json:"integrations"` } func NewConfiguration( @@ -18,5 +19,6 @@ func NewConfiguration( ApiEndpoint: apiEndpoint, UtilizationAnalyzerEndpoint: utilizationAnalyzerEndpoint, ApiKey: apiKey, + Integrations: map[string]string{}, } }