-
Notifications
You must be signed in to change notification settings - Fork 90
/
config.go
40 lines (34 loc) · 1.14 KB
/
config.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
package main
import "C"
import (
"encoding/json"
"fmt"
"github.com/replicatedhq/kots/pkg/config"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/template"
)
//export TemplateConfig
func TemplateConfig(configSpecData string, configValuesData string, licenseYaml string, registryJson string) *C.char {
registryInfo := struct {
Host string `json:"registryHostname"`
Username string `json:"registryUsername"`
Password string `json:"registryPassword"`
Namespace string `json:"namespace"`
}{}
if err := json.Unmarshal([]byte(registryJson), ®istryInfo); err != nil {
fmt.Printf("failed to unmarshal registry info: %s\n", err.Error())
return C.CString("")
}
localRegistry := template.LocalRegistry{
Host: registryInfo.Host,
Namespace: registryInfo.Namespace,
Username: registryInfo.Username,
Password: registryInfo.Password,
}
rendered, err := config.TemplateConfig(logger.NewLogger(), configSpecData, configValuesData, licenseYaml, localRegistry)
if err != nil {
fmt.Printf("failed to apply templates to config: %s\n", err.Error())
return C.CString("")
}
return C.CString(rendered)
}