-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8s.go
52 lines (44 loc) · 1.16 KB
/
k8s.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
package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
)
// request an ingestion token from the API.
func getIngestToken() string {
resp, err := createResource("/tokens", "")
handleError(err)
defer resp.Body.Close()
bytes, err := ioutil.ReadAll(resp.Body)
handleError(err)
var tokenResponse map[string]string
err = json.Unmarshal(bytes, &tokenResponse)
handleError(err)
if tokenResponse["token"] == "" {
panic("Got empty token response from API")
}
return tokenResponse["token"]
}
func deploy() {
app := "kubectl"
arg0 := "kustomize"
arg1 := "github.com/tuplestream/collector/kustomize"
cmd := exec.Command(app, arg0, arg1)
stdout, err := cmd.Output()
if err != nil {
fmt.Println("Error invoking kubectl!\n" + err.Error())
os.Exit(1)
}
token := getIngestToken()
// JWTs are base64URL encoded, we need to encode as base64 to
// store as a kubernetes secret
base64Encoded := base64.StdEncoding.EncodeToString([]byte(token))
// 'TODO' in base64, which got encoded via kustomize
placeholder := "VE9ETw=="
withToken := strings.Replace(string(stdout), placeholder, base64Encoded, 1)
fmt.Print(withToken)
}