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

Commit

Permalink
add support to update orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Feb 25, 2021
1 parent b1ec7a4 commit 662714e
Show file tree
Hide file tree
Showing 210 changed files with 400 additions and 228 deletions.
100 changes: 82 additions & 18 deletions client/orgs/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,36 @@ var analyticsRegions = [...]string{"asia-east1", "asia-east1", "asia-northeast1"
"europe-west1", "us-central1", "us-east1", "us-east4", "us-west1", "australia-southeast1",
"europe-west2"}

//OrgProperty contains an individual org flag or property
type orgProperty struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}

//OrgProperties stores all the org feature flags and properties
type orgProperties struct {
Property []orgProperty `json:"property,omitempty"`
}

type organization struct {
Name string `json:"name,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Description string `json:"description,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
LastModifiedAt string `json:"lastModifiedAt,omitempty"`
Environments []string `json:"environments,omitempty"`
Properties orgProperties `json:"properties,omitempty"`
AnalyticsRegion string `json:"analyticsRegion,omitempty"`
AuthorizedNetwork string `json:"authorizedNetwork,omitempty"`
RuntimeType string `json:"runtimeType,omitempty"`
SubscriptionType string `json:"subscriptionType,omitempty"`
CaCertificate string `json:"caCertificate,omitempty"`
RuntimeEncryptionKeyName string `json:"runtimeDatabaseEncryptionKeyName,omitempty"`
ProjectId string `json:"projectId,omitempty"`
State string `json:"state,omitempty"`
BillingType string `json:"BillingType,omitempty"`
}

