Skip to content

Commit fd23586

Browse files
authored
feat(product_catalog): filter by locality (scaleway#2617)
1 parent f7b6b3a commit fd23586

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

api/product_catalog/v2alpha1/product_catalog_sdk.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,22 @@ type PublicCatalogAPIListPublicCatalogProductsRequest struct {
584584

585585
// ProductTypes: the list of filtered product categories.
586586
ProductTypes []ListPublicCatalogProductsRequestProductType `json:"-"`
587+
588+
// Global: filter global products.
589+
// Precisely one of Global, Region, Zone, Datacenter must be set.
590+
Global *bool `json:"global,omitempty"`
591+
592+
// Region: filter products by region.
593+
// Precisely one of Global, Region, Zone, Datacenter must be set.
594+
Region *scw.Region `json:"region,omitempty"`
595+
596+
// Zone: filter products by zone.
597+
// Precisely one of Global, Region, Zone, Datacenter must be set.
598+
Zone *scw.Zone `json:"zone,omitempty"`
599+
600+
// Datacenter: filter products by datacenter.
601+
// Precisely one of Global, Region, Zone, Datacenter must be set.
602+
Datacenter *string `json:"datacenter,omitempty"`
587603
}
588604

589605
type PublicCatalogAPI struct {
@@ -606,10 +622,24 @@ func (s *PublicCatalogAPI) ListPublicCatalogProducts(req *PublicCatalogAPIListPu
606622
req.PageSize = &defaultPageSize
607623
}
608624

625+
defaultRegion, exist := s.client.GetDefaultRegion()
626+
if exist && req.Global == nil && req.Region == nil && req.Zone == nil && req.Datacenter == nil {
627+
req.Region = &defaultRegion
628+
}
629+
630+
defaultZone, exist := s.client.GetDefaultZone()
631+
if exist && req.Global == nil && req.Region == nil && req.Zone == nil && req.Datacenter == nil {
632+
req.Zone = &defaultZone
633+
}
634+
609635
query := url.Values{}
610636
parameter.AddToQuery(query, "page", req.Page)
611637
parameter.AddToQuery(query, "page_size", req.PageSize)
612638
parameter.AddToQuery(query, "product_types", req.ProductTypes)
639+
parameter.AddToQuery(query, "global", req.Global)
640+
parameter.AddToQuery(query, "region", req.Region)
641+
parameter.AddToQuery(query, "zone", req.Zone)
642+
parameter.AddToQuery(query, "datacenter", req.Datacenter)
613643

614644
scwReq := &scw.ScalewayRequest{
615645
Method: "GET",

0 commit comments

Comments
 (0)