def test_put_id(self): method = 'test_put_id' rv = self.app.get('/api/roles?session_id=test') roles = json_deserialize(rv.data) role = roles.get(self.new_role.theName) url = '/api/roles/id/%d' % role.theId upd_role = self.new_role upd_role.theName = 'Test2' upd_role_dict = self.new_role_dict upd_role_dict['object'] = upd_role upd_role_body = jsonpickle.encode(upd_role_dict) self.logger.info('[%s] JSON data: %s', method, upd_role_body) rv = self.app.put(url, content_type='application/json', data=upd_role_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') message = json_resp.get('message', None) self.assertIsNotNone(message, 'No message returned') rv = self.app.get('/api/roles/name/Test2?session_id=test') role = json_deserialize(rv.data) self.logger.info('[%s] Role: %s [%d]\n', method, role.theName, role.theId)
def test_post(self): method = 'test_post_new' rv = self.app.post('/api/assets', content_type='application/json', data=self.new_asset_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') asset_id = json_resp.get('asset_id', None) self.assertIsNotNone(asset_id, 'No asset ID returned') rv = self.app.get('/api/assets/id/%d?session_id=test' % asset_id) asset = json_deserialize(rv.data) self.logger.info('[%s] Asset: %s [%d]\n', method, asset.theName, asset.theId)
def test_post(self): method = 'test_post_new' rv = self.app.post('/api/assets', content_type='application/json', data=self.new_asset_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') asset_id = json_resp.get('asset_id', None) self.assertIsNotNone(asset_id, 'No asset ID returned') rv = self.app.get('/api/assets/id/%d?session_id=test' % asset_id) asset = json_deserialize(rv.data) self.logger.info('[%s] Asset: %s [%d]\n', method, asset.theName, asset.theId)
def test_update_props_name_put(self): method = 'test_update_props_name_put' url = '/api/assets/name/%s/properties' % quote(self.new_asset.theName) self.logger.info('[%s] Old asset property environment name: %s', method, self.new_asset_props[0].theEnvironmentName) upd_asset_props = self.new_asset_props upd_asset_props[0].theEnvironmentName = 'Psychosis' upd_asset_props_dict = { 'session_id': 'test', 'object': upd_asset_props } upd_asset_props_body = jsonpickle.encode(upd_asset_props_dict) self.logger.info('[%s] JSON data: %s', method, upd_asset_props_body) rv = self.app.put(url, content_type='application/json', data=upd_asset_props_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') message = json_resp.get('message', None) self.assertIsNotNone(message, 'No message returned') rv = self.app.get('/api/assets/name/Test2/properties?session_id=test') self.logger.debug('[%s] Response data: %s', method, rv.data) asset_props = jsonpickle.decode(rv.data) self.logger.info('[%s] Asset property environment: %s\n', method, asset_props[0]['theEnvironmentName'])
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, RiskModel.required) json_dict['__python_obj__'] = Risk.__module__+'.'+Risk.__name__ if json_dict['theMisuseCase']: mc_dict = json_dict['theMisuseCase'] check_required_keys(mc_dict, MisuseCaseModel.required) mc_dict['__python_obj__'] = MisuseCase.__module__+'.'+MisuseCase.__name__ for idx in range(0, len(mc_dict['theEnvironmentProperties'])): mcep_dict = mc_dict['theEnvironmentProperties'][idx] check_required_keys(mcep_dict, MisuseCaseEnvironmentPropertiesModel.required) mcep_dict['__python_obj__'] = MisuseCaseEnvironmentProperties.__module__+'.'+MisuseCaseEnvironmentProperties.__name__ mc_dict['theEnvironmentProperties'][idx] = mcep_dict json_dict['theMisuseCase'] = mc_dict risk = json_deserialize(json_dict) if isinstance(risk, Risk): return risk else: raise MalformedJSONHTTPError()
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, VulnerabilityModel.required) json_dict[ '__python_obj__'] = Vulnerability.__module__ + '.' + Vulnerability.__name__ for idx in range(0, len(json_dict['theEnvironmentProperties'])): property = json_dict['theEnvironmentProperties'][idx] check_required_keys( property, VulnerabilityEnvironmentPropertiesModel.required) property[ '__python_obj__'] = VulnerabilityEnvironmentProperties.__module__ + '.' + VulnerabilityEnvironmentProperties.__name__ json_dict['theEnvironmentProperties'][idx] = property vulnerability = json_serialize(json_dict) vulnerability = json_deserialize(vulnerability) if not isinstance(vulnerability, Vulnerability): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return vulnerability
def test_update_props_name_put(self): method = 'test_update_props_name_put' url = '/api/assets/name/%s/properties' % quote(self.new_asset.theName) self.logger.info('[%s] Old asset property environment name: %s', method, self.new_asset_props[0].theEnvironmentName) upd_asset_props = self.new_asset_props upd_asset_props[0].theEnvironmentName = 'Psychosis' upd_asset_props_dict = { 'session_id': 'test', 'object': upd_asset_props } upd_asset_props_body = jsonpickle.encode(upd_asset_props_dict) self.logger.info('[%s] JSON data: %s', method, upd_asset_props_body) rv = self.app.put(url, content_type='application/json', data=upd_asset_props_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') message = json_resp.get('message', None) self.assertIsNotNone(message, 'No message returned') rv = self.app.get('/api/assets/name/Test2/properties?session_id=test') self.logger.debug('[%s] Response data: %s', method, rv.data) asset_props = jsonpickle.decode(rv.data) self.logger.info('[%s] Asset property environment: %s\n', method, asset_props[0]['theEnvironmentName'])
def from_json(self, request, to_props=False): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] if to_props and isinstance(json_dict, list): props = self.convert_props(fake_props=json_dict) return props else: assert isinstance(json_dict, dict) check_required_keys(json_dict, AssetModel.required) json_dict['__python_obj__'] = Asset.__module__+'.'+Asset.__name__ env_props = json_dict.pop('theEnvironmentProperties', []) env_props = self.convert_props(fake_props=env_props) json_dict.pop('theEnvironmentDictionary', None) json_dict.pop('theAssetPropertyDictionary', None) asset = json_serialize(json_dict) asset = json_deserialize(asset) if isinstance(asset, Asset): asset.theEnvironmentProperties = env_props return asset else: self.close() raise MalformedJSONHTTPError()
def from_json(self, request): """ :rtype : Attacker :raise MalformedJSONHTTPError: """ json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, AttackerModel.required) json_dict[ '__python_obj__'] = Attacker.__module__ + '.' + Attacker.__name__ attacker_props = self.convert_props( fake_props=json_dict['theEnvironmentProperties']) json_dict['theEnvironmentProperties'] = [] attacker = json_serialize(json_dict) attacker = json_deserialize(attacker) attacker.theEnvironmentProperties = attacker_props if not isinstance(attacker, Attacker): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return attacker
def test_get_id(self): method = 'test_get_id' rv = self.app.get('/api/assets/id/127?session_id=test') asset = json_deserialize(rv.data) self.assertIsNotNone(asset, 'No results after deserialization') self.assertIsInstance(asset, Asset, 'The result is not an asset as expected') self.logger.info('[%s] Asset: %s [%d]\n', method, asset.theName, asset.theId)
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] assert isinstance(json_dict, dict) check_required_keys(json_dict, EnvironmentModel.required) json_dict['__python_obj__'] = Environment.__module__+'.'+Environment.__name__ if json_dict.has_key('theTensions'): assert isinstance(json_dict['theTensions'], list) tensions = json_dict['theTensions'] json_dict['theTensions'] = {} for tension in tensions: check_required_keys(tension, EnvironmentTensionModel.required) key = tuple([tension['base_attr_id'], tension['attr_id']]) value = tuple([tension['value'], tension['rationale']]) json_dict['theTensions'][key] = value new_json_environment = json_serialize(json_dict) environment = json_deserialize(new_json_environment) if not isinstance(environment, Environment): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return environment
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, RiskModel.required) json_dict['__python_obj__'] = Risk.__module__ + '.' + Risk.__name__ if json_dict['theMisuseCase']: mc_dict = json_dict['theMisuseCase'] check_required_keys(mc_dict, MisuseCaseModel.required) mc_dict[ '__python_obj__'] = MisuseCase.__module__ + '.' + MisuseCase.__name__ for idx in range(0, len(mc_dict['theEnvironmentProperties'])): mcep_dict = mc_dict['theEnvironmentProperties'][idx] check_required_keys( mcep_dict, MisuseCaseEnvironmentPropertiesModel.required) mcep_dict[ '__python_obj__'] = MisuseCaseEnvironmentProperties.__module__ + '.' + MisuseCaseEnvironmentProperties.__name__ mc_dict['theEnvironmentProperties'][idx] = mcep_dict json_dict['theMisuseCase'] = mc_dict risk = json_deserialize(json_dict) if isinstance(risk, Risk): return risk else: raise MalformedJSONHTTPError()
def from_json(self, request, to_props=False): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] if to_props and isinstance(json_dict, list): props = self.convert_props(fake_props=json_dict) return props else: assert isinstance(json_dict, dict) check_required_keys(json_dict, AssetModel.required) json_dict[ '__python_obj__'] = Asset.__module__ + '.' + Asset.__name__ env_props = json_dict.pop('theEnvironmentProperties', []) env_props = self.convert_props(fake_props=env_props) json_dict.pop('theEnvironmentDictionary', None) json_dict.pop('theAssetPropertyDictionary', None) asset = json_serialize(json_dict) asset = json_deserialize(asset) if isinstance(asset, Asset): asset.theEnvironmentProperties = env_props return asset else: self.close() raise MalformedJSONHTTPError()
def test_get_name(self): method = 'test_get_name' url = '/api/roles/name/%s?session_id=test' % quote(self.existing_role_name) rv = self.app.get(url) role = json_deserialize(rv.data) self.assertIsNotNone(role, 'No results after deserialization') self.assertIsInstance(role, Role, 'The result is not an role as expected') self.logger.info('[%s] Role: %s [%d]\n', method, role.theName, role.theId)
def test_get_name(self): method = 'test_get_name' url = '/api/assets/name/%s?session_id=test' % quote(self.existing_asset_name) rv = self.app.get(url) asset = json_deserialize(rv.data) self.assertIsNotNone(asset, 'No results after deserialization') self.assertIsInstance(asset, Asset, 'The result is not an asset as expected') self.logger.info('[%s] Asset: %s [%d]\n', method, asset.theName, asset.theId)
def test_get_id(self): method = 'test_get_id' rv = self.app.get('/api/assets/id/127?session_id=test') asset = json_deserialize(rv.data) self.assertIsNotNone(asset, 'No results after deserialization') self.assertIsInstance(asset, Asset, 'The result is not an asset as expected') self.logger.info('[%s] Asset: %s [%d]\n', method, asset.theName, asset.theId)
def test_get_all(self): method = 'test_get_all' rv = self.app.get('/api/roles?session_id=test') roles = json_deserialize(rv.data) self.assertIsNotNone(roles, 'No results after deserialization') self.assertIsInstance(roles, dict, 'The result is not a dictionary as expected') self.assertGreater(len(roles), 0, 'No roles in the dictionary') self.assertIsInstance(roles.values()[0], Role) self.logger.info('[%s] Roles found: %d', method, len(roles)) self.logger.info('[%s] First role: %s [%d]\n', method, roles.values()[0].theName, roles.values()[0].theId)
def from_json(self, request): json_dict = super(DependencyDAO, self).from_json(request) check_required_keys(json_dict, DependencyModel.required) json_dict[ '__python_obj__'] = Dependency.__module__ + '.' + Dependency.__name__ dependency = json_deserialize(json_dict) if isinstance(dependency, Dependency): return dependency else: self.close() raise MalformedJSONHTTPError(json_serialize(json_dict))
def test_get_name(self): method = 'test_get_name' url = '/api/assets/name/%s?session_id=test' % quote( self.existing_asset_name) rv = self.app.get(url) asset = json_deserialize(rv.data) self.assertIsNotNone(asset, 'No results after deserialization') self.assertIsInstance(asset, Asset, 'The result is not an asset as expected') self.logger.info('[%s] Asset: %s [%d]\n', method, asset.theName, asset.theId)
def test_get_name(self): method = 'test_get_name' url = '/api/roles/name/%s?session_id=test' % quote( self.existing_role_name) rv = self.app.get(url) role = json_deserialize(rv.data) self.assertIsNotNone(role, 'No results after deserialization') self.assertIsInstance(role, Role, 'The result is not an role as expected') self.logger.info('[%s] Role: %s [%d]\n', method, role.theName, role.theId)
def test_delete_name(self): method = 'test_delete_name' url = '/api/assets/name/{}?session_id=test'.format(quote(self.new_asset.theName)) rv = self.app.delete(url) url = '/api/assets/name/Test2?session_id=test'.format(quote(self.new_asset.theName)) rv = self.app.delete(url) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') message = json_resp.get('message', None) self.assertIsNotNone(message, 'No message returned') self.logger.info('[%s] Message: %s\n', method, message)
def test_put_name(self): method = 'test_put_name' url = '/api/roles/name/%s' % quote(self.new_role.theName) upd_role = self.new_role upd_role.theName = 'Test3' upd_role_dict = self.new_role_dict upd_role_dict['object'] = upd_role upd_role_body = jsonpickle.encode(upd_role_dict) self.logger.info('[%s] JSON data: %s', method, upd_role_body) rv = self.app.put(url, content_type='application/json', data=upd_role_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') message = json_resp.get('message', None) self.assertIsNotNone(message, 'No message returned') rv = self.app.get('/api/roles/name/Test3?session_id=test') role = json_deserialize(rv.data) self.logger.info('[%s] Role: %s [%d]\n', method, role.theName, role.theId)
def test_post(self): method = 'test_post_new' rv = self.app.post('/api/roles', content_type='application/json', data=self.new_role_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') role_id = json_resp.get('role_id', None) self.assertIsNotNone(role_id, 'No role ID returned') self.logger.info('[%s] Role ID: %d', method, role_id) rv = self.app.get('/api/roles/id/%d?session_id=test' % role_id) role = jsonpickle.decode(rv.data) self.logger.info('[%s] Role: %s [%d]\n', method, role['theName'], role['theId'])
def test_get_all(self): method = 'test_get_all' rv = self.app.get('/api/roles?session_id=test') roles = json_deserialize(rv.data) self.assertIsNotNone(roles, 'No results after deserialization') self.assertIsInstance(roles, dict, 'The result is not a dictionary as expected') self.assertGreater(len(roles), 0, 'No roles in the dictionary') self.assertIsInstance(roles.values()[0], Role) self.logger.info('[%s] Roles found: %d', method, len(roles)) self.logger.info('[%s] First role: %s [%d]\n', method, roles.values()[0].theName, roles.values()[0].theId)
def test_delete_name(self): method = 'test_delete_name' url = '/api/assets/name/{}?session_id=test'.format( quote(self.new_asset.theName)) rv = self.app.delete(url) url = '/api/assets/name/Test2?session_id=test'.format( quote(self.new_asset.theName)) rv = self.app.delete(url) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') message = json_resp.get('message', None) self.assertIsNotNone(message, 'No message returned') self.logger.info('[%s] Message: %s\n', method, message)
def test_put_name(self): method = 'test_put_name' url = '/api/assets/name/%s' % quote(self.new_asset.theName) upd_asset = self.new_asset upd_asset.theName = 'Test2' upd_asset_dict = self.new_asset_dict upd_asset_dict['object'] = upd_asset upd_asset_body = jsonpickle.encode(upd_asset_dict) self.logger.info('[%s] JSON data: %s', method, upd_asset_body) rv = self.app.put(url, content_type='application/json', data=upd_asset_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') message = json_resp.get('message', None) self.assertIsNotNone(message, 'No message returned') rv = self.app.get('/api/assets/name/Test2?session_id=test') asset = json_deserialize(rv.data) self.logger.info('[%s] Asset: %s [%d]\n', method, asset.theName, asset.theId)
def test_post(self): method = 'test_post_new' rv = self.app.post('/api/roles', content_type='application/json', data=self.new_role_body) self.logger.debug('[%s] Response data: %s', method, rv.data) json_resp = json_deserialize(rv.data) self.assertIsNotNone(json_resp, 'No results after deserialization') role_id = json_resp.get('role_id', None) self.assertIsNotNone(role_id, 'No role ID returned') self.logger.info('[%s] Role ID: %d', method, role_id) rv = self.app.get('/api/roles/id/%d?session_id=test' % role_id) role = jsonpickle.decode(rv.data) self.logger.info('[%s] Role: %s [%d]\n', method, role['theName'], role['theId'])
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, ProjectSettings.required) json_dict[ '__python_obj__'] = ProjectSettings.__module__ + '.' + ProjectSettings.__name__ contrs = json_dict['contributions'] or [] if not isinstance(contrs, list): contrs = [] for idx in range(0, len(contrs)): try: check_required_keys(contrs[idx], Contributor.required) json_dict['contributions'][idx] = (contrs[idx]['firstName'], contrs[idx]['surname'], contrs[idx]['affliation'], contrs[idx]['role']) except MissingParameterHTTPError: SilentHTTPError( 'A contribution did not contain all required fields. Skipping this one.' ) revisions = json_dict['revisions'] or [] if not isinstance(revisions, list): revisions = [] for idx in range(0, len(revisions)): try: check_required_keys(revisions[idx], Revision.required) json_dict['revisions'][idx] = (revisions[idx]['id'], revisions[idx]['date'], revisions[idx]['description']) except MissingParameterHTTPError: SilentHTTPError( 'A revision did not contain all required fields. Skipping this one.' ) json_dict['definitions'] = json_dict.get('definitions', None) or {} json_dict['definitions'] = json_dict['definitions'].items() settings = json_deserialize(json_dict) return settings
def type_from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, ValueTypeModel.required) json_dict['__python_obj__'] = ValueType.__module__+'.'+ValueType.__name__ value_type = json_serialize(json_dict) value_type = json_deserialize(value_type) if not isinstance(value_type, ValueType): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return value_type
def type_from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, ValueTypeModel.required) json_dict[ '__python_obj__'] = ValueType.__module__ + '.' + ValueType.__name__ value_type = json_serialize(json_dict) value_type = json_deserialize(value_type) if not isinstance(value_type, ValueType): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return value_type
def from_json(self, request): """ :rtype Role """ json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, RoleModel.required) json_dict['__python_obj__'] = Role.__module__+'.'+Role.__name__ role = json_serialize(json_dict) role = json_deserialize(role) if not isinstance(role, Role): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return role
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, ThreatModel.required) json_dict['__python_obj__'] = Threat.__module__+'.'+Threat.__name__ threat_props = self.convert_props(fake_props=json_dict['theEnvironmentProperties']) json_dict['theEnvironmentProperties'] = [] threat = json_serialize(json_dict) threat = json_deserialize(threat) threat.theEnvironmentProperties = threat_props if not isinstance(threat, Threat): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return threat
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, ThreatModel.required) json_dict['__python_obj__'] = Threat.__module__ + '.' + Threat.__name__ threat_props = self.convert_props( fake_props=json_dict['theEnvironmentProperties']) json_dict['theEnvironmentProperties'] = [] threat = json_serialize(json_dict) threat = json_deserialize(threat) threat.theEnvironmentProperties = threat_props if not isinstance(threat, Threat): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return threat
def from_json(self, request): self.logger.debug('Request data: %s', request.data) json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, GoalModel.required) json_dict['__python_obj__'] = Goal.__module__ + '.' + Goal.__name__ props_list = json_dict.pop('theEnvironmentProperties', []) json_dict.pop('theEnvironmentDictionary', None) real_props = self.convert_properties(fake_props=props_list) new_json_goal = json_serialize(json_dict) new_json_goal = json_deserialize(new_json_goal) new_json_goal.theEnvironmentProperties = real_props if not isinstance(new_json_goal, Goal): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return new_json_goal
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, VulnerabilityModel.required) json_dict['__python_obj__'] = Vulnerability.__module__+'.'+Vulnerability.__name__ for idx in range(0, len(json_dict['theEnvironmentProperties'])): property = json_dict['theEnvironmentProperties'][idx] check_required_keys(property, VulnerabilityEnvironmentPropertiesModel.required) property['__python_obj__'] = VulnerabilityEnvironmentProperties.__module__+'.'+VulnerabilityEnvironmentProperties.__name__ json_dict['theEnvironmentProperties'][idx] = property vulnerability = json_serialize(json_dict) vulnerability = json_deserialize(vulnerability) if not isinstance(vulnerability, Vulnerability): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return vulnerability
def from_json(self, request): self.logger.debug('Request data: %s', request.data) json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, GoalModel.required) json_dict['__python_obj__'] = Goal.__module__+'.'+Goal.__name__ props_list = json_dict.pop('theEnvironmentProperties', []) json_dict.pop('theEnvironmentDictionary', None) real_props = self.convert_properties(fake_props=props_list) new_json_goal = json_serialize(json_dict) new_json_goal = json_deserialize(new_json_goal) new_json_goal.theEnvironmentProperties = real_props if not isinstance(new_json_goal, Goal): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return new_json_goal
def from_json(self, request): json = request.get_json(silent=True) if json is False or json is None: self.close() raise MalformedJSONHTTPError(data=request.get_data()) json_dict = json['object'] check_required_keys(json_dict, ProjectSettings.required) json_dict['__python_obj__'] = ProjectSettings.__module__+'.'+ProjectSettings.__name__ contrs = json_dict['contributions'] or [] if not isinstance(contrs, list): contrs = [] for idx in range(0, len(contrs)): try: check_required_keys(contrs[idx], Contributor.required) json_dict['contributions'][idx] = (contrs[idx]['firstName'], contrs[idx]['surname'], contrs[idx]['affliation'], contrs[idx]['role']) except MissingParameterHTTPError: SilentHTTPError('A contribution did not contain all required fields. Skipping this one.') revisions = json_dict['revisions'] or [] if not isinstance(revisions, list): revisions = [] for idx in range(0, len(revisions)): try: check_required_keys(revisions[idx], Revision.required) json_dict['revisions'][idx] = (revisions[idx]['id'], revisions[idx]['date'], revisions[idx]['description']) except MissingParameterHTTPError: SilentHTTPError('A revision did not contain all required fields. Skipping this one.') json_dict['definitions'] = json_dict.get('definitions', None) or {} json_dict['definitions'] = json_dict['definitions'].items() settings = json_deserialize(json_dict) return settings