CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
credentials Namespace Reference

Functions

def get_credentials
 
def get_credentials_for_schema
 
def get_credentials_from_file
 
def netrc_machine
 

Variables

string admin_role = 'admin'
 
string authPathEnvVar = 'COND_AUTH_PATH'
 
string dbkey_filename = 'db.key'
 
tuple dbkey_folder = os.path.join('.cms_cond',dbkey_filename)
 
string defAuthPathEnvVar = 'HOME'
 
string netrcFileName = '.netrc'
 
string reader_role = 'reader'
 
string writer_role = 'writer'
 

Function Documentation

def credentials.get_credentials (   machine,
  authPath = None 
)

Definition at line 26 of file credentials.py.

References get_credentials_from_file().

Referenced by db_credentials.get_db_credentials().

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

Definition at line 37 of file credentials.py.

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

Definition at line 19 of file credentials.py.

Referenced by get_credentials().

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

Definition at line 16 of file credentials.py.

16 
17 def netrc_machine( service, role ):
18  return '%s@%s' %(role,service)
def netrc_machine
Definition: credentials.py:16

Variable Documentation

string credentials.admin_role = 'admin'

Definition at line 14 of file credentials.py.

string credentials.authPathEnvVar = 'COND_AUTH_PATH'

Definition at line 7 of file credentials.py.

string credentials.dbkey_filename = 'db.key'

Definition at line 9 of file credentials.py.

tuple credentials.dbkey_folder = os.path.join('.cms_cond',dbkey_filename)

Definition at line 10 of file credentials.py.

string credentials.defAuthPathEnvVar = 'HOME'

Definition at line 6 of file credentials.py.

string credentials.netrcFileName = '.netrc'

Definition at line 5 of file credentials.py.

string credentials.reader_role = 'reader'

Definition at line 12 of file credentials.py.

string credentials.writer_role = 'writer'

Definition at line 13 of file credentials.py.