github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/vars/unset.go (about) 1 package vars 2 3 import ( 4 "fmt" 5 6 "github.com/Sirupsen/logrus" 7 "github.com/daticahealth/cli/commands/services" 8 ) 9 10 func CmdUnset(svcName string, variables []string, iv IVars, is services.IServices) error { 11 service, err := is.RetrieveByLabel(svcName) 12 if err != nil { 13 return err 14 } 15 if service == nil { 16 return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"datica services list\" command.", svcName) 17 } 18 for _, variable := range variables { 19 err := iv.Unset(service.ID, variable) 20 if err != nil { 21 return err 22 } 23 } 24 logrus.Printf("Unset. For these environment variable changes to take effect, you will need to redeploy your service with \"datica redeploy %s\"", svcName) 25 return nil 26 } 27 28 // Unset deletes an environment variable. Any changes to environment variables 29 // will not take effect until the service is redeployed by pushing new code 30 // or via `datica redeploy`. 31 func (v *SVars) Unset(svcID, variable string) error { 32 headers := v.Settings.HTTPManager.GetHeaders(v.Settings.SessionToken, v.Settings.Version, v.Settings.Pod, v.Settings.UsersID) 33 resp, statusCode, err := v.Settings.HTTPManager.Delete(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/env/%s", v.Settings.PaasHost, v.Settings.PaasHostVersion, v.Settings.EnvironmentID, svcID, variable), headers) 34 if err != nil { 35 return err 36 } 37 return v.Settings.HTTPManager.ConvertResp(resp, statusCode, nil) 38 }