Skip to content

Commit

Permalink
aws: Add iam.GetRole (#3015)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolujimoh authored May 17, 2024
1 parent 3bc4eb7 commit b42e681
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions backend/mock/service/awsmock/awsmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ func (s *svc) S3GetAccessPointPolicy(ctx context.Context, account, region, acces
}, nil
}

func (s *svc) GetIAMRole(ctx context.Context, account, region, roleName string) (*iam.GetRoleOutput, error) {
return &iam.GetRoleOutput{
Role: &iamtypes.Role{
RoleName: aws.String(roleName),
Arn: aws.String(fmt.Sprintf("arn:aws:iam::%s:role/%s", account, roleName)),
},
}, nil
}

func (s *svc) GetDirectClient(account string, region string) (clutchawsclient.DirectClient, error) {
panic("implement me")
}
Expand Down
1 change: 1 addition & 0 deletions backend/service/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ type Client interface {
GetCallerIdentity(ctx context.Context, account, region string) (*sts.GetCallerIdentityOutput, error)

SimulateCustomPolicy(ctx context.Context, account, region string, customPolicySimulatorParams *iam.SimulateCustomPolicyInput) (*iam.SimulateCustomPolicyOutput, error)
GetIAMRole(ctx context.Context, account, region, roleName string) (*iam.GetRoleOutput, error)

Accounts() []string
AccountsAndRegions() map[string][]string
Expand Down
16 changes: 16 additions & 0 deletions backend/service/aws/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,19 @@ func (c *client) SimulateCustomPolicy(ctx context.Context, account, region strin

return cl.iam.SimulateCustomPolicy(ctx, customPolicySimulatorParams)
}

func (c *client) GetIAMRole(
ctx context.Context,
account,
region,
roleName string,
) (*iam.GetRoleOutput, error) {
cl, err := c.getAccountRegionClient(account, region)
if err != nil {
return nil, err
}

return cl.iam.GetRole(ctx, &iam.GetRoleInput{
RoleName: &roleName,
})
}
9 changes: 9 additions & 0 deletions backend/service/aws/iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
type mockIAM struct {
getSimulationResultsErr error
getSimulationResults *iam.SimulateCustomPolicyOutput
getGetIAMRoleResultsErr error
getGetIAMRoleResults *iam.GetRoleOutput
}

func TestIAMSimulateCustomPolicy(t *testing.T) {
Expand Down Expand Up @@ -104,3 +106,10 @@ func (m *mockIAM) SimulateCustomPolicy(ctx context.Context, params *iam.Simulate
}
return m.getSimulationResults, nil
}

func (m *mockIAM) GetRole(ctx context.Context, params *iam.GetRoleInput, optFns ...func(*iam.Options)) (*iam.GetRoleOutput, error) {
if m.getGetIAMRoleResultsErr != nil {
return nil, m.getGetIAMRoleResultsErr
}
return m.getGetIAMRoleResults, nil
}
1 change: 1 addition & 0 deletions backend/service/aws/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type stsClient interface {

type iamClient interface {
SimulateCustomPolicy(ctx context.Context, params *iam.SimulateCustomPolicyInput, optFns ...func(*iam.Options)) (*iam.SimulateCustomPolicyOutput, error)
GetRole(ctx context.Context, params *iam.GetRoleInput, optFns ...func(options *iam.Options)) (*iam.GetRoleOutput, error)
}

type kinesisClient interface {
Expand Down

0 comments on commit b42e681

Please sign in to comment.