def test_get_tenant_no_group(self): """Test get_tenant with a user with no group.""" user = Mock() group = Mock() group.id = 909090 user.groups.first.return_value = group with self.assertRaises(ValidationError): get_tenant(user)
def get_tag_keys(request): """Get a list of tag keys to validate filters.""" tenant = get_tenant(request.user) handler = OCPTagQueryHandler('', {}, tenant) tags = handler.get_tag_keys(filters=False) tags = [':'.join(['tag', tag]) for tag in tags] return tags
def retrieve(self, request, *args, **kwargs): """Get a provider.""" response = super().retrieve(request=request, args=args, kwargs=kwargs) tenant = get_tenant(request.user) manager = ProviderManager(kwargs['uuid']) response.data['infrastructure'] = manager.get_infrastructure_name( tenant) response.data['stats'] = manager.provider_statistics(tenant) return response
def list(self, request, *args, **kwargs): """Obtain the list of providers.""" response = super().list(request=request, args=args, kwargs=kwargs) for provider in response.data['data']: manager = ProviderManager(provider['uuid']) tenant = get_tenant(request.user) provider['stats'] = manager.provider_statistics(tenant) provider['infrastructure'] = manager.get_infrastructure_name( tenant) return response
def retrieve(self, request, *args, **kwargs): """Get a provider. @api {get} /cost-management/v1/providers/:uuid/ Get a provider @apiName GetProvider @apiGroup Provider @apiVersion 1.0.0 @apiDescription Get a provider. @apiHeader {String} token User authorization token. @apiParam {String} uuid Provider unique ID. @apiSuccess {String} uuid The identifier of the provider. @apiSuccess {String} name The name of the provider. @apiSuccess {Object} authentication The authentication for the provider. @apiSuccess {Object} billing_source The billing source information for the provider. @apiSuccess {Object} customer The customer the provider is assocaited with. @apiSuccess {Object} created_by The user the provider was created by. @apiSuccess {Object} stats Report processing statistics. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "uuid": "9002b1db-0bf9-48bb-bd2a-9dc0c8e2742a", "name": "My Company AWS production", "authentication": { "uuid": "00dde2ed-91cc-401e-89ca-1d5e848ae3a6", 'provider_resource_name': 'arn:aws:s3:::cost_s3' }, "billing_source": { "uuid": "7347c1af-220c-4148-b52b-65e314f24999", "bucket": "cost_s3" }, "customer": { "uuid": "600562e7-d7d7-4516-8522-410e72792daf", "name": "My Tech Company", "owner": { "uuid": "57e60f90-8c0c-4bd1-87a0-2143759aae1c", "username": "******", "email": "*****@*****.**" }, "date_created": "2018-05-09T18:17:29.386Z" }, "created_by": { "uuid": "57e60f90-8c0c-4bd1-87a0-2143759aae1c", "username": "******", "email": "*****@*****.**" }, "stats": { "2019-01-01": [ { "assembly_id": "f0d262ff-cc93-449c-a834-74c4d958d45f", "billing_period_start": "2019-01-01", "files_processed": "1/1", "last_process_start_date": "2019-01-07 21:50:58", "last_process_complete_date": "2019-01-07 21:51:01", "summary_data_creation_datetime": "2019-01-07 21:51:32", "summary_data_updated_datetime": "2019-01-07 21:51:32" } ] }, "infrastructure": "Unknown" } """ response = super().retrieve(request=request, args=args, kwargs=kwargs) tenant = get_tenant(request.user) manager = ProviderManager(kwargs['uuid']) response.data['infrastructure'] = manager.get_infrastructure_name( tenant) response.data['stats'] = manager.provider_statistics(tenant) return response
def list(self, request, *args, **kwargs): """Obtain the list of providers. @api {get} /cost-management/v1/providers/ Obtain the list of providers @apiName GetProviders @apiGroup Provider @apiVersion 1.0.0 @apiDescription Obtain the list of providers. @apiHeader {String} token User authorization token. @apiParam (Query) {Number} page Parameter for selecting the page of data (default is 1) @apiParam (Query) {Number} page_size Parameter for selecting the amount of data in a page (default is 10) @apiSuccess {Object} meta The metadata for pagination. @apiSuccess {Object} links The object containing links of results. @apiSuccess {Object[]} data The array of results. @apiSuccessExample {json} Success-Response: HTTP/1.1 200 OK { "meta": { "count": 1 } "links": { "first": "/cost-management/v1/providers/?page=1", "next": None, "previous": None, "last": "/cost-management/v1/providers/?page=1" }, "data": [ { "uuid": "9002b1db-0bf9-48bb-bd2a-9dc0c8e2742a", "name": "My Company AWS production", "authentication": { "uuid": "00dde2ed-91cc-401e-89ca-1d5e848ae3a6", 'provider_resource_name': 'arn:aws:s3:::cost_s3' }, "billing_source": { "uuid": "7347c1af-220c-4148-b52b-65e314f24999", "bucket": "cost_s3" }, "customer": { "uuid": "600562e7-d7d7-4516-8522-410e72792daf", "name": "My Tech Company", "owner": { "uuid": "57e60f90-8c0c-4bd1-87a0-2143759aae1c", "username": "******", "email": "*****@*****.**" }, "date_created": "2018-05-09T18:17:29.386Z" }, "created_by": { "uuid": "57e60f90-8c0c-4bd1-87a0-2143759aae1c", "username": "******", "email": "*****@*****.**" }, "stats": { "2019-01-01": [ { "assembly_id": "f0d262ff-cc93-449c-a834-74c4d958d45f", "billing_period_start": "2019-01-01", "files_processed": "1/1", "last_process_start_date": "2019-01-07 21:50:58", "last_process_complete_date": "2019-01-07 21:51:01", "summary_data_creation_datetime": "2019-01-07 21:51:32", "summary_data_updated_datetime": "2019-01-07 21:51:32" } ] } "infrastructure": "Unknown" } ] } """ response = super().list(request=request, args=args, kwargs=kwargs) for provider in response.data['data']: manager = ProviderManager(provider['uuid']) tenant = get_tenant(request.user) provider['stats'] = manager.provider_statistics(tenant) provider['infrastructure'] = manager.get_infrastructure_name( tenant) return response