diff --git a/README.md b/README.md index f38cb52d66..4046b53439 100644 --- a/README.md +++ b/README.md @@ -1183,7 +1183,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address' ### master (unreleased) -* No entry +* Add marketplace alias in the cache to resolve image ([#330](https://github.com/scaleway/scaleway-cli/issues/330)) View full [commits list](https://github.com/scaleway/scaleway-cli/compare/v1.9.0...master) diff --git a/pkg/api/api.go b/pkg/api/api.go index 28182fb2b0..fb64b5ebbc 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -1246,7 +1246,7 @@ func (s *ScalewayAPI) PostImage(volumeID string, name string, bootscript string, return "", err } // FIXME region, arch, owner, title - s.Cache.InsertImage(image.Image.Identifier, "fr-1", image.Image.Arch, image.Image.Organization, image.Image.Name) + s.Cache.InsertImage(image.Image.Identifier, "fr-1", image.Image.Arch, image.Image.Organization, image.Image.Name, "") return image.Image.Identifier, nil } @@ -1365,7 +1365,7 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) { if version.ID == image.CurrentPublicVersion { for _, localImage := range version.LocalImages { images.Images[i].Public = true - s.Cache.InsertImage(localImage.ID, localImage.Zone, localImage.Arch, image.Organization.ID, image.Name) + s.Cache.InsertImage(localImage.ID, localImage.Zone, localImage.Arch, image.Organization.ID, image.Name, image.CurrentPublicVersion) } } } @@ -1385,7 +1385,7 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) { return nil, err } for _, orgaImage := range OrgaImages.Images { - s.Cache.InsertImage(orgaImage.Identifier, "fr-1", orgaImage.Arch, orgaImage.Organization, orgaImage.Name) + s.Cache.InsertImage(orgaImage.Identifier, "fr-1", orgaImage.Arch, orgaImage.Organization, orgaImage.Name, "") images.Images = append(images.Images, MarketImage{ Categories: []string{"MyImages"}, CreationDate: orgaImage.CreationDate, @@ -1436,7 +1436,7 @@ func (s *ScalewayAPI) GetImage(imageID string) (*ScalewayImage, error) { return nil, err } // FIXME region, arch, owner, title - s.Cache.InsertImage(oneImage.Image.Identifier, "fr-1", oneImage.Image.Arch, oneImage.Image.Organization, oneImage.Image.Name) + s.Cache.InsertImage(oneImage.Image.Identifier, "fr-1", oneImage.Image.Arch, oneImage.Image.Organization, oneImage.Image.Name, "") return &oneImage.Image, nil } diff --git a/pkg/api/cache.go b/pkg/api/cache.go index 9f5161c5aa..de4b97ed25 100644 --- a/pkg/api/cache.go +++ b/pkg/api/cache.go @@ -28,6 +28,9 @@ const ( CacheOwner // CacheTitle permits to access at the title field CacheTitle + // CacheMarketPlaceUUID is used to determine the UUID of local images + CacheMarketPlaceUUID + // CacheMaxfield is used to determine the size of array CacheMaxfield ) @@ -284,6 +287,10 @@ func (c *ScalewayCache) LookUpImages(needle string, acceptUUID bool) ScalewayRes entry := NewScalewayResolverResult(identifier, fields[CacheTitle], fields[CacheArch], IdentifierImage) entry.ComputeRankMatch(needle) res = append(res, entry) + } else if strings.HasPrefix(fields[CacheMarketPlaceUUID], needle) || nameRegex.MatchString(fields[CacheMarketPlaceUUID]) { + entry := NewScalewayResolverResult(identifier, fields[CacheTitle], fields[CacheArch], IdentifierImage) + entry.ComputeRankMatch(needle) + res = append(res, entry) } } @@ -564,13 +571,13 @@ func (c *ScalewayCache) ClearServers() { } // InsertImage registers an image in the cache -func (c *ScalewayCache) InsertImage(identifier, region, arch, owner, name string) { +func (c *ScalewayCache) InsertImage(identifier, region, arch, owner, name, marketPlaceUUID string) { c.Lock.Lock() defer c.Lock.Unlock() fields, exists := c.Images[identifier] if !exists || fields[CacheTitle] != name { - c.Images[identifier] = [CacheMaxfield]string{region, arch, owner, name} + c.Images[identifier] = [CacheMaxfield]string{region, arch, owner, name, marketPlaceUUID} c.Modified = true } }