-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from smart-on-fhir/mikix/oracle-support2
oracle: actually let you connect against an Oracle server
- Loading branch information
Showing
18 changed files
with
493 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""Exception classes and error handling""" | ||
|
||
# Error return codes, mostly just distinguished for the benefit of tests. | ||
# These start at 10 just to leave some room for future use. | ||
SQL_USER_MISSING = 10 | ||
SQL_PASSWORD_MISSING = 11 | ||
MSTOOL_FAILED = 12 | ||
MSTOOL_MISSING = 13 | ||
CTAKES_MISSING = 14 | ||
SMART_CREDENTIALS_MISSING = 15 | ||
BULK_EXPORT_FAILED = 16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
"""Connects to oracle database""" | ||
|
||
import getpass | ||
import logging | ||
import os | ||
import sys | ||
|
||
import oracledb | ||
|
||
from cumulus import errors | ||
|
||
def get_data_source_name() -> str: | ||
return os.environ.get('I2B2_SQL_DSN', None) | ||
|
||
|
||
def get_user() -> str: | ||
def _get_user() -> str: | ||
""" | ||
:return: user for I2b2 database | ||
""" | ||
return os.environ.get('I2B2_SQL_USER', None) | ||
user = os.environ.get('CUMULUS_SQL_USER') | ||
if not user: | ||
print('To connect to an Oracle SQL server, please set the environment variable CUMULUS_SQL_USER', | ||
file=sys.stderr) | ||
raise SystemExit(errors.SQL_USER_MISSING) | ||
return user | ||
|
||
|
||
def get_password() -> str: | ||
def _get_password() -> str: | ||
""" | ||
:return: password for the DSN | ||
""" | ||
pwd = os.environ.get('I2B2_SQL_PASS', None) | ||
if not pwd or len(pwd) < 4: | ||
user = get_user() | ||
return getpass.getpass(f'Enter password for I2B2_SQL_USER {user}: ') | ||
pwd = os.environ.get('CUMULUS_SQL_PASSWORD') | ||
if not pwd: | ||
print('To connect to an Oracle SQL server, please set the environment variable CUMULUS_SQL_PASSWORD', | ||
file=sys.stderr) | ||
raise SystemExit(errors.SQL_PASSWORD_MISSING) | ||
return pwd | ||
|
||
|
||
def connect() -> oracledb.Connection: | ||
def connect(dsn: str) -> oracledb.Connection: | ||
""" | ||
:return: connection to oracle database | ||
""" | ||
logging.info('Attempting to connect to %s', get_data_source_name()) | ||
return oracledb.connect(user=get_user(), password=get_password(), dsn=get_data_source_name()) | ||
logging.info('Attempting to connect to %s', dsn) | ||
return oracledb.connect(user=_get_user(), password=_get_password(), dsn=dsn) |
Oops, something went wrong.