forked from a2call/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm.go
46 lines (42 loc) · 1.39 KB
/
rm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package sites
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/daticahealth/cli/commands/services"
"github.com/daticahealth/cli/models"
)
func CmdRm(name string, is ISites, iservices services.IServices, downStream string) error {
serviceProxy, err := iservices.RetrieveByLabel(downStream)
if err != nil {
return err
}
sites, err := is.List(serviceProxy.ID)
if err != nil {
return err
}
var site *models.Site
for _, s := range *sites {
if s.Name == name {
site = &s
break
}
}
if site == nil {
return fmt.Errorf("Could not find a site with the label \"%s\". You can list sites with the \"datica sites list\" command.", name)
}
err = is.Rm(site.ID, serviceProxy.ID)
if err != nil {
return err
}
logrus.Println("Site removed")
logrus.Println("To make your changes go live, you must redeploy your service proxy with the \"datica redeploy service_proxy\" command")
return nil
}
func (s *SSites) Rm(siteID int, svcID string) error {
headers := s.Settings.HTTPManager.GetHeaders(s.Settings.SessionToken, s.Settings.Version, s.Settings.Pod, s.Settings.UsersID)
resp, statusCode, err := s.Settings.HTTPManager.Delete(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/sites/%d", s.Settings.PaasHost, s.Settings.PaasHostVersion, s.Settings.EnvironmentID, svcID, siteID), headers)
if err != nil {
return err
}
return s.Settings.HTTPManager.ConvertResp(resp, statusCode, nil)
}