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

Commit

Permalink
support create new orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Nov 10, 2019
1 parent 590ee2e commit ccba743
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ The following parameters are supported. See Common Reference for a list of addit

## <a name="org"/> org

* [create](#createorg)
* [list](#listorgs)
* [get](#getorg)
* [setmart](#setmart)
Expand Down
71 changes: 71 additions & 0 deletions cmd/org/createorg/createorg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package createorg

import (
"fmt"
"net/url"
"path"
"strings"

"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/cmd/shared"
)

//Cmd to get org details
var Cmd = &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",
Args: func(cmd *cobra.Command, args []string) error {
if !validRegion(region) {
return fmt.Errorf("Invalid analytics region."+
" Analytics region must be one of : %v", analyticsRegions)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
u, _ := url.Parse(baseURL)
u.Path = path.Join(u.Path)
q := u.Query()
q.Set("parent", "projects/"+shared.RootArgs.ProjectID)
u.RawQuery = q.Encode()

orgPayload := []string{}
orgPayload = append(orgPayload, "\"name\":\""+shared.RootArgs.Org+"\"")
orgPayload = append(orgPayload, "\"analyticsRegion\":\""+region+"\"")

payload := "{" + strings.Join(orgPayload, ",") + "}"
_, err = shared.HttpClient(true, u.String(), payload)
return
},
}

var analyticsRegions = [...]string{"asia-east1", "asia-east1", "asia-northeast1", "asia-southeast1",
"europe-west1", "us-central1", "us-east1", "us-east4", "us-west1", "australia-southeast1",
"europe-west2"}

func validRegion(region string) bool {
for _, r := range analyticsRegions {
if region == r {
return true
}
}
return false
}

const baseURL = "https://apigee.googleapis.com/v1/organizations"

var region string

func init() {

Cmd.Flags().StringVarP(&shared.RootArgs.Org, "org", "o",
"", "Apigee organization name")
Cmd.Flags().StringVarP(&region, "reg", "r",
"", "Analytics region name")
Cmd.Flags().StringVarP(&shared.RootArgs.ProjectID, "prj", "p",
"", "GCP Project ID")

_ = Cmd.MarkFlagRequired("prj")
_ = Cmd.MarkFlagRequired("org")
_ = Cmd.MarkFlagRequired("reg")
}
3 changes: 2 additions & 1 deletion cmd/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org

import (
"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/cmd/org/createorg"
"github.com/srinandan/apigeecli/cmd/org/getorg"
"github.com/srinandan/apigeecli/cmd/org/listorgs"
"github.com/srinandan/apigeecli/cmd/org/setmart"
Expand All @@ -15,7 +16,7 @@ var Cmd = &cobra.Command{
}

func init() {

Cmd.AddCommand(createorg.Cmd)
Cmd.AddCommand(listorgs.Cmd)
Cmd.AddCommand(getorg.Cmd)
Cmd.AddCommand(setmart.Cmd)
Expand Down

0 comments on commit ccba743

Please sign in to comment.