Skip to content

Commit e564bff

Browse files
committed
function to write native credentials works now.
1 parent ac092f4 commit e564bff

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

irods/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
import logging
44
import os
55

6+
def env_filename_from_keyword_args(kwargs):
7+
try:
8+
env_file = kwargs.pop('irods_env_file')
9+
except KeyError:
10+
try:
11+
env_file = os.environ['IRODS_ENVIRONMENT_FILE']
12+
except KeyError:
13+
env_file = os.path.expanduser('~/.irods/irods_environment.json')
14+
return env_file
15+
16+
def derived_auth_filename(env_file):
17+
return '' if not env_file else os.path.join(os.path.dirname(env_file),'.irodsA')
18+
619
# This has no effect if basicConfig() was previously called.
720
logging.basicConfig()
821

irods/account.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
2+
from irods import derived_auth_filename
23

34
class iRODSAccount(object):
45

56
@property
67
def derived_auth_file(self):
7-
return '' if not self.env_file else os.path.join(os.path.dirname(self.env_file),'.irodsA')
8+
return derived_auth_filename(self.env_file)
89

910
def __init__(self, irods_host, irods_port, irods_user_name, irods_zone_name,
1011
irods_authentication_scheme='native',

irods/client_init.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
from irods import (env_filename_from_keyword_args, derived_auth_filename)
12
import irods.client_configuration as cfg
23
import irods.password_obfuscation as obf
34
import irods.helpers as h
45
import getpass
56
import sys
67

7-
def write_native_credentials_to_secrets_file( password ):
8-
s = h.make_session()
9-
assert(not s.auth_file)
10-
open(s.pool.account.derived_auth_file,'w').write(obf.encode(password))
8+
def write_native_credentials_to_secrets_file(password, **kw):
9+
env_file = env_filename_from_keyword_args(kw)
10+
auth_file = derived_auth_filename(env_file)
11+
open(auth_file,'w').write(obf.encode(password))
1112
return True
1213

13-
def write_pam_credentials_to_secrets_file( password ):
14+
def write_pam_credentials_to_secrets_file( password ,**kw):
1415
s = h.make_session()
1516
s.pool.account.password = password
1617
with cfg.loadlines( [dict(setting='legacy_auth.pam.password_for_auto_renew',value=None),

irods/test/helpers.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from irods.session import iRODSSession
2222
from irods.message import (iRODSMessage, IRODS_VERSION)
2323
from irods.password_obfuscation import encode
24+
from irods import env_filename_from_keyword_args
2425
from six.moves import range
2526

2627
class iRODSUserLogins(object):
@@ -148,7 +149,6 @@ def recast(k):
148149
os.chmod(auth,0o600)
149150
return (config, auth)
150151

151-
152152
# Create a connection for test, based on ~/.irods environment by default.
153153

154154
def make_session(test_server_version = True, **kwargs):
@@ -166,13 +166,7 @@ def make_session(test_server_version = True, **kwargs):
166166
**kwargs: Keyword arguments. Fed directly to the iRODSSession
167167
constructor. """
168168

169-
try:
170-
env_file = kwargs.pop('irods_env_file')
171-
except KeyError:
172-
try:
173-
env_file = os.environ['IRODS_ENVIRONMENT_FILE']
174-
except KeyError:
175-
env_file = os.path.expanduser('~/.irods/irods_environment.json')
169+
env_file = env_filename_from_keyword_args( kwargs )
176170
session = iRODSSession( irods_env_file = env_file, **kwargs )
177171
if test_server_version:
178172
connected_version = session.server_version[:3]

0 commit comments

Comments
 (0)