Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround PRC different behavior file/dictionary #300

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions ibridges/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from __future__ import annotations

import json
import os
import socket
import warnings
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Optional, Union

import irods.session
Expand Down Expand Up @@ -251,12 +253,28 @@ def authenticate_using_auth_file(self) -> iRODSSession:
Internal use only.
"""
try:
irods_session = irods.session.iRODSSession(
irods_env_file=self._irods_env_path,
application_name=APP_NAME,
connection_timeout=self.connection_timeout,
)
_ = irods_session.server_version
if self._irods_env_path is not None:
irods_session = irods.session.iRODSSession(
irods_env_file=self._irods_env_path,
application_name=APP_NAME,
connection_timeout=self.connection_timeout,
)
else:
# Create a temporary file for the irods environment dictionary.
# From Python 3.12 we could use the delete_on_close parameter.
with NamedTemporaryFile(delete=False, mode="w") as handle:
temp_ienv_path = handle.name
try:
handle.write(json.dumps(self._irods_env))
handle.close()
irods_session = irods.session.iRODSSession(
irods_env_file=temp_ienv_path,
application_name=APP_NAME,
connection_timeout=self.connection_timeout,
)
finally:
os.unlink(temp_ienv_path)
_ = irods_session.server_version # pylint: disable=possibly-used-before-assignment
except NonAnonymousLoginWithoutPassword as e:
raise ValueError("No cached password found.") from e
except Exception as e:
Expand Down