Skip to content

Commit

Permalink
Merge pull request #54 from yuwang-RH/new0611
Browse files Browse the repository at this point in the history
OCM-8693 | test: Add tag/untag role/policy functions
  • Loading branch information
ciaranRoche authored Jun 11, 2024
2 parents 4b2400f + 35d934f commit 2ad1e6f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/aws/aws_client/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,28 @@ func (client *AWSClient) CleanPolicies(cleanRule func(types.Policy) bool) error
}
return nil
}

func (client *AWSClient) TagPolicy(policyArn string, tags map[string]string) error {
var policyTags []types.Tag
for tagKey, tagValue := range tags {
policyTags = append(policyTags, types.Tag{
Key: &tagKey,
Value: &tagValue,
})
}
input := &iam.TagPolicyInput{
PolicyArn: &policyArn,
Tags: policyTags,
}
_, err := client.IamClient.TagPolicy(context.TODO(), input)
return err
}

func (client *AWSClient) UntagPolicy(policyArn string, tagKeys []string) error {
input := &iam.UntagPolicyInput{
PolicyArn: &policyArn,
TagKeys: tagKeys,
}
_, err := client.IamClient.UntagPolicy(context.TODO(), input)
return err
}
25 changes: 25 additions & 0 deletions pkg/aws/aws_client/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,28 @@ func completeRolePolicyDocument(statement map[string]interface{}) (string, error
assumeRolePolicyDocument, err := json.Marshal(rolePolicyDocument)
return string(assumeRolePolicyDocument), err
}

func (client *AWSClient) TagRole(roleName string, tags map[string]string) error {
var roleTags []types.Tag
for tagKey, tagValue := range tags {
roleTags = append(roleTags, types.Tag{
Key: &tagKey,
Value: &tagValue,
})
}
input := &iam.TagRoleInput{
RoleName: &roleName,
Tags: roleTags,
}
_, err := client.IamClient.TagRole(context.TODO(), input)
return err
}

func (client *AWSClient) UntagRole(roleName string, tagKeys []string) error {
input := &iam.UntagRoleInput{
RoleName: &roleName,
TagKeys: tagKeys,
}
_, err := client.IamClient.UntagRole(context.TODO(), input)
return err
}

0 comments on commit 2ad1e6f

Please sign in to comment.