1
- import logging , logging .handlers
2
1
import argparse
3
- import os
4
- import boto3
5
2
import hashlib
6
- import tempfile
3
+ import logging
4
+ import logging .handlers
5
+ import os
7
6
import shutil
7
+ import tempfile
8
+ import boto3
8
9
9
10
logging .getLogger ("botocore" ).setLevel (logging .CRITICAL )
10
11
12
+
11
13
def get_sha256_hash (file_path ):
12
14
logging .debug ('Hashing "%s" using SHA256' % file_path )
13
15
BUF_SIZE = 65536 # lets read stuff in 64kb chunks!
@@ -29,13 +31,14 @@ def process_parameters_with_prefix(param_prefix, cred_path, aws_region, aws_acce
29
31
def get_parameters (parameter_names_list ):
30
32
parameter_list = []
31
33
if parameter_names_list :
32
- result = ssm .get_parameters (Names = parameter_names_list , WithDecryption = True )
33
- if result :
34
- if 'ResponseMetadata' in result :
35
- if 'HTTPStatusCode' in result ['ResponseMetadata' ]:
36
- if result ['ResponseMetadata' ]['HTTPStatusCode' ] == 200 :
37
- if 'Parameters' in result :
38
- parameter_list = result ['Parameters' ]
34
+ for parameter_name in parameter_names_list :
35
+ result = ssm .get_parameter (Name = parameter_name , WithDecryption = True )
36
+ if result :
37
+ if 'ResponseMetadata' in result :
38
+ if 'HTTPStatusCode' in result ['ResponseMetadata' ]:
39
+ if result ['ResponseMetadata' ]['HTTPStatusCode' ] == 200 :
40
+ if 'Parameter' in result :
41
+ parameter_list .append (result ['Parameter' ])
39
42
return parameter_list
40
43
41
44
def process_parameter (param_name , param_value ):
@@ -47,7 +50,7 @@ def process_parameter(param_name, param_value):
47
50
new_file_full_path = temp_dir + os .sep + filename + '.new'
48
51
logging .debug ('Storing retrieved value for parameter "%s" in "%s"' % (param_name , new_file_full_path ))
49
52
with open (new_file_full_path , 'w' ) as f :
50
- f .write (param_value . replace ( ' \\ n' , ' \n ' ) )
53
+ f .write (param_value )
51
54
new_file_sha256_hash = get_sha256_hash (new_file_full_path )
52
55
logging .debug ('Comparing file hashes' )
53
56
if existing_file_sha256_hash != new_file_sha256_hash :
0 commit comments