func (cmd *unbindFromRunningGroup) Run(context *cli.Context) { name := context.Args()[0] 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 default: cmd.ui.Failed(err.Error()) } cmd.ui.Say(T("Unbinding security group {{.security_group}} from defaults for running as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(securityGroup.Name), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) err = cmd.runningGroupRepo.UnbindFromRunningSet(securityGroup.Guid) if err != nil { cmd.ui.Failed(err.Error()) } 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.")) }
func (cmd CreateUser) Run(c *cli.Context) { username := c.Args()[0] password := c.Args()[1] cmd.ui.Say(T("Creating user {{.TargetUser}} as {{.CurrentUser}}...", map[string]interface{}{ "TargetUser": terminal.EntityNameColor(username), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) err := cmd.userRepo.Create(username, password) switch err.(type) { case nil: case *errors.ModelAlreadyExistsError: cmd.ui.Warn("%s", err.Error()) default: cmd.ui.Failed(T("Error creating user {{.TargetUser}}.\n{{.Error}}", map[string]interface{}{ "TargetUser": terminal.EntityNameColor(username), "Error": err.Error(), })) } cmd.ui.Ok() cmd.ui.Say(T("\nTIP: Assign roles with '{{.CurrentUser}} set-org-role' and '{{.CurrentUser}} set-space-role'", map[string]interface{}{"CurrentUser": cf.Name()})) }
func (cmd *UnsetEnv) Run(c *cli.Context) { varName := c.Args()[1] app := cmd.appReq.GetApplication() cmd.ui.Say(T("Removing env variable {{.VarName}} from app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "VarName": terminal.EntityNameColor(varName), "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username())})) envParams := app.EnvironmentVars if _, ok := envParams[varName]; !ok { cmd.ui.Ok() cmd.ui.Warn(T("Env variable {{.VarName}} was not set.", map[string]interface{}{"VarName": varName})) return } delete(envParams, varName) _, apiErr := cmd.appRepo.Update(app.Guid, models.AppParams{EnvironmentVars: &envParams}) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() cmd.ui.Say(T("TIP: Use '{{.Command}}' to ensure your env variable changes take effect", map[string]interface{}{"Command": terminal.CommandColor(cf.Name() + " restage")})) }
func (cmd *UnbindService) Run(c *cli.Context) { app := cmd.appReq.GetApplication() instance := cmd.serviceInstanceReq.GetServiceInstance() cmd.ui.Say(T("Unbinding app {{.AppName}} from service {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(app.Name), "ServiceName": terminal.EntityNameColor(instance.Name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) found, apiErr := cmd.serviceBindingRepo.Delete(instance, app.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() if !found { cmd.ui.Warn(T("Binding between {{.InstanceName}} and {{.AppName}} did not exist", map[string]interface{}{"InstanceName": instance.Name, "AppName": app.Name})) } }
func (cmd *ShowService) Run(c *cli.Context) { serviceInstance := cmd.serviceInstanceReq.GetServiceInstance() cmd.ui.Say("") cmd.ui.Say(T("Service instance: {{.ServiceName}}", map[string]interface{}{"ServiceName": terminal.EntityNameColor(serviceInstance.Name)})) if serviceInstance.IsUserProvided() { cmd.ui.Say(T("Service: {{.ServiceDescription}}", map[string]interface{}{ "ServiceDescription": terminal.EntityNameColor(T("user-provided")), })) } else { cmd.ui.Say(T("Service: {{.ServiceDescription}}", map[string]interface{}{ "ServiceDescription": terminal.EntityNameColor(serviceInstance.ServiceOffering.Label), })) cmd.ui.Say(T("Plan: {{.ServicePlanName}}", map[string]interface{}{ "ServicePlanName": terminal.EntityNameColor(serviceInstance.ServicePlan.Name), })) cmd.ui.Say(T("Description: {{.ServiceDescription}}", map[string]interface{}{"ServiceDescription": terminal.EntityNameColor(serviceInstance.ServiceOffering.Description)})) cmd.ui.Say(T("Documentation url: {{.URL}}", map[string]interface{}{ "URL": terminal.EntityNameColor(serviceInstance.ServiceOffering.DocumentationUrl), })) } }
func (cmd *UpdateService) Run(c *cli.Context) { serviceInstanceName := c.Args()[0] serviceInstance, err := cmd.serviceRepo.FindInstanceByName(serviceInstanceName) if err != nil { cmd.ui.Failed(err.Error()) return } planName := c.String("p") if planName != "" { cmd.ui.Say(T("Updating service instance {{.ServiceName}} as {{.UserName}}...", map[string]interface{}{ "ServiceName": terminal.EntityNameColor(serviceInstanceName), "UserName": terminal.EntityNameColor(cmd.config.Username()), })) err := cmd.updateServiceWithPlan(serviceInstance, planName) switch err.(type) { case nil: cmd.ui.Ok() default: cmd.ui.Failed(err.Error()) } } else { cmd.ui.Ok() cmd.ui.Say(T("No changes were made")) } }
func (cmd UnsetSpaceQuota) Run(c *cli.Context) { spaceName := c.Args()[0] quotaName := c.Args()[1] space, apiErr := cmd.spaceRepo.FindByName(spaceName) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } quota, apiErr := cmd.quotaRepo.FindByName(quotaName) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Say(T("Unassigning space quota {{.QuotaName}} from space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "QuotaName": terminal.EntityNameColor(quota.Name), "SpaceName": terminal.EntityNameColor(space.Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) apiErr = cmd.quotaRepo.UnassignQuotaFromSpace(space.Guid, quota.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() }
func (cmd *RenameService) Run(c *cli.Context) { newName := c.Args()[1] serviceInstance := cmd.serviceInstanceReq.GetServiceInstance() cmd.ui.Say(T("Renaming service {{.ServiceName}} to {{.NewServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "ServiceName": terminal.EntityNameColor(serviceInstance.Name), "NewServiceName": terminal.EntityNameColor(newName), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) err := cmd.serviceRepo.RenameService(serviceInstance, newName) if err != nil { if httpError, ok := err.(errors.HttpError); ok && httpError.ErrorCode() == errors.SERVICE_INSTANCE_NAME_TAKEN { cmd.ui.Failed(T("{{.ErrorDescription}}\nTIP: Use '{{.CFServicesCommand}}' to view all services in this org and space.", map[string]interface{}{ "ErrorDescription": httpError.Error(), "CFServicesCommand": cf.Name() + " " + "services", })) } else { cmd.ui.Failed(err.Error()) } } cmd.ui.Ok() }
func (cmd *Push) bindAppToServices(services []string, app models.Application) { for _, serviceName := range services { serviceInstance, err := cmd.serviceRepo.FindInstanceByName(serviceName) if err != nil { cmd.ui.Failed(T("Could not find service {{.ServiceName}} to bind to {{.AppName}}", map[string]interface{}{"ServiceName": serviceName, "AppName": app.Name})) return } cmd.ui.Say(T("Binding service {{.ServiceName}} to app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "ServiceName": terminal.EntityNameColor(serviceInstance.Name), "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) err = cmd.serviceBinder.BindApplication(app, serviceInstance) switch httpErr := err.(type) { case errors.HttpError: if httpErr.ErrorCode() == errors.APP_ALREADY_BOUND { err = nil } } if err != nil { cmd.ui.Failed(T("Could not bind to service {{.ServiceName}}\nError: {{.Err}}", map[string]interface{}{"ServiceName": serviceName, "Err": err.Error()})) } cmd.ui.Ok() } }
func (cmd ListSpaces) Run(c *cli.Context) { cmd.ui.Say(T("Getting spaces in org {{.TargetOrgName}} as {{.CurrentUser}}...\n", map[string]interface{}{ "TargetOrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) foundSpaces := false table := cmd.ui.Table([]string{T("name")}) apiErr := cmd.spaceRepo.ListSpaces(func(space models.Space) bool { table.Add(space.Name) foundSpaces = true return true }) table.Print() if apiErr != nil { cmd.ui.Failed(T("Failed fetching spaces.\n{{.ErrorDescription}}", map[string]interface{}{ "ErrorDescription": apiErr.Error(), })) return } if !foundSpaces { cmd.ui.Say(T("No spaces found")) } }
func (cmd DeleteUser) Run(c *cli.Context) { username := c.Args()[0] force := c.Bool("f") if !force && !cmd.ui.ConfirmDelete(T("user"), username) { return } cmd.ui.Say(T("Deleting user {{.TargetUser}} as {{.CurrentUser}}...", map[string]interface{}{ "TargetUser": terminal.EntityNameColor(username), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) user, apiErr := cmd.userRepo.FindByUsername(username) switch apiErr.(type) { case nil: case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(T("User {{.TargetUser}} does not exist.", map[string]interface{}{"TargetUser": username})) return default: cmd.ui.Failed(apiErr.Error()) return } apiErr = cmd.userRepo.Delete(user.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() }
func (cmd CreateService) Run(c *cli.Context) { serviceName := c.Args()[0] planName := c.Args()[1] serviceInstanceName := c.Args()[2] cmd.ui.Say(T("Creating service {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "ServiceName": terminal.EntityNameColor(serviceInstanceName), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) err := cmd.CreateService(serviceName, planName, serviceInstanceName) switch err.(type) { case nil: cmd.ui.Ok() case *errors.ModelAlreadyExistsError: cmd.ui.Ok() cmd.ui.Warn(err.Error()) default: cmd.ui.Failed(err.Error()) } }
func (cmd CreateOrg) Run(c *cli.Context) { name := c.Args()[0] cmd.ui.Say(T("Creating org {{.OrgName}} as {{.Username}}...", map[string]interface{}{ "OrgName": terminal.EntityNameColor(name), "Username": terminal.EntityNameColor(cmd.config.Username())})) org := models.Organization{OrganizationFields: models.OrganizationFields{Name: name}} quotaName := c.String("q") if quotaName != "" { quota, err := cmd.quotaRepo.FindByName(quotaName) if err != nil { cmd.ui.Failed(err.Error()) } org.QuotaDefinition.Guid = quota.Guid } err := cmd.orgRepo.Create(org) if err != nil { if apiErr, ok := err.(errors.HttpError); ok && apiErr.ErrorCode() == errors.ORG_EXISTS { cmd.ui.Ok() cmd.ui.Warn(T("Org {{.OrgName}} already exists", map[string]interface{}{"OrgName": name})) return } else { cmd.ui.Failed(err.Error()) } } cmd.ui.Ok() cmd.ui.Say(T("\nTIP: Use '{{.Command}}' to target new org", map[string]interface{}{"Command": terminal.CommandColor(cf.Name() + " target -o " + name)})) }
func (cmd DeleteServiceBroker) Run(c *cli.Context) { brokerName := c.Args()[0] if !c.Bool("f") && !cmd.ui.ConfirmDelete(T("service-broker"), brokerName) { return } cmd.ui.Say(T("Deleting service broker {{.Name}} as {{.Username}}...", map[string]interface{}{ "Name": terminal.EntityNameColor(brokerName), "Username": terminal.EntityNameColor(cmd.config.Username()), })) broker, apiErr := cmd.repo.FindByName(brokerName) switch apiErr.(type) { case nil: case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(T("Service Broker {{.Name}} does not exist.", map[string]interface{}{"Name": brokerName})) return default: cmd.ui.Failed(apiErr.Error()) return } apiErr = cmd.repo.Delete(broker.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() return }
func (cmd *Env) Run(c *cli.Context) { app, err := cmd.appRepo.Read(c.Args()[0]) if notFound, ok := err.(*errors.ModelNotFoundError); ok { cmd.ui.Failed(notFound.Error()) } cmd.ui.Say(T("Getting env variables for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) env, err := cmd.appRepo.ReadEnv(app.Guid) if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Ok() cmd.ui.Say("") cmd.displaySystemiAndAppProvidedEnvironment(env.System, env.Application) cmd.ui.Say("") cmd.displayUserProvidedEnvironment(env.Environment) cmd.ui.Say("") cmd.displayRunningEnvironment(env.Running) cmd.ui.Say("") cmd.displayStagingEnvironment(env.Staging) cmd.ui.Say("") }
func (cmd *MapRoute) Run(c *cli.Context) { hostName := c.String("n") domain := cmd.domainReq.GetDomain() app := cmd.appReq.GetApplication() route, apiErr := cmd.routeCreator.CreateRoute(hostName, domain, cmd.config.SpaceFields()) if apiErr != nil { cmd.ui.Failed(T("Error resolving route:\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()})) } cmd.ui.Say(T("Adding route {{.URL}} to app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "URL": terminal.EntityNameColor(route.URL()), "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) apiErr = cmd.routeRepo.Bind(route.Guid, app.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() }
func (cmd DeleteSpaceQuota) Run(context *cli.Context) { quotaName := context.Args()[0] if !context.Bool("f") { response := cmd.ui.ConfirmDelete("quota", quotaName) if !response { return } } cmd.ui.Say(T("Deleting space quota {{.QuotaName}} as {{.Username}}...", map[string]interface{}{ "QuotaName": terminal.EntityNameColor(quotaName), "Username": terminal.EntityNameColor(cmd.config.Username()), })) quota, apiErr := cmd.spaceQuotaRepo.FindByName(quotaName) switch (apiErr).(type) { case nil: // no error case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(T("Quota {{.QuotaName}} does not exist", map[string]interface{}{"QuotaName": quotaName})) return default: cmd.ui.Failed(apiErr.Error()) } apiErr = cmd.spaceQuotaRepo.Delete(quota.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) } cmd.ui.Ok() }
func (cmd *Push) updateApp(app models.Application, appParams models.AppParams) (updatedApp models.Application) { cmd.ui.Say(T("Updating app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) if appParams.EnvironmentVars != nil { for key, val := range app.EnvironmentVars { if _, ok := (*appParams.EnvironmentVars)[key]; !ok { (*appParams.EnvironmentVars)[key] = val } } } var apiErr error updatedApp, apiErr = cmd.appRepo.Update(app.Guid, appParams) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) } cmd.ui.Ok() cmd.ui.Say("") return }
func (cmd UpdateServiceBroker) Run(c *cli.Context) { serviceBroker, apiErr := cmd.repo.FindByName(c.Args()[0]) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Say(T("Updating service broker {{.Name}} as {{.Username}}...", map[string]interface{}{ "Name": terminal.EntityNameColor(serviceBroker.Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) serviceBroker.Username = c.Args()[1] serviceBroker.Password = c.Args()[2] serviceBroker.Url = c.Args()[3] apiErr = cmd.repo.Update(serviceBroker) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() }
func (cmd *CreateRoute) CreateRoute(hostName string, domain models.DomainFields, space models.SpaceFields) (route models.Route, apiErr error) { cmd.ui.Say(T("Creating route {{.Hostname}} for org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "Hostname": terminal.EntityNameColor(domain.UrlForHost(hostName)), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(space.Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) route, apiErr = cmd.routeRepo.CreateInSpace(hostName, domain.Guid, space.Guid) if apiErr != nil { var findApiResponse error route, findApiResponse = cmd.routeRepo.FindByHostAndDomain(hostName, domain) if findApiResponse != nil || route.Space.Guid != space.Guid || route.Domain.Guid != domain.Guid { return } apiErr = nil cmd.ui.Ok() cmd.ui.Warn(T("Route {{.URL}} already exists", map[string]interface{}{"URL": route.URL()})) return } cmd.ui.Ok() return }
func (cmd DeleteOrphanedRoutes) Run(c *cli.Context) { force := c.Bool("f") if !force { response := cmd.ui.Confirm(T("Really delete orphaned routes?{{.Prompt}}", map[string]interface{}{"Prompt": terminal.PromptColor(">")})) if !response { return } } cmd.ui.Say(T("Getting routes as {{.Username}} ...\n", map[string]interface{}{"Username": terminal.EntityNameColor(cmd.config.Username())})) apiErr := cmd.routeRepo.ListRoutes(func(route models.Route) bool { if len(route.Apps) == 0 { cmd.ui.Say(T("Deleting route {{.Route}}...", map[string]interface{}{"Route": terminal.EntityNameColor(route.Host + "." + route.Domain.Name)})) apiErr := cmd.routeRepo.Delete(route.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return false } } return true }) if apiErr != nil { cmd.ui.Failed(T("Failed fetching routes.\n{{.Err}}", map[string]interface{}{"Err": apiErr.Error()})) return } cmd.ui.Ok() }
func (cmd *UnmapRoute) Run(c *cli.Context) { hostName := c.String("n") domain := cmd.domainReq.GetDomain() app := cmd.appReq.GetApplication() route, apiErr := cmd.routeRepo.FindByHostAndDomain(hostName, domain) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) } cmd.ui.Say(T("Removing route {{.URL}} from app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "URL": terminal.EntityNameColor(route.URL()), "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) apiErr = cmd.routeRepo.Unbind(route.Guid, app.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() }
func (cmd SetSpaceQuota) Run(context *cli.Context) { spaceName := context.Args()[0] quotaName := context.Args()[1] cmd.ui.Say(T("Assigning space quota {{.QuotaName}} to space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "QuotaName": terminal.EntityNameColor(quotaName), "SpaceName": terminal.EntityNameColor(spaceName), "Username": terminal.EntityNameColor(cmd.config.Username()), })) space, err := cmd.spaceRepo.FindByName(spaceName) if err != nil { cmd.ui.Failed(err.Error()) } if space.SpaceQuotaGuid != "" { cmd.ui.Failed(T("This space already has an assigned space quota.")) } quota, err := cmd.quotaRepo.FindByName(quotaName) if err != nil { cmd.ui.Failed(err.Error()) } err = cmd.quotaRepo.AssociateSpaceWithQuota(space.Guid, quota.Guid) if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Ok() }
func (cmd UpdateSecurityGroup) Run(context *cli.Context) { name := context.Args()[0] securityGroup, err := cmd.securityGroupRepo.Read(name) if err != nil { cmd.ui.Failed(err.Error()) } pathToJSONFile := context.Args()[1] rules, err := json.ParseJSON(pathToJSONFile) if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Say(T("Updating security group {{.security_group}} as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) err = cmd.securityGroupRepo.Update(securityGroup.Guid, rules) if err != nil { cmd.ui.Failed(err.Error()) } 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.")) }
func (cmd CreateUserProvidedService) Run(c *cli.Context) { name := c.Args()[0] drainUrl := c.String("l") params := c.String("p") params = strings.Trim(params, `"`) paramsMap := make(map[string]interface{}) err := json.Unmarshal([]byte(params), ¶msMap) if err != nil && params != "" { paramsMap = cmd.mapValuesFromPrompt(params, paramsMap) } cmd.ui.Say(T("Creating user provided service {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "ServiceName": terminal.EntityNameColor(name), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) apiErr := cmd.userProvidedServiceInstanceRepo.Create(name, drainUrl, paramsMap) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() }
func (cmd DeleteSecurityGroup) Run(context *cli.Context) { name := context.Args()[0] cmd.ui.Say(T("Deleting security group {{.security_group}} as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) if !context.Bool("f") { response := cmd.ui.ConfirmDelete(T("security group"), name) if !response { return } } group, err := cmd.securityGroupRepo.Read(name) switch err.(type) { case nil: case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(T("Security group {{.security_group}} does not exist", map[string]interface{}{"security_group": name})) return default: cmd.ui.Failed(err.Error()) } err = cmd.securityGroupRepo.Delete(group.Guid) if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Ok() }
func (cmd *CopySource) findSpaceGuid(targetOrg, targetSpace string) string { org, err := cmd.orgRepo.FindByName(targetOrg) if err != nil { cmd.ui.Failed(err.Error()) } var space models.SpaceFields var foundSpace bool for _, s := range org.Spaces { if s.Name == targetSpace { space = s foundSpace = true } } if !foundSpace { cmd.ui.Failed(fmt.Sprintf(T("Could not find space {{.Space}} in organization {{.Org}}", map[string]interface{}{ "Space": terminal.EntityNameColor(targetSpace), "Org": terminal.EntityNameColor(targetOrg), }, ))) } return space.Guid }
func (cmd *DeleteSpace) Run(c *cli.Context) { spaceName := c.Args()[0] if !c.Bool("f") { if !cmd.ui.ConfirmDelete(T("space"), spaceName) { return } } cmd.ui.Say(T("Deleting space {{.TargetSpace}} in org {{.TargetOrg}} as {{.CurrentUser}}...", map[string]interface{}{ "TargetSpace": terminal.EntityNameColor(spaceName), "TargetOrg": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) space := cmd.spaceReq.GetSpace() apiErr := cmd.spaceRepo.Delete(space.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() if cmd.config.SpaceFields().Name == spaceName { cmd.config.SetSpaceFields(models.SpaceFields{}) cmd.ui.Say(T("TIP: No space targeted, use '{{.CfTargetCommand}}' to target a space", map[string]interface{}{"CfTargetCommand": cf.Name() + " target -s"})) } return }
func (cmd *UnsetSpaceRole) Run(c *cli.Context) { spaceName := c.Args()[2] role := models.UserInputToSpaceRole[c.Args()[3]] user := cmd.userReq.GetUser() org := cmd.orgReq.GetOrganization() space, apiErr := cmd.spaceRepo.FindByNameInOrg(spaceName, org.Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Say(T("Removing role {{.Role}} from user {{.TargetUser}} in org {{.TargetOrg}} / space {{.TargetSpace}} as {{.CurrentUser}}...", map[string]interface{}{ "Role": terminal.EntityNameColor(role), "TargetUser": terminal.EntityNameColor(user.Username), "TargetOrg": terminal.EntityNameColor(org.Name), "TargetSpace": terminal.EntityNameColor(space.Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) apiErr = cmd.userRepo.UnsetSpaceRole(user.Guid, space.Guid, role) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() }
func (cmd UnbindSecurityGroup) flavorText(secName string, orgName string, spaceName string) { cmd.ui.Say(T("Unbinding security group {{.security_group}} from {{.organization}}/{{.space}} as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(secName), "organization": terminal.EntityNameColor(orgName), "space": terminal.EntityNameColor(spaceName), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) }