Skip to content

Commit 7787310

Browse files
authored
feat!: remove separate UTA password param (#166)
1 parent 6a55280 commit 7787310

File tree

3 files changed

+14
-52
lines changed

3 files changed

+14
-52
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ If you have trouble installing UTA, you can visit [these two READMEs](https://gi
6262
6363
#### Connecting to the database
6464
65-
To connect to the UTA database, you can use the default url (`postgresql://uta_admin@localhost:5433/uta/uta_20210129`). If you use the default url, you must either set the password using environment variable `UTA_PASSWORD` or setting the parameter `db_pwd` in the UTA class.
65+
To connect to the UTA database, you can use the default url (`postgresql://uta_admin:uta@localhost:5433/uta/uta_20210129`).
6666
67-
If you do not wish to use the default, you must set the environment variable `UTA_DB_URL` which has the format of `driver://user:pass@host:port/database/schema`.
67+
If you do not wish to use the default, you must set the environment variable `UTA_DB_URL` which has the format of `driver://user:password@host:port/database/schema`.
6868
6969
### Data Downloads
7070

cool_seq_tool/app.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def __init__(
2929
transcript_file_path: Path = TRANSCRIPT_MAPPINGS_PATH,
3030
lrg_refseqgene_path: Path = LRG_REFSEQGENE_PATH,
3131
mane_data_path: Path = MANE_SUMMARY_PATH,
32-
db_url: str = UTA_DB_URL, db_pwd: str = "",
33-
gene_query_handler: Optional[GeneQueryHandler] = None,
32+
db_url: str = UTA_DB_URL, gene_query_handler: Optional[GeneQueryHandler] = None,
3433
gene_db_url: str = "", gene_db_region: str = "us-east-2",
3534
sr: Optional[SeqRepo] = None
3635
) -> None:
@@ -40,8 +39,7 @@ def __init__(
4039
:param Path lrg_refseqgene_path: The path to LRG_RefSeqGene
4140
:param Path mane_data_path: Path to RefSeq MANE summary data
4241
:param str db_url: PostgreSQL connection URL
43-
Format: `driver://user:pass@host/database/schema`
44-
:param str db_pwd: User's password for uta database
42+
Format: `driver://user:password@host/database/schema`
4543
:param Optional[GeneQueryHandler] gene_query_handler: Gene normalizer query
4644
handler instance. If this is provided, will use a current instance. If this
4745
is not provided, will create a new instance.
@@ -60,7 +58,7 @@ def __init__(
6058
lrg_refseqgene_path=lrg_refseqgene_path)
6159
self.mane_transcript_mappings = MANETranscriptMappings(
6260
mane_data_path=mane_data_path)
63-
self.uta_db = UTADatabase(db_url=db_url, db_pwd=db_pwd)
61+
self.uta_db = UTADatabase(db_url=db_url)
6462
gene_normalizer = GeneNormalizer(gene_query_handler, gene_db_url,
6563
gene_db_region)
6664
self.gene_query_handler = gene_normalizer.query_handler

cool_seq_tool/data_sources/uta_database.py

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
LIFTOVER_CHAIN_38_TO_37 = environ.get("LIFTOVER_CHAIN_38_TO_37")
2727

2828
UTA_DB_URL = environ.get("UTA_DB_URL",
29-
"postgresql://uta_admin@localhost:5433/uta/uta_20210129")
29+
"postgresql://uta_admin:uta@localhost:5433/uta/uta_20210129")
3030

3131
logger = logging.getLogger("cool_seq_tool")
3232

@@ -37,16 +37,14 @@ class UTADatabase:
3737
def __init__(
3838
self,
3939
db_url: str = UTA_DB_URL,
40-
db_pwd: str = "",
4140
chain_file_37_to_38: Optional[str] = None,
4241
chain_file_38_to_37: Optional[str] = None
4342
) -> None:
4443
"""Initialize DB class. Downstream libraries should use the create()
4544
method to construct a new instance: await UTADatabase.create()
4645
4746
:param db_url: PostgreSQL connection URL
48-
Format: `driver://user:pass@host/database/schema`
49-
:param db_pwd: User's password for uta database
47+
Format: `driver://user:password@host/database/schema`
5048
:param chain_file_37_to_38: Optional path to chain file for 37 to 38 assembly.
5149
This is used for pyliftover. If this is not provided, will check to see if
5250
LIFTOVER_CHAIN_37_TO_38 env var is set. If neither is provided, will allow
@@ -57,9 +55,9 @@ def __init__(
5755
pyliftover to download a chain file from UCSC
5856
"""
5957
self.schema = None
60-
self.db_url = db_url
61-
self.db_pwd = db_pwd
6258
self._connection_pool = None
59+
original_pwd = db_url.split("//")[-1].split("@")[0].split(":")[-1]
60+
self.db_url = db_url.replace(original_pwd, quote(original_pwd))
6361
self.args = self._get_conn_args()
6462

6563
chain_file_37_to_38 = chain_file_37_to_38 or LIFTOVER_CHAIN_37_TO_38
@@ -74,38 +72,10 @@ def __init__(
7472
else:
7573
self.liftover_38_to_37 = LiftOver("hg38", "hg19")
7674

77-
@staticmethod
78-
def _update_db_url(db_pwd: str, db_url: str) -> str:
79-
"""Return new db_url containing password.
80-
81-
:param str db_pwd: User's password for uta database
82-
:param str db_url: PostgreSQL connection URL
83-
Format: `driver://user:pass@host/database/schema`
84-
:return: PostgreSQL connection URL
85-
"""
86-
if "UTA_DB_URL" in environ:
87-
return environ["UTA_DB_URL"]
88-
if not db_pwd and "UTA_PASSWORD" not in environ:
89-
raise Exception("Environment variable UTA_PASSWORD "
90-
"or `db_pwd` param must be set")
91-
else:
92-
uta_password_in_environ = "UTA_PASSWORD" in environ
93-
if uta_password_in_environ and db_pwd:
94-
if db_pwd != environ["UTA_PASSWORD"]:
95-
raise Exception("If both environment variable UTA_PASSWORD"
96-
" and param db_pwd is set, they must "
97-
"both be the same")
98-
else:
99-
if uta_password_in_environ and not db_pwd:
100-
db_pwd = environ["UTA_PASSWORD"]
101-
db_url = db_url.split("@")
102-
db_url_with_pass = f"{db_url[0]}:{db_pwd}@{db_url[1]}"
103-
environ["UTA_DB_URL"] = db_url_with_pass
104-
return db_url_with_pass
105-
10675
def _get_conn_args(self) -> Dict:
10776
"""Return connection arguments.
10877
78+
:param db_url: raw connection URL
10979
:return: Database credentials
11080
"""
11181
if "UTA_DB_PROD" in environ:
@@ -124,11 +94,7 @@ def _get_conn_args(self) -> Dict:
12494
return dict(host=host, port=int(port), database=database, user=username,
12595
password=password)
12696
else:
127-
db_url = self._update_db_url(self.db_pwd, self.db_url)
128-
original_pwd = db_url.split("//")[-1].split("@")[0].split(":")[-1]
129-
db_url = db_url.replace(original_pwd, quote(original_pwd))
130-
131-
url = ParseResult(urlparse.urlparse(db_url))
97+
url = ParseResult(urlparse.urlparse(self.db_url))
13298
self.schema = url.schema
13399
password = unquote(url.password) if url.password else ""
134100
return dict(host=url.hostname, port=url.port,
@@ -158,16 +124,14 @@ async def create_pool(self) -> None:
158124

159125
@classmethod
160126
async def create(
161-
cls: Type[UTADatabaseType], db_url: str = UTA_DB_URL,
162-
db_pwd: str = "") -> UTADatabaseType:
127+
cls: Type[UTADatabaseType], db_url: str = UTA_DB_URL) -> UTADatabaseType:
163128
"""Provide fully-initialized class instance (a la factory pattern)
164129
:param UTADatabaseType cls: supplied implicitly
165130
:param str db_url: PostgreSQL connection URL
166-
Format: `driver://user:pass@host/database/schema`
167-
:param str db_pwd: User's password for uta database
131+
Format: `driver://user:password@host/database/schema`
168132
:return: UTA DB access class instance
169133
"""
170-
self = cls(db_url, db_pwd)
134+
self = cls(db_url)
171135
await self._create_genomic_table()
172136
await self.create_pool()
173137
return self

0 commit comments

Comments
 (0)