Esempio n. 1
0
 def test_update_query_parameters_empty_intersection(self):
     """Test that a group by account filtered list causes 403 when empty intersection of accounts."""
     query_parameters = {
         'group_by': {'account': ['account1', 'account5'], 'region': ['*']}
     }
     access = {
         'aws.account': {'read': ['account4', 'account2']}
     }
     with self.assertRaises(PermissionDenied):
         update_query_parameters_for_aws(query_parameters, access)
Esempio n. 2
0
 def test_update_query_parameters_add_account_filter_obj(self):
     """Test that if no group_by or filter is present a filter of accounts is added."""
     query_parameters = {}
     access = {'aws.account': {'read': ['account1', 'account2']}}
     out = update_query_parameters_for_aws(query_parameters, access)
     expected = {'filter': {'account': ['account1', 'account2']}}
     self.assertEqual(expected, out)
Esempio n. 3
0
    def __init__(self, query_parameters, url_data, tenant, **kwargs):
        """Establish AWS report query handler.

        Args:
            query_parameters    (Dict): parameters for query
            url_data        (String): URL string to provide order information
            tenant    (String): the tenant to use to access CUR data
            kwargs    (Dict): A dictionary for internal query alteration based on path

        """
        provider = 'AWS'

        self._initialize_kwargs(kwargs)

        if kwargs.get('access'):
            query_parameters = update_query_parameters_for_aws(
                query_parameters, kwargs.get('access'))

        # do not override mapper if its already set
        try:
            getattr(self, '_mapper')
        except AttributeError:
            self._mapper = AWSProviderMap(
                provider=provider, report_type=kwargs.get('report_type'))

        self.group_by_options = self._mapper.provider_map.get(
            'group_by_options')
        self.query_parameters = query_parameters
        self.url_data = url_data
        self._limit = self.get_query_param_data('filter', 'limit')

        super().__init__(query_parameters, tenant, **kwargs)
Esempio n. 4
0
 def test_update_query_parameters_with_wildcard(self):
     """Test wildcard doesn't update query parameters."""
     query_parameters = {
         'group_by': {'account': ['*'], 'region': ['*']}
     }
     access = {
         'aws.account': {'read': ['*']}
     }
     out = update_query_parameters_for_aws(query_parameters, access)
     self.assertEqual(query_parameters, out)
Esempio n. 5
0
 def test_update_query_parameters_filtered_intersection(self):
     """Test that a filter by account filtered list is replaced with only the intersection of accounts."""
     query_parameters = {
         'filter': {
             'account': ['account1', 'account5'],
             'region': ['*']
         }
     }
     access = {'aws.account': {'read': ['account1', 'account2']}}
     out = update_query_parameters_for_aws(query_parameters, access)
     expected = {'filter': {'account': ['account1'], 'region': ['*']}}
     self.assertEqual(expected, out)
Esempio n. 6
0
 def test_update_query_parameters_replace_wildcard(self):
     """Test that a group by account wildcard is replaced with only the subset of accounts."""
     query_parameters = {'group_by': {'account': ['*'], 'region': ['*']}}
     access = {'aws.account': {'read': ['account1', 'account2']}}
     out = update_query_parameters_for_aws(query_parameters, access)
     expected = {
         'group_by': {
             'account': ['account1', 'account2'],
             'region': ['*']
         }
     }
     self.assertEqual(expected, out)
Esempio n. 7
0
    def __init__(self, query_parameters, url_data,
                 tenant, **kwargs):
        """Establish AWS report query handler.

        Args:
            query_parameters    (Dict): parameters for query
            url_data        (String): URL string to provide order information
            tenant    (String): the tenant to use to access CUR data
            kwargs    (Dict): A dictionary for internal query alteration based on path
        """
        if not kwargs.get('provider'):
            kwargs['provider'] = 'AWS'
        if kwargs.get('access'):
            query_parameters = update_query_parameters_for_aws(query_parameters, kwargs.get('access'))
        super().__init__(query_parameters, url_data,
                         tenant, **kwargs)