-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from jeff-roche/dragoman
feat: dragoman decryption
- Loading branch information
Showing
7 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package setters | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/jeff-roche/biome/src/repos" | ||
) | ||
|
||
const DRAGOMAN_ENV_KEY = "from_dragoman" | ||
|
||
// DragomanEnvironmentSetter will decrypt a secret that has been encrypted with dragoman | ||
type DragomanEnvironmentSetter struct { | ||
Encrypted string // The dragoman encrypted string | ||
EnvKey string // The environment variable to be set | ||
repo repos.DragomanRepoIfc // The repo that handles decrypting with dragoman | ||
} | ||
|
||
// NewDragomanEnvironmentSetter is the builder function for DragomanEnvironmentSetter | ||
func NewDragomanEnvironmentSetter(key string, val string) (*DragomanEnvironmentSetter, error) { | ||
dragomanRepo, err := repos.NewDragomanRepo() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &DragomanEnvironmentSetter{ | ||
EnvKey: key, | ||
Encrypted: val, | ||
repo: dragomanRepo, | ||
}, nil | ||
} | ||
|
||
func (s DragomanEnvironmentSetter) SetEnv() error { | ||
dec, err := s.repo.Decrypt(s.Encrypted) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if s.EnvKey == "" { | ||
return fmt.Errorf("no environment key specified") | ||
} | ||
|
||
return os.Setenv(s.EnvKey, dec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package repos | ||
|
||
import "github.com/meltwater/dragoman/cryptography" | ||
|
||
// The interface for the Secrets Manager Repository | ||
type DragomanRepoIfc interface { | ||
Decrypt(string) (string, error) | ||
} | ||
|
||
// DragomanRepo handles decryption via dragoman | ||
type DragomanRepo struct { | ||
client interface{} | ||
} | ||
|
||
// NewDragomanRepo is the builder function for DragomanRepo | ||
func NewDragomanRepo() (*DragomanRepo, error) { | ||
return &DragomanRepo{ | ||
client: nil, | ||
}, nil | ||
} | ||
|
||
func (r DragomanRepo) Decrypt(val string) (string, error) { | ||
|
||
// Setup the allowed cryptography techniques | ||
// Currently allow KMS Envelope encryption and Secrets Manager | ||
strat, err := cryptography.NewWildcardDecryptionStrategy([]cryptography.StrategyBuilder{ | ||
func() (cryptography.Decryptor, error) { return cryptography.NewKmsCryptoStrategy("") }, | ||
func() (cryptography.Decryptor, error) { return cryptography.NewSecretsManagerCryptoStrategy("") }, | ||
}) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
data, err := strat.Decrypt(val) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return string(data), nil | ||
} |