Skip to content

Commit

Permalink
refactor: remove tag handling functions
Browse files Browse the repository at this point in the history
OTT-6362
  • Loading branch information
thatsddr committed Sep 2, 2024
1 parent fc0dc93 commit d1aefb6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions awsmt/helpers_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
)

func v2Untag(client *mediatailorV2.Client, oldTags map[string]string, resourceArn string) error {
func untag(client *mediatailorV2.Client, oldTags map[string]string, resourceArn string) error {
var removeTags []string
for k := range oldTags {
removeTags = append(removeTags, k)
Expand All @@ -23,7 +23,7 @@ func v2Untag(client *mediatailorV2.Client, oldTags map[string]string, resourceAr
return nil
}

func v2Tag(client *mediatailorV2.Client, newTags map[string]string, resourceArn string) error {
func tag(client *mediatailorV2.Client, newTags map[string]string, resourceArn string) error {
if len(newTags) == 0 {
return nil
}
Expand All @@ -33,12 +33,12 @@ func v2Tag(client *mediatailorV2.Client, newTags map[string]string, resourceArn
return nil
}

func V2UpdatesTags(client *mediatailorV2.Client, oldTags map[string]string, newTags map[string]string, resourceArn string) error {
func UpdatesTags(client *mediatailorV2.Client, oldTags map[string]string, newTags map[string]string, resourceArn string) error {
if !tagsEqual(oldTags, newTags) {
if err := v2Untag(client, oldTags, resourceArn); err != nil {
if err := untag(client, oldTags, resourceArn); err != nil {
return err
}
if err := v2Tag(client, newTags, resourceArn); err != nil {
if err := tag(client, newTags, resourceArn); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (r *resourceChannel) Update(ctx context.Context, req resource.UpdateRequest
)
}

err = V2UpdatesTags(r.client, channel.Tags, plan.Tags, *channel.Arn)
err = UpdatesTags(r.client, channel.Tags, plan.Tags, *channel.Arn)
if err != nil {
resp.Diagnostics.AddError(
"Error while updating channel tags"+err.Error(),
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_live_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (r *resourceLiveSource) Update(ctx context.Context, req resource.UpdateRequ
}

// Update tags
err = V2UpdatesTags(r.client, liveSource.Tags, plan.Tags, *liveSource.Arn)
err = UpdatesTags(r.client, liveSource.Tags, plan.Tags, *liveSource.Arn)
if err != nil {
resp.Diagnostics.AddError(
"Error while updating live source tags"+err.Error(),
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_playback_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (r *resourcePlaybackConfiguration) Update(ctx context.Context, req resource
// the PutPlaybackConfiguration method to add and update tags. We use this approach for every resource in the provider.
// Consequences: The Update function logic is now more complicated, but tag removal is supported.

err = V2UpdatesTags(r.client, playbackConfiguration.Tags, plan.Tags, *playbackConfiguration.PlaybackConfigurationArn)
err = UpdatesTags(r.client, playbackConfiguration.Tags, plan.Tags, *playbackConfiguration.PlaybackConfigurationArn)
if err != nil {
resp.Diagnostics.AddError(
"Error while updating playback configuration tags"+err.Error(),
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_source_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (r *resourceSourceLocation) Update(ctx context.Context, req resource.Update
return
}

err = V2UpdatesTags(r.client, sourceLocation.Tags, plan.Tags, *sourceLocation.Arn)
err = UpdatesTags(r.client, sourceLocation.Tags, plan.Tags, *sourceLocation.Arn)
if err != nil {
resp.Diagnostics.AddError(
"Error while updating playback configuration tags"+err.Error(),
Expand Down
2 changes: 1 addition & 1 deletion awsmt/resource_vod_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (r *resourceVodSource) Update(ctx context.Context, req resource.UpdateReque
}

// Update tags
err = V2UpdatesTags(r.client, vodSource.Tags, plan.Tags, *vodSource.Arn)
err = UpdatesTags(r.client, vodSource.Tags, plan.Tags, *vodSource.Arn)
if err != nil {
resp.Diagnostics.AddError(
"Error while updating vod source tags"+err.Error(),
Expand Down

0 comments on commit d1aefb6

Please sign in to comment.