-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathget-app-config.go
More file actions
108 lines (88 loc) · 2.2 KB
/
get-app-config.go
File metadata and controls
108 lines (88 loc) · 2.2 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"time"
"github.com/franela/goreq"
)
// Config repo from which extract the configuration and user to use
type Config struct {
ReceiveUser string `json:"receive_user"`
ReceiveRepo string `json:"receive_repo"`
}
// Release application configuration
type Release struct {
Owner string `json:"owner"`
App string `json:"app"`
Values map[string]interface{} `json:"values"`
Memory map[string]interface{} `json:"memory"`
CPU map[string]interface{} `json:"cpu"`
Tags map[string]interface{} `json:"tags"`
UUID string `json:"uuid"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
const (
contentType string = "application/json"
userAgent string = "deis-builder"
)
func init() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: [options]\n\n")
flag.PrintDefaults()
}
}
func main() {
url := flag.String("url", "", "Controller hook URL")
builderKey := flag.String("key", "", "Builder Key")
user := flag.String("user", "", "Controller username")
app := flag.String("app", "", "Controller application name")
flag.Parse()
if flag.NFlag() < 4 {
flag.Usage()
os.Exit(1)
}
if *url == "" {
fmt.Println("invalid url")
os.Exit(64)
}
if *builderKey == "" {
fmt.Println("invalid builder key")
os.Exit(64)
}
if *user == "" {
fmt.Println("invalid user")
os.Exit(64)
}
if *app == "" {
fmt.Println("invalid app")
os.Exit(64)
}
data := Config{ReceiveUser: *user, ReceiveRepo: *app}
req := goreq.Request{
Method: "POST",
Uri: *url,
Body: data,
ContentType: contentType,
Accept: contentType,
UserAgent: userAgent,
}
req.AddHeader("X-Deis-Builder-Auth", *builderKey)
res, err := req.Do()
if res.StatusCode == 404 {
fmt.Println("check the deis-controller. Is not running")
os.Exit(2)
}
if err != nil || res.StatusCode != 200 {
fmt.Println("failed retrieving config from controller")
body, _ := res.Body.ToString()
fmt.Println(body)
os.Exit(1)
}
var release Release
res.Body.FromJsonTo(&release)
toSring, _ := json.Marshal(release)
fmt.Println(string(toSring))
}