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
3 changed files with 35 additions and 0 deletions

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)
}
}
}