mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-18 18:32:30 +00:00
⚡ Fix the updateLicense
method
This commit is contained in:
parent
fab0f713ed
commit
8c7d9ea8fd
@ -61,17 +61,19 @@ func acquireLicense() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateLicense(licenseKey string) {
|
func updateLicense(licenseKey string) {
|
||||||
|
log.Info().Str("key", licenseKey).Msg("Received license:")
|
||||||
|
|
||||||
config.Config.License = licenseKey
|
config.Config.License = licenseKey
|
||||||
err := config.WriteConfig(&config.Config)
|
err := config.WriteConfig(&config.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Send()
|
log.Error().Err(err).Send()
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
connector.PostLicenseSingle(config.Config.License)
|
||||||
connector.PostLicense(config.Config.License)
|
|
||||||
|
|
||||||
log.Info().Msg("Updated the license. Exiting.")
|
log.Info().Msg("Updated the license. Exiting.")
|
||||||
|
|
||||||
|
go func() {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
@ -105,8 +107,6 @@ func runLicenseRecieverServer() {
|
|||||||
|
|
||||||
licenseKey := string(data)
|
licenseKey := string(data)
|
||||||
|
|
||||||
log.Info().Str("key", licenseKey).Msg("Received license:")
|
|
||||||
|
|
||||||
updateLicense(licenseKey)
|
updateLicense(licenseKey)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -151,6 +151,26 @@ func (connector *Connector) PostLicense(license string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (connector *Connector) PostLicenseSingle(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 {
|
||||||
|
var resp *http.Response
|
||||||
|
if resp, err = utils.Post(postLicenseUrl, "application/json", bytes.NewBuffer(payloadMarshalled), connector.client); err != nil || resp.StatusCode != http.StatusOK {
|
||||||
|
log.Warn().Err(err).Msg("Failed sending the license to Hub.")
|
||||||
|
} else {
|
||||||
|
log.Debug().Str("license", license).Msg("Reported license to Hub:")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (connector *Connector) PostEnv(env map[string]interface{}) {
|
func (connector *Connector) PostEnv(env map[string]interface{}) {
|
||||||
if len(env) == 0 {
|
if len(env) == 0 {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user