Do POST /license after Hub is started

This commit is contained in:
M. Mert Yildiran 2023-01-31 22:31:44 +03:00
parent 4cb4ba568b
commit 17e038e703
No known key found for this signature in database
GPG Key ID: DA5D6DCBB758A461
3 changed files with 35 additions and 0 deletions

View File

@ -398,6 +398,10 @@ func postHubStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider
connector.PostRegexToHub(config.Config.Tap.PodRegexStr, state.targetNamespaces)
if config.Config.License != "" {
connector.PostLicense(config.Config.License)
}
url := kubernetes.GetLocalhostOnPort(config.Config.Tap.Proxy.Hub.SrcPort)
log.Info().Str("url", url).Msg(fmt.Sprintf(utils.Green, "Hub is available at:"))
}

View File

@ -35,6 +35,7 @@ type ConfigStruct struct {
DumpLogs bool `yaml:"dumplogs" default:"false"`
ConfigFilePath string `yaml:"configpath,omitempty" readonly:""`
HeadlessMode bool `yaml:"headless" default:"false"`
License string `yaml:"license" default:""`
}
func (config *ConfigStruct) SetDefaults() {

View File

@ -145,3 +145,33 @@ func (connector *Connector) PostRegexToHub(regex string, namespaces []string) {
}
}
}
type postLicenseRequest struct {
License string `json:"license"`
}
func (connector *Connector) PostLicense(license string) {
postLicenseUrl := fmt.Sprintf("%s/license", connector.url)
payload := postLicenseRequest{
License: license,
}
if payloadMarshalled, err := json.Marshal(payload); err != nil {
log.Error().Err(err).Msg("Failed to marshal the payload:")
} else {
ok := false
for !ok {
if _, err = utils.Post(postLicenseUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil {
if _, ok := err.(*url.Error); ok {
break
}
log.Debug().Err(err).Msg("Failed sending the license to Hub:")
} else {
ok = true
log.Debug().Str("license", license).Msg("Reported license to Hub:")
}
time.Sleep(time.Second)
}
}
}