diff --git a/api/integrations_aws.go b/api/integrations_aws.go index 95f6c03f4..dac9b6658 100644 --- a/api/integrations_aws.go +++ b/api/integrations_aws.go @@ -176,14 +176,14 @@ type AwsIntegrationData struct { AccountMappingFile string `json:"ACCOUNT_MAPPING_FILE,omitempty" mapstructure:"ACCOUNT_MAPPING_FILE"` } -func (aws *AwsIntegrationData) EncodeAccountMappingFile(mapping string) { - encodedMappings := base64.StdEncoding.EncodeToString([]byte(mapping)) +func (aws *AwsIntegrationData) EncodeAccountMappingFile(mapping []byte) { + encodedMappings := base64.StdEncoding.EncodeToString(mapping) aws.AccountMappingFile = fmt.Sprintf("data:application/json;name=i.json;base64,%s", encodedMappings) } -func (aws *AwsIntegrationData) DecodeAccountMappingFile() (string, error) { +func (aws *AwsIntegrationData) DecodeAccountMappingFile() ([]byte, error) { if len(aws.AccountMappingFile) == 0 { - return "", nil + return []byte{}, nil } var ( @@ -191,10 +191,10 @@ func (aws *AwsIntegrationData) DecodeAccountMappingFile() (string, error) { raw, err = base64.StdEncoding.DecodeString(b64[1]) ) if err != nil { - return "", err + return []byte{}, err } - return string(raw), nil + return raw, nil } type AwsIntegrationCreds struct { diff --git a/api/integrations_aws_test.go b/api/integrations_aws_test.go index 4272fbde4..5407ec49f 100644 --- a/api/integrations_aws_test.go +++ b/api/integrations_aws_test.go @@ -44,7 +44,7 @@ func TestIntegrationsNewAwsCfgIntegration(t *testing.T) { } func TestIntegrationsNewAwsCfgIntegrationWithCustomTemplateFile(t *testing.T) { - accountMappingJSON := `{ + accountMappingJSON := []byte(`{ "defaultLaceworkAccountAws": "lw_account_1", "integration_mappings": { "lw_account_2": { @@ -60,7 +60,7 @@ func TestIntegrationsNewAwsCfgIntegrationWithCustomTemplateFile(t *testing.T) { ] } } - }` + }`) awsData := api.AwsIntegrationData{ Credentials: api.AwsIntegrationCreds{ RoleArn: "arn:foo:bar", @@ -76,16 +76,16 @@ func TestIntegrationsNewAwsCfgIntegrationWithCustomTemplateFile(t *testing.T) { "data:application/json;name=i.json;base64,", "check the custom_template_file encoder", ) - accountMappingString, err := subject.Data.DecodeAccountMappingFile() + accountMapping, err := subject.Data.DecodeAccountMappingFile() assert.Nil(t, err) - assert.Equal(t, accountMappingJSON, accountMappingString) + assert.Equal(t, accountMappingJSON, accountMapping) // When there is no custom account mapping file, this function should // return an empty string to match the pattern subject.Data.AccountMappingFile = "" - accountMappingString, err = subject.Data.DecodeAccountMappingFile() + accountMapping, err = subject.Data.DecodeAccountMappingFile() assert.Nil(t, err) - assert.Equal(t, "", accountMappingString) + assert.Empty(t, accountMapping) } diff --git a/cli/cmd/integration.go b/cli/cmd/integration.go index 7c5d641b0..d3fa10f48 100644 --- a/cli/cmd/integration.go +++ b/cli/cmd/integration.go @@ -371,7 +371,25 @@ func reflectIntegrationData(raw api.RawIntegration) [][]string { []string{"EXTERNAL ID", iData.Credentials.ExternalID}, } if iData.QueueUrl != "" { - return append(out, []string{"QUEUE URL", iData.QueueUrl}) + out = append(out, []string{"QUEUE URL", iData.QueueUrl}) + } + + accountMapping, err := iData.DecodeAccountMappingFile() + if err != nil { + cli.Log.Debugw("unable to decode account mapping file", + "integration_type", raw.Type, + "raw_data", iData.AccountMappingFile, + "error", err, + ) + } + + if len(accountMapping) != 0 { + // @afiune should we disable the colors here? + accountMappingJSON, err := cli.FormatJSONString(string(accountMapping)) + if err != nil { + accountMappingJSON = string(accountMapping) + } + out = append(out, []string{"ACCOUNT MAPPING FILE", accountMappingJSON}) } return out @@ -530,6 +548,12 @@ func reflectIntegrationData(raw api.RawIntegration) [][]string { "error", err, ) } + + // @afiune should we disable the colors here? + tmplStrPretty, err := cli.FormatJSONString(templateString) + if err != nil { + tmplStrPretty = templateString + } out := [][]string{ []string{"JIRA INTEGRATION TYPE", iData.JiraType}, []string{"JIRA URL", iData.JiraUrl}, @@ -537,7 +561,7 @@ func reflectIntegrationData(raw api.RawIntegration) [][]string { []string{"USERNAME", iData.Username}, []string{"ISSUE TYPE", iData.IssueType}, []string{"ISSUE GROUPING", iData.IssueGrouping}, - []string{"CUSTOM TEMPLATE FILE", templateString}, + []string{"CUSTOM TEMPLATE FILE", tmplStrPretty}, } return out diff --git a/cli/cmd/integration_aws.go b/cli/cmd/integration_aws.go index 1e109cd63..11d6b066a 100644 --- a/cli/cmd/integration_aws.go +++ b/cli/cmd/integration_aws.go @@ -137,7 +137,7 @@ func createAwsCloudTrailIntegration() error { return err } - aws.EncodeAccountMappingFile(content) + aws.EncodeAccountMappingFile([]byte(content)) } awsCT := api.NewAwsCloudTrailIntegration(answers.Name, aws)