cmd

package
v0.0.0-...-226c4f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

nolint

Index

Constants

View Source
const (
	RunPreparing = "preparing"
	RunExecuting = "executing"
	RunFailed    = "failed"
	RunCompleted = "completed"
)
View Source
const (
	JobQueued    = "queued"
	JobExecuting = "executing"
	JobFailed    = "failed"
	JobComplete  = "complete"
)

Variables

View Source
var (
	ExecuteAuthOps = auth.AuthOptions{}
	ExecuteAuthV3  = auth.AuthenticationV3(ExecuteAuthOps)
)
View Source
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"
)
View Source
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

View Source
var AutomationCmd = &cobra.Command{
	Use:   "automation",
	Short: locales.CmdShortDescription("automation"),
}

automationCmd represents the automation command

View Source
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

View Source
var AutomationCreateCmd = &cobra.Command{
	Use:   "create",
	Short: locales.CmdShortDescription("automation-create"),
}

createCmd represents the create command

View Source
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

View Source
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
	},
}
View Source
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

View Source
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

View Source
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

View Source
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

View Source
var AutomationUpdateChefCmd = &cobra.Command{
	Use:   "chef",
	Short: locales.CmdShortDescription("automation-update-chef"),
}

updateCmd represents the update command

View Source
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
	},
}
View Source
var AutomationUpdateCmd = &cobra.Command{
	Use:   "update",
	Short: locales.CmdShortDescription("automation-update"),
}

updateCmd represents the update command

View Source
var JobCmd = &cobra.Command{
	Use:   "job",
	Short: locales.CmdShortDescription("job"),
}

automationCmd represents the automation command

View Source
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
	},
}
View Source
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
	},
}
View Source
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
	},
}
View Source
var NodeCmd = &cobra.Command{
	Use:   "node",
	Short: locales.CmdShortDescription("arc"),
}
View Source
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
	},
}
View Source
var NodeFactCmd = &cobra.Command{
	Use:   "fact",
	Short: locales.CmdShortDescription("arc-node-fact"),
}
View Source
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
	},
}
View Source
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
	},
}
View Source
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
	},
}
View Source
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
	},
}
View Source
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
	},
}
View Source
var NodeTagCmd = &cobra.Command{
	Use:   "tag",
	Short: locales.CmdShortDescription("arc-node-tag"),
}
View Source
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
	},
}
View Source
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
	},
}
View Source
var (
	RestClient *restclient.Client
)
View Source
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

View Source
var RunCmd = &cobra.Command{
	Use:   "run",
	Short: locales.CmdShortDescription("run"),
}

automationCmd represents the automation command

View Source
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
	},
}
View Source
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
	},
}
View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: locales.CmdShortDescription("version"),
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.Println(version.String())
		return nil
	},
}

Functions

func CheckCmdWorksWithEndpointAndTokenFlag

func CheckCmdWorksWithEndpointAndTokenFlag(t *testing.T, cmd *cobra.Command, input string, responseBody string)

func CheckhErrorWhenNoEnvEndpointAndTokenSet

func CheckhErrorWhenNoEnvEndpointAndTokenSet(t *testing.T, cmd *cobra.Command, input string)

func CheckhErrorWhenNoEnvEndpointSet

func CheckhErrorWhenNoEnvEndpointSet(t *testing.T, cmd *cobra.Command, input string)

func CheckhErrorWhenNoEnvTokenSet

func CheckhErrorWhenNoEnvTokenSet(t *testing.T, cmd *cobra.Command, input string)

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 FullCmdTester(testCommand *cobra.Command, input string) resulter

func JsonDiff

func JsonDiff(responseBody, resulterOutput string) (bool, error)

func JsonListDiff

func JsonListDiff(responseBody, resulterOutput string) (bool, error)

func ResetFlags

func ResetFlags()

func StringDiff

func StringDiff(text1, text2 string) string

func TestServer

func TestServer(code int, body string, headers map[string]string) *httptest.Server

TestServer should be closed afterwards

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 AutomationRun struct {
	Id    string   `json:"id"`
	State string   `json:"state"`
	Jobs  []string `json:"jobs"`
}

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"`
}

func (*Chef) Marshal

func (c *Chef) Marshal() (string, error)

Marshal map chef json

func (*Chef) Unmarshal

func (c *Chef) Unmarshal(response string) error

Unmarshal map to chef struct

type JobState

type JobState byte

type PkiResult

type PkiResult struct {
	Token string `json:"token"`
	Url   string `json:"url"`
}

type Run

type Run struct {
	AutomationId string `json:"automation_id"`
	Selector     string `json:"selector"`
}

type Script

type Script struct {
	Automation
	AutomationType string            `json:"type"`
	Path           string            `json:"path"`
	Arguments      []string          `json:"arguments"`   // array of strings
	Environment    map[string]string `json:"environment"` // JSON
}

func (*Script) Marshal

func (s *Script) Marshal() (string, error)

Marshal map chef json

func (*Script) Unmarshal

func (s *Script) Unmarshal(response string) error

Unmarshal map to chef struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL