Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
manage developer app
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Dec 18, 2020
1 parent c932412 commit a534aa6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
17 changes: 17 additions & 0 deletions client/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package apps

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
Expand Down Expand Up @@ -129,6 +130,22 @@ func Get(appID string) (respBody []byte, err error) {
return respBody, err
}

//Manage
func Manage(appID string, action string) (respBody []byte, err error) {
if action != "revoke" && action != "approve" {
return nil, fmt.Errorf("invalid action. action must be revoke or approve")
}

u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apps", appID)
q := u.Query()
q.Set("action", action)
u.RawQuery = q.Encode()

respBody, err = apiclient.HttpClient(apiclient.GetPrintOutput(), u.String(), "", "POST", "application/octet-stream")
return respBody, err
}

//SearchApp
func SearchApp(name string) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)
Expand Down
1 change: 1 addition & 0 deletions cmd/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ func init() {
Cmd.AddCommand(ImpCmd)
Cmd.AddCommand(ExpCmd)
Cmd.AddCommand(KeysCmd)
Cmd.AddCommand(ManageCmd)
}
46 changes: 46 additions & 0 deletions cmd/apps/manageapp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2020 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 (
"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/apiclient"
"github.com/srinandan/apigeecli/client/apps"
)

//ManageCmd to create developer keys
var ManageCmd = &cobra.Command{
Use: "manage",
Short: "Approve or revoke a developer app",
Long: "Approve or revoke 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.Manage(name, action)
return
},
}

func init() {

ManageCmd.Flags().StringVarP(&name, "name", "n",
"", "Developer app name")
ManageCmd.Flags().StringVarP(&action, "action", "x",
"revoke", "Action to perform - revoke or approve")

_ = ManageCmd.MarkFlagRequired("name")
_ = ManageCmd.MarkFlagRequired("action")
}

0 comments on commit a534aa6

Please sign in to comment.