func (cmd *unbindFromStagingGroup) Execute(context flags.FlagContext) error { name := context.Args()[0] cmd.ui.Say(T("Unbinding security group {{.security_group}} from defaults for staging as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) securityGroup, err := cmd.securityGroupRepo.Read(name) switch (err).(type) { case nil: case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(T("Security group {{.security_group}} {{.error_message}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "error_message": terminal.WarningColor(T("does not exist.")), })) return nil default: return err } err = cmd.stagingGroupRepo.UnbindFromStagingSet(securityGroup.GUID) if err != nil { return err } cmd.ui.Ok() cmd.ui.Say("\n\n") cmd.ui.Say(T("TIP: Changes will not apply to existing running applications until they are restarted.")) return nil }
func (cmd API) setAPIEndpoint(endpoint string, skipSSL bool, cmdName string) error { if strings.HasSuffix(endpoint, "/") { endpoint = strings.TrimSuffix(endpoint, "/") } cmd.config.SetSSLDisabled(skipSSL) refresher := coreconfig.APIConfigRefresher{ Endpoint: endpoint, EndpointRepo: cmd.endpointRepo, Config: cmd.config, } warning, err := refresher.Refresh() if err != nil { cmd.config.SetAPIEndpoint("") cmd.config.SetSSLDisabled(false) switch typedErr := err.(type) { case *errors.InvalidSSLCert: cfAPICommand := terminal.CommandColor(fmt.Sprintf("%s %s --skip-ssl-validation", cf.Name, cmdName)) tipMessage := fmt.Sprintf(T("TIP: Use '{{.APICommand}}' to continue with an insecure API endpoint", map[string]interface{}{"APICommand": cfAPICommand})) return errors.New(T("Invalid SSL Cert for {{.URL}}\n{{.TipMessage}}", map[string]interface{}{"URL": typedErr.URL, "TipMessage": tipMessage})) default: return typedErr } } if warning != nil { cmd.ui.Say(terminal.WarningColor(warning.Warn())) } return nil }
func (cmd *Login) MetaData() commandregistry.CommandMetadata { fs := make(map[string]flags.FlagSet) fs["a"] = &flags.StringFlag{ShortName: "a", Usage: T("API endpoint (e.g. https://api.example.com)")} fs["u"] = &flags.StringFlag{ShortName: "u", Usage: T("Username")} fs["p"] = &flags.StringFlag{ShortName: "p", Usage: T("Password")} fs["o"] = &flags.StringFlag{ShortName: "o", Usage: T("Org")} fs["s"] = &flags.StringFlag{ShortName: "s", Usage: T("Space")} fs["sso"] = &flags.BoolFlag{Name: "sso", Usage: T("Use a one-time password to login")} fs["skip-ssl-validation"] = &flags.BoolFlag{Name: "skip-ssl-validation", Usage: T("Skip verification of the API endpoint. Not recommended!")} return commandregistry.CommandMetadata{ Name: "login", ShortName: "l", Description: T("Log user in"), Usage: []string{ T("CF_NAME login [-a API_URL] [-u USERNAME] [-p PASSWORD] [-o ORG] [-s SPACE]\n\n"), terminal.WarningColor(T("WARNING:\n Providing your password as a command line option is highly discouraged\n Your password may be visible to others and may be recorded in your shell history")), }, Examples: []string{ T("CF_NAME login (omit username and password to login interactively -- CF_NAME will prompt for both)"), T("CF_NAME login -u [email protected] -p pa55woRD (specify username and password as arguments)"), T("CF_NAME login -u [email protected] -p \"my password\" (use quotes for passwords with a space)"), T("CF_NAME login -u [email protected] -p \"\\\"password\\\"\" (escape quotes if used in password)"), T("CF_NAME login --sso (CF_NAME will provide a url to obtain a one-time password to login)"), }, Flags: fs, } }
func (cmd *Stop) Execute(c flags.FlagContext) error { app := cmd.appReq.GetApplication() if app.State == models.ApplicationStateStopped { cmd.ui.Say(terminal.WarningColor(T("App ") + app.Name + T(" is already stopped"))) } else { _, err := cmd.ApplicationStop(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name) if err != nil { return err } } return nil }
func (cmd *Authenticate) MetaData() commandregistry.CommandMetadata { return commandregistry.CommandMetadata{ Name: "auth", Description: T("Authenticate user non-interactively"), Usage: []string{ T("CF_NAME auth USERNAME PASSWORD\n\n"), terminal.WarningColor(T("WARNING:\n Providing your password as a command line option is highly discouraged\n Your password may be visible to others and may be recorded in your shell history")), }, Examples: []string{ T("CF_NAME auth [email protected] \"my password\" (use quotes for passwords with a space)"), T("CF_NAME auth [email protected] \"\\\"password\\\"\" (escape quotes if used in password)"), }, } }
func ColoredAppState(app models.ApplicationFields) string { appState := strings.ToLower(app.State) if app.RunningInstances == 0 { if appState == models.ApplicationStateStopped { return appState } return terminal.CrashedColor(appState) } if app.RunningInstances < app.InstanceCount { return terminal.WarningColor(appState) } return appState }
func (cmd *Start) ApplicationStart(app models.Application, orgName, spaceName string) (models.Application, error) { if app.State == "started" { cmd.ui.Say(terminal.WarningColor(T("App ") + app.Name + T(" is already started"))) return models.Application{}, nil } return cmd.WatchStaging(app, orgName, spaceName, func(app models.Application) (models.Application, error) { cmd.ui.Say(T("Starting app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(orgName), "SpaceName": terminal.EntityNameColor(spaceName), "CurrentUser": terminal.EntityNameColor(cmd.config.Username())})) state := "started" return cmd.appRepo.Update(app.GUID, models.AppParams{State: &state}) }) }
func (cmd *CreateSecurityGroup) Execute(context flags.FlagContext) error { name := context.Args()[0] pathToJSONFile := context.Args()[1] rules, err := json.ParseJSONArray(pathToJSONFile) if err != nil { return errors.New(T(`Incorrect json format: file: {{.JSONFile}} Valid json file example: [ { "protocol": "tcp", "destination": "10.244.1.18", "ports": "3306" } ]`, map[string]interface{}{"JSONFile": pathToJSONFile})) } cmd.ui.Say(T("Creating security group {{.security_group}} as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) err = cmd.securityGroupRepo.Create(name, rules) httpErr, ok := err.(errors.HTTPError) if ok && httpErr.ErrorCode() == errors.SecurityGroupNameTaken { cmd.ui.Ok() cmd.ui.Warn(T("Security group {{.security_group}} {{.error_message}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "error_message": terminal.WarningColor(T("already exists")), })) return nil } if err != nil { return err } cmd.ui.Ok() return nil }
func ColoredAppInstances(app models.ApplicationFields) string { healthString := fmt.Sprintf("%d/%d", app.RunningInstances, app.InstanceCount) if app.RunningInstances < 0 { healthString = fmt.Sprintf("?/%d", app.InstanceCount) } if app.RunningInstances == 0 { if strings.ToLower(app.State) == models.ApplicationStateStopped { return healthString } return terminal.CrashedColor(healthString) } if app.RunningInstances < app.InstanceCount { return terminal.WarningColor(healthString) } return healthString }
func ColoredInstanceState(instance models.AppInstanceFields) (colored string) { state := string(instance.State) switch state { case models.ApplicationStateStarted, models.ApplicationStateRunning: colored = T("running") case models.ApplicationStateStopped: colored = terminal.StoppedColor(T("stopped")) case models.ApplicationStateCrashed: colored = terminal.CrashedColor(T("crashed")) case models.ApplicationStateFlapping: colored = terminal.CrashedColor(T("crashing")) case models.ApplicationStateDown: colored = terminal.CrashedColor(T("down")) case models.ApplicationStateStarting: colored = terminal.AdvisoryColor(T("starting")) default: colored = terminal.WarningColor(state) } return }