Newer
Older
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"`
BobAPIAuthEncryptionKey string `json:"bob_api_auth_encryption_key"`
GenericEncryptionKey string `json:"generic_encryption_key"`
BobGoEncryptionKey string `json:"bobgo_encryption_key"`
ShipLogicPINEncryptionKey string `json:"ship_logic_pin_encryption_key"`
AppleSigningKey string `json:"apple_signing_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
}
func GetBobAPIAuthEncryptionKey(secretID string, isDebug bool) (string, error) {
encryptionKeys, err := GetEncryptionKeys(secretID, isDebug)
return encryptionKeys.BobAPIAuthEncryptionKey, err
}
func GetGenericEncryptionKey(secretID string, isDebug bool) (string, error) {
encryptionKeys, err := GetEncryptionKeys(secretID, isDebug)
return encryptionKeys.GenericEncryptionKey, err
}
func GetBobGoEncryptionKey(secretID string, isDebug bool) (string, error) {
encryptionKeys, err := GetEncryptionKeys(secretID, isDebug)
return encryptionKeys.BobGoEncryptionKey, err
}
func GetShipLogicPINEncryptionKey(secretID string, isDebug bool) (string, error) {
encryptionKeys, err := GetEncryptionKeys(secretID, isDebug)
return encryptionKeys.ShipLogicPINEncryptionKey, err
}
func GetAppleSigningKey(secretID string, isDebug bool) (string, error) {
encryptionKeys, err := GetEncryptionKeys(secretID, isDebug)
return encryptionKeys.AppleSigningKey, err
}