Change consts config field to env

This commit is contained in:
M. Mert Yildiran 2023-03-03 17:32:19 +03:00
parent 72a18871b1
commit 9a95fa364c
No known key found for this signature in database
GPG Key ID: DA5D6DCBB758A461
3 changed files with 9 additions and 9 deletions

View File

@ -448,7 +448,7 @@ func postHubStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider
} }
// Scripting // Scripting
connector.PostConsts(config.Config.Scripting.Consts) connector.PostEnv(config.Config.Scripting.Env)
scripts, err := config.Config.Scripting.GetScripts() scripts, err := config.Config.Scripting.GetScripts()
if err != nil { if err != nil {

View File

@ -10,7 +10,7 @@ import (
) )
type ScriptingConfig struct { type ScriptingConfig struct {
Consts map[string]interface{} `yaml:"consts"` Env map[string]interface{} `yaml:"env"`
Source string `yaml:"source" default:""` Source string `yaml:"source" default:""`
} }

View File

@ -181,27 +181,27 @@ func (connector *Connector) PostLicense(license string) {
} }
} }
func (connector *Connector) PostConsts(consts map[string]interface{}) { func (connector *Connector) PostEnv(env map[string]interface{}) {
if len(consts) == 0 { if len(env) == 0 {
return return
} }
postConstsUrl := fmt.Sprintf("%s/scripts/consts", connector.url) postEnvUrl := fmt.Sprintf("%s/scripts/env", connector.url)
if constsMarshalled, err := json.Marshal(consts); err != nil { if envMarshalled, err := json.Marshal(env); err != nil {
log.Error().Err(err).Msg("Failed to marshal the consts:") log.Error().Err(err).Msg("Failed to marshal the env:")
} else { } else {
ok := false ok := false
for !ok { for !ok {
var resp *http.Response var resp *http.Response
if resp, err = utils.Post(postConstsUrl, "application/json", bytes.NewBuffer(constsMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK { if resp, err = utils.Post(postEnvUrl, "application/json", bytes.NewBuffer(envMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK {
if _, ok := err.(*url.Error); ok { if _, ok := err.(*url.Error); ok {
break break
} }
log.Warn().Err(err).Msg("Failed sending the constants to Hub:") log.Warn().Err(err).Msg("Failed sending the constants to Hub:")
} else { } else {
ok = true ok = true
log.Info().Interface("consts", consts).Msg("Reported constants to Hub:") log.Info().Interface("env", env).Msg("Reported constants to Hub:")
} }
time.Sleep(DefaultSleep) time.Sleep(DefaultSleep)
} }