Documentation ¶
Overview ¶
nolint
Index ¶
- Constants
- Variables
- func CheckCmdWorksWithEndpointAndTokenFlag(t *testing.T, cmd *cobra.Command, input string, responseBody string)
- func CheckhErrorWhenNoEnvEndpointAndTokenSet(t *testing.T, cmd *cobra.Command, input string)
- func CheckhErrorWhenNoEnvEndpointSet(t *testing.T, cmd *cobra.Command, input string)
- func CheckhErrorWhenNoEnvTokenSet(t *testing.T, cmd *cobra.Command, input string)
- func Execute()
- func FullCmdTester(testCommand *cobra.Command, input string) resulter
- func JsonDiff(responseBody, resulterOutput string) (bool, error)
- func JsonListDiff(responseBody, resulterOutput string) (bool, error)
- func ResetFlags()
- func StringDiff(text1, text2 string) string
- func TestServer(code int, body string, headers map[string]string) *httptest.Server
- type Automation
- type AutomationRun
- type Chef
- type JobState
- type PkiResult
- type Run
- type Script
Constants ¶
const ( RunPreparing = "preparing" RunExecuting = "executing" RunFailed = "failed" RunCompleted = "completed" )
const ( JobQueued = "queued" JobExecuting = "executing" JobFailed = "failed" JobComplete = "complete" )
Variables ¶
var ( ExecuteAuthOps = auth.AuthOptions{} ExecuteAuthV3 = auth.AuthenticationV3(ExecuteAuthOps) )
var ( FLAG_LYRA_SERVICE_ENDPOINT = "lyra-service-endpoint" ENV_VAR_AUTOMATION_ENDPOINT_NAME = "LYRA_SERVICE_ENDPOINT" FLAG_ARC_SERVICE_ENDPOINT = "arc-service-endpoint" ENV_VAR_ARC_ENDPOINT_NAME = "ARC_SERVICE_ENDPOINT" ENV_VAR_TOKEN_NAME = "OS_TOKEN" ENV_VAR_REGION = "OS_REGION" ENV_VAR_AUTH_URL = "OS_AUTH_URL" ENV_VAR_USER_ID = "OS_USER_ID" ENV_VAR_USERNAME = "OS_USERNAME" ENV_VAR_PASSWORD = "OS_PASSWORD" ENV_VAR_PROJECT_ID = "OS_PROJECT_ID" ENV_VAR_PROJECT_NAME = "OS_PROJECT_NAME" ENV_VAR_USER_DOMAIN_ID = "OS_USER_DOMAIN_ID" ENV_VAR_USER_DOMAIN_NAME = "OS_USER_DOMAIN_NAME" ENV_VAR_PROJECT_DOMAIN_ID = "OS_PROJECT_DOMAIN_ID" ENV_VAR_PROJECT_DOMAIN_NAME = "OS_PROJECT_DOMAIN_NAME" ENV_VAR_APPLICATION_CREDENTIAL_ID = "OS_APPLICATION_CREDENTIAL_ID" ENV_VAR_APPLICATION_CREDENTIAL_NAME = "OS_APPLICATION_CREDENTIAL_NAME" ENV_VAR_APPLICATION_CREDENTIAL_SECRET = "OS_APPLICATION_CREDENTIAL_SECRET" FLAG_TOKEN = "token" FLAG_REGION = "region" FLAG_AUTH_URL = "auth-url" FLAG_USER_ID = "user-id" FLAG_USERNAME = "username" FLAG_PASSWORD = "password" FLAG_PROJECT_ID = "project-id" FLAG_PROJECT_NAME = "project-name" FLAG_USER_DOMAIN_ID = "user-domain-id" FLAG_USER_DOMAIN_NAME = "user-domain-name" FLAG_PROJECT_DOMAIN_ID = "project-domain-id" FLAG_PROEJECT_DOMAIN_NAME = "project-domain-name" FLAG_APPLICATION_CREDENTIAL_ID = "application-credential-id" FLAG_APPLICATION_CREDENTIAL_NAME = "application-credential-name" FLAG_APPLICATION_CREDENTIAL_SECRET = "application-credential-secret" FLAG_AUTOMATION_ID = "automation-id" FLAG_RUN_ID = "run-id" FLAG_JOB_ID = "job-id" FLAG_SELECTOR = "selector" FLAG_DEBUG = "debug" FLAG_ARC_NODE_ID = "node-id" FLAG_ARC_INSTALL_FORMAT = "install-format" TOKEN_EXPIRES_AT = "token_expires_at" )
var AuthenticateCmd = &cobra.Command{ Use: "authenticate", Short: locales.CmdShortDescription("authenticate"), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return nil }, RunE: func(cmd *cobra.Command, args []string) error { options := auth.AuthOptions{ IdentityEndpoint: viper.GetString(ENV_VAR_AUTH_URL), Username: viper.GetString(ENV_VAR_USERNAME), UserId: viper.GetString(ENV_VAR_USER_ID), Password: viper.GetString(ENV_VAR_PASSWORD), ProjectName: viper.GetString(ENV_VAR_PROJECT_NAME), ProjectId: viper.GetString(ENV_VAR_PROJECT_ID), UserDomainName: viper.GetString(ENV_VAR_USER_DOMAIN_NAME), UserDomainId: viper.GetString(ENV_VAR_USER_DOMAIN_ID), ProjectDomainName: viper.GetString(ENV_VAR_PROJECT_DOMAIN_NAME), ProjectDomainId: viper.GetString(ENV_VAR_PROJECT_DOMAIN_ID), ApplicationCredentialID: viper.GetString(ENV_VAR_APPLICATION_CREDENTIAL_ID), ApplicationCredentialName: viper.GetString(ENV_VAR_APPLICATION_CREDENTIAL_NAME), ApplicationCredentialSecret: viper.GetString(ENV_VAR_APPLICATION_CREDENTIAL_SECRET), } authV3 := auth.AuthenticationV3(options) response, err := authenticate(cmd, authV3) if err != nil { return err } delete(response, TOKEN_EXPIRES_AT) printer := print.Print{Data: response} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint = fmt.Sprintf("export %s=%s\nexport %s=%s\nexport %s=%s", ENV_VAR_AUTOMATION_ENDPOINT_NAME, response[ENV_VAR_AUTOMATION_ENDPOINT_NAME], ENV_VAR_ARC_ENDPOINT_NAME, response[ENV_VAR_ARC_ENDPOINT_NAME], ENV_VAR_TOKEN_NAME, response[ENV_VAR_TOKEN_NAME]) } fmt.Println(bodyPrint) return nil }, }
authenticateCmd represents the authenticate command
var AutomationCmd = &cobra.Command{ Use: "automation", Short: locales.CmdShortDescription("automation"), }
automationCmd represents the automation command
var AutomationCreateChefCmd = &cobra.Command{ Use: "chef", Short: locales.CmdShortDescription("automation-create-chef"), RunE: func(cmd *cobra.Command, args []string) error { chef = Chef{ Automation: Automation{ Name: viper.GetString("automation-create-chef-name"), Repository: viper.GetString("automation-create-chef-repository"), RepositoryRevision: viper.GetString("automation-create-chef-repository-revision"), Timeout: viper.GetInt("automation-create-chef-timeout"), }, ChefVersion: viper.GetString("automation-create-chef-version"), Debug: viper.GetBool("automation-create-chef-debug"), } if len(viper.GetString("automation-create-chef-repository-credentials")) > 0 { credentials := viper.GetString("automation-create-chef-repository-credentials") chef.Automation.RepositoryCredentials = &credentials } err := setupAutomationChefAttr(&chef) if err != nil { return err } response, err := automationCreateChef(&chef) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
createCmd represents the create command
var AutomationCreateCmd = &cobra.Command{ Use: "create", Short: locales.CmdShortDescription("automation-create"), }
createCmd represents the create command
var AutomationCreateScriptCmd = &cobra.Command{ Use: "script", Short: locales.CmdShortDescription("automation-create-script"), RunE: func(cmd *cobra.Command, args []string) error { script = Script{ Automation: Automation{ Name: viper.GetString("automation-create-script-name"), Repository: viper.GetString("automation-create-script-repository"), RepositoryRevision: viper.GetString("automation-create-script-repository-revision"), Timeout: viper.GetInt("automation-create-script-timeout"), }, Path: viper.GetString("automation-create-script-path"), } if len(viper.GetString("automation-create-script-repository-credentials")) > 0 { credentials := viper.GetString("automation-create-script-repository-credentials") script.Automation.RepositoryCredentials = &credentials } err := setupAutomationScriptAttr(&script) if err != nil { return err } response, err := automationCreateScript(&script) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
createCmd represents the create command
var AutomationDeleteCmd = &cobra.Command{ Use: "delete", Short: locales.CmdShortDescription("automation-delete"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("automation-delete-id")) == 0 { return errors.New(locales.ErrorMessages("automation-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { _, err := automationDelete(viper.GetString("automation-delete-id")) if err != nil { return err } cmd.Println("Automation with id ", viper.GetString("automation-delete-id"), " deleted.") return nil }, }
var AutomationExecuteCmd = &cobra.Command{ Use: "execute", Short: locales.CmdShortDescription("automation-execute"), PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return nil }, PreRunE: func(cmd *cobra.Command, args []string) error { return setupAutomationRun() }, RunE: func(cmd *cobra.Command, args []string) error { var response string if viper.GetBool("watch") { ExecuteAuthOps = auth.AuthOptions{ IdentityEndpoint: viper.GetString(ENV_VAR_AUTH_URL), Username: viper.GetString(ENV_VAR_USERNAME), UserId: viper.GetString(ENV_VAR_USER_ID), Password: viper.GetString(ENV_VAR_PASSWORD), ProjectName: viper.GetString(ENV_VAR_PROJECT_NAME), ProjectId: viper.GetString(ENV_VAR_PROJECT_ID), UserDomainName: viper.GetString(ENV_VAR_USER_DOMAIN_NAME), UserDomainId: viper.GetString(ENV_VAR_USER_DOMAIN_ID), ProjectDomainName: viper.GetString(ENV_VAR_PROJECT_DOMAIN_NAME), ProjectDomainId: viper.GetString(ENV_VAR_PROJECT_DOMAIN_ID), ApplicationCredentialID: viper.GetString(ENV_VAR_APPLICATION_CREDENTIAL_ID), ApplicationCredentialName: viper.GetString(ENV_VAR_APPLICATION_CREDENTIAL_NAME), ApplicationCredentialSecret: viper.GetString(ENV_VAR_APPLICATION_CREDENTIAL_SECRET), } ExecuteAuthV3 = auth.AuthenticationV3(ExecuteAuthOps) err := setupRestClient(cmd, &ExecuteAuthV3, true) if err != nil { return err } response, err = automationRunWait(cmd) if err != nil { return err } } else { err := setupRestClient(cmd, nil, false) if err != nil { return err } response, err = automationRun() if err != nil { return err } } // convert data to struct var dataStruct map[string]interface{} err := helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
updateCmd represents the update command
var AutomationListCmd = &cobra.Command{ Use: "list", Short: locales.CmdShortDescription("automation-list"), RunE: func(cmd *cobra.Command, args []string) error { response, err := automationList() if err != nil { return err } printer := print.Print{Data: response} var tablePrint string if viper.GetBool("json") { tablePrint, err = printer.JSON() if err != nil { return err } } else { tablePrint, err = printer.TableList([]string{"id", "name", "type", "repository", "repository_authentication_enabled", "repository_revision", "timeout", "run_list", "chef_version", "debug"}) if err != nil { return err } } fmt.Println(tablePrint) return nil }, }
automation/listCmd represents the automation/list command
var AutomationShowCmd = &cobra.Command{ Use: "show", Short: locales.CmdShortDescription("automation-show"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("show-automation-id")) == 0 { return errors.New("no automation id given") } return nil }, RunE: func(cmd *cobra.Command, args []string) error { response, err := automationShow() if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
showCmd represents the show command
var AutomationUpdateChefAttributesCmd = &cobra.Command{ Use: "attributes", Short: locales.CmdShortDescription("automation-update-chef-attributes"), Long: locales.CmdLongDescription("automation-update-chef-attributes"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("automation-update-chef-attributes-automation-id")) == 0 { return errors.New(locales.ErrorMessages("automation-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { chef = Chef{} err := setupAutomationUpdateChefAttributes(&chef) if err != nil { return err } response, err := automationUpdateChefAttributes(&chef) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
updateCmd represents the update command
var AutomationUpdateChefCmd = &cobra.Command{ Use: "chef", Short: locales.CmdShortDescription("automation-update-chef"), }
updateCmd represents the update command
var AutomationUpdateChefRunlistCmd = &cobra.Command{ Use: "runlist", Short: locales.CmdShortDescription("automation-update-chef-runlist"), Long: locales.CmdLongDescription("automation-update-chef-runlist"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("automation-update-chef-runlist-automation-id")) == 0 { return errors.New(locales.ErrorMessages("automation-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { chef = Chef{} chef.Runlist = helpers.StringToArray(viper.GetString("automation-update-chef-runlist")) response, err := automationUpdateChefRunlist(&chef) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
var AutomationUpdateCmd = &cobra.Command{ Use: "update", Short: locales.CmdShortDescription("automation-update"), }
updateCmd represents the update command
var JobCmd = &cobra.Command{ Use: "job", Short: locales.CmdShortDescription("job"), }
automationCmd represents the automation command
var JobListCmd = &cobra.Command{ Use: "list", Short: locales.CmdShortDescription("job-list"), RunE: func(cmd *cobra.Command, args []string) error { response, err := jobList() if err != nil { return err } printer := print.Print{Data: response} var tablePrint string if viper.GetBool("json") { tablePrint, err = printer.JSON() if err != nil { return err } } else { tablePrint, err = printer.TableList([]string{"request_id", "status", "action", "agent", "user", "created_at"}) if err != nil { return err } } fmt.Println(tablePrint) return nil }, }
var JobLogCmd = &cobra.Command{ Use: "log", Short: locales.CmdShortDescription("job-log"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("log-job-id")) == 0 { return errors.New(locales.ErrorMessages("job-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { response, err := jobLog(viper.GetString("log-job-id")) if err != nil { return err } fmt.Println(response) return nil }, }
var JobShowCmd = &cobra.Command{ Use: "show", Short: locales.CmdShortDescription("job-show"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("show-job-id")) == 0 { return errors.New(locales.ErrorMessages("job-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { response, err := jobShow(viper.GetString("show-job-id")) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
var NodeCmd = &cobra.Command{ Use: "node", Short: locales.CmdShortDescription("arc"), }
var NodeDeleteCmd = &cobra.Command{ Use: "delete", Short: locales.CmdShortDescription("arc-node-delete"), Long: locales.CmdLongDescription("arc-node-delete"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("arc-delete-node-id")) == 0 { return errors.New(locales.ErrorMessages("node-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { _, err := nodeDelete(viper.GetString("arc-delete-node-id")) if err != nil { return err } cmd.Println("Node with id ", viper.GetString("arc-delete-node-id"), " deleted.") return nil }, }
var NodeFactCmd = &cobra.Command{ Use: "fact", Short: locales.CmdShortDescription("arc-node-fact"), }
var NodeFactListCmd = &cobra.Command{ Use: "list", Short: locales.CmdShortDescription("arc-node-fact-list"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("arc-fact-list-node-id")) == 0 { return errors.New(locales.ErrorMessages("node-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { response, err := nodeFactList(viper.GetString("arc-fact-list-node-id")) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
var NodeInstallCmd = &cobra.Command{ Use: "install", Short: locales.CmdShortDescription("arc-node-install"), RunE: func(cmd *cobra.Command, args []string) error { err := checkArcInstallParams() if err != nil { return err } script, err := generateScript() if err != nil { return err } fmt.Println(script) return nil }, }
var NodeListCmd = &cobra.Command{ Use: "list", Short: locales.CmdShortDescription("arc-node-list"), RunE: func(cmd *cobra.Command, args []string) error { response, err := nodeList() if err != nil { return err } printer := print.Print{Data: response} var tablePrint string if viper.GetBool("json") { tablePrint, err = printer.JSON() if err != nil { return err } } else { tablePrint, err = printer.TableList([]string{"agent_id", "display_name", "organization", "project", "created_at", "updated_at", "updated_by", "updated_with"}) if err != nil { return err } } fmt.Println(tablePrint) return nil }, }
var NodeShowCmd = &cobra.Command{ Use: "show", Short: locales.CmdShortDescription("arc-node-show"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("arc-show-node-id")) == 0 { return errors.New(locales.ErrorMessages("node-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { response, err := nodeShow(viper.GetString("arc-show-node-id")) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
var NodeTagAddCmd = &cobra.Command{ Use: "add", Short: locales.CmdShortDescription("arc-node-tag-add"), Long: locales.CmdLongDescription("arc-node-tag-add"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("arc-tag-add-node-id")) == 0 { return errors.New(locales.ErrorMessages("node-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { body, err := parseArgs(args) if err != nil { return err } _, err = nodeTagAdd(viper.GetString("arc-tag-add-node-id"), body) if err != nil { return err } cmd.Println("Tags added successfully to the node with id ", viper.GetString("arc-tag-add-node-id")) return nil }, }
var NodeTagCmd = &cobra.Command{ Use: "tag", Short: locales.CmdShortDescription("arc-node-tag"), }
var NodeTagDeleteCmd = &cobra.Command{ Use: "delete", Short: locales.CmdShortDescription("arc-node-tag-delete"), Long: locales.CmdLongDescription("arc-node-tag-delete"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("arc-tag-delete-node-id")) == 0 { return errors.New(locales.ErrorMessages("node-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { for _, element := range args { _, err := nodeTagdelete(viper.GetString("arc-tag-delete-node-id"), element) if err != nil { return err } cmd.Println("Tag from agent with id ", viper.GetString("arc-tag-delete-node-id"), " and value ", element, " is deleted.") } return nil }, }
var NodeTagListCmd = &cobra.Command{ Use: "list", Short: locales.CmdShortDescription("arc-node-tag-list"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString("arc-tag-list-node-id")) == 0 { return errors.New(locales.ErrorMessages("node-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { response, err := nodeTagList(viper.GetString("arc-tag-list-node-id")) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
var (
RestClient *restclient.Client
)
var RootCmd = &cobra.Command{ Use: "lyra", Short: locales.CmdShortDescription("root"), Long: locales.CmdLongDescription("root"), SilenceUsage: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return setupRestClient(cmd, nil, false) }, }
RootCmd represents the base command when called without any subcommands
var RunCmd = &cobra.Command{ Use: "run", Short: locales.CmdShortDescription("run"), }
automationCmd represents the automation command
var RunListCmd = &cobra.Command{ Use: "list", Short: locales.CmdShortDescription("run-list"), RunE: func(cmd *cobra.Command, args []string) error { response, err := runList() if err != nil { return err } printer := print.Print{Data: response} var tablePrint string if viper.GetBool("json") { tablePrint, err = printer.JSON() if err != nil { return err } } else { tablePrint, err = printer.TableList([]string{"id", "automation_id", "automation_name", "state", "owner", "created_at"}) if err != nil { return err } } fmt.Println(tablePrint) return nil }, }
var RunShowCmd = &cobra.Command{ Use: "show", Short: locales.CmdShortDescription("run-show"), PreRunE: func(cmd *cobra.Command, args []string) error { if len(viper.GetString(FLAG_RUN_ID)) == 0 { return errors.New(locales.ErrorMessages("run-id-missing")) } return nil }, RunE: func(cmd *cobra.Command, args []string) error { response, err := runShow(viper.GetString(FLAG_RUN_ID)) if err != nil { return err } // convert data to struct var dataStruct map[string]interface{} err = helpers.JSONStringToStructure(response, &dataStruct) if err != nil { return err } printer := print.Print{Data: dataStruct} var bodyPrint string if viper.GetBool("json") { bodyPrint, err = printer.JSON() if err != nil { return err } } else { bodyPrint, err = printer.Table() if err != nil { return err } } fmt.Println(bodyPrint) return nil }, }
Functions ¶
func Execute ¶
func Execute()
Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.
func FullCmdTester ¶
func JsonListDiff ¶
func ResetFlags ¶
func ResetFlags()
func StringDiff ¶
Types ¶
type Automation ¶
type Automation struct { Id int `json:"id"` Name string `json:"name"` // required Repository string `json:"repository"` // required RepositoryRevision string `json:"repository_revision"` // required RepositoryCredentials *string `json:"repository_credentials,omitempty"` RepositoryAuthenticationEnabled *bool `json:"repository_authentication_enabled,omitempty"` Timeout int `json:"timeout"` // required }
removed tags since no use case yet Tags map[string]string `json:"tags,omitempty"` // JSON
type AutomationRun ¶
type Chef ¶
type Chef struct { Automation AutomationType string `json:"type"` Runlist []string `json:"run_list,omitempty"` // required, JSON Attributes interface{} `json:"chef_attributes,omitempty"` // JSON LogLevel string `json:"log_level,omitempty"` Debug bool `json:"debug,omitempty"` ChefVersion string `json:"chef_version,omitempty"` }
Source Files ¶
- authenticate.go
- automation.go
- automation_create.go
- automation_create_chef.go
- automation_create_script.go
- automation_delete.go
- automation_execute.go
- automation_list.go
- automation_show.go
- automation_update.go
- automation_update_chef.go
- automation_update_chef_attributes.go
- automation_update_chef_runlist.go
- bash-completion.go
- flags_envVars.go
- job.go
- job_list.go
- job_log.go
- job_show.go
- node.go
- node_delete.go
- node_fact.go
- node_fact_list.go
- node_install.go
- node_list.go
- node_show.go
- node_tag.go
- node_tag_add.go
- node_tag_delete.go
- node_tag_list.go
- root.go
- run.go
- run_list.go
- run_show.go
- test_helper.go
- version.go