Skip to content

Commit

Permalink
set a higher timeout on most API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Oct 15, 2023
1 parent ecd3ee7 commit 252cc55
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/ap/ap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_all_aps_of_project(
project_iri = quote_plus(project_iri, safe="")
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/permissions/ap/{project_iri}"
response = requests.get(url, headers=headers, timeout=5)
response = requests.get(url, headers=headers, timeout=10)
if response.status_code != 200:
raise ApiError("Could not get APs of project", response.text, response.status_code)
aps: list[dict[str, Any]] = response.json()["administrative_permissions"]
Expand Down
4 changes: 2 additions & 2 deletions dsp_permissions_scripts/ap/ap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _delete_single_ap(
ap_iri = quote_plus(ap.iri, safe="")
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/permissions/{ap_iri}"
response = requests.delete(url, headers=headers, timeout=5)
response = requests.delete(url, headers=headers, timeout=10)
if response.status_code != 200:
raise ApiError(f"Could not delete Administrative Permission {ap.iri}", response.text, response.status_code)
logger.info(f"Deleted Administrative Permission {ap.iri} on host {host}")
Expand All @@ -53,7 +53,7 @@ def _update_ap(
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/permissions/{iri}/hasPermissions"
payload = {"hasPermissions": create_admin_route_object_from_ap(ap)["hasPermissions"]}
response = requests.put(url, headers=headers, json=payload, timeout=5)
response = requests.put(url, headers=headers, json=payload, timeout=10)
if response.status_code != 200:
raise ApiError(
message=f"Could not update Administrative Permission {ap.iri}",
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/doap/doap_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_all_doaps_of_project(
project_iri = quote_plus(project_iri, safe="")
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/permissions/doap/{project_iri}"
response = requests.get(url, headers=headers, timeout=5)
response = requests.get(url, headers=headers, timeout=10)
if response.status_code != 200:
raise ApiError(f"Error while getting DOAPs of project {project_iri}", response.text, response.status_code)
doaps: list[dict[str, Any]] = response.json()["default_object_access_permissions"]
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/doap/doap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _update_doap_scope(
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/permissions/{iri}/hasPermissions"
payload = {"hasPermissions": create_admin_route_object_from_scope(scope)}
response = requests.put(url, headers=headers, json=payload, timeout=5)
response = requests.put(url, headers=headers, json=payload, timeout=10)
if response.status_code != 200:
raise ApiError( f"Could not update scope of DOAP {doap_iri}", response.text, response.status_code, payload)
new_doap = create_doap_from_admin_route_response(response.json()["default_object_access_permission"])
Expand Down
6 changes: 3 additions & 3 deletions dsp_permissions_scripts/oap/oap_get_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _get_resource(
protocol = get_protocol(host)
url = f"{protocol}://{host}/v2/resources/{iri}"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(url, headers=headers, timeout=5)
response = requests.get(url, headers=headers, timeout=10)
if response.status_code != 200:
raise ApiError( f"Error while getting resource {resource_iri}", response.text, response.status_code)
data: dict[str, Any] = response.json()
Expand Down Expand Up @@ -103,7 +103,7 @@ def _update_permissions_for_value(
protocol = get_protocol(host)
url = f"{protocol}://{host}/v2/values"
headers = {"Authorization": f"Bearer {token}"}
response = requests.put(url, headers=headers, json=payload, timeout=5)
response = requests.put(url, headers=headers, json=payload, timeout=10)
if response.status_code == 400 and response.text:
already = "dsp.errors.BadRequestException: The submitted permissions are the same as the current ones"
if already in response.text:
Expand Down Expand Up @@ -143,7 +143,7 @@ def _update_permissions_for_resource(
protocol = get_protocol(host)
url = f"{protocol}://{host}/v2/resources"
headers = {"Authorization": f"Bearer {token}"}
response = requests.put(url, headers=headers, json=payload, timeout=5)
response = requests.put(url, headers=headers, json=payload, timeout=10)
if response.status_code != 200:
raise ApiError(
message=f"ERROR while updating permissions of resource {resource_iri}",
Expand Down
2 changes: 1 addition & 1 deletion dsp_permissions_scripts/utils/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _get_token(host: str, email: str, pw: str) -> str:
"""
protocol = get_protocol(host)
url = f"{protocol}://{host}/v2/authentication"
response = requests.post(url, json={"email": email, "password": pw}, timeout=5)
response = requests.post(url, json={"email": email, "password": pw}, timeout=10)
if response.status_code != 200:
raise ApiError("Could not login", response.text, response.status_code)
token: str = response.json()["token"]
Expand Down
8 changes: 4 additions & 4 deletions dsp_permissions_scripts/utils/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _get_onto_iris_of_project(
protocol = get_protocol(host)
url = f"{protocol}://{host}/v2/ontologies/metadata"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(url, headers=headers, timeout=5)
response = requests.get(url, headers=headers, timeout=10)
if response.status_code != 200:
raise ApiError("Could not get onto IRIs", response.text, response.status_code)
all_ontologies = response.json().get("@graph")
Expand All @@ -61,7 +61,7 @@ def _get_class_iris_of_onto(
protocol = get_protocol(host)
url = f"{protocol}://{host}/v2/ontologies/allentities/{quote_plus(onto_iri)}"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(url, headers=headers, timeout=5)
response = requests.get(url, headers=headers, timeout=10)
if response.status_code != 200:
raise ApiError("Could not get class IRIs", response.text, response.status_code)
all_entities = response.json()["@graph"]
Expand Down Expand Up @@ -122,7 +122,7 @@ def _get_next_page(
This means that the page must be incremented until the response contains 0 or 1 resource.
"""
url = f"{protocol}://{host}/v2/resources?resourceClass={quote_plus(resclass_iri)}&page={page}"
response = requests.get(url, headers=headers, timeout=5)
response = requests.get(url, headers=headers, timeout=20)
if response.status_code != 200:
raise ApiError("Could not get next page", response.text, response.status_code)
result = response.json()
Expand All @@ -148,7 +148,7 @@ def get_project_iri_by_shortcode(shortcode: str, host: str) -> str:
"""
protocol = get_protocol(host)
url = f"{protocol}://{host}/admin/projects/shortcode/{shortcode}"
response = requests.get(url, timeout=5)
response = requests.get(url, timeout=10)
if response.status_code != 200:
raise ApiError("Cannot retrieve project IRI", response.text, response.status_code)
iri: str = response.json()["project"]["id"]
Expand Down

0 comments on commit 252cc55

Please sign in to comment.