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

Commit

Permalink
support trial instances
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed May 25, 2021
1 parent b0ab150 commit 345511d
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions cmd/instances/crtinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/spf13/cobra"
"github.com/srinandan/apigeecli/apiclient"
"github.com/srinandan/apigeecli/client/instances"
"github.com/srinandan/apigeecli/client/orgs"
)

//Cmd to create a new instance
Expand All @@ -32,17 +33,34 @@ var CreateCmd = &cobra.Command{
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
re := regexp.MustCompile(`projects\/([a-zA-Z0-9_-]+)\/locations\/([a-zA-Z0-9_-]+)\/keyRings\/([a-zA-Z0-9_-]+)\/cryptoKeys\/([a-zA-Z0-9_-]+)`)
ok := re.Match([]byte(diskEncryptionKeyName))
if !ok {
return fmt.Errorf("custom role must be of the format projects/{project-id}/locations/{location}/keyRings/{test}/cryptoKeys/{cryptoKey}")

if billingType, err = orgs.GetOrgField("billingType"); err != nil {
return err
}

if billingType != "EVALUATION" {
re := regexp.MustCompile(`projects\/([a-zA-Z0-9_-]+)\/locations\/([a-zA-Z0-9_-]+)\/keyRings\/([a-zA-Z0-9_-]+)\/cryptoKeys\/([a-zA-Z0-9_-]+)`)
ok := re.Match([]byte(diskEncryptionKeyName))
if !ok {
return fmt.Errorf("custom role must be of the format projects/{project-id}/locations/{location}/keyRings/{test}/cryptoKeys/{cryptoKey}")
}

if !isRangeValid(cidrRange) {
return fmt.Errorf("Valid ranges are SLASH_16,SLASH_17,SLASH_18,SLASH_19 or SLASH_20")
}
}

if billingType == "EVALUATION" {
_, err = instances.Create(name, location, "", "SLASH_23")
} else {
_, err = instances.Create(name, location, diskEncryptionKeyName, cidrRange)
}
_, err = instances.Create(name, location, diskEncryptionKeyName, cidrRange)
return
},
}

var diskEncryptionKeyName, cidrRange string
var diskEncryptionKeyName, cidrRange, billingType string
var allowedRanges = []string{"SLASH_16", "SLASH_17", "SLASH_18", "SLASH_19", "SLASH_20"}

func init() {

Expand All @@ -53,9 +71,17 @@ func init() {
CreateCmd.Flags().StringVarP(&diskEncryptionKeyName, "diskenc", "d",
"", "CloudKMS key name")
CreateCmd.Flags().StringVarP(&cidrRange, "cidr", "r",
"", "Peering CIDR Range; default is SLASH_16, other supported values SLASH_20")
"", "Peering CIDR Range; default is SLASH_16, other supported values SLASH_20, SLASH_23 for eval")

_ = CreateCmd.MarkFlagRequired("name")
_ = CreateCmd.MarkFlagRequired("location")
_ = CreateCmd.MarkFlagRequired("diskenc")
}

func isRangeValid(cidrRange string) bool {
for _, allowedRange := range allowedRanges {
if allowedRange == cidrRange {
return true
}
}
return false
}

0 comments on commit 345511d

Please sign in to comment.