-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from release-engineering/update-dependencies
Update dependencies
- Loading branch information
Showing
6 changed files
with
118 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
# This is a list of pypi packages to be installed into virtualenv. Alternatively, | ||
# you can install these as RPMs instead of pypi packages. See the dependecies | ||
# with: | ||
# $ rpmspec -q --requires resultsdb.spec | ||
# $ rpmspec -q --buildrequires resultsdb.spec | ||
|
||
# A note for maintainers: Please keep this list in sync and in the same order | ||
# as the spec file. | ||
|
||
Flask >= 0.10.1 | ||
iso8601 >= 0.1.11 | ||
resultsdb_api >= 2.0 | ||
six >= 1.10.0 | ||
Flask >= 2.2.5 | ||
cachelib | ||
iso8601 >= 0.1.11 | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import logging | ||
from json import dumps | ||
|
||
import requests | ||
from flask import current_app, has_app_context | ||
from requests.adapters import HTTPAdapter | ||
from requests.exceptions import ConnectionError, ConnectTimeout, RetryError | ||
from urllib3.exceptions import ProxyError, SSLError | ||
from urllib3.util.retry import Retry | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class ErrorResponse(requests.Response): | ||
def __init__(self, status_code, error_message, url): | ||
super().__init__() | ||
self.status_code = status_code | ||
self._error_message = error_message | ||
self.url = url | ||
self.reason = error_message.encode() | ||
|
||
@property | ||
def content(self): | ||
return dumps({"message": self._error_message}).encode() | ||
|
||
|
||
class RequestsSession(requests.Session): | ||
def request(self, *args, **kwargs): # pylint:disable=arguments-differ | ||
log.debug("Request: args=%r, kwargs=%r", args, kwargs) | ||
|
||
req_url = kwargs.get("url", args[1]) | ||
|
||
kwargs.setdefault("headers", {"Content-Type": "application/json"}) | ||
if has_app_context(): | ||
kwargs.setdefault("timeout", current_app.config["REQUESTS_TIMEOUT"]) | ||
|
||
try: | ||
ret_val = super().request(*args, **kwargs) | ||
except (ConnectTimeout, RetryError) as e: | ||
ret_val = ErrorResponse(504, str(e), req_url) | ||
except (ConnectionError, ProxyError, SSLError) as e: | ||
ret_val = ErrorResponse(502, str(e), req_url) | ||
|
||
log.debug("Request finished: %r", ret_val) | ||
return ret_val | ||
|
||
|
||
def get_requests_session(): | ||
"""Get http(s) session for request processing.""" | ||
|
||
session = RequestsSession() | ||
retry = Retry( | ||
total=3, | ||
read=3, | ||
connect=3, | ||
backoff_factor=1, | ||
status_forcelist=(500, 502, 503, 504), | ||
) | ||
adapter = HTTPAdapter(max_retries=retry) | ||
session.mount("http://", adapter) | ||
session.mount("https://", adapter) | ||
session.headers["User-Agent"] = "resultsdb_frontend" | ||
return session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from resultsdb_frontend.requests_session import get_requests_session | ||
|
||
|
||
def _prepare_params(**kwargs): | ||
return { | ||
key: ",".join(str(v) for v in value) if isinstance(value, list) else str(value) | ||
for key, value in kwargs.items() | ||
if value is not None | ||
} | ||
|
||
|
||
class ResultsDBapi: | ||
def __init__(self, api_url): | ||
self.url = api_url.rstrip("/") | ||
self.session = get_requests_session() | ||
|
||
def _get(self, api, **kwargs): | ||
r = self.session.get(f"{self.url}{api}", **kwargs) | ||
r.raise_for_status() | ||
return r.json() | ||
|
||
def get_group(self, uuid): | ||
return self._get(f"/groups/{uuid}") | ||
|
||
def get_groups(self, **kwargs): | ||
return self._get("/groups", params=_prepare_params(**kwargs)) | ||
|
||
def get_result(self, id): | ||
return self._get(f"/results/{id}") | ||
|
||
def get_results(self, **kwargs): | ||
return self._get("/results", params=_prepare_params(**kwargs)) | ||
|
||
def get_testcase(self, name): | ||
return self._get(f"/testcases/{name}") | ||
|
||
def get_testcases(self, **kwargs): | ||
return self._get("/testcases", params=_prepare_params(**kwargs)) |