forked from a2call/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rake.go
44 lines (40 loc) · 1.32 KB
/
rake.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
package rake
import (
"encoding/json"
"fmt"
"github.com/Sirupsen/logrus"
"github.com/daticahealth/cli/commands/services"
)
func CmdRake(svcName, taskName string, ir IRake, is services.IServices) error {
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"datica services list\" command.", svcName)
}
logrus.Printf("Executing Rake task: %s", taskName)
err = ir.Run(taskName, service.ID)
if err != nil {
return err
}
logrus.Println("Rake task output viewable in your logging dashboard")
return nil
}
// Run executes a rake task. This is only applicable for ruby-based
// applications.
func (r *SRake) Run(taskName, svcID string) error {
rakeTask := map[string]string{
"command": taskName,
}
b, err := json.Marshal(rakeTask)
if err != nil {
return err
}
headers := r.Settings.HTTPManager.GetHeaders(r.Settings.SessionToken, r.Settings.Version, r.Settings.Pod, r.Settings.UsersID)
resp, statusCode, err := r.Settings.HTTPManager.Post(b, fmt.Sprintf("%s%s/environments/%s/services/%s/rake", r.Settings.PaasHost, r.Settings.PaasHostVersion, r.Settings.EnvironmentID, svcID), headers)
if err != nil {
return err
}
return r.Settings.HTTPManager.ConvertResp(resp, statusCode, nil)
}