github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/releases/rm.go (about) 1 package releases 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/Sirupsen/logrus" 8 "github.com/daticahealth/cli/commands/services" 9 "github.com/daticahealth/cli/config" 10 ) 11 12 func CmdRm(svcName, releaseName string, ir IReleases, is services.IServices) error { 13 if strings.ContainsAny(releaseName, config.InvalidChars) { 14 return fmt.Errorf("Invalid release name. Names must not contain the following characters: %s", config.InvalidChars) 15 } 16 service, err := is.RetrieveByLabel(svcName) 17 if err != nil { 18 return err 19 } 20 if service == nil { 21 return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"datica services list\" command.", svcName) 22 } 23 err = ir.Rm(releaseName, service.ID) 24 if err != nil { 25 return err 26 } 27 logrus.Printf("Release '%s' has been successfully removed.", releaseName) 28 return nil 29 } 30 31 func (r *SReleases) Rm(releaseName, svcID string) error { 32 headers := r.Settings.HTTPManager.GetHeaders(r.Settings.SessionToken, r.Settings.Version, r.Settings.Pod, r.Settings.UsersID) 33 resp, statusCode, err := r.Settings.HTTPManager.Delete(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/releases/%s", r.Settings.PaasHost, r.Settings.PaasHostVersion, r.Settings.EnvironmentID, svcID, releaseName), headers) 34 if err != nil { 35 return err 36 } 37 return r.Settings.HTTPManager.ConvertResp(resp, statusCode, nil) 38 }