def post(self): session_id = get_session_id(session, request) if session_id is None: raise CairisHTTPError( status_code=httplib.BAD_REQUEST, message="The session is neither started or no session ID is provided with the request.", ) content_length = request.content_length max_length = 10 * 1024 * 1024 if content_length > max_length: raise MissingParameterHTTPError(exception=RuntimeError("File exceeded maximum size (10MB)")) try: file = request.files["file"] except LookupError as ex: raise MissingParameterHTTPError(param_names=["file"]) except Exception as ex: raise CairisHTTPError(status_code=httplib.CONFLICT, message=str(ex.message), status="Unknown error") dao = UploadDAO(session_id) filename = dao.upload_image(file) resp_dict = {"message": "File successfully uploaded", "filename": filename} resp = make_response(json_serialize(resp_dict, session_id=session_id), httplib.OK) resp.contenttype = "application/json" return resp
def post(self): session_id = get_session_id(session, request) content_length = request.content_length max_length = 30*1024*1024 if content_length > max_length: raise MissingParameterHTTPError(exception=RuntimeError('File exceeded maximum size (30MB)')) try: package = request.files['file'] except LookupError as ex: raise MissingParameterHTTPError(param_names=['file']) except Exception as ex: raise CairisHTTPError(status_code=CONFLICT, message=str(ex.message), status='Unknown error') try: dao = ImportDAO(session_id) dao.package_import(package.stream.read()) dao.close() except DatabaseProxyException as ex: raise ARMHTTPError(ex) except ARMException as ex: raise ARMHTTPError(ex) except Exception as ex: raise CairisHTTPError(status_code=500,message=str(ex.message),status='Unknown error') resp_dict = {'message': 'Package successfully imported'} resp = make_response(json_serialize(resp_dict, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) if session_id is None: raise CairisHTTPError( status_code=BAD_REQUEST, message='The session is neither started or no session ID is provided with the request.' ) content_length = request.content_length max_length = 10*1024*1024 if content_length > max_length: raise MissingParameterHTTPError(exception=RuntimeError('File exceeded maximum size (10MB)')) try: file = request.files['file'] except LookupError as ex: raise MissingParameterHTTPError(param_names=['file']) except Exception as ex: raise CairisHTTPError( status_code=CONFLICT, message=str(ex.message), status='Unknown error' ) dao = UploadDAO(session_id) dao.set_image(file.filename,file.stream.read(),file.mimetype) resp_dict = {'message': 'File successfully uploaded', 'filename': file.filename} resp = make_response(json_serialize(resp_dict, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def from_json(self, request): """ :rtype : UseCase :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, UseCaseModel.required) json_dict['__python_obj__'] = UseCase.__module__ + '.' + UseCase.__name__ usecase_props = self.convert_props(fake_props=json_dict['theEnvironmentProperties']) json_dict['theEnvironmentProperties'] = [] usecase = json_serialize(json_dict) usecase = json_deserialize(usecase) usecase.theEnvironmentProperties = usecase_props if not isinstance(usecase, UseCase): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: frcs = json_dict['theReferenceContributions'] refContribs = [] for frc in frcs: refContribs.append(ReferenceContribution(usecase.theName,frc['theContributionTo'],frc['theReferenceContribution']['theMeansEnd'],frc['theReferenceContribution']['theContribution'])) return usecase,refContribs
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, ResponseModel.required) json_dict['__python_obj__'] = Response.__module__+'.'+Response.__name__ property_dict = json_dict['theEnvironmentProperties'] try: real_props = self.convert_props(fake_props=property_dict, response_type=json_dict['theResponseType']) json_dict['theEnvironmentProperties'] = real_props json_resp = json_serialize(json_dict) response = json_deserialize(json_resp) if isinstance(response, Response): return response else: raise MalformedJSONHTTPError() except MalformedJSONHTTPError as ex: self.close() raise ex
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): """ :rtype : Countermeasure :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, CountermeasureModel.required) json_dict['__python_obj__'] = Countermeasure.__module__ + '.' + Countermeasure.__name__ countermeasure_props = self.convert_props(fake_props=json_dict['theEnvironmentProperties']) json_dict['theEnvironmentProperties'] = [] countermeasure = json_serialize(json_dict) countermeasure = json_deserialize(countermeasure) countermeasure.theEnvironmentProperties = countermeasure_props if not isinstance(countermeasure, Countermeasure): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return countermeasure
def get(self, task,environment): session_id = get_session_id(session, request) dao = TaskDAO(session_id) taskLoad = dao.task_load_by_name_environment(task,environment) dao.close() resp = make_response(json_serialize(taskLoad, session_id=session_id), OK) return resp
def from_json(self, request): """ :rtype : Task :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, TaskModel.required) json_dict['__python_obj__'] = Task.__module__ + '.' + Task.__name__ task_props = self.convert_props(fake_props=json_dict['theEnvironmentProperties']) json_dict['theEnvironmentProperties'] = [] task = json_serialize(json_dict) task = json_deserialize(task) task.theEnvironmentProperties = task_props if not isinstance(task, Task): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return task
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 get(self, task,environment): session_id = get_session_id(session, request) dao = TaskDAO(session_id) cmLoad = dao.task_hindrance_by_name_environment(task,environment) dao.close() resp = make_response(json_serialize(cmLoad, session_id=session_id), httplib.OK) return resp
def get(self, environment): session_id = get_session_id(session, request) dao = RiskDAO(session_id) element_names = dao.risk_model_elements(environment) resp = make_response(json_serialize(element_names, session_id=session_id), httplib.OK) resp.contenttype = 'application/json' return resp
def get(self, task,environment): session_id = get_session_id(session, request) dao = TaskDAO(session_id) taskScore = dao.task_score_by_name_environment(task,environment) dao.close() resp = make_response(json_serialize(taskScore, session_id=session_id), httplib.OK) return resp
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 : Persona :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, PersonaModel.required) json_dict['__python_obj__'] = Persona.__module__ + '.' + Persona.__name__ persona_props = self.convert_props(fake_props=json_dict['theEnvironmentProperties']) json_dict['theEnvironmentProperties'] = [] persona = json_serialize(json_dict) persona = json_deserialize(persona) persona.theEnvironmentProperties = persona_props if not isinstance(persona, Persona): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: return persona
def from_json(self, request,domain_name=None): 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, RequirementModel.required) json_dict['__python_obj__'] = Requirement.__module__+'.'+Requirement.__name__ json_dict['attrs'] = {} json_dict['dirtyAttrs'] = {} json_dict['theVersion'] = -1 json_dict['attrs']['originator'] = json_dict['theOriginator'] json_dict['attrs']['supportingMaterial'] = '' json_dict['attrs']['fitCriterion'] = json_dict['theFitCriterion'] if (domain_name != None): json_dict['attrs']['asset'] = domain_name else: json_dict['attrs']['asset'] = json_dict['theDomain'] json_dict['attrs']['rationale'] = json_dict['theRationale'] json_dict['attrs']['type'] = json_dict['theType'] requirement = json_serialize(json_dict) requirement = json_deserialize(requirement) if not isinstance(requirement, Requirement): self.close() raise MalformedJSONHTTPError(data=request.get_data()) else: requirement.theAsset = json_dict['attrs']['asset'] return requirement
def get(self, name): session_id = get_session_id(session, request) dao = RoleDAO(session_id) found_role = dao.get_role_by_name(name) dao.close() resp = make_response(json_serialize(found_role, session_id=session_id)) resp.headers['Content-Type'] = "application/json" return resp
def get(self): session_id = get_session_id(session, request) dao = PersonaCharacteristicDAO(session_id) objts = dao.get_persona_characteristics_summary() dao.close() resp = make_response(json_serialize(objts, session_id=session_id)) resp.headers['Content-Type'] = "application/json" return resp
def get(self, name): session_id = get_session_id(session, request) dao = RoleDAO(session_id) props = dao.get_role_props(name) dao.close() resp = make_response(json_serialize(props, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def get(self): session_id = get_session_id(session, request) dao = TrustBoundaryDAO(session_id) tbs = dao.get_trust_boundaries() dao.close() resp = make_response(json_serialize(tbs, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def get(self, name): session_id = get_session_id(session, request) dao = CountermeasureDAO(session_id) spNames = dao.countermeasure_patterns(name) dao.close() resp = make_response(json_serialize(spNames, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def get(self): session_id = get_session_id(session, request) dao = ProjectDAO(session_id) dbs = dao.show_databases() dao.close() resp = make_response(json_serialize(dbs, session_id=session_id), OK) resp.headers['Content-type'] = 'application/json' return resp
def get(self,environment_name,head_name,tail_name): session_id = get_session_id(session, request) dao = AssetAssociationDAO(session_id) assoc = dao.get_asset_association(environment_name,head_name,tail_name) dao.close() resp = make_response(json_serialize(assoc, session_id=session_id)) resp.headers['Content-Type'] = "application/json" return resp
def get(self, persona_name): session_id = get_session_id(session, request) dao = PersonaDAO(session_id) persona_props = dao.get_persona_props(name=persona_name) dao.close() resp = make_response(json_serialize(asset_props, session_id=session_id)) resp.contenttype = 'application/json' return resp
def get(self): session_id = get_session_id(session, request) dao = PersonaDAO(session_id) pTypes = dao.get_persona_types() dao.close() resp = make_response(json_serialize(pTypes, session_id=session_id), httplib.OK) resp.contenttype = 'application/json' return resp
def get(self,name): session_id = get_session_id(session, request) dao = ArchitecturalPatternDAO(session_id) ap = dao.get_architectural_pattern(name) dao.close() resp = make_response(json_serialize(ap, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def get(self,architectural_pattern_name,environment_name): session_id = get_session_id(session, request) dao = ArchitecturalPatternDAO(session_id) cwm = dao.get_weakness_analysis(architectural_pattern_name,environment_name) dao.close() resp = make_response(json_serialize(cwm, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def get(self,environment_name): session_id = get_session_id(session, request) dao = ThreatDAO(session_id) model = dao.get_threat_model(environment_name) dao.close() resp = make_response(json_serialize(model, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def get(self): session_id = get_session_id(session, request) dao = ExportDAO(session_id) modelBuf = dao.file_export() dao.close() resp = make_response(json_serialize(modelBuf, session_id=session_id), httplib.OK) resp.headers['Content-Type'] = 'application/json' return resp
def get(self): session_id = get_session_id(session, request) dao = ThreatDAO(session_id) objts = dao.get_threats_summary() dao.close() resp = make_response(json_serialize(objts, session_id=session_id)) resp.headers['Content-Type'] = "application/json" return resp
def get(self, name): session_id = get_session_id(session, request) environment_name = request.args.get('environment', '') dao = ThreatDAO(session_id) threat_type = dao.get_threat_type_by_name( name=name, environment_name=environment_name) dao.close() resp = make_response( json_serialize(threat_type, session_id=session_id), httplib.OK) resp.headers['Content-type'] = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) environment_name = request.args.get('environment', '') dao = AssetDAO(session_id) new_value_type = dao.type_from_json(request) dao.add_asset_type(new_value_type, environment_name=environment_name) dao.close() resp_dict = {'message': 'Asset type successfully added'} resp = make_response(json_serialize(resp_dict), OK) resp.contenttype = 'application/json' return resp
def delete(self, name, security_pattern_name): session_id = get_session_id(session, request) dao = CountermeasureDAO(session_id) dao.remove_situated_pattern(name, security_pattern_name) dao.close() resp_dict = { 'message': 'Situated pattern ' + security_pattern_name + ' removed' } resp = make_response(json_serialize(resp_dict), OK) resp.headers['Content-type'] = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = ConceptReferenceDAO(session_id) new_cr = dao.from_json(request) dao.add_concept_reference(new_cr) dao.close() resp_dict = {'message': 'Concept Reference successfully added'} resp = make_response(json_serialize(resp_dict, session_id=session_id), httplib.OK) resp.contenttype = 'application/json' return resp
def get(self, threat, vulnerability): session_id = get_session_id(session, request) dao = RiskDAO(session_id) template_misuse_case = dao.get_misuse_case_by_threat_vulnerability( threat, vulnerability) dao.close() resp = make_response( json_serialize(template_misuse_case, session_id=session_id), httplib.OK) resp.headers['Content-type'] = 'application/json' return resp
def get(self, persona, variable, characteristic): session_id = get_session_id(session, request) model_generator = get_model_generator() dao = PersonaDAO(session_id) if variable == 'All': variable = '' if characteristic == 'All': characteristic = '' char_names = dao.get_persona_characteristics(persona, variable, characteristic) dao.close() resp = make_response(json_serialize(char_names, session_id=session_id), httplib.OK) resp.headers['Content-type'] = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = EnvironmentDAO(session_id) new_environment = dao.from_json(request) new_environment_id = dao.add_environment(new_environment) dao.close() resp_dict = { 'message': 'Environment successfully added', 'environment_id': new_environment_id } resp = make_response(json_serialize(resp_dict), OK) resp.headers['Content-type'] = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) asset_name = request.args.get('asset', None) environment_name = request.args.get('environment', None) dao = RequirementDAO(session_id) new_req = dao.from_json(request) req_id = dao.add_requirement(new_req, asset_name=asset_name, environment_name=environment_name) dao.close() resp_dict = {'message': 'Requirement successfully added', 'requirement_id': req_id} resp = make_response(json_serialize(resp_dict), httplib.OK) resp.contenttype = 'application/json' return resp
def put(self, name): session_id = get_session_id(session, request) dao = PersonaCharacteristicDAO(session_id) upd_pc, ps, rss, rcs = dao.from_json(request) dao.update_persona_characteristic(upd_pc, name) if (ps != None): dao.assignIntentionalElements(ps, rss, rcs) dao.close() resp_dict = {'message': 'Persona Characteristic successfully updated'} resp = make_response(json_serialize(resp_dict), OK) resp.contenttype = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = UseCaseDAO(session_id) new_usecase,ucContribs = dao.from_json(request) usecase_id = dao.add_usecase(new_usecase) for rc in ucContribs: dao.assign_usecase_contribution(rc) dao.close() resp_dict = {'message': 'UseCase successfully added', 'usecase_id': usecase_id} resp = make_response(json_serialize(resp_dict), OK) resp.contenttype = 'application/json' return resp
def put(self, p1, p2, p3, p4, p5, p6): session_id = get_session_id(session, request) dao = self.DAOModule(session_id) pathValues = [] for parameterName, defaultValue in self.thePathParameters: pathValues.append(request.args.get(parameterName, defaultValue)) objt = dao.from_json(request) getattr(dao, self.thePutMethod)(objt, p1, p2, p3, p4, p5, p6, pathValues) resp_dict = {'message': objt.name() + ' updated'} resp = make_response(json_serialize(resp_dict, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def delete(self, p1, p2, p3, p4, p5, p6): session_id = get_session_id(session, request) dao = self.DAOModule(session_id) pathValues = [] for parameterName, defaultValue in self.thePathParameters: pathValues.append(request.args.get(parameterName, defaultValue)) getattr(dao, self.theDelMethod)(p1, p2, p3, p4, p5, p6, pathValues) resp_dict = { 'message': p1 + ' / ' + p2 + ' / ' + p4 + ' / ' + p6 + ' deleted' } resp = make_response(json_serialize(resp_dict, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def delete(self, parameter_string): session_id = get_session_id(session, request) dao = self.DAOModule(session_id) pathValues = [] for parameterName, defaultValue in self.thePathParameters: pathValues.append(request.args.get(parameterName, defaultValue)) delMsg = getattr(dao, self.theDelMethod)(parameter_string, pathValues) resp_dict = {'message': parameter_string + ' deleted'} if (delMsg != None): resp_dict = {'message': delMsg} resp = make_response(json_serialize(resp_dict, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def put(self, p1, p2): session_id = get_session_id(session, request) dao = self.DAOModule(session_id) objt = dao.from_json(request) dao.update_object(objt, p1, p2) dao.close() resp_dict = {} if (isinstance(objt, dict)): resp_dict = {'message': objt['theName'] + ' updated'} else: resp_dict = {'message': objt.name() + ' updated'} resp = make_response(json_serialize(resp_dict), OK) resp.headers['Content-type'] = 'application/json' return resp
def get(self): session_id = get_session_id(session, request) ordered = request.args.get('ordered', 0) constraint_id = request.args.get('constraint_id', '') dao = RequirementDAO(session_id) reqs = dao.get_requirements(constraint_id=constraint_id, ordered=(ordered == '1')) dao.close() resp = make_response(json_serialize(reqs, session_id=session_id), OK) resp.headers['Content-type'] = 'application/json' resp.headers['Access-Control-Allow-Origin'] = "*" return resp
def post(self, p1, p2): session_id = get_session_id(session, request) dao = self.DAOModule(session_id) pathValues = [] for parameterName, defaultValue in self.thePathParameters: pathValues.append(request.args.get(parameterName, defaultValue)) postMsg = getattr(dao, self.thePostMethod)(p1, p2, pathValues) resp_dict = {'message': self.thePostMessage} if (postMsg != None): resp_dict = {'message': postMsg} resp = make_response(json_serialize(resp_dict, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def get(self, name): session_id = get_session_id(session, request) environment_name = request.args.get('environment', '') dao = AttackerDAO(session_id) attacker_motivation = dao.get_attacker_motivation_by_name( name=name, environment_name=environment_name) dao.close() resp = make_response( json_serialize(attacker_motivation, session_id=session_id), httplib.OK) resp.headers['Content-type'] = 'application/json' return resp
def put(self, name, environment_name): session_id = get_session_id(session, request) dao = AssetDAO(session_id) asset_value = dao.type_from_json(request) dao.update_asset_value(asset_value, name=name, environment_name=environment_name) dao.close() resp_dict = {'message': 'Asset type successfully updated'} resp = make_response(json_serialize(resp_dict), OK) resp.headers['Content-type'] = 'application/json' return resp
def put(self, asset_name): session_id = get_session_id(session, request) dao = AssetDAO(session_id) asset_prop = dao.from_json(request, to_props=True) dao.update_asset_properties(asset_prop, name=asset_name) dao.close() resp_dict = { 'message': 'The asset properties were successfully updated.' } resp = make_response(json_serialize(resp_dict), OK) resp.contenttype = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = PersonaCharacteristicDAO(session_id) new_pc, ps, rss, rcs = dao.from_json(request) dao.add_persona_characteristic(new_pc) if (ps != None): dao.assignIntentionalElements(ps, rss, rcs) dao.close() resp_dict = {'message': new_pc.characteristic() + ' created'} resp = make_response(json_serialize(resp_dict, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def get(self, environment, depender, dependee, dependency): session_id = get_session_id(session, request) dao = DependencyDAO(session_id) found_dependency = dao.get_dependency(environment=environment, depender=depender, dependee=dependee, dependency=dependency) dao.close() resp = make_response( json_serialize(found_dependency, session_id=session_id), httplib.OK) resp.headers['Content-type'] = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = VulnerabilityDAO(session_id) new_vuln = dao.from_json(request) vuln_id = dao.add_vulnerability(new_vuln) dao.close() resp_dict = { 'message': 'Vulnerability successfully added', 'vulnerability_id': vuln_id } resp = make_response(json_serialize(resp_dict), httplib.OK) resp.contenttype = 'application/json' return resp
def post(self, db_name, user_id, permission): session_id = get_session_id(session, request) dao = PermissionsDAO(session_id) dao.set_permission(db_name, user_id, permission) dao.close() msg = 'Permission successfully ' if (permission == 'grant'): msg += 'granted' else: msg += 'revoked' resp_dict = {'message': msg} resp = make_response(json_serialize(resp_dict, session_id=session_id), OK) resp.contenttype = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = CountermeasureDAO(session_id) new_countermeasure = dao.from_json(request) countermeasure_id = dao.add_countermeasure(new_countermeasure) dao.close() resp_dict = { 'message': 'Countermeasure successfully added', 'countermeasure_id': countermeasure_id } resp = make_response(json_serialize(resp_dict), OK) resp.contenttype = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = PersonaDAO(session_id) new_persona = dao.from_json(request) persona_id = dao.add_persona(new_persona) dao.close() resp_dict = { 'message': 'Persona successfully added', 'persona_id': persona_id } resp = make_response(json_serialize(resp_dict), httplib.OK) resp.contenttype = 'application/json' return resp
def post(self, environment, depender, dependee, dependency): session_id = get_session_id(session, request) dao = DependencyDAO(session_id) new_dependency = dao.from_json(request) new_dependency_id = dao.add_dependency(new_dependency) dao.close() resp_dict = { 'message': 'Dependency successfully added', 'dependency_id': new_dependency_id } resp = make_response(json_serialize(resp_dict), httplib.OK) resp.headers['Content-type'] = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = AttackerDAO(session_id) new_attacker = dao.from_json(request) attacker_id = dao.add_attacker(new_attacker) dao.close() resp_dict = { 'message': 'Attacker successfully added', 'attacker_id': attacker_id } resp = make_response(json_serialize(resp_dict), httplib.OK) resp.contenttype = 'application/json' return resp
def put(self, name): session_id = get_session_id(session, request) environment_name = request.args.get('environment', '') dao = VulnerabilityDAO(session_id) vulnerability_type = dao.type_from_json(request) dao.update_vulnerability_type(vulnerability_type, name=name, environment_name=environment_name) dao.close() resp_dict = {'message': 'Vulnerability type successfully updated'} resp = make_response(json_serialize(resp_dict), httplib.OK) resp.headers['Content-type'] = 'application/json' return resp
def post(self): session_id = get_session_id(session, request) dao = ThreatDAO(session_id) new_threat = dao.from_json(request) threat_id = dao.add_threat(new_threat) dao.close() resp_dict = { 'message': 'Threat successfully added', 'threat_id': threat_id } resp = make_response(json_serialize(resp_dict), OK) resp.contenttype = 'application/json' return resp
def put(self, name): session_id = get_session_id(session, request) environment_name = request.args.get('environment', '') dao = AttackerDAO(session_id) attacker_motivation = dao.type_from_json(request) dao.update_attacker_motivation(attacker_motivation, name=name, environment_name=environment_name) dao.close() resp_dict = {'message': 'Attacker motivation successfully updated'} resp = make_response(json_serialize(resp_dict), httplib.OK) resp.headers['Content-type'] = 'application/json' return resp