Skip to content

Commit

Permalink
go fumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWoolfenden committed Jan 24, 2025
1 parent cdee658 commit b5d2224
Show file tree
Hide file tree
Showing 23 changed files with 1,373 additions and 1,371 deletions.
2,205 changes: 1,099 additions & 1,106 deletions src/aws.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/aws_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ var tFLookupDataAWS = map[string]interface{}{
"aws_lb_listener_rule": dataAwsLbListenerRule,
"aws_spot_datafeed_subscription": dataAwsSpotDatafeedSubscription,
"aws_servicecatalogappregistry_attribute_group": dataServicecatalogappregistryAttributeGroup,
"aws_servicecatalogappregistry_attribute_group_associations": dataServicecatalogappregistryAttributeGroupAssociations,
"aws_servicecatalogappregistry_attribute_group_associations": dataServicecatalogappregistryAttributeGroupAssociations, //nolint:lll
"aws_route53_records": dataAwsRoute53Records,
"aws_cloudwatch_event_buses": dataAwsCloudwatchEventBuses,
"aws_ecs_clusters": dataAwsEcsClusters,
Expand All @@ -604,7 +604,7 @@ func GetAWSDataPermissions(result ResourceV2) ([]string, error) {
return Permissions, err
}

// AwsDataLookup is a map to connect resource name to an object map
// AwsDataLookup is a map to connect resource name to an object map.
func AwsDataLookup(find string) interface{} {
return tFLookupDataAWS[find]
}
6 changes: 4 additions & 2 deletions src/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ func TestGetAWSPermissions(t *testing.T) {
"s3:GetEncryptionConfiguration",
"s3:GetBucketRequestPayment",
"s3:GetBucketCORS",
"s3:DeleteBucket"},
"s3:DeleteBucket",
},
wantErr: false,
},
{
Expand Down Expand Up @@ -266,7 +267,8 @@ func TestGetAWSResourcePermissions(t *testing.T) {
"s3:GetEncryptionConfiguration",
"s3:GetBucketRequestPayment",
"s3:GetBucketCORS",
"s3:DeleteBucket"},
"s3:DeleteBucket",
},
wantErr: false,
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/azure_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func GetAZUREDataPermissions(result ResourceV2) ([]string, error) {
}

func AzureDataLookup(name string) interface{} {
var TFLookupAzureData = map[string]interface{}{
TFLookupAzureData := map[string]interface{}{
"azurerm_app_service": dataAzurermAppService,
"azurerm_app_service_certificate": dataAzurermAppServiceCertificate,
"azurerm_app_service_certificate_order": dataAzurermAppServiceCertificateOrder,
Expand Down
1 change: 0 additions & 1 deletion src/azure_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func AZUREPolicy(permissions []string, policyName string) (string, error) {
var output bytes.Buffer

tmpl, err := template.New("test").Parse(string(policyAZURETemplate))

if err != nil {
return "", &templateParseError{err}
}
Expand Down
19 changes: 9 additions & 10 deletions src/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

// Compare IAC codebase to AWS policy.
func Compare(directory string, arn string, init bool) (bool, error) {

valid, err := inputValidationCompare(directory, arn)
if err != nil {
return valid, &inputValidationError{err}
Expand All @@ -28,33 +27,28 @@ func Compare(directory string, arn string, init bool) (bool, error) {
defer cancel()

cfg, err := config.LoadDefaultConfig(ctx)

if err != nil {
return false, &awsConfigError{err}
}

client := iam.NewFromConfig(cfg)

version, err := GetVersion(client, arn)

if err != nil {
return false, &getVersionError{err}
}

policy, err := GetPolicyVersion(client, arn, *version)

if err != nil {
return false, &getPolicyVersionError{err}
}

iacPolicy, err := MakePolicy(directory, nil, init, false)

if err != nil {
return false, &getIAMVersionError{err}
}

sorted, err := SortActions(iacPolicy.AWS.JSONOut)

if err != nil {
return false, &sortActionsError{iacPolicy.AWS.JSONOut}
}
Expand Down Expand Up @@ -85,13 +79,20 @@ func inputValidationCompare(directory string, arn string) (bool, error) {
return false, nil
}

type compareDifferenceError struct {
err error
}

func (m *compareDifferenceError) Error() string {
return fmt.Sprintf("compare difference failed: %v", m.err)
}

// CompareIAMPolicy takes two IAM policies and compares.
func CompareIAMPolicy(policy string, oldPolicy string) (bool, error) {
differ := diff.New()
compare, err := differ.Compare([]byte(policy), []byte(oldPolicy))

if err != nil {
return false, err
return false, &compareDifferenceError{err}
}

if compare.Modified() {
Expand All @@ -112,7 +113,6 @@ func (m *formatterError) Error() string {
func ShowDifferences(policy string, compare diff.Diff) (bool, error) {
var aJSON map[string]interface{}
err := json.Unmarshal([]byte(policy), &aJSON)

if err != nil {
return false, &marshallPolicyError{err}
}
Expand All @@ -124,7 +124,6 @@ func ShowDifferences(policy string, compare diff.Diff) (bool, error) {

myFormatter := formatter.NewAsciiFormatter(aJSON, myConfig)
diffString, err := myFormatter.Format(compare)

if err != nil {
return false, &formatterError{err}
}
Expand Down
3 changes: 0 additions & 3 deletions src/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func coverageAWS() error {

target = Prepend + target
err := os.WriteFile("aws.md", []byte(target), 0o700)

if err != nil {
return &fileWriteError{err}
}
Expand Down Expand Up @@ -89,7 +88,6 @@ func coverageAzure() error {

target = Prepend + target
err := os.WriteFile("azure.md", []byte(target), 0o700)

if err != nil {
return &fileWriteError{err}
}
Expand Down Expand Up @@ -124,7 +122,6 @@ func coverageGcp() error {

target = Prepend + target
err := os.WriteFile("google.md", []byte(target), 0o700)

if err != nil {
return &fileWriteError{}
}
Expand Down
10 changes: 9 additions & 1 deletion src/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ func getAWSCredentials(iamRole string, region string) (*sts.AssumeRoleOutput, er
return result, nil
}

type getAWSCredentialsError struct {
err error
}

func (e getAWSCredentialsError) Error() string {
return fmt.Sprintf("failed to get AWS credentials: %v", e.err)
}

func setAWSAuth(iamRole string, region string) error {
credentials, err := getAWSCredentials(iamRole, region)
if err != nil {
return err
return &getAWSCredentialsError{err}
}

_ = os.Setenv("AWS_ACCESS_KEY_ID", *credentials.Credentials.AccessKeyId)
Expand Down
2 changes: 0 additions & 2 deletions src/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (e *fileStringEmptyError) Error() string {

// GetResources retrieves all the resources in a tf file.
func GetResources(file string, dirName string) ([]ResourceV2, error) {

var Resources []ResourceV2

if file == "" {
Expand Down Expand Up @@ -123,7 +122,6 @@ func GetResourceBlocks(file string) (*hclsyntax.Body, error) {
}

src, err := os.ReadFile(temp)

if err != nil {
return nil, fmt.Errorf("failed to read file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func Test_getLocalModules(t *testing.T) {
}

for _, tt := range tests {
//t.Parallel()
// t.Parallel()
t.Run(tt.name, func(t *testing.T) {
got, err := pike.GetLocalModules(tt.args.block, tt.args.dirName)
if (err != nil) != tt.wantErr {
Expand Down
Loading

0 comments on commit b5d2224

Please sign in to comment.