Skip to content

Commit

Permalink
golint
Browse files Browse the repository at this point in the history
  • Loading branch information
christophetd committed May 31, 2023
1 parent 287cfc0 commit ece6404
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ func doFindRoleRelationshipsCommand(targetCluster string) error {
if outputFile != "" {
log.Println("Writing " + strings.ToUpper(outputFormat) + " output to " + outputFile)
return os.WriteFile(outputFile, []byte(output), 0644)
} else {
print(output)
}

print(output)
return nil
}

Expand Down Expand Up @@ -128,18 +127,17 @@ func getTextOutput(resolver *role_relationships.EKSCluster) (string, error) {
}
if !found {
return "No service accounts found that can assume AWS roles", nil
} else {
return t.Render(), nil
}
return t.Render(), nil
}

type Vertex struct {
Id int
ID int
Label string
}

func (v *Vertex) ID() int {
return v.Id
func (v *Vertex) GetID() int {
return v.ID
}
func getDotOutput(resolver *role_relationships.EKSCluster) (string, error) {
graphAst, _ := gographviz.ParseString(`digraph G { }`)
Expand Down
4 changes: 2 additions & 2 deletions internal/aws/iam_evaluation/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (m *Policy) Authorize(context *AuthorizationContext) *AuthorizationResult {

if willAllow {
return &AuthorizationResultAllow
} else {
return &AuthorizationResultDeny // implicit deny
}

return &AuthorizationResultDeny // implicit deny
}
11 changes: 5 additions & 6 deletions internal/aws/iam_evaluation/policy_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ParseRoleTrustPolicy(policy string) (*Policy, error) {
}
resultPolicy.Statements = append(resultPolicy.Statements, statement)
}

return &resultPolicy, nil
}

Expand Down Expand Up @@ -107,9 +107,8 @@ func parsePrincipals(principals interface{}) ([]*Principal, error) {
case string:
if principals == "*" {
return []*Principal{{Type: PrincipalTypeUnknown, ID: "*"}}, nil
} else {
return nil, fmt.Errorf("invalid principal: %s", principals)
}
return nil, fmt.Errorf("invalid principal: %s", principals)
case map[string]interface{}:
results := []*Principal{}
for principalType, principalValue := range principals {
Expand All @@ -125,7 +124,7 @@ func parsePrincipals(principals interface{}) ([]*Principal, error) {
}
}

func parseSinglePrincipal(rawPrincipalType string, principalId interface{}) ([]*Principal, error) {
func parseSinglePrincipal(rawPrincipalType string, principalID interface{}) ([]*Principal, error) {
types := map[string]PrincipalType{
"aws": PrincipalTypeAWS,
"federated": PrincipalTypeFederated,
Expand All @@ -136,9 +135,9 @@ func parseSinglePrincipal(rawPrincipalType string, principalId interface{}) ([]*
if !ok {
return nil, fmt.Errorf("invalid principal type: %s", rawPrincipalType)
}
values, err := ensureStringArray(principalId)
values, err := ensureStringArray(principalID)
if err != nil {
return nil, fmt.Errorf("invalid principal value: %v", principalId)
return nil, fmt.Errorf("invalid principal value: %v", principalID)
}

principals := []*Principal{}
Expand Down
10 changes: 5 additions & 5 deletions internal/aws/iam_evaluation/policy_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func Test_ensureStringArray(t *testing.T) {
func Test_parseSinglePrincipal(t *testing.T) {
type args struct {
rawPrincipalType string
principalId interface{}
principalID interface{}
}
tests := []struct {
name string
Expand All @@ -157,15 +157,15 @@ func Test_parseSinglePrincipal(t *testing.T) {
name: "parse string principal",
args: args{
rawPrincipalType: "aws",
principalId: "foo",
principalID: "foo",
},
want: []*Principal{{Type: PrincipalTypeAWS, ID: "foo"}},
},
{
name: "parse array principal",
args: args{
rawPrincipalType: "federated",
principalId: []string{"foo", "bar"},
principalID: []string{"foo", "bar"},
},
want: []*Principal{
{Type: PrincipalTypeFederated, ID: "foo"},
Expand All @@ -176,14 +176,14 @@ func Test_parseSinglePrincipal(t *testing.T) {
name: "parse invalid principal",
args: args{
rawPrincipalType: "IDoNotExist",
principalId: "foo",
principalID: "foo",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseSinglePrincipal(tt.args.rawPrincipalType, tt.args.principalId)
got, err := parseSinglePrincipal(tt.args.rawPrincipalType, tt.args.principalID)
if (err != nil) != tt.wantErr {
t.Errorf("parseSinglePrincipal() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ func (m *ImdsTester) TestImdsAccessible() (*ImdsTestResult, error) {
}
if strings.Contains(podLogs, "Failed to connect") {
return &ImdsTestResult{IsImdsAccessible: false}, nil
} else {
return &ImdsTestResult{IsImdsAccessible: true, NodeRoleName: podLogs}, nil
}
return &ImdsTestResult{IsImdsAccessible: true, NodeRoleName: podLogs}, nil
}

func (m *ImdsTester) handleCtrlC() {
Expand Down

0 comments on commit ece6404

Please sign in to comment.