| |
@@ -36,10 +36,10 @@
|
| |
from oraculum import app, CACHE, db
|
| |
from oraculum.models.dashboard_users import DashboardUserData
|
| |
|
| |
-
|
| |
- def get_json(json_url, attempt_retry=True, log_errors=True, ignore_json_errors=False):
|
| |
+ def get_resource(url, attempt_retry=True, log_errors=True):
|
| |
"""
|
| |
- Returns json data from provided url
|
| |
+ Returns data from provided url
|
| |
+ Returns None on error
|
| |
"""
|
| |
session = requests.Session()
|
| |
|
| |
@@ -51,35 +51,51 @@
|
| |
else:
|
| |
session.mount('https://', HTTPAdapter())
|
| |
try:
|
| |
- resp = session.get(json_url, timeout=60)
|
| |
+ resp = session.get(url, timeout=60)
|
| |
except (ConnectionError, RetryError):
|
| |
- # Return none if retrying failed too
|
| |
if log_errors:
|
| |
- app.logger.error("Request to %s failed." % json_url)
|
| |
- return None
|
| |
- if not attempt_retry:
|
| |
- try:
|
| |
- return json.loads(resp.text)
|
| |
- except JSONDecodeError:
|
| |
- if ignore_json_errors:
|
| |
- return resp.text
|
| |
- if log_errors:
|
| |
- app.logger.error("Request to %s failed because resource returned invalid data." % json_url)
|
| |
+ app.logger.error("Request to %s failed." % url)
|
| |
+ if not attempt_retry:
|
| |
return None
|
| |
+ else:
|
| |
+ get_resource(url, attempt_retry=False, log_errors=log_errors)
|
| |
+
|
| |
+ return resp.text
|
| |
+
|
| |
+
|
| |
+ def get_json(json_url, attempt_retry=True, log_errors=True):
|
| |
+ """
|
| |
+ Returns json data from provided url
|
| |
+ Returns None on error
|
| |
+ """
|
| |
+ json_resp = get_resource(json_url, attempt_retry=attempt_retry, log_errors=log_errors)
|
| |
try:
|
| |
- return json.loads(resp.text)
|
| |
+ return json.loads(json_resp)
|
| |
except JSONDecodeError:
|
| |
- if ignore_json_errors:
|
| |
- return resp.text
|
| |
- get_json(json_url, attempt_retry=False, log_errors=log_errors, ignore_json_errors=ignore_json_errors)
|
| |
+ if log_errors:
|
| |
+ app.logger.error("Request to %s failed because resource returned invalid json data." % json_url)
|
| |
+ return None
|
| |
+
|
| |
+ def get_yaml(yaml_url, attempt_retry=True, log_errors=True):
|
| |
+ """
|
| |
+ Returns yaml data from provided url
|
| |
+ Returns None on error
|
| |
+ """
|
| |
+ yaml_resp = get_resource(yaml_url, attempt_retry=attempt_retry, log_errors=log_errors)
|
| |
+ try:
|
| |
+ return yaml.safe_load(yaml_resp)
|
| |
+ except yaml.YAMLError:
|
| |
+ if log_errors:
|
| |
+ app.logger.error("Request to %s failed because resource returned invalid yaml data." % yaml_url)
|
| |
+ return None
|
| |
|
| |
def branched_frozen():
|
| |
"""
|
| |
Returns true if current branched is frozen
|
| |
"""
|
| |
- result = get_json("https://pagure.io/fedora-infra/ansible/raw/master/f/vars/all/Frozen.yaml", ignore_json_errors=True)
|
| |
+ result = get_yaml("https://pagure.io/fedora-infra/ansible/raw/master/f/vars/all/Frozen.yaml")
|
| |
try:
|
| |
- return yaml.safe_load(result)["Frozen"]
|
| |
+ return result["Frozen"]
|
| |
except (KeyError, AttributeError):
|
| |
app.logger.error("Failed to detect freeze status for branched...")
|
| |
return None
|
| |
Add tests, adjust code using it