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

feat: fall back on scrambled password #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 27 additions & 5 deletions snakemake_storage_plugin_irods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, Iterable, Optional, List
from urllib.parse import urlparse

from irods import password_obfuscation
from irods.session import iRODSSession
from irods.models import DataObject
from irods.exception import (
Expand Down Expand Up @@ -34,6 +35,10 @@


env_msg = "Value in ~/.irods/irods_environment.json has higher priority, if present. "
pswd_msg = (
"If no password is provided in the settings or environment file, the"
+ " password in ~/.irods/.irodsA will be used with native authentication. "
)


@dataclass
Expand Down Expand Up @@ -65,9 +70,9 @@ class StorageProviderSettings(StorageProviderSettingsBase):
password: Optional[str] = field(
default=None,
metadata={
"help": f"The password for the iRODS server. {env_msg}",
"help": f"The password for the iRODS server. {env_msg} {pswd_msg}",
"env_var": True,
"required": True,
"required": False,
},
)
zone: Optional[str] = field(
Expand All @@ -89,7 +94,8 @@ class StorageProviderSettings(StorageProviderSettingsBase):
authentication_scheme: str = field(
default="native",
metadata={
"help": f"The authentication scheme for the iRODS server. {env_msg}",
"help": "The authentication scheme for the iRODS server. "
+ f"{env_msg} {pswd_msg}",
"env_var": False,
"required": True,
},
Expand Down Expand Up @@ -231,13 +237,29 @@ def __post_init__(self):
else:
ssl_settings = {}

if self.settings.password is None:
irodsA = os.path.expanduser("~/.irods/.irodsA")
try:
with open(irodsA, "r") as r:
scrambled_password = r.read()
password = password_obfuscation.decode(scrambled_password)
authentication_scheme = "native"
except OSError as err:
raise Exception(
"Error: could not retrieve irods_password from"
+ " settings or ~/.irods/.irodsA file."
) from err
else:
password = self.settings.password
authentication_scheme = self.settings.authentication_scheme

self.session = iRODSSession(
host=self.settings.host,
port=self.settings.port,
user=self.settings.username,
password=self.settings.password,
password=password,
zone=self.settings.zone,
authentication_scheme=self.settings.authentication_scheme,
authentication_scheme=authentication_scheme,
**ssl_settings,
)

Expand Down
Loading