88# OF ANY KIND, either express or implied. See the License for the specific language
99# governing permissions and limitations under the License.
1010
11+ import logging
1112from .simplessm import SimpleSSM
13+ from .simples3 import SimpleS3
1214
1315
1416class SecretResolver :
@@ -18,6 +20,11 @@ def supports(self, secret_type):
1820 def resolve (self , secret_type , secret_params ):
1921 return None
2022
23+ def get_param_or_exception (self , key , params ):
24+ if key not in params :
25+ raise Exception ("Could not find required key '{}' in the secret params: {}" .format (key , params ))
26+ return params [key ]
27+
2128
2229class SSMSecretResolver (SecretResolver ):
2330 def __init__ (self , default_aws_profile = None ):
@@ -29,17 +36,33 @@ def supports(self, secret_type):
2936 def resolve (self , secret_type , secret_params ):
3037 aws_profile = secret_params .get ("aws_profile" , self .default_aws_profile )
3138 if not aws_profile :
32- raise Exception ("Could not find the aws_profile in the secret params: {}" .format (secret_params ))
39+ raise Exception ("Could not find the aws_profile in the secret params for SSM secret : {}" .format (secret_params ))
3340
3441 path = self .get_param_or_exception ("path" , secret_params )
3542 region_name = secret_params .get ("region_name" , "us-east-1" )
3643 ssm = SimpleSSM (aws_profile , region_name )
3744 return ssm .get (path )
3845
39- def get_param_or_exception (self , key , params ):
40- if key not in params :
41- raise Exception ("Could not find required key '{}' in the secret params: {}" .format (key , params ))
42- return params [key ]
46+
47+ class S3SecretResolver (SecretResolver ):
48+ def __init__ (self , default_aws_profile = None ):
49+ self .default_aws_profile = default_aws_profile
50+
51+ def supports (self , secret_type ):
52+ return secret_type == "s3"
53+
54+ def resolve (self , secret_type , secret_params ):
55+ aws_profile = secret_params .get ("aws_profile" , self .default_aws_profile )
56+ if not aws_profile :
57+ raise Exception ("Could not find the aws_profile in the secret params for S3 secret: {}" .format (secret_params ))
58+
59+ bucket = self .get_param_or_exception ("bucket" , secret_params )
60+ path = self .get_param_or_exception ("path" , secret_params )
61+ region_name = secret_params .get ("region_name" , "us-east-1" )
62+ base64Encode = secret_params .get ("base64encode" , False )
63+ base64Encode = base64Encode == 'true'
64+ s3 = SimpleS3 (aws_profile , region_name )
65+ return s3 .get (bucket , path , base64Encode )
4366
4467
4568# TODO - vault resolver
@@ -54,7 +77,7 @@ def resolve(self, secret_type, secret_params):
5477class AggregatedSecretResolver (SecretResolver ):
5578
5679 def __init__ (self , default_aws_profile = None ):
57- self .secret_resolvers = (SSMSecretResolver (default_aws_profile ), VaultSecretResolver ())
80+ self .secret_resolvers = (SSMSecretResolver (default_aws_profile ), S3SecretResolver ( default_aws_profile ), VaultSecretResolver ())
5881
5982 def supports (self , secret_type ):
6083 return any ([resolver .supports (secret_type ) for resolver in self .secret_resolvers ])
0 commit comments