-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for GET/ENABLE/DISABLE maintenance mode in GoC.
- Loading branch information
1 parent
69a365d
commit 9c95093
Showing
10 changed files
with
256 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,105 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/nikhilsbhat/gocd-cli/pkg/render" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
goCDEnableMaintenance bool | ||
goCDDisableMaintenance bool | ||
) | ||
|
||
func registerMaintenanceCommand() *cobra.Command { | ||
return &cobra.Command{} | ||
maintenanceCommand := &cobra.Command{ | ||
Use: "maintenance", | ||
Short: "Command to operate on maintenance modes in GoCD [https://api.gocd.org/current/#maintenance-mode]", | ||
Long: `Command leverages GoCD environments apis' [https://api.gocd.org/current/#maintenance-mode] to | ||
ENABLE/DISABLE/GET maintenance mode information from GoCD`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := cmd.Usage(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
maintenanceCommand.SetUsageTemplate(getUsageTemplate()) | ||
|
||
registerMaintenanceFlags(maintenanceCommand) | ||
|
||
maintenanceCommand.AddCommand(enableOrDisableMaintenanceCommand()) | ||
maintenanceCommand.AddCommand(getMaintenanceCommand()) | ||
|
||
for _, command := range maintenanceCommand.Commands() { | ||
command.SilenceUsage = true | ||
} | ||
|
||
return maintenanceCommand | ||
} | ||
|
||
func getMaintenanceCommand() *cobra.Command { | ||
getMaintenanceCmd := &cobra.Command{ | ||
Use: "get", | ||
Short: "Command to GET a maintenance mode information from GoCD [https://api.gocd.org/current/#get-maintenance-mode-info]", | ||
Args: cobra.NoArgs, | ||
PreRunE: setCLIClient, | ||
Example: `gocd-cli maintenance get`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
response, err := client.GetMaintenanceModeInfo() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(jsonQuery) != 0 { | ||
cliLogger.Debugf(queryEnabledMessage, jsonQuery) | ||
|
||
baseQuery, err := render.SetQuery(response, jsonQuery) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cliLogger.Debugf(baseQuery.Print()) | ||
|
||
return cliRenderer.Render(baseQuery.RunQuery()) | ||
} | ||
|
||
return cliRenderer.Render(response) | ||
}, | ||
} | ||
|
||
return getMaintenanceCmd | ||
} | ||
|
||
func enableOrDisableMaintenanceCommand() *cobra.Command { | ||
enableDisableMaintenanceModeCmd := &cobra.Command{ | ||
Use: "action", | ||
Short: `Command to ENABLE/DISABLE maintenance mode in GoCD, | ||
[https://api.gocd.org/current/#enable-maintenance-mode,https://api.gocd.org/current/#disable-maintenance-mode]`, | ||
Args: cobra.NoArgs, | ||
PreRunE: setCLIClient, | ||
Example: `gocd-cli maintenance --enable/--disable`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var action string | ||
if goCDEnableMaintenance { | ||
action = "enabling" | ||
if err := client.EnableMaintenanceMode(); err != nil { | ||
return err | ||
} | ||
} | ||
if goCDDisableMaintenance { | ||
action = "disabling" | ||
if err := client.DisableMaintenanceMode(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return cliRenderer.Render(fmt.Sprintf("%s maintenance mode was successful", action)) | ||
}, | ||
} | ||
|
||
return enableDisableMaintenanceModeCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## gocd-cli maintenance | ||
|
||
Command to operate on maintenance modes in GoCD [https://api.gocd.org/current/#maintenance-mode] | ||
|
||
### Synopsis | ||
|
||
Command leverages GoCD environments apis' [https://api.gocd.org/current/#maintenance-mode] to | ||
ENABLE/DISABLE/GET maintenance mode information from GoCD | ||
|
||
``` | ||
gocd-cli maintenance [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--disable set this to disable maintenance mode in GoCD | ||
--enable set this to enable maintenance mode in GoCD | ||
-h, --help help for maintenance | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-t, --auth-token string token to authenticate with GoCD server, should not be co-used with basic auth (username/password) | ||
--ca-file-path string path to file containing CA cert used to authenticate GoCD server, if you have one | ||
--from-file string file containing configurations of objects that needs to be created in GoCD, config-repo/pipeline-group/environment and etc. | ||
--json enable this to Render output in JSON format | ||
-l, --log-level string log level for gocd cli, log levels supported by [https://github.com/sirupsen/logrus] will work (default "info") | ||
--no-color enable this to Render output in YAML format | ||
-p, --password string password to authenticate with GoCD server | ||
-q, --query string query to filter the results, ex: '.material.attributes.type | id eq git'. this uses library gojsonq beneath | ||
more queries can be found here https://github.com/thedevsaddam/gojsonq/wiki/Queries | ||
--save-config enable this to locally save auth configs used to connect GoCD server (path: $HOME/.gocd/auth_config.yaml) | ||
--server-url string GoCD server URL base path (default "http://localhost:8153/go") | ||
--skip-cache-config if enabled locally save auth configs would not be used to authenticate GoCD server (path: $HOME/.gocd/auth_config.yaml) | ||
--to-file string file to which the output needs to be written to (this works only if --yaml or --json is enabled) | ||
-u, --username string username to authenticate with GoCD server | ||
--yaml enable this to Render output in YAML format | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [gocd-cli](gocd-cli.md) - Command line interface for GoCD | ||
* [gocd-cli maintenance action](gocd-cli_maintenance_action.md) - Command to ENABLE/DISABLE maintenance mode in GoCD, | ||
[https://api.gocd.org/current/#enable-maintenance-mode,https://api.gocd.org/current/#disable-maintenance-mode] | ||
* [gocd-cli maintenance get](gocd-cli_maintenance_get.md) - Command to GET a maintenance mode information from GoCD [https://api.gocd.org/current/#get-maintenance-mode-info] | ||
|
||
###### Auto generated by spf13/cobra on 20-Mar-2023 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## gocd-cli maintenance action | ||
|
||
Command to ENABLE/DISABLE maintenance mode in GoCD, | ||
[https://api.gocd.org/current/#enable-maintenance-mode,https://api.gocd.org/current/#disable-maintenance-mode] | ||
|
||
``` | ||
gocd-cli maintenance action [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
gocd-cli maintenance --enable/--disable | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for action | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-t, --auth-token string token to authenticate with GoCD server, should not be co-used with basic auth (username/password) | ||
--ca-file-path string path to file containing CA cert used to authenticate GoCD server, if you have one | ||
--disable set this to disable maintenance mode in GoCD | ||
--enable set this to enable maintenance mode in GoCD | ||
--from-file string file containing configurations of objects that needs to be created in GoCD, config-repo/pipeline-group/environment and etc. | ||
--json enable this to Render output in JSON format | ||
-l, --log-level string log level for gocd cli, log levels supported by [https://github.com/sirupsen/logrus] will work (default "info") | ||
--no-color enable this to Render output in YAML format | ||
-p, --password string password to authenticate with GoCD server | ||
-q, --query string query to filter the results, ex: '.material.attributes.type | id eq git'. this uses library gojsonq beneath | ||
more queries can be found here https://github.com/thedevsaddam/gojsonq/wiki/Queries | ||
--save-config enable this to locally save auth configs used to connect GoCD server (path: $HOME/.gocd/auth_config.yaml) | ||
--server-url string GoCD server URL base path (default "http://localhost:8153/go") | ||
--skip-cache-config if enabled locally save auth configs would not be used to authenticate GoCD server (path: $HOME/.gocd/auth_config.yaml) | ||
--to-file string file to which the output needs to be written to (this works only if --yaml or --json is enabled) | ||
-u, --username string username to authenticate with GoCD server | ||
--yaml enable this to Render output in YAML format | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [gocd-cli maintenance](gocd-cli_maintenance.md) - Command to operate on maintenance modes in GoCD [https://api.gocd.org/current/#maintenance-mode] | ||
|
||
###### Auto generated by spf13/cobra on 20-Mar-2023 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## gocd-cli maintenance get | ||
|
||
Command to GET a maintenance mode information from GoCD [https://api.gocd.org/current/#get-maintenance-mode-info] | ||
|
||
``` | ||
gocd-cli maintenance get [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
gocd-cli maintenance get | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for get | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-t, --auth-token string token to authenticate with GoCD server, should not be co-used with basic auth (username/password) | ||
--ca-file-path string path to file containing CA cert used to authenticate GoCD server, if you have one | ||
--disable set this to disable maintenance mode in GoCD | ||
--enable set this to enable maintenance mode in GoCD | ||
--from-file string file containing configurations of objects that needs to be created in GoCD, config-repo/pipeline-group/environment and etc. | ||
--json enable this to Render output in JSON format | ||
-l, --log-level string log level for gocd cli, log levels supported by [https://github.com/sirupsen/logrus] will work (default "info") | ||
--no-color enable this to Render output in YAML format | ||
-p, --password string password to authenticate with GoCD server | ||
-q, --query string query to filter the results, ex: '.material.attributes.type | id eq git'. this uses library gojsonq beneath | ||
more queries can be found here https://github.com/thedevsaddam/gojsonq/wiki/Queries | ||
--save-config enable this to locally save auth configs used to connect GoCD server (path: $HOME/.gocd/auth_config.yaml) | ||
--server-url string GoCD server URL base path (default "http://localhost:8153/go") | ||
--skip-cache-config if enabled locally save auth configs would not be used to authenticate GoCD server (path: $HOME/.gocd/auth_config.yaml) | ||
--to-file string file to which the output needs to be written to (this works only if --yaml or --json is enabled) | ||
-u, --username string username to authenticate with GoCD server | ||
--yaml enable this to Render output in YAML format | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [gocd-cli maintenance](gocd-cli_maintenance.md) - Command to operate on maintenance modes in GoCD [https://api.gocd.org/current/#maintenance-mode] | ||
|
||
###### Auto generated by spf13/cobra on 20-Mar-2023 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters