Skip to content

Commit

Permalink
support labels for proxies #46
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Aug 4, 2022
1 parent fbb2bed commit 4edd39e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
23 changes: 23 additions & 0 deletions client/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,29 @@ func UndeployProxy(name string, revision int) (respBody []byte, err error) {
return respBody, err
}

//Update
func Update(name string, labels map[string]string) (respBody []byte, err error) {

if len(labels) != 0 {
u, _ := url.Parse(apiclient.BaseURL)
q := u.Query()
q.Set("updateMask", "labels")
u.RawQuery = q.Encode()

labelsArr := []string{}
for key, value := range labels {
labelsArr = append(labelsArr, "\""+key+"\":\""+value+"\"")
}
payload := "{\"labels\":{" + strings.Join(labelsArr, ",") + "}}"
fmt.Println(payload)

u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name)
respBody, err = apiclient.HttpClient(apiclient.GetPrintOutput(), u.String(), payload, "PATCH")
}

return respBody, err
}

//CleanProxy
func CleanProxy(name string, reportOnly bool, keepList []string) (err error) {

Expand Down
2 changes: 1 addition & 1 deletion cmd/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func init() {
Cmd.AddCommand(CreateCmd)
Cmd.AddCommand(ExpCmd)
Cmd.AddCommand(DepCmd)
Cmd.AddCommand(DepWaitCmd)
Cmd.AddCommand(DelCmd)
Cmd.AddCommand(FetCmd)
Cmd.AddCommand(GetCmd)
Expand All @@ -47,4 +46,5 @@ func init() {
Cmd.AddCommand(TraceCmd)
Cmd.AddCommand(CleanCmd)
Cmd.AddCommand(KvmCmd)
Cmd.AddCommand(UpdateCmd)
}
47 changes: 47 additions & 0 deletions cmd/apis/updapis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2022 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 apis

import (
"github.com/apigee/apigeecli/apiclient"
"github.com/apigee/apigeecli/client/apis"
"github.com/spf13/cobra"
)

//UpdateCmd to list api
var UpdateCmd = &cobra.Command{
Use: "update",
Short: "Update APIs in an Apigee Org",
Long: "Update APIs in an Apigee Org",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apis.Update(name, labels)
return
},
}

var labels map[string]string

func init() {
UpdateCmd.Flags().StringVarP(&name, "name", "n",
"", "API Proxy name")
UpdateCmd.Flags().StringToStringVar(&labels, "labels",
nil, "Labels")

_ = UpdateCmd.MarkFlagRequired("name")
_ = UpdateCmd.MarkFlagRequired("labels")
}

0 comments on commit 4edd39e

Please sign in to comment.