2021-09-09 17:43:00 +00:00
|
|
|
//go:build !noawskms
|
2020-12-02 08:44:18 +00:00
|
|
|
// +build !noawskms
|
|
|
|
|
2020-11-30 20:46:34 +00:00
|
|
|
package kms
|
|
|
|
|
2020-12-02 08:44:18 +00:00
|
|
|
import (
|
|
|
|
// we import awskms here to be able to disable AWS KMS support using a build tag
|
|
|
|
_ "gocloud.dev/secrets/awskms"
|
|
|
|
|
|
|
|
"github.com/drakkan/sftpgo/version"
|
2020-11-30 20:46:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type awsSecret struct {
|
|
|
|
baseGCloudSecret
|
|
|
|
}
|
|
|
|
|
2020-12-02 08:44:18 +00:00
|
|
|
func init() {
|
|
|
|
version.AddFeature("+awskms")
|
|
|
|
}
|
|
|
|
|
2020-11-30 20:46:34 +00:00
|
|
|
func newAWSSecret(base baseSecret, url, masterKey string) SecretProvider {
|
|
|
|
return &awsSecret{
|
|
|
|
baseGCloudSecret{
|
|
|
|
baseSecret: base,
|
|
|
|
url: url,
|
|
|
|
masterKey: masterKey,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *awsSecret) Name() string {
|
|
|
|
return awsProviderName
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *awsSecret) IsEncrypted() bool {
|
|
|
|
return s.Status == SecretStatusAWS
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *awsSecret) Encrypt() error {
|
|
|
|
if err := s.baseGCloudSecret.Encrypt(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
s.Status = SecretStatusAWS
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *awsSecret) Decrypt() error {
|
|
|
|
if !s.IsEncrypted() {
|
|
|
|
return errWrongSecretStatus
|
|
|
|
}
|
|
|
|
return s.baseGCloudSecret.Decrypt()
|
|
|
|
}
|