From 0dc4bcf5103bcacb5d4f161121954047f83a0060 Mon Sep 17 00:00:00 2001 From: Renuka Fernando Date: Wed, 31 Mar 2021 22:03:33 +0530 Subject: [PATCH 1/3] Add gateway env flag for mg undeploy API command --- import-export-cli/cmd/mg/undeployAPI.go | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/import-export-cli/cmd/mg/undeployAPI.go b/import-export-cli/cmd/mg/undeployAPI.go index c78785075..e3a876f9e 100644 --- a/import-export-cli/cmd/mg/undeployAPI.go +++ b/import-export-cli/cmd/mg/undeployAPI.go @@ -20,6 +20,7 @@ package mg import ( "fmt" + "strings" "github.com/spf13/cobra" mgImpl "github.com/wso2/product-apim-tooling/import-export-cli/impl/mg" @@ -27,12 +28,15 @@ import ( ) var ( - undeployAPICmdAPIName string - undeployAPICmdAPIVersion string - undeployAPICmdAPIVHost string - undeployAPIEnv string + undeployAPICmdAPIName string + undeployAPICmdAPIVersion string + undeployAPICmdAPIVHost string + undeployAPICmdAPIGatewayEnv string + undeployAPIEnv string ) +const gatewayNameSeparator = ":" + const ( undeployAPICmdShortDesc = "Undeploy an API in Microgateway" undeployAPICmdLongDesc = "Undeploy an API in Microgateway by specifying name, version, environment, username " + @@ -41,10 +45,14 @@ const ( 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` + + ` + utils.ProjectName + ` ` + mgCmdLiteral + ` ` + undeployCmdLiteral + ` ` + apiCmdLiteral + ` -n petstore -v 0.0.1 -e dev --gateway-env "Production and Sandbox" Label1 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{ @@ -60,6 +68,9 @@ var UndeployAPICmd = &cobra.Command{ queryParams["apiName"] = undeployAPICmdAPIName queryParams["version"] = undeployAPICmdAPIVersion queryParams["vhost"] = undeployAPICmdAPIVHost + // Since other flags does not use args[], gateway-env flag will own all the args + gatewayNames := append(args, undeployAPICmdAPIGatewayEnv) + queryParams["environments"] = strings.Join(gatewayNames, gatewayNameSeparator) err := mgImpl.UndeployAPI(undeployAPIEnv, queryParams) if err != nil { utils.HandleErrorAndExit("Error undeploying API", err) @@ -75,6 +86,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().StringVarP(&undeployAPICmdAPIGatewayEnv, "gateway-env", "g", "", "Gateway environment the API needs to be undeployed from") _ = UndeployAPICmd.MarkFlagRequired("environment") _ = UndeployAPICmd.MarkFlagRequired("name") From 4f316df24aa31bef48013459c65b35e3999834db Mon Sep 17 00:00:00 2001 From: Renuka Fernando Date: Fri, 2 Apr 2021 10:19:48 +0530 Subject: [PATCH 2/3] Indent examples of mg undeploy API command --- import-export-cli/cmd/mg/undeployAPI.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/import-export-cli/cmd/mg/undeployAPI.go b/import-export-cli/cmd/mg/undeployAPI.go index e3a876f9e..9e546c2d0 100644 --- a/import-export-cli/cmd/mg/undeployAPI.go +++ b/import-export-cli/cmd/mg/undeployAPI.go @@ -43,11 +43,11 @@ const ( "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 petstore -v 0.0.1 -e dev --gateway-env "Production and Sandbox" Label1 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 +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 --gateway-env "Production and Sandbox" Label1 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 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. From ee5f56ebad413e0da8c7af122f204b013e51c4b5 Mon Sep 17 00:00:00 2001 From: Renuka Fernando Date: Fri, 2 Apr 2021 14:35:22 +0530 Subject: [PATCH 3/3] Use a slice to hold gateway environments --- import-export-cli/cmd/mg/undeployAPI.go | 18 +++++++------- .../docs/apictl_mg_undeploy_api.md | 24 ++++++++++++------- .../apictl_bash_completions.sh | 6 +++++ 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/import-export-cli/cmd/mg/undeployAPI.go b/import-export-cli/cmd/mg/undeployAPI.go index 9e546c2d0..23f6f3706 100644 --- a/import-export-cli/cmd/mg/undeployAPI.go +++ b/import-export-cli/cmd/mg/undeployAPI.go @@ -28,11 +28,11 @@ import ( ) var ( - undeployAPICmdAPIName string - undeployAPICmdAPIVersion string - undeployAPICmdAPIVHost string - undeployAPICmdAPIGatewayEnv string - undeployAPIEnv string + undeployAPICmdAPIName string + undeployAPICmdAPIVersion string + undeployAPICmdAPIVHost string + undeployAPICmdAPIGatewayEnvs []string + undeployAPIEnv string ) const gatewayNameSeparator = ":" @@ -45,7 +45,7 @@ const ( 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 --gateway-env "Production and Sandbox" Label1 Label2 + ` + 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 @@ -68,9 +68,7 @@ var UndeployAPICmd = &cobra.Command{ queryParams["apiName"] = undeployAPICmdAPIName queryParams["version"] = undeployAPICmdAPIVersion queryParams["vhost"] = undeployAPICmdAPIVHost - // Since other flags does not use args[], gateway-env flag will own all the args - gatewayNames := append(args, undeployAPICmdAPIGatewayEnv) - queryParams["environments"] = strings.Join(gatewayNames, gatewayNameSeparator) + queryParams["environments"] = strings.Join(undeployAPICmdAPIGatewayEnvs, gatewayNameSeparator) err := mgImpl.UndeployAPI(undeployAPIEnv, queryParams) if err != nil { utils.HandleErrorAndExit("Error undeploying API", err) @@ -86,7 +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().StringVarP(&undeployAPICmdAPIGatewayEnv, "gateway-env", "g", "", "Gateway environment 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") diff --git a/import-export-cli/docs/apictl_mg_undeploy_api.md b/import-export-cli/docs/apictl_mg_undeploy_api.md index 3e0cf97af..e04585298 100644 --- a/import-export-cli/docs/apictl_mg_undeploy_api.md +++ b/import-export-cli/docs/apictl_mg_undeploy_api.md @@ -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 diff --git a/import-export-cli/shell-completions/apictl_bash_completions.sh b/import-export-cli/shell-completions/apictl_bash_completions.sh index a727f57f2..0666b3bf0 100644 --- a/import-export-cli/shell-completions/apictl_bash_completions.sh +++ b/import-export-cli/shell-completions/apictl_bash_completions.sh @@ -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")