def modify()

in rdk/rdk.py [0:0]


    def modify(self):
        #Parse the command-line arguments necessary for modifying a Config Rule.
        self.__parse_rule_args(False)

        print("Running modify!")

        self.args.rulename = self.__clean_rule_name(self.args.rulename)

        #Get existing parameters
        old_params, tags = self.__get_rule_parameters(self.args.rulename)

        if not self.args.custom_lambda_name and 'CustomLambdaName' in old_params:
            self.args.custom_lambda_name = old_params['CustomLambdaName']

        if not self.args.resource_types and 'SourceEvents' in old_params:
            self.args.resource_types = old_params['SourceEvents']

        if not self.args.maximum_frequency and 'SourcePeriodic' in old_params:
            self.args.maximum_frequency = old_params['SourcePeriodic']

        if not self.args.runtime and old_params['SourceRuntime']:
            self.args.runtime = old_params['SourceRuntime']

        if not self.args.input_parameters and 'InputParameters' in old_params:
            self.args.input_parameters = old_params['InputParameters']

        if not self.args.optional_parameters and 'OptionalParameters' in old_params:
            self.args.optional_parameters = old_params['OptionalParameters']

        if not self.args.source_identifier and 'SourceIdentifier' in old_params:
            self.args.source_identifier = old_params['SourceIdentifier']

        if not self.args.tags and tags:
            self.args.tags = tags

        if not self.args.remediation_action and 'Remediation' in old_params:
            params = old_params["Remediation"]
            self.args.auto_remediate = params.get("Automatic", "")
            execution_controls = params.get("ExecutionControls", "")
            if execution_controls:
                ssm_controls = execution_controls["SsmControls"]
                self.args.remediation_concurrent_execution_percent = ssm_controls.get("ConcurrentExecutionRatePercentage", "")
                self.args.remediation_error_rate_percent = ssm_controls.get("ErrorPercentage", "")
            self.args.remediation_parameters = json.dumps(params["Parameters"]) if params.get("Parameters") else None
            self.args.auto_remediation_retry_attempts = params.get("MaximumAutomaticAttempts", "")
            self.args.auto_remediation_retry_time = params.get("RetryAttemptSeconds", "")
            self.args.remediation_action = params.get("TargetId", "")
            self.args.remediation_action_version = params.get("TargetVersion", "")

        if 'RuleSets' in old_params:
            if not self.args.rulesets:
                self.args.rulesets = old_params['RuleSets']

        #Write the parameters to a file in the rule directory.
        self.__populate_params()

        print ("Modified Rule '"+self.args.rulename+"'.  Use the `deploy` command to push your changes to AWS.")