Newer
Older
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
39
40
41
42
43
44
package encryption
import (
"encoding/json"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/logs"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/secrets_manager"
)
type EncryptionKeysSecret struct {
EncryptionKeysValue string `json:"EncryptionKeys"`
}
type EncryptionKeys struct {
FirebaseEncryptionKey string `json:"firebase_encryption_key"`
JWTEncryptionKey string `json:"jwt_encryption_key"`
}
func GetEncryptionKeys(secretID string, isDebug bool) (EncryptionKeys, error) {
encryptionKeysSecretString, _ := secrets_manager.GetSecret(secretID, isDebug)
var encryptionKeys EncryptionKeys
var encryptionKeysSecret EncryptionKeysSecret
err := json.Unmarshal([]byte(encryptionKeysSecretString), &encryptionKeysSecret)
if err == nil {
err = json.Unmarshal([]byte(encryptionKeysSecret.EncryptionKeysValue), &encryptionKeys)
}
return encryptionKeys, err
}
func GetJWTEncryptionKey(secretID string, isDebug bool) (string, error) {
encryptionKeys, err := GetEncryptionKeys(secretID, isDebug)
if err != nil {
logs.ErrorWithMsg("Could not get encryption keys from secret manager", err)
return "", errors.Error("failed to get encryption keys for login")
}
return encryptionKeys.JWTEncryptionKey, nil
}
func GetFirebaseCredentialsEncryptionKey(secretID string, isDebug bool) (string, error) {
encryptionKeys, err := GetEncryptionKeys(secretID, isDebug)
return encryptionKeys.FirebaseEncryptionKey, err
}