Skip to content

Commit f180bfc

Browse files
authored
Multi line parameters (#2)
Get one paramater at a time, and don't strip out newline characters.
1 parent 40dd9e9 commit f180bfc

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM jfloff/alpine-python:2.7-slim
1+
FROM python:3.8-slim
22

33
MAINTAINER Signiant DevOps <devops@signiant.com>
44

parameter_sync.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import logging, logging.handlers
21
import argparse
3-
import os
4-
import boto3
52
import hashlib
6-
import tempfile
3+
import logging
4+
import logging.handlers
5+
import os
76
import shutil
7+
import tempfile
8+
import boto3
89

910
logging.getLogger("botocore").setLevel(logging.CRITICAL)
1011

12+
1113
def get_sha256_hash(file_path):
1214
logging.debug('Hashing "%s" using SHA256' % file_path)
1315
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
2931
def get_parameters(parameter_names_list):
3032
parameter_list = []
3133
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'])
3942
return parameter_list
4043

4144
def process_parameter(param_name, param_value):
@@ -47,7 +50,7 @@ def process_parameter(param_name, param_value):
4750
new_file_full_path = temp_dir + os.sep + filename + '.new'
4851
logging.debug('Storing retrieved value for parameter "%s" in "%s"' % (param_name, new_file_full_path))
4952
with open(new_file_full_path, 'w') as f:
50-
f.write(param_value.replace('\\n', '\n'))
53+
f.write(param_value)
5154
new_file_sha256_hash = get_sha256_hash(new_file_full_path)
5255
logging.debug('Comparing file hashes')
5356
if existing_file_sha256_hash != new_file_sha256_hash:

0 commit comments

Comments
 (0)