-
Notifications
You must be signed in to change notification settings - Fork 0
/
secrets.go
38 lines (32 loc) · 883 Bytes
/
secrets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package repository
import (
"crypto/sha1"
"encoding/json"
"fmt"
securityv1 "github.com/caapim/layer7-operator/api/v1"
"github.com/caapim/layer7-operator/pkg/util"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// NewSecret
func NewSecret(repository *securityv1.Repository, name string, data map[string][]byte) *corev1.Secret {
dataBytes, _ := json.Marshal(data)
h := sha1.New()
h.Write(dataBytes)
sha1Sum := fmt.Sprintf("%x", h.Sum(nil))
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: repository.Namespace,
Labels: util.DefaultLabels(name, repository.Spec.Labels),
Annotations: map[string]string{"checksum/data": sha1Sum},
},
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Secret",
},
Type: corev1.SecretTypeOpaque,
Data: data,
}
return secret
}