def __init__(self, role_arn, aws_regions=None, all_aws_regions=None): super(OrganizationAggregationSource, self).__init__( capitalize_start=True, capitalize_arn=False ) # Can't have both the regions and all_regions flag present -- also can't have them both missing: if aws_regions and all_aws_regions: raise InvalidParameterValueException( "Your configuration aggregator contains a list of regions and also specifies " "the use of all regions. You must choose one of these options." ) if not (aws_regions or all_aws_regions): raise InvalidParameterValueException( "Your request does not specify any regions. Select AWS Config-supported " "regions and try again." ) self.role_arn = role_arn self.aws_regions = aws_regions if not all_aws_regions: all_aws_regions = False self.all_aws_regions = all_aws_regions
def __init__(self, account_ids, aws_regions=None, all_aws_regions=None): super(AccountAggregatorSource, self).__init__(capitalize_start=True) # Can't have both the regions and all_regions flag present -- also can't have them both missing: if aws_regions and all_aws_regions: raise InvalidParameterValueException( 'Your configuration aggregator contains a list of regions and also specifies ' 'the use of all regions. You must choose one of these options.' ) if not (aws_regions or all_aws_regions): raise InvalidParameterValueException( 'Your request does not specify any regions. Select AWS Config-supported ' 'regions and try again.') self.account_ids = account_ids self.aws_regions = aws_regions if not all_aws_regions: all_aws_regions = False self.all_aws_regions = all_aws_regions
def put_evaluations(self, evaluations=None, result_token=None, test_mode=False): if not evaluations: raise InvalidParameterValueException( "The Evaluations object in your request cannot be null." "Add the required parameters and try again." ) if not result_token: raise InvalidResultTokenException() # Moto only supports PutEvaluations with test mode currently (missing rule and token support) if not test_mode: raise NotImplementedError( "PutEvaluations without TestMode is not yet implemented" ) return { "FailedEvaluations": [], } # At this time, moto is not adding failed evaluations.
def put_configuration_aggregator(self, config_aggregator, region): # Validate the name: if len(config_aggregator['ConfigurationAggregatorName']) > 256: raise NameTooLongException( config_aggregator['ConfigurationAggregatorName'], 'configurationAggregatorName') account_sources = None org_source = None # Tag validation: tags = validate_tags(config_aggregator.get('Tags', [])) # Exception if both AccountAggregationSources and OrganizationAggregationSource are supplied: if config_aggregator.get( 'AccountAggregationSources') and config_aggregator.get( 'OrganizationAggregationSource'): raise InvalidParameterValueException( 'The configuration aggregator cannot be created because your request contains both the' ' AccountAggregationSource and the OrganizationAggregationSource. Include only ' 'one aggregation source and try again.') # If neither are supplied: if not config_aggregator.get( 'AccountAggregationSources') and not config_aggregator.get( 'OrganizationAggregationSource'): raise InvalidParameterValueException( 'The configuration aggregator cannot be created because your request is missing either ' 'the AccountAggregationSource or the OrganizationAggregationSource. Include the ' 'appropriate aggregation source and try again.') if config_aggregator.get('AccountAggregationSources'): # Currently, only 1 account aggregation source can be set: if len(config_aggregator['AccountAggregationSources']) > 1: raise TooManyAccountSources( len(config_aggregator['AccountAggregationSources'])) account_sources = [] for a in config_aggregator['AccountAggregationSources']: account_sources.append( AccountAggregatorSource( a['AccountIds'], aws_regions=a.get('AwsRegions'), all_aws_regions=a.get('AllAwsRegions'))) else: org_source = OrganizationAggregationSource( config_aggregator['OrganizationAggregationSource']['RoleArn'], aws_regions=config_aggregator['OrganizationAggregationSource']. get('AwsRegions'), all_aws_regions=config_aggregator[ 'OrganizationAggregationSource'].get('AllAwsRegions')) # Grab the existing one if it exists and update it: if not self.config_aggregators.get( config_aggregator['ConfigurationAggregatorName']): aggregator = ConfigAggregator( config_aggregator['ConfigurationAggregatorName'], region, account_sources=account_sources, org_source=org_source, tags=tags) self.config_aggregators[ config_aggregator['ConfigurationAggregatorName']] = aggregator else: aggregator = self.config_aggregators[ config_aggregator['ConfigurationAggregatorName']] aggregator.tags = tags aggregator.account_aggregation_sources = account_sources aggregator.organization_aggregation_source = org_source aggregator.last_updated_time = datetime2int(datetime.utcnow()) return aggregator.to_dict()
def put_configuration_aggregator(self, config_aggregator, region): # Validate the name: if len(config_aggregator["ConfigurationAggregatorName"]) > 256: raise NameTooLongException( config_aggregator["ConfigurationAggregatorName"], "configurationAggregatorName", ) account_sources = None org_source = None # Tag validation: tags = validate_tags(config_aggregator.get("Tags", [])) # Exception if both AccountAggregationSources and OrganizationAggregationSource are supplied: if config_aggregator.get( "AccountAggregationSources") and config_aggregator.get( "OrganizationAggregationSource"): raise InvalidParameterValueException( "The configuration aggregator cannot be created because your request contains both the" " AccountAggregationSource and the OrganizationAggregationSource. Include only " "one aggregation source and try again.") # If neither are supplied: if not config_aggregator.get( "AccountAggregationSources") and not config_aggregator.get( "OrganizationAggregationSource"): raise InvalidParameterValueException( "The configuration aggregator cannot be created because your request is missing either " "the AccountAggregationSource or the OrganizationAggregationSource. Include the " "appropriate aggregation source and try again.") if config_aggregator.get("AccountAggregationSources"): # Currently, only 1 account aggregation source can be set: if len(config_aggregator["AccountAggregationSources"]) > 1: raise TooManyAccountSources( len(config_aggregator["AccountAggregationSources"])) account_sources = [] for source in config_aggregator["AccountAggregationSources"]: account_sources.append( AccountAggregatorSource( source["AccountIds"], aws_regions=source.get("AwsRegions"), all_aws_regions=source.get("AllAwsRegions"), )) else: org_source = OrganizationAggregationSource( config_aggregator["OrganizationAggregationSource"]["RoleArn"], aws_regions=config_aggregator["OrganizationAggregationSource"]. get("AwsRegions"), all_aws_regions=config_aggregator[ "OrganizationAggregationSource"].get("AllAwsRegions"), ) # Grab the existing one if it exists and update it: if not self.config_aggregators.get( config_aggregator["ConfigurationAggregatorName"]): aggregator = ConfigAggregator( config_aggregator["ConfigurationAggregatorName"], region, account_sources=account_sources, org_source=org_source, tags=tags, ) self.config_aggregators[ config_aggregator["ConfigurationAggregatorName"]] = aggregator else: aggregator = self.config_aggregators[ config_aggregator["ConfigurationAggregatorName"]] aggregator.tags = tags aggregator.account_aggregation_sources = account_sources aggregator.organization_aggregation_source = org_source aggregator.last_updated_time = datetime2int(datetime.utcnow()) return aggregator.to_dict()