class Meta: queryset = Licence.objects.all() authentication = ApiKeyAuthentication() filtering = { 'number_bought': ALL, 'sn': ALL, 'niw': ALL, 'invoice_date': ALL, 'valid_thru': ALL, 'order_no': ALL, 'price': ALL, 'accounting_id': ALL, 'asset_type': ALL, 'provider': ALL, 'invoice_no': ALL, 'manufacturer': ALL_WITH_RELATIONS, 'licence_type': ALL_WITH_RELATIONS, 'property_of': ALL_WITH_RELATIONS, 'software_category': ALL_WITH_RELATIONS, } list_allowed_methods = ['get'] throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = Homepage.objects.all() resource_name = 'homepage2' fields = ['id'] authentication = BasicAuthentication() authorization = DjangoAuthorization() throttle = CacheThrottle(throttle_at=1)
class Meta: queryset = CI.objects.filter(type__id=db.CI_TYPES.SERVICE.id).all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization(required_perms=[ Perm.read_configuration_item_info_generic, ]) filtering = { 'added_manually': ALL, 'barcode': ALL, 'business_service': ALL, 'created': ALL, 'modified': ALL, 'name': ALL, 'object_id': ALL, 'pci_scope': ALL, 'resource_uri': ALL, 'state': ALL, 'status': ALL, 'technical_service': ALL, 'uid': ALL, 'zabbix_id': ALL, } excludes = ('cache_version', ) list_allowed_methods = ['get'] resource_name = 'service' throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = IPAddress.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization(required_perms=[ Perm.read_network_structure, ]) filtering = { 'address': ALL, 'created': ALL, 'device': ALL, 'hostname': ALL, 'http_family': ALL, 'id': ALL, 'is_management': ALL, 'last_plugins': ALL, 'last_puppet': ALL, 'last_seen': ALL, 'modified': ALL, 'number': ALL, 'snmp_community': ALL, } excludes = ( 'dns_info', 'max_save_priority', 'save_priorities', 'snmp_name', 'cache_version', ) cache = SimpleCache() throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = VentureRole.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization( required_perms=[ Perm.read_dc_structure, ] ) filtering = { 'created': ALL, 'devices': ALL, 'id': ALL, 'modified': ALL, 'name': ALL, 'parent': ALL, 'path': ALL, 'properties': ALL, 'venture': ALL_WITH_RELATIONS, } excludes = ('save_priorities', 'max_save_priority', 'cache_version', ) cache = SimpleCache() throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: resource_name = 'quality' object_class = rundoc allowed_methods = ['get', 'post', 'put'] authorization = Authorization() authentication = ApiKeyAuthentication() throttle = CacheThrottle(throttle_at=500, timeframe=60)
class Meta: queryset = Deployment.objects.all() authentication = ApiKeyAuthentication() authorization = DjangoAuthorization() filtering = { 'id': ALL, 'created': ALL, 'modified': ALL, 'status_lastchanged': ALL, 'issue_key': ALL, 'user': ALL_WITH_RELATIONS, 'device': ALL_WITH_RELATIONS, 'mac': ALL, 'status': ALL, 'ip': ALL, 'hostname': ALL, 'img_path': ALL, 'kickstart_path': ALL, 'venture': ALL_WITH_RELATIONS, 'venture_role': ALL_WITH_RELATIONS, 'puppet_certificate_revoked': ALL, } excludes = ('save_priorities', 'max_save_priority',) cache = SimpleCache() limit = 10 throttle = CacheThrottle(throttle_at=THROTTLE_AT, timeframe=TIMEFREME, expiration=EXPIRATION)
class Meta: queryset = Deployment.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization( required_perms=[ Perm.read_deployment, ] ) filtering = { 'created': ALL, 'device': ALL_WITH_RELATIONS, 'done_plugins': ALL, 'hostname': ALL, 'id': ALL, 'img_path': ALL, 'ip': ALL, 'is_running': ALL, 'issue_key': ALL, 'kickstart_path': ALL, 'mac': ALL, 'modified': ALL, 'status': ALL, 'status_lastchanged': ALL, 'user': ALL_WITH_RELATIONS, 'venture': ALL_WITH_RELATIONS, 'venture_role': ALL_WITH_RELATIONS, } excludes = ('save_priorities', 'max_save_priority', 'cache_version', ) cache = SimpleCache() throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = CIChangeCMDBHistory.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization(required_perms=[ Perm.read_configuration_item_info_generic, ]) filtering = { 'ci': ALL, 'comment': ALL, 'created': ALL, 'field_name': ALL, 'id': ALL, 'modified': ALL, 'new_value': ALL, 'old_value': ALL, 'resource_uri': ALL, 'time': ALL, } excludes = ('cache_version', ) list_allowed_methods = ['get'] resource_name = 'cichangecmdbhistory' throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta(DeviceResource.Meta): queryset = Device.objects.filter(model__type__in={ DeviceType.rack_server.id, DeviceType.blade_server.id }) throttle = CacheThrottle(throttle_at=THROTTLE_AT, timeframe=TIMEFREME, expiration=EXPIRATION)
class Meta: queryset = Device.objects.filter(is_active=True) resource_name = 'devices' allowed_methods = ['get', 'patch'] authentication = ApiKeyAuthentication() authorization = AttachedUserAuthorization() throttle = CacheThrottle( throttle_at=1, timeframe=2) # throttle at 1 request per 2 seconds collection_name = 'devices' include_resource_uri = True detail_uri_name = 'serial_number' filtering = { 'given_name': ALL, } fields = [ 'poll_rate', 'given_name', 'power_mode', 'location', 'is_charging', 'battery_life', 'temperature', 'operating_current', 'signal_strength', 'gps_activated', 'gps_satellite_count', 'last_request', ]
class Meta: queryset = CIChangeZabbixTrigger.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization(required_perms=[ Perm.read_configuration_item_info_generic, ]) filtering = { 'comments': ALL, 'created': ALL, 'description': ALL, 'host': ALL, 'host_id': ALL, 'id': ALL, 'lastchange': ALL, 'modified': ALL, 'priority': ALL, 'resource_uri': ALL, 'status': ALL, 'trigger_id': ALL, } excludes = ('cache_version', ) list_allowed_methods = ['get', 'post'] resource_name = 'cichangezabbixtrigger' throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = CIChangePuppet.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization(required_perms=[ Perm.read_configuration_item_info_puppet, ]) filtering = { 'configuration_version': ALL, 'created': ALL, 'host': ALL, 'id': ALL, 'kind': ALL, 'modified': ALL, 'resource_uri': ALL, 'status': ALL, 'time': ALL, } excludes = ('cache_version', ) list_allowed_methods = ['get', 'post'] resource_name = 'cichangepuppet' throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta(DeviceResource.Meta): queryset = Device.objects.all() throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = CIChange.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization(required_perms=[ Perm.read_configuration_item_info_generic, ]) filtering = { 'created': ALL, 'external_key': ALL, 'id': ALL, 'message': ALL, 'modified': ALL, 'object_id': ALL, 'priority': ALL, 'registration_type': ALL, 'resource_uri': ALL, 'time': ALL, 'type': ALL, } excludes = ('cache_version', ) allowed_methods = ['get'] resource_name = 'cichange' throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = CIOwner.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization(required_perms=[ Perm.read_configuration_item_info_generic, ]) list_allowed_methods = ['get', 'post'] filtering = { 'cache_version': ALL, 'created': ALL, 'email': ALL, 'first_name': ALL, 'id': ALL, 'last_name': ALL, 'modified': ALL, 'resource_uri': ALL, 'sAMAccountName': ALL, } excludes = ('cache_version', ) resource_name = 'ciowners' throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = DeviceModel.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization(required_perms=[ Perm.read_dc_structure, ]) filtering = { 'chassis_size': ALL, 'created': ALL, 'group': ALL, 'id': ALL, 'modified': ALL, 'name': ALL, } excludes = ( 'save_priorities', 'max_save_priority', 'cache_version', ) cache = SimpleCache() filtering = { 'type': ALL, } throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = Venture.objects.all() authentication = ApiKeyAuthentication() authorization = RalphAuthorization( required_perms=[ Perm.read_dc_structure, ] ) filtering = { 'created': ALL, 'data_center': ALL_WITH_RELATIONS, 'business_segment': ALL_WITH_RELATIONS, 'profit_center': ALL_WITH_RELATIONS, 'department': ALL_WITH_RELATIONS, 'devices': ALL, 'id': ALL, 'is_infrastructure': ALL, 'modified': ALL, 'name': ALL, 'path': ALL, 'roles': ALL, 'show_in_ralph': ALL, 'symbol': ALL, } excludes = ('save_priorities', 'max_save_priority', 'cache_version', ) cache = SimpleCache() throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: detail_allowed_methods = ['get'] list_allowed_methods = [] max_limit = 100 queryset = Person.objects.all() resource_name = 'persona' serializer = LibreBormeJSONSerializer(formats=['json']) throttle = CacheThrottle(throttle_at=60, timeframe=3600)
class Meta: queryset = CI.objects.all() authentication = ApiKeyAuthentication() authorization = DjangoAuthorization() resource_name = 'ci' throttle = CacheThrottle(throttle_at=THROTTLE_AT, timeframe=TIMEFREME, expiration=EXPIRATION)
class Meta: queryset = CI.objects.filter(type__id=db.CI_TYPES.SERVICE.id).all() authentication = ApiKeyAuthentication() authorization = DjangoAuthorization() resource_name = 'service' throttle = CacheThrottle(throttle_at=THROTTLE_AT, timeframe=TIMEFREME, expiration=EXPIRATION)
class Meta: queryset = DeviceModelGroup.objects.all() authentication = ApiKeyAuthentication() authorization = DjangoAuthorization() cache = SimpleCache() throttle = CacheThrottle(throttle_at=THROTTLE_AT, timeframe=TIMEFREME, expiration=EXPIRATION)
class Meta: allowed_methods = ['get'] excludes = ['active'] queryset = City.available.all() resource_name = 'city' throttle = CacheThrottle(throttle_at=settings.BIXI_THROTTLE_AT, timeframe=settings.BIXI_TIMEFRAME, expiration=settings.BIXI_EXPIRATION)
class Meta(DeviceResource.Meta): queryset = Device.objects.filter( model__type=DeviceType.virtual_server.id, ) throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: queryset = AssetManufacturer.objects.all() authentication = ApiKeyAuthentication() list_allowed_methods = ['get'] throttle = CacheThrottle( throttle_at=THROTTLE_AT, timeframe=TIMEFRAME, expiration=EXPIRATION, )
class Meta: allowed_methods = ['get'] excludes = ['public_id', 'terminal_name'] max_limit = 0 queryset = Station.available.all() resource_name = 'station' throttle = CacheThrottle(throttle_at=settings.BIXI_THROTTLE_AT, timeframe=settings.BIXI_TIMEFRAME, expiration=settings.BIXI_EXPIRATION)
class Meta: queryset = CIRelation.objects.all() authentication = ApiKeyAuthentication() authorization = DjangoAuthorization() list_allowed_methods = ['get'] resource_name = 'cirelation' throttle = CacheThrottle(throttle_at=THROTTLE_AT, timeframe=TIMEFREME, expiration=EXPIRATION)
class Meta: queryset = CIChangeStatusOfficeIncident.objects.all() authentication = ApiKeyAuthentication() authorization = DjangoAuthorization() list_allowed_methods = ['get', 'post'] resource_name = 'cichangestatusofficeincident' throttle = CacheThrottle(throttle_at=THROTTLE_AT, timeframe=TIMEFREME, expiration=EXPIRATION)
class Meta: queryset = CIChangeZabbixTrigger.objects.all() authentication = ApiKeyAuthentication() authorization = DjangoAuthorization() list_allowed_methods = ['get', 'post'] resource_name = 'cichangezabbixtrigger' throttle = CacheThrottle(throttle_at=THROTTLE_AT, timeframe=TIMEFREME, expiration=EXPIRATION)
class Meta(MarketplaceResource.Meta): resource_name = 'feedback' always_return_data = True list_allowed_methods = ['post'] detail_allowed_methods = [] authentication = OptionalOAuthAuthentication() authorization = Authorization() object_class = GenericObject include_resource_uri = False throttle = CacheThrottle(throttle_at=30)
def test_throttling(self, mocked_time): mocked_time.time.return_value = time.time() throttle_1 = CacheThrottle(throttle_at=2, timeframe=5, expiration=2) self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 0) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 1) self.assertEqual(cache.get('cody_accesses'), None) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.accessed('cody'), None) self.assertEqual(throttle_1.should_be_throttled('cody'), False) self.assertEqual(len(cache.get('daniel_accesses')), 2) self.assertEqual(len(cache.get('cody_accesses')), 1) # THROTTLE'D! self.assertEqual(throttle_1.should_be_throttled('daniel'), 5) self.assertEqual(len(cache.get('daniel_accesses')), 2) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.should_be_throttled('daniel'), 5) self.assertEqual(len(cache.get('daniel_accesses')), 3) self.assertEqual(throttle_1.accessed('daniel'), None) # Should be no interplay. self.assertEqual(throttle_1.should_be_throttled('cody'), False) self.assertEqual(throttle_1.accessed('cody'), None) # Test the timeframe. mocked_time.time.return_value += throttle_1.timeframe + 1 self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 0)
def test_throttling(self): throttle_1 = CacheThrottle(throttle_at=2, timeframe=5, expiration=2) self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 0) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 1) self.assertEqual(cache.get('cody_accesses'), None) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.accessed('cody'), None) self.assertEqual(throttle_1.should_be_throttled('cody'), False) self.assertEqual(len(cache.get('daniel_accesses')), 2) self.assertEqual(len(cache.get('cody_accesses')), 1) # THROTTLE'D! self.assertEqual(throttle_1.should_be_throttled('daniel'), True) self.assertEqual(len(cache.get('daniel_accesses')), 2) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.should_be_throttled('daniel'), True) self.assertEqual(len(cache.get('daniel_accesses')), 3) self.assertEqual(throttle_1.accessed('daniel'), None) # Should be no interplay. self.assertEqual(throttle_1.should_be_throttled('cody'), False) self.assertEqual(throttle_1.accessed('cody'), None) # Test the timeframe. time.sleep(3) self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 0)
def test_throttling(self): throttle_1 = CacheThrottle(throttle_at=2, timeframe=5, expiration=2) self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 0) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 1) self.assertEqual(cache.get('cody_accesses'), None) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.accessed('cody'), None) self.assertEqual(throttle_1.should_be_throttled('cody'), False) self.assertEqual(len(cache.get('daniel_accesses')), 2) self.assertEqual(len(cache.get('cody_accesses')), 1) # THROTTLE'D! self.assertEqual(throttle_1.should_be_throttled('daniel'), True) self.assertEqual(len(cache.get('daniel_accesses')), 2) self.assertEqual(throttle_1.accessed('daniel'), None) self.assertEqual(throttle_1.should_be_throttled('daniel'), True) self.assertEqual(len(cache.get('daniel_accesses')), 3) self.assertEqual(throttle_1.accessed('daniel'), None) # Should be no interplay. self.assertEqual(throttle_1.should_be_throttled('cody'), False) self.assertEqual(throttle_1.accessed('cody'), None) # Test the timeframe. ret_time = time.time() + throttle_1.timeframe + 1 with mock.patch('tastypie.throttle.time') as mocked_time: mocked_time.time.return_value = ret_time self.assertEqual(throttle_1.should_be_throttled('daniel'), False) self.assertEqual(len(cache.get('daniel_accesses')), 0)