这是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
1 change: 1 addition & 0 deletions cmd/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ func init() {
Cmd.AddCommand(ExpCmd)
Cmd.AddCommand(KeysCmd)
Cmd.AddCommand(ManageCmd)
Cmd.AddCommand(UpdateCmd)
}
57 changes: 57 additions & 0 deletions cmd/apps/updateapp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2023 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 apps

import (
"internal/apiclient"

"internal/client/apps"

"github.com/spf13/cobra"
)

// UpdateCmd to update an app
var UpdateCmd = &cobra.Command{
Use: "update",
Short: "Update a Developer App",
Long: "Update a Developer App",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = apps.Update(name, email, expires, callback, apiProducts, scopes, attrs)
return
},
}

func init() {
UpdateCmd.Flags().StringVarP(&name, "name", "n",
"", "Name of the developer app")
UpdateCmd.Flags().StringVarP(&email, "email", "e",
"", "The developer's email")
UpdateCmd.Flags().StringVarP(&expires, "expires", "x",
"", "A setting, in milliseconds, for the lifetime of the consumer key")
UpdateCmd.Flags().StringVarP(&callback, "callback", "c",
"", "The callbackUrl is used by OAuth")
UpdateCmd.Flags().StringArrayVarP(&apiProducts, "prods", "p",
[]string{}, "A list of api products")
UpdateCmd.Flags().StringArrayVarP(&scopes, "scopes", "s",
[]string{}, "OAuth scopes")
UpdateCmd.Flags().StringToStringVar(&attrs, "attrs",
nil, "Custom attributes")

_ = UpdateCmd.MarkFlagRequired("name")
_ = UpdateCmd.MarkFlagRequired("email")
}
55 changes: 39 additions & 16 deletions internal/client/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,40 @@ type attribute struct {
Value string `json:"value,omitempty"`
}

type Action uint8

const (
CREATE Action = iota
UPDATE
)

// Create
func Create(name string, email string, expires string, callback string, apiProducts []string, scopes []string, attrs map[string]string) (respBody []byte, err error) {
return createOrUpdate(name, email, expires, callback, apiProducts, scopes, attrs, CREATE)
}

// Delete
func Delete(name string, developerID string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerID, "apps", name)
respBody, err = apiclient.HttpClient(u.String(), "", "DELETE")
return respBody, err
}

// Get
func Get(appID string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps", appID)
respBody, err = apiclient.HttpClient(u.String())
return respBody, err
}

// Update
func Update(name string, email string, expires string, callback string, apiProducts []string, scopes []string, attrs map[string]string) (respBody []byte, err error) {
return createOrUpdate(name, email, expires, callback, apiProducts, scopes, attrs, UPDATE)
}

func createOrUpdate(name string, email string, expires string, callback string, apiProducts []string, scopes []string, attrs map[string]string, action Action) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)

app := []string{}
Expand Down Expand Up @@ -113,24 +145,15 @@ func Create(name string, email string, expires string, callback string, apiProdu
}

payload := "{" + strings.Join(app, ",") + "}"
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", email, "apps")
respBody, err = apiclient.HttpClient(u.String(), payload)
return respBody, err
}

// Delete
func Delete(name string, developerID string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerID, "apps", name)
respBody, err = apiclient.HttpClient(u.String(), "", "DELETE")
return respBody, err
}
if action == CREATE {
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", email, "apps")
respBody, err = apiclient.HttpClient(u.String(), payload)
} else {
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", email, "apps", name)
respBody, err = apiclient.HttpClient(u.String(), payload, "PUT")
}

// Get
func Get(appID string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps", appID)
respBody, err = apiclient.HttpClient(u.String())
return respBody, err
}

Expand Down