From 4edd39eb91602048d7682642e200bc7aa2ddbf79 Mon Sep 17 00:00:00 2001 From: srinandan <13950006+srinandan@users.noreply.github.com> Date: Thu, 4 Aug 2022 13:59:05 -0700 Subject: [PATCH] support labels for proxies #46 --- client/apis/apis.go | 23 ++++++++++++++++++++++ cmd/apis/apis.go | 2 +- cmd/apis/updapis.go | 47 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 cmd/apis/updapis.go diff --git a/client/apis/apis.go b/client/apis/apis.go index f5563ac53..4bd5dd50d 100644 --- a/client/apis/apis.go +++ b/client/apis/apis.go @@ -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) { diff --git a/cmd/apis/apis.go b/cmd/apis/apis.go index b96baf8e1..b32483369 100644 --- a/cmd/apis/apis.go +++ b/cmd/apis/apis.go @@ -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) @@ -47,4 +46,5 @@ func init() { Cmd.AddCommand(TraceCmd) Cmd.AddCommand(CleanCmd) Cmd.AddCommand(KvmCmd) + Cmd.AddCommand(UpdateCmd) } diff --git a/cmd/apis/updapis.go b/cmd/apis/updapis.go new file mode 100644 index 000000000..784f964b6 --- /dev/null +++ b/cmd/apis/updapis.go @@ -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") +}