CMS 3D CMS Logo

Functions
credentials Namespace Reference

Functions

def get_credentials (machine, authPath=None)
 
def get_credentials_for_schema (service, schema, role, authPath=None)
 
def get_credentials_from_file (machine, authPath)
 
def netrc_machine (service, role)
 

Function Documentation

◆ get_credentials()

def credentials.get_credentials (   machine,
  authPath = None 
)

Definition at line 26 of file credentials.py.

26 def get_credentials( machine, authPath=None ):
27  if authPath is None:
28  if authPathEnvVar in os.environ:
29  authPath = os.environ[authPathEnvVar]
30  else:
31  if defAuthPathEnvVar in os.environ:
32  authPath = os.environ[defAuthPathEnvVar]
33  else:
34  authPath = ''
35  return get_credentials_from_file( machine, authPath )
36 

References get_credentials_from_file().

Referenced by db_credentials.get_db_credentials().

◆ get_credentials_for_schema()

def credentials.get_credentials_for_schema (   service,
  schema,
  role,
  authPath = None 
)

Definition at line 37 of file credentials.py.

37 def get_credentials_for_schema( service, schema, role, authPath=None ):
38  if authPath is None:
39  if authPathEnvVar in os.environ:
40  authPath = os.environ[authPathEnvVar]
41  else:
42  if defAuthPathEnvVar in os.environ:
43  authPath = os.environ[defAuthPathEnvVar]
44  else:
45  authPath = ''
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) )
53  import netrc
54  params = netrc.netrc( authFile ).authenticators(machine)
55  if params is None:
56  msg = 'The required credentials have not been found in the .netrc file.'
57  raise Exception(msg)
58  return params
59  else:
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)
68 

◆ get_credentials_from_file()

def credentials.get_credentials_from_file (   machine,
  authPath 
)

Definition at line 19 of file credentials.py.

19 def get_credentials_from_file( machine, authPath ):
20  authFile = netrcFileName
21  if not authPath is None:
22  authFile = os.path.join( authPath, authFile )
23  creds = netrc.netrc( authFile ).authenticators(machine)
24  return creds
25 

Referenced by get_credentials().

◆ netrc_machine()

def credentials.netrc_machine (   service,
  role 
)

Definition at line 16 of file credentials.py.

16 def netrc_machine( service, role ):
17  return '%s@%s' %(role,service)
18 
credentials.get_credentials_for_schema
def get_credentials_for_schema(service, schema, role, authPath=None)
Definition: credentials.py:37
credentials.get_credentials_from_file
def get_credentials_from_file(machine, authPath)
Definition: credentials.py:19
credentials.get_credentials
def get_credentials(machine, authPath=None)
Definition: credentials.py:26
credentials.netrc_machine
def netrc_machine(service, role)
Definition: credentials.py:16
Exception