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