-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add tag-on-create #516
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,14 @@ | |
// Write writes a given value to a secret identified by id. If the secret | ||
// already exists, then write a new version. | ||
func (s *SSMStore) Write(ctx context.Context, id SecretId, value string) error { | ||
return s.write(ctx, id, value, nil) | ||
} | ||
|
||
func (s *SSMStore) WriteWithTags(ctx context.Context, id SecretId, value string, tags map[string]string) error { | ||
return s.write(ctx, id, value, tags) | ||
} | ||
|
||
func (s *SSMStore) write(ctx context.Context, id SecretId, value string, tags map[string]string) error { | ||
version := 1 | ||
// first read to get the current version | ||
current, err := s.Read(ctx, id, -1) | ||
|
@@ -99,6 +107,10 @@ | |
version = current.Meta.Version + 1 | ||
} | ||
|
||
if len(tags) > 0 && version != 1 { | ||
return errors.New("tags on write only supported for new secrets") | ||
} | ||
|
||
putParameterInput := &ssm.PutParameterInput{ | ||
KeyId: aws.String(s.KMSKey()), | ||
Name: aws.String(s.idToName(id)), | ||
|
@@ -114,6 +126,12 @@ | |
return err | ||
} | ||
|
||
if len(tags) > 0 { | ||
if err := s.WriteTags(ctx, id, tags, false); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ (More of the WriteTags method) - It looks like the WriteTags also take in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand your scenario correctly, it would be fine, because you can use In the implementation of Let me know if I misunderstood your scenario! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense! thank you for walking me through it! |
||
return fmt.Errorf("failed to write tags on successfully created secret: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Curious if there is a particular reason why tagging is only support for new secrets? Sorry if I am missing it somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't miss anything! (I thought for a second that I had documented why, but it's just in my notes.) I was thinking of what chamber should do when the secret already exists and it already has tags.
--tags
, what should happen to the other tags that you don't list? Should they be deleted or left alone? Admittedly, we could add the--delete-other-tags
option fromchamber tag write
to let you pick.--tags
, what should happen to the existing tags? Should they be all dropped out or left alone? We could maybe add another option,--delete-existing-tags
or something, to let you pick.It's because of this complexity that, at least for this pass, I opted to restrict tags to just new secrets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the context! I did not know that it would override the existing tag prior.