这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions internal/client/products/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type APIProduct struct {
QuotaTimeUnit string `json:"quotaTimeUnit,omitempty"`
Scopes []string `json:"scopes,omitempty"`
QuotaCounterScope string `json:"quotaCounterScope,omitempty"`
Space string `json:"space,omitempty"`
}

type OperationGroup struct {
Expand Down Expand Up @@ -142,6 +143,17 @@ func Delete(name string) (respBody []byte, err error) {
return respBody, err
}

// Move between spaces
func Move(name string, space string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
q := u.Query()
q.Set("space", space)
u.RawQuery = q.Encode()
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", name, ":move")
respBody, err = apiclient.HttpClient(u.String(), "")
return respBody, err
}

// upsert - use Action to control if upsert is enabled
func upsert(p APIProduct, a Action) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
Expand Down Expand Up @@ -213,7 +225,7 @@ func ListAttributes(name string) (respBody []byte, err error) {
}

// List
func List(count int, startKey string, expand bool) (respBody []byte, err error) {
func List(count int, startKey string, expand bool, space string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.GetApigeeBaseURL())
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts")
q := u.Query()
Expand All @@ -228,6 +240,9 @@ func List(count int, startKey string, expand bool) (respBody []byte, err error)
if startKey != "" {
q.Set("startKey", startKey)
}
if space != "" {
q.Set("space", space)
}

u.RawQuery = q.Encode()

Expand All @@ -237,7 +252,7 @@ func List(count int, startKey string, expand bool) (respBody []byte, err error)
}

// ListFilter
func ListFilter(filter map[string]string) (respBody []byte, err error) {
func ListFilter(filter map[string]string, space string) (respBody []byte, err error) {
maxProducts := 1000
nextPage := true
startKey := ""
Expand All @@ -247,7 +262,7 @@ func ListFilter(filter map[string]string) (respBody []byte, err error) {
apiclient.ClientPrintHttpResponse.Set(false)

for nextPage {
pageResp, err := List(maxProducts, startKey, true)
pageResp, err := List(maxProducts, startKey, true, space)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -305,13 +320,13 @@ func ListFilter(filter map[string]string) (respBody []byte, err error) {
}

// Export
func Export(conn int) (payload [][]byte, err error) {
func Export(conn int, space string) (payload [][]byte, err error) {
// parent workgroup
var pwg sync.WaitGroup
var mu sync.Mutex

entityType := "apiproducts"
products, err := listAllProducts()
products, err := listAllProducts(space)
if err != nil {
return apiclient.GetEntityPayloadList(), err
}
Expand Down Expand Up @@ -461,7 +476,7 @@ func readProductsFile(filePath string) ([]APIProduct, error) {
return products, nil
}

func listAllProducts() (products apiProducts, err error) {
func listAllProducts(space string) (products apiProducts, err error) {
var startKey string
products = apiProducts{}

Expand All @@ -474,14 +489,16 @@ func listAllProducts() (products apiProducts, err error) {
for {

p := apiProducts{}

q := u.Query()
if startKey != "" {
q := u.Query()

q.Set("startKey", startKey)
q.Set("count", "1000")
u.RawQuery = q.Encode()
}

if space != "" {
q.Set("space", space)
}
u.RawQuery = q.Encode()
respBody, err := apiclient.HttpClient(u.String())
startKey = ""
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/org/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var ExportCmd = &cobra.Command{
}

clilog.Info.Println("Exporting API Products...")
if productResponse, err = products.Export(conn); proceedOnError(err) != nil {
if productResponse, err = products.Export(conn, space); proceedOnError(err) != nil {
return err
}
if err = apiclient.WriteArrayByteArrayToFile(
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/org/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ var ImportCmd = &cobra.Command{

var (
importTrace, importDebugmask bool
folder, space string
folder string
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var Cmd = &cobra.Command{
Long: "Manage Apigee Orgs",
}

var org, region string
var org, region, space string

func init() {
Cmd.PersistentFlags().StringVarP(&region, "region", "r",
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/products/crtprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var CreateCmd = &cobra.Command{
p.Environments = environments
p.Proxies = proxies
p.Scopes = scopes
p.Space = space

p.OperationGroup, err = getOperationGroup(operationGroupFile)
if err != nil {
Expand Down Expand Up @@ -117,6 +118,8 @@ func init() {
"", "File containing gRPC Operation Group JSON. See samples for how to create the file")
CreateCmd.Flags().StringVarP(&quotaCounterScope, "quota-counter-scope", "",
"", "Scope of the quota decides how the quota counter gets applied; can be PROXY or OPERATION")
CreateCmd.Flags().StringVarP(&space, "space", "",
"", "Apigee Space to associate to")
// TODO: apiresource -r later

_ = CreateCmd.MarkFlagRequired("name")
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/products/expprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var ExpCmd = &cobra.Command{

const exportFileName = "products.json"
apiclient.DisableCmdPrintHttpResponse()
payload, err := products.Export(conn)
payload, err := products.Export(conn, space)
if err != nil {
return err
}
Expand All @@ -46,4 +46,6 @@ var ExpCmd = &cobra.Command{
func init() {
ExpCmd.Flags().IntVarP(&conn, "conn", "c",
4, "Number of connections")
ExpCmd.Flags().StringVarP(&space, "space", "",
"", "Apigee Space associated to")
}
7 changes: 5 additions & 2 deletions internal/cmd/products/listproducts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ var ListCmd = &cobra.Command{
cmd.SilenceUsage = true

if len(filter) > 0 {
_, err = products.ListFilter(filter)
_, err = products.ListFilter(filter, space)
} else {
_, err = products.List(count, startKey, expand)
_, err = products.List(count, startKey, expand, space)
}
return err
},
Expand Down Expand Up @@ -72,4 +72,7 @@ func init() {

ListCmd.Flags().BoolVarP(&expand, "expand", "x",
false, "Expand Details")

ListCmd.Flags().StringVarP(&space, "space", "",
"", "Apigee Space associated to")
}
48 changes: 48 additions & 0 deletions internal/cmd/products/moveprod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package products

import (
"internal/apiclient"
"internal/client/products"

"github.com/spf13/cobra"
)

// MoveCmd to move products between spaces
var MoveCmd = &cobra.Command{
Use: "move",
Short: "Move an API product between Spaces",
Long: "Move an API product between Spaces",
Args: func(cmd *cobra.Command, args []string) (err error) {
apiclient.SetRegion(region)
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true
_, err = products.Move(name, space)
return err
},
}

func init() {
MoveCmd.Flags().StringVarP(&name, "name", "n",
"", "Name of the API Product")
MoveCmd.Flags().StringVarP(&space, "space", "",
"", "Name of the Apigee Space moving to")

_ = MoveCmd.MarkFlagRequired("name")
_ = MoveCmd.MarkFlagRequired("space")
}
12 changes: 8 additions & 4 deletions internal/cmd/products/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,25 @@ var (
)

var (
description, approval, displayName, quota, quotaInterval, quotaUnit string
environments, proxies, scopes []string
attrs map[string]string
description, approval, displayName, quota, quotaInterval, quotaUnit, space string
environments, proxies, scopes []string
attrs map[string]string
)

var examples = []string{
`apigeecli products create --name $product_name \
--display-name $product_name \
--opgrp $ops_file \
--envs $env \
--space $space \
--approval auto \
--attrs access=public --default-token`, `apigeecli products create --name $product_name \
--attrs access=public --default-token`,
`apigeecli products create --name $product_name \
--display-name $product_name \
--opgrp $ops_file \
--envs $env \
--approval auto \
--space $space \
--attrs access=public \
--quota 100 --interval 1 --unit minute --default-token`,
`apigeecli products import -f samples/apiproduct-legacy.json --default-token`,
Expand All @@ -75,6 +78,7 @@ func init() {
Cmd.AddCommand(UpdateCmd)
Cmd.AddCommand(AttributesCmd)
Cmd.AddCommand(RatePlanCmd)
Cmd.AddCommand(MoveCmd)
}

func getOperationGroup(operationGroupFile string) (*products.OperationGroup, error) {
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/products/updprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var UpdateCmd = &cobra.Command{
p.Environments = environments
p.Proxies = proxies
p.Scopes = scopes
p.Space = space

p.OperationGroup, err = getOperationGroup(operationGroupFile)
if err != nil {
Expand Down Expand Up @@ -110,6 +111,8 @@ func init() {
"", "File containing gRPC Operation Group JSON. See samples for how to create the file")
UpdateCmd.Flags().StringVarP(&quotaCounterScope, "quota-counter-scope", "",
"", "Scope of the quota decides how the quota counter gets applied; can be PROXY or OPERATION")
UpdateCmd.Flags().StringVarP(&space, "space", "",
"", "Associated Apigee Space. Pass this if the API Product being updated is part of a space")
// TODO: apiresource -r later

_ = UpdateCmd.MarkFlagRequired("name")
Expand Down