Client sends get request for advisory information from OpenVuln API. :var auth_token: OAuth2 Token for API authorization. :var headers: Headers containing OAuth2 Token and data type for request.
| 61 | super(PlatformAlias, self).__init__(PLATFORMALIAS, *args) |
| 62 | |
| 63 | class OpenVulnQueryClient(object): |
| 64 | """Client sends get request for advisory information from OpenVuln API. |
| 65 | |
| 66 | :var auth_token: OAuth2 Token for API authorization. |
| 67 | :var headers: Headers containing OAuth2 Token and data type for |
| 68 | request. |
| 69 | """ |
| 70 | |
| 71 | def __init__(self, client_id, client_secret, auth_url=None, |
| 72 | user_agent='TestApp'): |
| 73 | """ |
| 74 | :param client_id: Client application Id as retrieved from API provider |
| 75 | :param client_secret: Client secret as retrieved from API provider |
| 76 | :param auth_url: POST URL to request auth token response (default |
| 77 | from config) |
| 78 | :param user_agent: Communicates the name of the app per request. |
| 79 | |
| 80 | """ |
| 81 | logging.basicConfig(level=logging.WARNING) |
| 82 | self.logger = logging.getLogger(__name__) |
| 83 | self.auth_url = auth_url if auth_url else config.REQUEST_TOKEN_URL |
| 84 | self.auth_token = authorization.get_oauth_token( |
| 85 | client_id, client_secret, request_token_url=self.auth_url) |
| 86 | self.headers = rest_api.rest_with_auth_headers( |
| 87 | self.auth_token, user_agent) |
| 88 | |
| 89 | def get_by_all(self, adv_format, all_adv, a_filter=None): |
| 90 | """Return all the advisories using requested advisory format""" |
| 91 | req_cfg = { |
| 92 | 'filter': a_filter.path, |
| 93 | } |
| 94 | req_path = "all/{filter}".format(**req_cfg) |
| 95 | advisories = self.get_request(req_path, a_filter.params) |
| 96 | return self.advisory_list(advisories['advisories'], adv_format) |
| 97 | |
| 98 | def get_by_cve(self, adv_format, cve_id, a_filter=None): |
| 99 | """Return the advisory using requested cve id""" |
| 100 | req_cfg = { |
| 101 | 'cve_id': cve_id, |
| 102 | } |
| 103 | req_path = "cve/{cve_id}".format(**req_cfg) |
| 104 | advisories = self.get_request(req_path) |
| 105 | return self.advisory_list(advisories['advisories'], adv_format) |
| 106 | |
| 107 | def get_by_bugid(self, adv_format, bug_id, a_filter=None): |
| 108 | """Return the advisory using requested cve id""" |
| 109 | req_cfg = { |
| 110 | 'bug_id': bug_id, |
| 111 | } |
| 112 | req_path = "bugid/{bug_id}".format(**req_cfg) |
| 113 | advisories = self.get_request(req_path) |
| 114 | return self.advisory_list(advisories['advisories'], adv_format) |
| 115 | |
| 116 | def get_by_advisory(self, adv_format, an_advisory, a_filter=None): |
| 117 | """Return the advisory using requested advisory id""" |
| 118 | req_cfg = { |
| 119 | 'advisory': an_advisory, |
| 120 | } |
nothing calls this directly
no outgoing calls
no test coverage detected