Skip to content

Commit 2ffbff8

Browse files
committed
Merge branch 'develop' into synpy-1575-correct-column-name-regular-expression
2 parents f0c4bb6 + 8a9ad21 commit 2ffbff8

File tree

4 files changed

+207
-126
lines changed

4 files changed

+207
-126
lines changed

Diff for: synapseclient/api/entity_factory.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,19 @@ def _check_entity_restrictions(
412412
if restriction_information and restriction_information.get(
413413
"hasUnmetAccessRequirement", None
414414
):
415-
warning_message = (
416-
"\nThis entity has access restrictions. Please visit the web page for this entity "
417-
f'(syn.onweb("{synapse_id}")). Look for the "Access" label and the lock icon underneath '
418-
'the file name. Click "Request Access", and then review and fulfill the file '
419-
"download requirement(s).\n"
420-
)
415+
if not syn.credentials or not syn.credentials._token:
416+
warning_message = (
417+
"You have not provided valid credentials for authentication with Synapse."
418+
" Please provide an authentication token and use `synapseclient.login()` before your next attempt."
419+
" See https://python-docs.synapse.org/tutorials/authentication/ for more information."
420+
)
421+
else:
422+
warning_message = (
423+
"\nThis entity has access restrictions. Please visit the web page for this entity "
424+
f'(syn.onweb("{synapse_id}")). Look for the "Access" label and the lock icon underneath '
425+
'the file name. Click "Request Access", and then review and fulfill the file '
426+
"download requirement(s).\n"
427+
)
421428
if download_file and bundle.get("entityType") not in ("project", "folder"):
422429
raise SynapseUnmetAccessRestrictions(warning_message)
423-
syn.logger.warn(warning_message)
430+
syn.logger.warning(warning_message)

Diff for: synapseclient/client.py

+31-12
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ class Synapse(object):
248248
authEndpoint: Location of authentication service
249249
fileHandleEndpoint: Location of file service
250250
portalEndpoint: Location of the website
251-
serviceTimeoutSeconds: Wait time before timeout (currently unused)
252251
debug: Print debugging messages if True
253252
skip_checks: Skip version and endpoint checks
254253
configPath: Path to config File with setting for Synapse. Defaults to ~/.synapseConfig
@@ -281,6 +280,9 @@ class Synapse(object):
281280
raised. These will be appended to the default `User-Agent` header that
282281
already includes the version of this client that you are using, and the
283282
HTTP library used to make the request.
283+
timeout: The timeout in seconds for HTTP requests. The default is 70 seconds.
284+
You may increase this if you are experiencing timeouts when interacting
285+
with slow services.
284286
285287
Example: Getting started
286288
Logging in to Synapse using an authToken
@@ -336,6 +338,7 @@ def __init__(
336338
asyncio_event_loop: asyncio.AbstractEventLoop = None,
337339
cache_client: bool = True,
338340
user_agent: Union[str, List[str]] = None,
341+
http_timeout_seconds: int = 70,
339342
) -> "Synapse":
340343
"""
341344
Initialize Synapse object
@@ -374,6 +377,9 @@ def __init__(
374377
raised. These will be appended to the default `User-Agent` header that
375378
already includes the version of this client that you are using, and the
376379
HTTP library used to make the request.
380+
http_timeout_seconds: The timeout in seconds for HTTP requests.
381+
The default is 70 seconds. You may increase this if you are
382+
experiencing timeouts when interacting with slow services.
377383
378384
Raises:
379385
ValueError: Warn for non-boolean debug value.
@@ -391,7 +397,8 @@ def __init__(
391397
else:
392398
self._requests_session_async_synapse = {}
393399

394-
httpx_timeout = httpx.Timeout(70, pool=None)
400+
self._http_timeout_seconds = http_timeout_seconds
401+
httpx_timeout = httpx.Timeout(http_timeout_seconds, pool=None)
395402
self._requests_session_storage = requests_session_storage or httpx.Client(
396403
timeout=httpx_timeout
397404
)
@@ -505,7 +512,7 @@ async def close_connection() -> None:
505512
await self._requests_session_async_synapse[asyncio_event_loop].aclose()
506513
del self._requests_session_async_synapse[asyncio_event_loop]
507514

508-
httpx_timeout = httpx.Timeout(70, pool=None)
515+
httpx_timeout = httpx.Timeout(self._http_timeout_seconds, pool=None)
509516
self._requests_session_async_synapse.update(
510517
{
511518
asyncio_event_loop: httpx.AsyncClient(
@@ -758,6 +765,7 @@ def setEndpoints(
758765
endpoints[point],
759766
allow_redirects=False,
760767
headers=synapseclient.USER_AGENT,
768+
timeout=self._http_timeout_seconds,
761769
),
762770
verbose=self.debug,
763771
**STANDARD_RETRY_PARAMS,
@@ -1445,17 +1453,26 @@ def _check_entity_restrictions(
14451453
Raises:
14461454
SynapseUnmetAccessRestrictions: Warning for unmet access requirements.
14471455
"""
1448-
restrictionInformation = bundle["restrictionInformation"]
1449-
if restrictionInformation["hasUnmetAccessRequirement"]:
1450-
warning_message = (
1451-
"\nThis entity has access restrictions. Please visit the web page for this entity "
1452-
f'(syn.onweb("{id_of(entity)}")). Look for the "Access" label and the lock icon underneath '
1453-
'the file name. Click "Request Access", and then review and fulfill the file '
1454-
"download requirement(s).\n"
1455-
)
1456+
restriction_information = bundle.get("restrictionInformation", None)
1457+
if restriction_information and restriction_information.get(
1458+
"hasUnmetAccessRequirement", None
1459+
):
1460+
if not self.credentials or not self.credentials._token:
1461+
warning_message = (
1462+
"You have not provided valid credentials for authentication with Synapse."
1463+
" Please provide an authentication token and use `synapseclient.login()` before your next attempt."
1464+
" See https://python-docs.synapse.org/tutorials/authentication/ for more information."
1465+
)
1466+
else:
1467+
warning_message = (
1468+
"\nThis entity has access restrictions. Please visit the web page for this entity "
1469+
f'(syn.onweb("{id_of(entity)}")). Look for the "Access" label and the lock icon underneath '
1470+
'the file name. Click "Request Access", and then review and fulfill the file '
1471+
"download requirement(s).\n"
1472+
)
14561473
if downloadFile and bundle.get("entityType") not in ("project", "folder"):
14571474
raise SynapseUnmetAccessRestrictions(warning_message)
1458-
warnings.warn(warning_message)
1475+
self.logger.warning(warning_message)
14591476

14601477
def _getFromFile(
14611478
self, filepath: str, limitSearch: str = None, md5: str = None
@@ -6207,12 +6224,14 @@ def _rest_call(
62076224

62086225
auth = kwargs.pop("auth", self.credentials)
62096226
requests_method_fn = getattr(requests_session, method)
6227+
timeout = kwargs.pop("timeout", self._http_timeout_seconds)
62106228
response = with_retry(
62116229
lambda: requests_method_fn(
62126230
uri,
62136231
data=data,
62146232
headers=headers,
62156233
auth=auth,
6234+
timeout=timeout,
62166235
**kwargs,
62176236
),
62186237
verbose=self.debug,

Diff for: synapseclient/core/credentials/cred_data.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def secret(self) -> str:
109109
return self._token
110110

111111
def __call__(self, r):
112-
r.headers.update({"Authorization": f"Bearer {self.secret}"})
112+
if self.secret:
113+
r.headers.update({"Authorization": f"Bearer {self.secret}"})
113114
return r
114115

115116
def __repr__(self):

0 commit comments

Comments
 (0)