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(pubsub): add support for snapshot labels #6835
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"time" | ||
|
||
pb "google.golang.org/genproto/googleapis/pubsub/v1" | ||
fmpb "google.golang.org/genproto/protobuf/field_mask" | ||
"google.golang.org/protobuf/types/known/timestamppb" | ||
) | ||
|
||
|
@@ -42,11 +43,32 @@ func (s *Snapshot) ID() string { | |
return s.name[slash+1:] | ||
} | ||
|
||
// SetLabels replaces the current set of labels completely with the new set. | ||
func (s *Snapshot) SetLabels(ctx context.Context, label map[string]string) (*SnapshotConfig, error) { | ||
var fields []string | ||
fields = append(fields, "labels") | ||
sc, err := s.c.subc.UpdateSnapshot(ctx, &pb.UpdateSnapshotRequest{ | ||
Snapshot: &pb.Snapshot{ | ||
Name: s.name, | ||
Labels: label, | ||
}, | ||
UpdateMask: &fmpb.FieldMask{ | ||
Paths: fields, | ||
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. you don't appear to manipulate the fields in the mask, maybe just declare the paths using a literal ex:
|
||
}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return toSnapshotConfig(sc, s.c) | ||
} | ||
|
||
// SnapshotConfig contains the details of a Snapshot. | ||
type SnapshotConfig struct { | ||
*Snapshot | ||
Topic *Topic | ||
Expiration time.Time | ||
// The set of labels for the snapshot. | ||
Labels map[string]string | ||
} | ||
|
||
// Snapshot creates a reference to a snapshot. | ||
|
@@ -151,5 +173,6 @@ func toSnapshotConfig(snap *pb.Snapshot, c *Client) (*SnapshotConfig, error) { | |
Snapshot: &Snapshot{c: c, name: snap.Name}, | ||
Topic: newTopic(c, snap.Topic), | ||
Expiration: exp, | ||
Labels: snap.Labels, | ||
}, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe "SetLabels set or replaces the labels on a given snapshot."
The existing docstring seems overly focused on the replace case.