这是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/developers/developers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func init() {
Cmd.AddCommand(ListCmd)
Cmd.AddCommand(GetCmd)
Cmd.AddCommand(DelCmd)
Cmd.AddCommand(UpdateCmd)
Cmd.AddCommand(CreateCmd)
Cmd.AddCommand(ImpCmd)
Cmd.AddCommand(ExpCmd)
Expand Down
83 changes: 83 additions & 0 deletions cmd/developers/upddev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 developers

import (
"fmt"

"internal/apiclient"

"internal/client/developers"

"github.com/spf13/cobra"
)

// UpdateCmd to update developer
var UpdateCmd = &cobra.Command{
Use: "update",
Short: "Update an Apigee developer configuration",
Long: "Update an Apigee developer configuration",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = developers.Update(email, firstName, lastName, userName, cmd.Flag("status").Value.String(), attrs)
return
},
}

type developerStatus string

var status developerStatus

const (
active developerStatus = "active"
inactive developerStatus = "inactive"
)

func (s *developerStatus) String() string {
return string(*s)
}

func (s *developerStatus) Set(r string) error {
switch r {
case "active", "inactive":
*s = developerStatus(r)
return nil
default:
return fmt.Errorf("must be %s or %s", active, inactive)
}
}

func (s *developerStatus) Type() string {
return "developerStatus"
}

func init() {
UpdateCmd.Flags().StringVarP(&email, "email", "n",
"", "The developer's email")
UpdateCmd.Flags().StringVarP(&firstName, "first", "f",
"", "The first name of the developer")
UpdateCmd.Flags().StringVarP(&lastName, "last", "s",
"", "The last name of the developer")
UpdateCmd.Flags().StringVarP(&userName, "user", "u",
"", "The username of the developer")
UpdateCmd.Flags().Var(&status, "status",
fmt.Sprintf("must be %s or %s", active, inactive))
UpdateCmd.Flags().StringToStringVar(&attrs, "attrs",
nil, "Custom attributes")

_ = UpdateCmd.MarkFlagRequired("email")
}
4 changes: 1 addition & 3 deletions internal/client/apis/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ type violation struct {
Description string `json:"description,omitempty"`
}

type routingchanges struct {
}
type routingchanges struct{}

type routingconflicts struct {
EnvironmentGroup string `json:"environmentGroup,omitempty"`
Expand Down Expand Up @@ -112,7 +111,6 @@ func DeleteProxyRevision(name string, revision int) (respBody []byte, err error)

// DeployProxy
func DeployProxy(name string, revision int, overrides bool, sequencedRollout bool, safeDeploy bool, serviceAccountName string) (respBody []byte, err error) {

if safeDeploy {
var safeResp []byte
d := deploychangereport{}
Expand Down
59 changes: 58 additions & 1 deletion internal/client/developers/developers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Appdeveloper struct {
Attributes []Attribute `json:"attributes,omitempty"`
Username string `json:"userName,omitempty"`
DeveloperId string `json:"developerId,omitempty"`
Status *string `json:"status,omitempty"`
}

// Appdevelopers hold an array of developers
Expand Down Expand Up @@ -94,6 +95,63 @@ func Get(email string) (respBody []byte, err error) {
return respBody, err
}

// Update
func Update(email string, firstName string, lastName string, username string, status string, attrs map[string]string) (respBody []byte, err error) {
apiclient.ClientPrintHttpResponse.Set(false)
devRespBody, err := Get(email)
if err != nil {
return nil, err
}
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())

d := Appdeveloper{}
if err = json.Unmarshal(devRespBody, &d); err != nil {
return nil, err
}

if firstName != "" {
d.FirstName = firstName
}

if lastName != "" {
d.LastName = lastName
}

if username != "" {
d.Username = username
}

if status != "" {
apiclient.ClientPrintHttpResponse.Set(false)
err = setDeveloperStatus(email, status)
apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting())
if err != nil {
return nil, err
}
}

reqBody, err := json.Marshal(d)
if err != nil {
return nil, err
}

u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email))
respBody, err = apiclient.HttpClient(u.String(), string(reqBody), "PUT")
return respBody, err
}

func setDeveloperStatus(email string, action string) (err error) {
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email))
q := u.Query()
q.Set("action", action)
u.RawQuery = q.Encode()

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

// GetDeveloperId
func GetDeveloperId(email string) (developerId string, err error) {
apiclient.ClientPrintHttpResponse.Set(false)
Expand Down Expand Up @@ -168,7 +226,6 @@ func Export() (respBody []byte, err error) {

// Import
func Import(conn int, filePath string) error {

entities, err := ReadDevelopersFile(filePath)
if err != nil {
clilog.Error.Println("Error reading file: ", err)
Expand Down
1 change: 0 additions & 1 deletion internal/client/sharedflows/sharedflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ func Export(conn int, folder string, allRevisions bool) (err error) {
lastRevision := maxRevision(proxy.Revision)
jobChan <- revision{name: proxy.Name, rev: lastRevision}
}

}
close(jobChan)
fanOutWg.Wait()
Expand Down