-
Notifications
You must be signed in to change notification settings - Fork 0
/
promote.go
60 lines (48 loc) · 1.13 KB
/
promote.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/urfave/cli"
)
// PromoteApplication moves an application from one environment to another
func PromoteApplication(c *cli.Context) error {
type environment struct {
Name string `json:"name"`
UUID string `json:"uuid"`
}
type application struct {
Name string `json:"name"`
UUID string `json:"uuid"`
Environments []environment `json:"environments"`
}
appName := c.Args().Get(0)
envSrcName := c.Args().Get(1)
envDstName := c.Args().Get(2)
body, err := HTTPGet("/api/v1/applications/" + appName)
if err != nil {
return err
}
var app application
err = json.Unmarshal([]byte(body), &app)
if err != nil {
return errors.New("Unable to read JSON response.")
}
// get environment
var envSrc environment
var envDst environment
for _, v := range app.Environments {
if v.Name == envSrcName {
envSrc = v
}
if v.Name == envDstName {
envDst = v
}
}
_, err = HTTPPost("/api/v1/environments/promote/" + envSrc.UUID + "/" + envDst.UUID)
if err != nil {
return err
}
fmt.Println("Promotion successful")
return nil
}