39 if authPathEnvVar
in os.environ:
40 authPath = os.environ[authPathEnvVar]
42 if defAuthPathEnvVar
in os.environ:
43 authPath = os.environ[defAuthPathEnvVar]
46 dbkey_path = os.path.join(authPath,dbkey_folder)
47 if not os.path.exists(dbkey_path):
48 authFile = os.path.join(authPath,
'.netrc')
49 if not os.path.exists(authFile):
50 raise Exception(
"Can't get db credentials, since neither db key nor Netrc file have been found.")
51 machine =
'%s@%s.%s' %(role,schema.lower(),service)
52 logging.debug(
'Looking up db credentials %s in file %s ' %(machine,authFile) )
54 params = netrc.netrc( authFile ).authenticators(machine)
56 msg =
'The required credentials have not been found in the .netrc file.'
60 import libCondDBPyBind11Interface
as credential_db
61 roles_map = { reader_role: credential_db.reader_role, writer_role: credential_db.writer_role, admin_role: credential_db.admin_role }
62 connection_string =
'oracle://%s/%s'%(service.lower(),schema.upper())
63 logging.debug(
'Looking up db credentials for %s in credential store' %connection_string )
64 (dbuser,username,password) = credential_db.get_credentials_from_db(connection_string,roles_map[role],authPath)
65 if username==
'' or password==
'':
66 raise Exception(
'No credentials found to connect on %s with the required access role.'%connection_string)
67 return (username,dbuser,password)