Skip to content

Commit

Permalink
fix(image): only use numerical IDs for label auto-completion (#865)
Browse files Browse the repository at this point in the history
We currently use the deprecated `Get` method here. Instead we can just
parse an integer and use that as the ID, since you can only get or
update labels on images you can modify (snapshots and backups), which
only have numerical IDs and no names anyway.
  • Loading branch information
phm07 authored Sep 9, 2024
1 parent 260ae1d commit 1d10d92
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/hcapi2/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ func (c *imageClient) Names() []string {
return names
}

// ImageLabelKeys returns a slice containing the keys of all labels assigned to
// the Image with the passed idOrName.
func (c *imageClient) LabelKeys(idOrName string) []string {
img, _, err := c.Get(context.Background(), idOrName)
// LabelKeys returns a slice containing the keys of all labels assigned to
// the Image with the passed id.
func (c *imageClient) LabelKeys(id string) []string {
imgID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return nil
}
img, _, err := c.GetByID(context.Background(), imgID)
if err != nil || img == nil || len(img.Labels) == 0 {
return nil
}
Expand Down

0 comments on commit 1d10d92

Please sign in to comment.