Exemple #1
0
    def __init__(self, event, context):
        """
        Initializes helper setup class
        :param event: 
        :param context: 
        """
        CustomResource.__init__(self, event, context)

        self.arguments = copy(self.resource_properties)
        self.arguments = {a: self.resource_properties[a] for a in self.resource_properties if a not in ["ServiceToken",
                                                                                                        "Timeout"]}

        self.configuration_bucket = os.getenv(configuration.ENV_CONFIG_BUCKET, None)
        self.automator_role_arn = self.arguments.get("OpsAutomatorLambdaRole")
        self.events_forward_role = self.arguments.get("EventForwardLambdaRole")
        self.ops_automator_topic_arn = self.arguments.get("OpsAutomatorTopicArn")
        self.use_ecs = TaskConfiguration.as_boolean(self.arguments.get("UseEcs", False))
        self.optimize_cross_account_template = TaskConfiguration.as_boolean(
            (self.arguments.get("OptimizeCrossAccountTemplate", False)))

        self.account = os.getenv(handlers.ENV_OPS_AUTOMATOR_ACCOUNT)

        self.stack_version = self.arguments["StackVersion"]

        # setup logging
        dt = datetime.utcnow()
        classname = self.__class__.__name__
        logstream = LOG_STREAM.format(classname, dt.year, dt.month, dt.day)
        self._logger = QueuedLogger(logstream=logstream, context=context, buffersize=50)
Exemple #2
0
        def setup_action_parameter(name, action_parameter):
            # single action parameter setup
            parameter_template = {}

            # parameter type
            parameter_type = action_parameter[actions.PARAM_TYPE]
            if parameter_type in [int, long, float, Decimal]:
                parameter_template["Type"] = "Number"
            elif isinstance([], parameter_type):
                parameter_template["Type"] = "CommaDelimitedList"
            else:
                parameter_template["Type"] = "String"
                if action_parameter.get(actions.PARAM_REQUIRED, False) and actions.PARAM_MIN_LEN not in action_parameter:
                    parameter_template[actions.PARAM_MIN_LEN] = 1
                # default allowed values for booleans
                if parameter_type == bool:
                    parameter_template["AllowedValues"] = YES_NO

            # for every parameter option...
            for p in PARAM_OPTIONS:
                if p in action_parameter:
                    if p == actions.PARAM_DEFAULT:
                        if parameter_type in [bool]:
                            value = TaskConfiguration.as_boolean(action_parameter[actions.PARAM_DEFAULT])
                            parameter_template[p] = YES if value else NO
                        continue

                    if isinstance(action_parameter[p], type([])):
                        parameter_template[p] = action_parameter[p]
                    else:
                        parameter_template[p] = str(action_parameter[p])

            # add parameter to template
            self._template_parameters[name] = parameter_template

            # add label
            if actions.PARAM_LABEL in action_parameter:
                self._parameter_labels[name] = {"default": action_parameter[actions.PARAM_LABEL]}