Skip to content

Commit

Permalink
Add mutex for get/store sensitive action details (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaaldjorMike authored Jul 31, 2024
1 parent 6d836fa commit 49cbb94
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/kubernetes/humioaction_secret_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,44 @@ package kubernetes
import (
"fmt"
"github.com/humio/humio-operator/api/v1alpha1"
"sync"
)

var haSecrets map[string]string = make(map[string]string)
var haWebhookHeaders map[string]map[string]string = make(map[string]map[string]string)
var (
haSecrets = make(map[string]string)
haSecretsMu sync.Mutex
haWebhookHeaders = make(map[string]map[string]string)
haWebhookHeadersMu sync.Mutex
)

func GetSecretForHa(hn *v1alpha1.HumioAction) (string, bool) {
haSecretsMu.Lock()
defer haSecretsMu.Unlock()
if secret, found := haSecrets[fmt.Sprintf("%s %s", hn.Namespace, hn.Name)]; found {
return secret, true
}
return "", false
}

func StoreSingleSecretForHa(hn *v1alpha1.HumioAction, token string) {
haSecretsMu.Lock()
defer haSecretsMu.Unlock()
key := fmt.Sprintf("%s %s", hn.Namespace, hn.Name)
haSecrets[key] = token
}

func GetFullSetOfMergedWebhookheaders(hn *v1alpha1.HumioAction) (map[string]string, bool) {
haWebhookHeadersMu.Lock()
defer haWebhookHeadersMu.Unlock()
if secret, found := haWebhookHeaders[fmt.Sprintf("%s %s", hn.Namespace, hn.Name)]; found {
return secret, true
}
return nil, false
}

func StoreFullSetOfMergedWebhookActionHeaders(hn *v1alpha1.HumioAction, resolvedSecretHeaders map[string]string) {
haWebhookHeadersMu.Lock()
defer haWebhookHeadersMu.Unlock()
key := fmt.Sprintf("%s %s", hn.Namespace, hn.Name)
if len(resolvedSecretHeaders) == 0 {
haWebhookHeaders[key] = hn.Spec.WebhookProperties.Headers
Expand Down

0 comments on commit 49cbb94

Please sign in to comment.