Skip to content

Commit

Permalink
Merge pull request #680 from renuka-fernando/mg-undeploy-gateway
Browse files Browse the repository at this point in the history
Add gateway env flag for mg undeploy API command
  • Loading branch information
pubudu538 authored Apr 2, 2021
2 parents 17376ae + ee5f56e commit a74d17f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
28 changes: 19 additions & 9 deletions import-export-cli/cmd/mg/undeployAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,39 @@ package mg

import (
"fmt"
"strings"

"github.com/spf13/cobra"
mgImpl "github.com/wso2/product-apim-tooling/import-export-cli/impl/mg"
"github.com/wso2/product-apim-tooling/import-export-cli/utils"
)

var (
undeployAPICmdAPIName string
undeployAPICmdAPIVersion string
undeployAPICmdAPIVHost string
undeployAPIEnv string
undeployAPICmdAPIName string
undeployAPICmdAPIVersion string
undeployAPICmdAPIVHost string
undeployAPICmdAPIGatewayEnvs []string
undeployAPIEnv string
)

const gatewayNameSeparator = ":"

const (
undeployAPICmdShortDesc = "Undeploy an API in Microgateway"
undeployAPICmdLongDesc = "Undeploy an API in Microgateway by specifying name, version, environment, username " +
"and optionally vhost"
)

var undeployAPICmdExamples = utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` --environment dev -n petstore -v 0.0.1
` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev --vhost www.pets.com
` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n SwaggerPetstore -v 0.0.1 --environment dev` +
var undeployAPICmdExamples = ` ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` --environment dev -n petstore -v 0.0.1
` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev --vhost www.pets.com
` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev -g "Production and Sandbox" -g Label1 -g Label2
` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev --vhost www.pets.com --gateway-env "Production and Sandbox"
` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n SwaggerPetstore -v 0.0.1 --environment dev
"\n\nNote: The flags --name (-n), --version (-v), --environment (-e) are mandatory. " +
"The user needs to be logged in to use this command."
Note: The flags --name (-n), --version (-v), --environment (-e) are mandatory.
If the flag (--gateway-env (-g)) is not provided, API will be undeployed from all deployed gateway environments.
If the flag (--vhost (-t)) is not provided, API with all VHosts will be undeployed.
The user needs to be logged in to use this command.`

// UndeployAPICmd represents the undeploy api command
var UndeployAPICmd = &cobra.Command{
Expand All @@ -60,6 +68,7 @@ var UndeployAPICmd = &cobra.Command{
queryParams["apiName"] = undeployAPICmdAPIName
queryParams["version"] = undeployAPICmdAPIVersion
queryParams["vhost"] = undeployAPICmdAPIVHost
queryParams["environments"] = strings.Join(undeployAPICmdAPIGatewayEnvs, gatewayNameSeparator)
err := mgImpl.UndeployAPI(undeployAPIEnv, queryParams)
if err != nil {
utils.HandleErrorAndExit("Error undeploying API", err)
Expand All @@ -75,6 +84,7 @@ func init() {
UndeployAPICmd.Flags().StringVarP(&undeployAPICmdAPIName, "name", "n", "", "API name")
UndeployAPICmd.Flags().StringVarP(&undeployAPICmdAPIVersion, "version", "v", "", "API version")
UndeployAPICmd.Flags().StringVarP(&undeployAPICmdAPIVHost, "vhost", "t", "", "Virtual host the API needs to be undeployed from")
UndeployAPICmd.Flags().StringSliceVarP(&undeployAPICmdAPIGatewayEnvs, "gateway-env", "g", []string{}, "Gateway environments the API needs to be undeployed from")

_ = UndeployAPICmd.MarkFlagRequired("environment")
_ = UndeployAPICmd.MarkFlagRequired("name")
Expand Down
24 changes: 15 additions & 9 deletions import-export-cli/docs/apictl_mg_undeploy_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ apictl mg undeploy api [flags]
### Examples

```
apictl mg undeploy api --environment dev -n petstore -v 0.0.1
apictl mg undeploy api -n petstore -v 0.0.1 -e dev --vhost www.pets.com
apictl mg undeploy api -n SwaggerPetstore -v 0.0.1 --environment dev
apictl mg undeploy api --environment dev -n petstore -v 0.0.1
apictl mg undeploy api -n petstore -v 0.0.1 -e dev --vhost www.pets.com
apictl mg undeploy api -n petstore -v 0.0.1 -e dev -g "Production and Sandbox" -g Label1 -g Label2
apictl mg undeploy api -n petstore -v 0.0.1 -e dev --vhost www.pets.com --gateway-env "Production and Sandbox"
apictl mg undeploy api -n SwaggerPetstore -v 0.0.1 --environment dev
Note: The flags --name (-n), --version (-v), --environment (-e) are mandatory. The user needs to be logged in to use this command.
Note: The flags --name (-n), --version (-v), --environment (-e) are mandatory.
If the flag (--gateway-env (-g)) is not provided, API will be undeployed from all deployed gateway environments.
If the flag (--vhost (-t)) is not provided, API with all VHosts will be undeployed.
The user needs to be logged in to use this command.
```

### Options

```
-e, --environment string Microgateway adapter environment to be undeployed from
-h, --help help for api
-n, --name string API name
-v, --version string API version
-t, --vhost string Virtual host the API needs to be undeployed from
-e, --environment string Microgateway adapter environment to be undeployed from
-g, --gateway-env strings Gateway environments the API needs to be undeployed from
-h, --help help for api
-n, --name string API name
-v, --version string API version
-t, --vhost string Virtual host the API needs to be undeployed from
```

### Options inherited from parent commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,12 @@ _apictl_mg_undeploy_api()
local_nonpersistent_flags+=("--environment")
local_nonpersistent_flags+=("--environment=")
local_nonpersistent_flags+=("-e")
flags+=("--gateway-env=")
two_word_flags+=("--gateway-env")
two_word_flags+=("-g")
local_nonpersistent_flags+=("--gateway-env")
local_nonpersistent_flags+=("--gateway-env=")
local_nonpersistent_flags+=("-g")
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
Expand Down

0 comments on commit a74d17f

Please sign in to comment.