-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (44 loc) · 1.37 KB
/
main.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
package main
import (
"context"
"encoding/base64"
"encoding/json"
"log"
"net/http"
"github.com/gopaytech/internal-access-helper/config"
"github.com/gopaytech/internal-access-helper/settings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ArgoCDSecret struct {
CACert string `json:"ca.crt"`
Token string `json:"token"`
}
func main() {
settings, err := settings.NewSettings()
if err != nil {
log.Fatal(err)
}
k8s, err := config.LoadKubernetes()
if err != nil {
log.Fatal(err)
}
client := k8s.Client()
secret, err := client.CoreV1().Secrets(settings.ArgoCDNamespace).Get(context.Background(), settings.ArgoCDManagerSecretName, metav1.GetOptions{})
if err != nil {
log.Printf("failed to get namespace %s secret %s: %s\n", settings.ArgoCDNamespace, settings.ArgoCDManagerSecretName, err.Error())
}
argoCDSecret := ArgoCDSecret{}
if !settings.DisableFeatures {
argoCDSecret.CACert = base64.StdEncoding.EncodeToString(secret.Data["ca.crt"])
argoCDSecret.Token = base64.StdEncoding.EncodeToString(secret.Data["token"])
}
argoCDSecretByte, err := json.Marshal(argoCDSecret)
if err != nil {
log.Printf("failed to marshal argoCDSecret")
}
http.HandleFunc("/argocd", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write(argoCDSecretByte)
})
log.Fatal(http.ListenAndServe(":"+settings.HTTPPort, nil))
}