Skip to content

Commit

Permalink
[cli] Added additional commands to outputs (#1138)
Browse files Browse the repository at this point in the history
* [cli] Added additional commands to outputs

'set' - Set one output, using user_input (pass --update to overwrite
existing outputs)

'get' - Get configured outputs for a service (includes creds) optionally
pass --decriptors to only pull certain descriptor secrets for the
service

'set-from-file' - Set numerous outputs via a json file. Can set multiple
services and descriptors (pass --update to overwrite existing outputs)

'generate-skeleton' - Use to create a skeleton json file to be used with
'set-from-file'

Signed-off-by: jack1902 <39212456+jack1902@users.noreply.github.com>

* [cli] Added 'list' to outputs

Also updated inline with PR comments

Signed-off-by: jack1902 <39212456+jack1902@users.noreply.github.com>
  • Loading branch information
jack1902 authored Feb 21, 2020
1 parent 90c42f6 commit 9718c28
Show file tree
Hide file tree
Showing 4 changed files with 490 additions and 62 deletions.
62 changes: 38 additions & 24 deletions streamalert_cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,30 +176,9 @@ def user_input(requested_info, mask, input_restrictions):

if not mask:
while not response:
response = input(prompt) # nosec

# Restrict having spaces or colons in items (applies to things like
# descriptors, etc)
if isinstance(input_restrictions, re.Pattern):
valid_response = input_restrictions.match(response)
if not valid_response:
LOGGER.error('The supplied input should match the following '
'regular expression: %s', input_restrictions.pattern)
elif callable(input_restrictions):
# Functions can be passed here to perform complex validation of input
# Transform the response with the validating function
response = input_restrictions(response)
valid_response = response is not None and response is not False
if not valid_response:
LOGGER.error('The supplied input failed to pass the validation '
'function: %s', input_restrictions.__doc__)
else:
valid_response = not any(x in input_restrictions for x in response)
if not valid_response:
restrictions = ', '.join(
'\'{}\''.format(restriction) for restriction in input_restrictions)
LOGGER.error('The supplied input should not contain any of the following: %s',
restrictions)
response = input(prompt) # nosec

valid_response = response_is_valid(response, input_restrictions)

if not valid_response:
return user_input(requested_info, mask, input_restrictions)
Expand All @@ -210,6 +189,41 @@ def user_input(requested_info, mask, input_restrictions):
return response


def response_is_valid(response, input_restrictions):
"""Check if the response meets the input_restrictions
Args:
response (str): Description of the information needed
Returns:
bool: True if input_restrictions are met else False
"""
valid_response = False
# Restrict having spaces or colons in items (applies to things like
# descriptors, etc)
if isinstance(input_restrictions, re.Pattern):
valid_response = input_restrictions.match(response)
if not valid_response:
LOGGER.error('The supplied input should match the following '
'regular expression: %s', input_restrictions.pattern)
elif callable(input_restrictions):
# Functions can be passed here to perform complex validation of input
# Transform the response with the validating function
response = input_restrictions(response)
valid_response = response is not None and response is not False
if not valid_response:
LOGGER.error('The supplied input failed to pass the validation '
'function: %s', input_restrictions.__doc__)
else:
valid_response = not any(x in input_restrictions for x in response)
if not valid_response:
restrictions = ', '.join(
'\'{}\''.format(restriction) for restriction in input_restrictions)
LOGGER.error('The supplied input should not contain any of the following: %s',
restrictions)
return valid_response


def save_parameter(region, name, value, description, force_overwrite=False):
"""Function to save the designated value to parameter store
Expand Down
Loading

0 comments on commit 9718c28

Please sign in to comment.