test loading secret key
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
12
models/db_unlock.go
Normal file
12
models/db_unlock.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package models
|
||||
|
||||
type Unlock struct {
|
||||
SecretsKey string `json:"secrets"`
|
||||
}
|
||||
|
||||
func (u *Unlock) UnlockSecrets() (*Unlock, error) {
|
||||
|
||||
// Receive secrets key and store in memory somehow
|
||||
|
||||
return u, nil
|
||||
}
|
@@ -8,7 +8,6 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
@@ -156,7 +155,9 @@ func (s *Secret) UpdateSecret() (*Secret, error) {
|
||||
|
||||
func (s *Secret) EncryptSecret() (*Secret, error) {
|
||||
|
||||
keyString := os.Getenv("SECRETS_KEY")
|
||||
//keyString := os.Getenv("SECRETS_KEY")
|
||||
keyString := secretKey
|
||||
|
||||
// The key argument should be the AES key, either 16 or 32 bytes
|
||||
// to select AES-128 or AES-256.
|
||||
key := []byte(keyString)
|
||||
@@ -203,7 +204,9 @@ func (s *Secret) EncryptSecret() (*Secret, error) {
|
||||
func (s *Secret) DecryptSecret() (*Secret, error) {
|
||||
// The key argument should be the AES key, either 16 or 32 bytes
|
||||
// to select AES-128 or AES-256.
|
||||
keyString := os.Getenv("SECRETS_KEY")
|
||||
//keyString := os.Getenv("SECRETS_KEY")
|
||||
keyString := secretKey
|
||||
|
||||
key := []byte(keyString)
|
||||
|
||||
if len(s.Secret) < nonceSize {
|
||||
|
@@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
var db *sqlx.DB
|
||||
var secretKey string
|
||||
|
||||
const (
|
||||
sqlFile = "smt.db"
|
||||
@@ -80,6 +81,11 @@ func ConnectDatabase() {
|
||||
//defer db.Close()
|
||||
}
|
||||
|
||||
func LoadSecretKey(key string) {
|
||||
// Store the secret key so that we can access it when encrypting/decrypting
|
||||
secretKey = key
|
||||
}
|
||||
|
||||
func DisconnectDatabase() {
|
||||
log.Printf("DisconnectDatabase called")
|
||||
defer db.Close()
|
||||
|
Reference in New Issue
Block a user