-
Notifications
You must be signed in to change notification settings - Fork 1
Multi line parameters #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM jfloff/alpine-python:2.7-slim | ||
FROM python:3.8-slim | ||
|
||
MAINTAINER Signiant DevOps <devops@signiant.com> | ||
|
||
|
This file contains hidden or 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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import logging, logging.handlers | ||
import argparse | ||
import os | ||
import boto3 | ||
import hashlib | ||
import tempfile | ||
import logging | ||
import logging.handlers | ||
import os | ||
import shutil | ||
import tempfile | ||
import boto3 | ||
|
||
logging.getLogger("botocore").setLevel(logging.CRITICAL) | ||
|
||
|
||
def get_sha256_hash(file_path): | ||
logging.debug('Hashing "%s" using SHA256' % file_path) | ||
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 | |
def get_parameters(parameter_names_list): | ||
parameter_list = [] | ||
if parameter_names_list: | ||
result = ssm.get_parameters(Names=parameter_names_list, WithDecryption=True) | ||
if result: | ||
if 'ResponseMetadata' in result: | ||
if 'HTTPStatusCode' in result['ResponseMetadata']: | ||
if result['ResponseMetadata']['HTTPStatusCode'] == 200: | ||
if 'Parameters' in result: | ||
parameter_list = result['Parameters'] | ||
for parameter_name in parameter_names_list: | ||
result = ssm.get_parameters(Names=[parameter_name], WithDecryption=True) | ||
if result: | ||
if 'ResponseMetadata' in result: | ||
if 'HTTPStatusCode' in result['ResponseMetadata']: | ||
if result['ResponseMetadata']['HTTPStatusCode'] == 200: | ||
if 'Parameters' in result: | ||
parameter_list = parameter_list + result['Parameters'] | ||
return parameter_list | ||
|
||
def process_parameter(param_name, param_value): | ||
|
@@ -47,7 +50,7 @@ def process_parameter(param_name, param_value): | |
new_file_full_path = temp_dir + os.sep + filename + '.new' | ||
logging.debug('Storing retrieved value for parameter "%s" in "%s"' % (param_name, new_file_full_path)) | ||
with open(new_file_full_path, 'w') as f: | ||
f.write(param_value.replace('\\n', '\n')) | ||
f.write(param_value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm this should still work with files that did have unescaped new lines so that's good. |
||
new_file_sha256_hash = get_sha256_hash(new_file_full_path) | ||
logging.debug('Comparing file hashes') | ||
if existing_file_sha256_hash != new_file_sha256_hash: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're only going to get one at a time, why not use get_parameter instead of get_parameters?
For the record, this seems to be WAY less efficient than sending a list of parameter names. If there is a limit to how many parameters you can put in the list (not documented, but clearly a problem) then why not break up the list in chunks of size X and call this method multiple times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to get_parameter.
This is much less efficient, but the get_paramter call is very quick.