def from_json(cls, json: MutableMapping[str, Any]) \ -> 'ScanIssueReturnedGetNone': with JsonParser(json): assert json.pop('messageType', None) == 'scanIssue' req_res = tuple(cls.__pop_requests_responses(json)) remed_back = ensure((str, type(None)), json.pop('remediationBackground', None)) remed_detail = ensure((str, type(None)), json.pop('remediationDetail', None)) issue_detail = ensure((str, type(None)), json.pop('issueDetail', None)) return ScanIssueReturnedGetNone( protocol=ensure(str, json.pop('protocol')), host=ensure(str, json.pop('host')), port=ensure(int, json.pop('port')), severity=IssueSeverity(json.pop('severity')), confidence=IssueConfidence(json.pop('confidence')), url=ensure(str, json.pop('url')), name=ensure(str, json.pop('name')), requests_responses=req_res, remediation_background=remed_back, remediation_detail=remed_detail, issue_background=ensure(str, json.pop('issueBackground')), issue_detail=issue_detail, in_scope=ensure(bool, json.pop('inScope')), issue_type=IssueType(json.pop('issueType')), )
def _common_returned(json: MutableMapping[str, Any]) -> Dict[str, Any]: return dict( port=ensure(int, json.pop('port')), raw=b64decode(json.pop('raw').encode()), in_scope=ensure(bool, json.pop('inScope')), tool_flag=ensure(int, json.pop('toolFlag')), reference_id=ensure(int, json.pop('referenceID')), )
def _common_returned(json: MutableMapping[str, Any]) -> Dict[str, Any]: return dict( port=ensure(int, json.pop('port')), raw=b64decode(json.pop('raw').encode()), in_scope=ensure(bool, json.pop('inScope')), tool_flag=ensure(int, json.pop('toolFlag')), reference_id=ensure(int, json.pop('referenceID')), )
def from_json(cls, json: MutableMapping[str, Any]) -> 'RequestReturned': with JsonParser(json): json.pop('messageType') json.pop('query', None) # TODO sometimes it's there json.pop('comment', None) # TODO sometimes it's there return RequestReturned( http_version=parse_http_version(json.pop('httpVersion')), headers=tuple( (ensure(str, k), ensure(str, v)) for k, v in pop_all(json.pop('headers')).items()), body=b64decode(json.pop('body').encode()), **dict( chain( _common_returned(json).items(), pop_all(ensure_values(str, json)).items(), )))
def from_json(cls, json: MutableMapping[str, Any]) -> 'RequestReturned': with JsonParser(json): json.pop('messageType') json.pop('query', None) # TODO sometimes it's there json.pop('comment', None) # TODO sometimes it's there return RequestReturned( http_version=parse_http_version(json.pop('httpVersion')), headers=tuple( (ensure(str, k), ensure(str, v)) for k, v in pop_all(json.pop('headers')).items() ), body=b64decode(json.pop('body').encode()), **dict(chain( _common_returned(json).items(), pop_all(ensure_values(str, json)).items(), )) )
def from_json(cls, json: MutableMapping[str, Any]) \ -> 'RequestReturnedGetNone': with JsonParser(json): assert json.pop('messageType', None) == 'request' return RequestReturnedGetNone( in_scope=ensure(bool, json.pop('inScope')), http_version=parse_http_version(json.pop('httpVersion')), body=b64decode(json.pop('body').encode()), tool_flag=ensure(int, json.pop('toolFlag')), url=ensure(str, json.pop('url')), method=ensure(str, json.pop('method')), protocol=ensure(str, json.pop('protocol')), path=ensure(str, json.pop('path')), headers=tuple(cls.__pop_headers(json)), port=ensure(int, json.pop('port')), host=ensure(str, json.pop('host')), raw=b64decode(json.pop('raw').encode()), reference_id=ensure(int, json.pop('referenceID')), query=ensure((str, type(None)), json.pop('query', None)), )
def from_json(cls, json: MutableMapping[str, Any]) -> 'Cookie': with JsonParser(json): expiration_raw = json.pop('expiration', None) expiration = None if expiration_raw is not None: expiration = datetime.strptime(expiration_raw, cls.__date_format) return Cookie(expiration=expiration, domain=ensure((str, type(None)), json.pop('domain', None)), **pop_all(ensure_values(str, json)))
def from_json(cls, json: MutableMapping[str, Any]) -> 'Scan': with JsonParser(json): return Scan( status=ensure(str, json.pop('status')), # TODO how to parse? issues=tuple(json.pop('issues')) and tuple(), **pop_all(translate_keys(ensure_values(int, json), { 'insertionPointCount': 'insertion_point_count', 'requestCount': 'request_count', 'percentComplete': 'percent_complete', })) )
def from_json(cls, json: MutableMapping[str, Any]) -> 'Cookie': with JsonParser(json): expiration_raw = json.pop('expiration', None) expiration = None if expiration_raw is not None: expiration = datetime.strptime(expiration_raw, cls.__date_format) return Cookie( expiration=expiration, domain=ensure((str, type(None)), json.pop('domain', None)), **pop_all(ensure_values(str, json)) )
def from_json(cls, json: MutableMapping[str, Any]) \ -> 'ResponseReturnedGetNone': with JsonParser(json): assert json.pop('messageType', None) == 'response' return ResponseReturnedGetNone( in_scope=ensure(bool, json.pop('inScope')), protocol=ensure(str, json.pop('protocol')), port=ensure(int, json.pop('port')), raw=b64decode(json.pop('raw').encode()), body=b64decode(json.pop('body').encode()), headers=tuple(cls.__pop_headers(json)), cookies=tuple(cls.__pop_cookies(json)), mime_type=ensure(str, json.pop('mimeType')), host=ensure(str, json.pop('host')), tool_flag=ensure(int, json.pop('toolFlag')), status_code=ensure(int, json.pop('statusCode')), reference_id=ensure(int, json.pop('referenceID')), )
def __pop_headers(cls, json: MutableMapping[str, Any]) \ -> Generator[Tuple[str, str], None, None]: yield from ((ensure(str, k), ensure(str, v)) for k, v in pop_all(json.pop('headers')).items())
def from_json(cls, json: MutableMapping[str, Any]) -> 'ResponseReturned': with JsonParser(json): return ResponseReturned( status_code=ensure(int, json.pop('statusCode')), **dict(_common_returned(json).items()) )
def from_json(cls, json: MutableMapping[str, Any]) -> 'ResponseReturned': with JsonParser(json): return ResponseReturned(status_code=ensure(int, json.pop('statusCode')), **dict(_common_returned(json).items()))