def test_parse_arn_without_region_or_account(self): """Assert successful ARN parsing without a region or an account id.""" mock_arn = fake_arn() arn_object = utils.AwsArn(mock_arn) region = arn_object.region self.assertEqual(region, None) account_id = arn_object.account_id self.assertEqual(account_id, None)
def __init__(self, customer_name, auth_credential, bucket, report_name=None, **kwargs): """ Constructor. Args: customer_name (String) Name of the customer auth_credential (String) Authentication credential for S3 bucket (RoleARN) report_name (String) Name of the Cost Usage Report to download (optional) bucket (String) Name of the S3 bucket containing the CUR """ super().__init__(**kwargs) self.customer_name = customer_name.replace(' ', '_') LOG.debug('Connecting to AWS...') session = utils.get_assume_role_session(utils.AwsArn(auth_credential), 'MasuDownloaderSession') self.cur = session.client('cur') # fetch details about the report from the cloud provider defs = self.cur.describe_report_definitions() if not report_name: report_names = [] for report in defs.get('ReportDefinitions', []): if bucket == report.get('S3Bucket'): report_names.append(report['ReportName']) # FIXME: Get the first report in the bucket until Koku can specify # which report the user wants if report_names: report_name = report_names[0] self.report_name = report_name self.bucket = bucket report_defs = defs.get('ReportDefinitions', []) report = [ rep for rep in report_defs if rep['ReportName'] == self.report_name ] if not report: raise MasuProviderError( 'Cost and Usage Report definition not found.') self.report = report.pop() self.s3_client = session.client('s3')
def test_parse_arn_with_region_and_account(self): """Assert successful account ID parsing from a well-formed ARN.""" mock_account_id = fake_aws_account_id() mock_arn = fake_arn(account_id=mock_account_id, region='test-region-1') arn_object = utils.AwsArn(mock_arn) partition = arn_object.partition self.assertIsNotNone(partition) service = arn_object.service self.assertIsNotNone(service) region = arn_object.region self.assertIsNotNone(region) account_id = arn_object.account_id self.assertIsNotNone(account_id) resource_type = arn_object.resource_type self.assertIsNotNone(resource_type) resource_separator = arn_object.resource_separator self.assertIsNotNone(resource_separator) resource = arn_object.resource self.assertIsNotNone(resource) reconstructed_arn = 'arn:' + \ partition + ':' + \ service + ':' + \ region + ':' + \ account_id + ':' + \ resource_type + \ resource_separator + \ resource self.assertEqual(mock_account_id, account_id) self.assertEqual(mock_arn, reconstructed_arn)