func validRegion(region string) bool {
for _, r := range analyticsRegions {
if region == r {
Expand Down Expand Up @@ -98,24 +128,6 @@ func GetDeployedIngressConfig() (respBody []byte, err error) {

//SetOrgProperty is used to set org properties
func SetOrgProperty(name string, value string) (err error) {
//OrgProperty contains an individual org flag or property
type orgProperty struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}
//OrgProperties stores all the org feature flags and properties
type orgProperties struct {
Property []orgProperty `json:"property,omitempty"`
}
//Org structure
type organization struct {
Name string `json:"name,omitempty"`
CreatedAt string `json:"-,omitempty"`
LastModifiedAt string `json:"-,omitempty"`
Environments []string `json:"-,omitempty"`
Properties orgProperties `json:"properties,omitempty"`
AnalyticsRegion string `json:"-,omitempty"`
}

u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg())
Expand Down Expand Up @@ -162,3 +174,55 @@ func SetOrgProperty(name string, value string) (err error) {

return err
}

//Update
func Update(description string, displayName string, region string, network string, runtimeType string, databaseKey string) (respBody []byte, err error) {

apiclient.SetPrintOutput(false)
orgBody, err := Get()
if err != nil {
return nil, err
}
apiclient.SetPrintOutput(true)

org := organization{}
err = json.Unmarshal(orgBody, &org)
if err != nil {
return nil, err
}

if description != "" {
org.Description = description
}

if displayName != "" {
org.DisplayName = displayName
}

if region != "" {
org.AnalyticsRegion = region
}

if network != "" {
org.AuthorizedNetwork = network
}

if runtimeType != "" {
org.RuntimeType = runtimeType
}

if databaseKey != "" {
org.RuntimeEncryptionKeyName = databaseKey
}

newOrgBody, err := json.Marshal(org)
if err != nil {
return nil, err
}

u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg())
respBody, err = apiclient.HttpClient(apiclient.GetPrintOutput(), u.String(), string(newOrgBody), "PUT")

return respBody, err
}
6 changes: 4 additions & 2 deletions cmd/org/createorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Create a new Apigee Org",
Long: "Create a new Apigee Org; Your GCP project must be whitelist for this operation",
Long: "Create a new Apigee Org",
Args: func(cmd *cobra.Command, args []string) (err error) {
if runtimeType != "HYBRID" && runtimeType != "CLOUD" {
return fmt.Errorf("runtime type must be CLOUD or HYBRID")
Expand All @@ -48,14 +48,16 @@ var CreateCmd = &cobra.Command{
},
}

var region, projectID, network, runtimeType, databaseKey string
var region, projectID, network, runtimeType, description, databaseKey string

func init() {

CreateCmd.Flags().StringVarP(&region, "reg", "r",
"", "Analytics region name")
CreateCmd.Flags().StringVarP(&projectID, "prj", "p",
"", "GCP Project ID")
CreateCmd.Flags().StringVarP(&description, "desc", "d",
"", "Apigee org description")
CreateCmd.Flags().StringVarP(&network, "net", "n",
"default", "Authorized network; if using a shared VPC format is projects/{host-project-id}/{location}/networks/{network-name}")
CreateCmd.Flags().StringVarP(&databaseKey, "key", "k",
Expand Down
1 change: 1 addition & 0 deletions cmd/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ func init() {
Cmd.AddCommand(IngressCmd)
Cmd.AddCommand(ExportCmd)
Cmd.AddCommand(ImportCmd)
Cmd.AddCommand(UpdateCmd)
}
67 changes: 67 additions & 0 deletions cmd/org/updateorg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 org

import (
"fmt"

"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/apiclient"
"github.com/srinandan/apigeecli/client/orgs"
)

//UpdateCmd to get org details
var UpdateCmd = &cobra.Command{
Use: "update",
Short: "Update settings of an Apigee Org",
Long: "Update settings of an Apigee Org",
Args: func(cmd *cobra.Command, args []string) (err error) {
if runtimeType != "HYBRID" && runtimeType != "CLOUD" {
return fmt.Errorf("runtime type must be CLOUD or HYBRID")
}
if runtimeType == "CLOUD" {
if network == "" {
return fmt.Errorf("authorized network must be supplied")
}
if databaseKey == "" {
return fmt.Errorf("runtime database encryption key must be supplied")
}
}
apiclient.SetProjectID(projectID)
return apiclient.SetApigeeOrg(projectID)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = orgs.Update(description, "", region, network, runtimeType, databaseKey)
return
},
}

func init() {

UpdateCmd.Flags().StringVarP(&region, "reg", "r",
"", "Analytics region name")
UpdateCmd.Flags().StringVarP(&description, "desc", "d",
"", "Apigee org description")
UpdateCmd.Flags().StringVarP(&network, "net", "n",
"default", "Authorized network; if using a shared VPC format is projects/{host-project-id}/{location}/networks/{network-name}")
UpdateCmd.Flags().StringVarP(&databaseKey, "key", "k",
"", "Runtime Database Encryption Key")
UpdateCmd.Flags().StringVarP(&runtimeType, "runtime-type", "",
"HYBRID", "Runtime type: CLOUD or HYBRID")

_ = UpdateCmd.MarkFlagRequired("prj")
_ = UpdateCmd.MarkFlagRequired("reg")
_ = UpdateCmd.MarkFlagRequired("runtime-type")
}
2 changes: 1 addition & 1 deletion docs/apigeecli.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ This command lets you interact with Apigee APIs.
* [apigeecli targetservers](apigeecli_targetservers.md) - Manage Target Servers
* [apigeecli token](apigeecli_token.md) - Manage OAuth 2.0 access tokens

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Manage Apigee API proxies in an org
* [apigeecli apis trace](apigeecli_apis_trace.md) - Manage debugging/tracing of Apigee API proxies
* [apigeecli apis undeploy](apigeecli_apis_undeploy.md) - Undeploys a revision of an existing API proxy

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apis clean [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ apigeecli apis create [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apis delete [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_deploy-wait.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ apigeecli apis deploy-wait [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ apigeecli apis deploy [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apis export [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apis fetch [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apis get [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apis import [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_kvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Manage API proxy scoped KVMs
* [apigeecli apis kvm delete](apigeecli_apis_kvm_delete.md) - Deletes an API Proxy scoped KVM
* [apigeecli apis kvm list](apigeecli_apis_kvm_list.md) - List all KVMs for an API proxy

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_kvm_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ apigeecli apis kvm create [flags]

* [apigeecli apis kvm](apigeecli_apis_kvm.md) - Manage API proxy scoped KVMs

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_kvm_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apis kvm delete [flags]

* [apigeecli apis kvm](apigeecli_apis_kvm.md) - Manage API proxy scoped KVMs

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_kvm_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ apigeecli apis kvm list [flags]

* [apigeecli apis kvm](apigeecli_apis_kvm.md) - Manage API proxy scoped KVMs

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ apigeecli apis list [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_listdeploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ apigeecli apis listdeploy [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ Manage debugging/tracing of Apigee API proxy revisions deployed in an environmen
* [apigeecli apis trace get](apigeecli_apis_trace_get.md) - Get a debug session for an API proxy revision
* [apigeecli apis trace list](apigeecli_apis_trace_list.md) - List all debug sessions for an API proxy revision

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_trace_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ apigeecli apis trace create [flags]

* [apigeecli apis trace](apigeecli_apis_trace.md) - Manage debugging/tracing of Apigee API proxies

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_trace_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ apigeecli apis trace get [flags]

* [apigeecli apis trace](apigeecli_apis_trace.md) - Manage debugging/tracing of Apigee API proxies

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_trace_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ apigeecli apis trace list [flags]

* [apigeecli apis trace](apigeecli_apis_trace.md) - Manage debugging/tracing of Apigee API proxies

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apis_undeploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ apigeecli apis undeploy [flags]

* [apigeecli apis](apigeecli_apis.md) - Manage Apigee API proxies in an org

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ Manage Apigee Developer Applications
* [apigeecli apps list](apigeecli_apps_list.md) - Returns a list of Developer Applications
* [apigeecli apps manage](apigeecli_apps_manage.md) - Approve or revoke a developer app

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apps_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ apigeecli apps create [flags]

* [apigeecli apps](apigeecli_apps.md) - Manage Apigee Developer Applications

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apps_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apps delete [flags]

* [apigeecli apps](apigeecli_apps.md) - Manage Apigee Developer Applications

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apps_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ apigeecli apps export [flags]

* [apigeecli apps](apigeecli_apps.md) - Manage Apigee Developer Applications

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apps_genkey.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ apigeecli apps genkey [flags]

* [apigeecli apps](apigeecli_apps.md) - Manage Apigee Developer Applications

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apps_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ apigeecli apps get [flags]

* [apigeecli apps](apigeecli_apps.md) - Manage Apigee Developer Applications

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apps_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ apigeecli apps import [flags]

* [apigeecli apps](apigeecli_apps.md) - Manage Apigee Developer Applications

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
2 changes: 1 addition & 1 deletion docs/apigeecli_apps_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Manage developer apps keys
* [apigeecli apps keys manage](apigeecli_apps_keys_manage.md) - Approve or revoke a developer app key
* [apigeecli apps keys update](apigeecli_apps_keys_update.md) - Update a developer app key

###### Auto generated by spf13/cobra on 18-Feb-2021
###### Auto generated by spf13/cobra on 25-Feb-2021
Loading

0 comments on commit 662714e

Please sign in to comment.