def verify_placeholder_tags(tags, action_placeholders=None, exclude_tags=None): checked_tags = [(tagging.TAG_VAL_ACCOUNT, services.get_aws_account()), (tagging.TAG_VAL_AUTOMATOR_STACK, os.getenv(handlers.ENV_STACK_NAME, "\.*")), (tagging.TAG_VAL_DATE, DATE), (tagging.TAG_VAL_DATE_TIME, DATETIME), (tagging.TAG_VAL_DAY, DD), (tagging.TAG_VAL_HOUR, HOUR), (tagging.TAG_VAL_ISO_DATE, ISO_DATE), (tagging.TAG_VAL_ISO_DATETIME, ISO_DATETIME), (tagging.TAG_VAL_ISO_TIME, ISO_TIME), (tagging.TAG_VAL_ISO_WEEKDAY, ISO_WEEKDAY), (tagging.TAG_VAL_MINUTE, MN), (tagging.TAG_VAL_MONTH, MM), (tagging.TAG_VAL_MONTH_NAME, MONTH_NAME_SHORT), (tagging.TAG_VAL_MONTH_NAME_LONG, MONTH_NAME_LONG), (tagging.TAG_VAL_REGION, REGIONS), (tagging.TAG_VAL_SECOND, SS), (tagging.TAG_VAL_TASK_TAG, TAG_NAME), (tagging.TAG_VAL_TASK, TASK), (tagging.TAG_VAL_TASK_ID, TASK_ID), (tagging.TAG_VAL_TIME, TIME), (tagging.TAG_VAL_TIMEZONE, TIMEZONE), (tagging.TAG_VAL_WEEKDAY, WEEK_NAME_SHORT), (tagging.TAG_VAL_WEEKDAY_LONG, WEEK_NAME_LONG), (tagging.TAG_VAL_YEAR, YYYY), (tags.get("tag-" + tagging.TAG_VAL_TASK), TASK)] if exclude_tags is not None: for e in exclude_tags: for c in checked_tags: if c[0] == e: checked_tags.remove(c) break expression = "&".join([ "(tag-{}=\\^{}$)".format(e[0], (e[1] if e[1] else "").replace( "(", "%(").replace(")", "%)").replace(" ", "\\s")) for e in checked_tags ]) expression += "&!{}=*".format(NAME_OF_TAG_TO_DELETE) if action_placeholders is not None: action_tags = [(p, action_placeholders[p]) for p in action_placeholders] expression += "&" + "&".join([ "(tag-{}={})".format(e[0], (e[1] if e[1] else "").replace( "(", "%(").replace(")", "%)").replace( " ", "\\s" if e[1] and e[1][0] == '\\' else " ")) for e in action_tags ]) return TagFilterExpression(expression).is_match(tags)
def aws_account(self): """ Returns the (cached) AWS account, using the role if one was specified, otherwise the account is retrieved by getting the caller identity from the STS service :return: Current AWS account number for the instance of the service class """ if self._aws_account is None: if self.role_arn not in [None, ""]: self._aws_account = services.account_from_role_arn(self.role_arn) else: self._aws_account = services.get_aws_account(self.sts_client) return self._aws_account
def build_events_forward_template(template_filename, script_filename, stack, event_role_arn, ops_automator_topic_arn, version): with open(script_filename, "rt") as f: script_text = f.readlines() with open(template_filename, "rt") as f: template = json.loads("".join(f.readlines()), object_pairs_hook=OrderedDict) code = template["Resources"]["EventsForwardFunction"]["Properties"][ "Code"] code["ZipFile"]["Fn::Join"][1] = script_text return json.dumps(template, indent=3) \ .replace("%version%", version) \ .replace("%ops-automator-stack%", stack) \ .replace("%ops-automator-region%", services.get_session().region_name) \ .replace("%ops-automator-account%", services.get_aws_account()) \ .replace("%ops-automator-topic-arn%", ops_automator_topic_arn) \ .replace("%event-forward-role%", event_role_arn)
def __init__(self, method_name): unittest.TestCase.__init__(self, method_name) self.created_snapshots = None self.account = services.get_aws_account()
def __init__(self, method_name): unittest.TestCase.__init__(self, method_name) self.account = services.get_aws_account()
def __init__(self, action_name, tested_region=None, test_region=None, action_stack_name=None, logger=None, task_list_tag_name=None, debug=False): self.debug = debug self.logger = logger if logger is not None else ConsoleLogger( debug=self.debug) if getattr(self.logger, "test") is None: setattr(self.logger, "test", getattr(self.logger, "info")) self.context = None self.action_name = action_name self.action_class = actions.get_action_class(self.action_name) self.action_properties = actions.get_action_properties( self.action_name) self.tested_region = tested_region if tested_region is not None else boto3.Session( ).region_name self.test_region = test_region if test_region is not None else boto3.Session( ).region_name if task_list_tag_name is not None: os.environ[handlers.ENV_AUTOMATOR_TAG_NAME] = task_list_tag_name self.interval = None os.environ[ handlers.ENV_OPS_AUTOMATOR_ACCOUNT] = services.get_aws_account() if action_stack_name is None: self.action_stack_name = testing.action_stack_name( self.action_name) else: self.action_stack_name = action_stack_name self._action_stack = None os.environ[handlers.ENV_STACK_NAME] = self.action_stack_name actions.set_report_output_provider(create_output_writer) self._action_stack_resources = None self._assumed_role = None self._tested_account = None self._session = None self._cloudformation_client = None self._action_stack_template = None self._events = None self._tag_filter = None self.results = None self.parameters = None self.task_name = None self.action_select_parameters = None self.run_after_select = None self.max_concurrency = None self.concurrency_key = None self.log_subject = None self.run_in_regions = None self.run_after_select = None self.executed_tasks = []