Skip to content

Commit

Permalink
fixed ModuleNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
toluaina committed Sep 28, 2021
1 parent 800f75b commit 1f22c21
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pgsync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = "Tolu Aina"
__email__ = "[email protected]"
__version__ = "2.1.5"
__version__ = "2.1.6"
21 changes: 12 additions & 9 deletions pgsync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def wrapper(*args, **kwargs):
return wrapper


def get_auth(key):
try:
plugins: Plugins = Plugins("plugins", ["Auth"])
return plugins.auth(key)
except ModuleNotFoundError as e:
logger.warning(f"ModuleNotFoundError: {e}")
return None


def get_elasticsearch_url(
scheme: Optional[str] = None,
user: Optional[str] = None,
Expand All @@ -113,14 +122,12 @@ def get_elasticsearch_url(
"""
Return the URL to connect to Elasticsearch.
"""
plugins: Plugins = Plugins("plugins", ["Auth"])

scheme: str = scheme or ELASTICSEARCH_SCHEME
host: str = host or ELASTICSEARCH_HOST
port: str = port or ELASTICSEARCH_PORT
user: str = user or ELASTICSEARCH_USER
password: str = (
plugins.auth("ELASTICSEARCH_PASSWORD")
get_auth("ELASTICSEARCH_PASSWORD")
or password
or ELASTICSEARCH_PASSWORD
)
Expand All @@ -140,11 +147,9 @@ def get_postgres_url(
"""
Return the URL to connect to Postgres.
"""
plugins: Plugins = Plugins("plugins", ["Auth"])

user: str = user or PG_USER
host: str = host or PG_HOST
password: str = plugins.auth("PG_PASSWORD") or password or PG_PASSWORD
password: str = get_auth("PG_PASSWORD") or password or PG_PASSWORD
port: str = port or PG_PORT
if not password:
logger.debug("Connecting to Postgres without password.")
Expand All @@ -164,10 +169,8 @@ def get_redis_url(
"""
Return the URL to connect to Redis.
"""
plugins: Plugins = Plugins("plugins", ["Auth"])

host: str = host or REDIS_HOST
password: str = plugins.auth("REDIS_AUTH") or password or REDIS_AUTH
password: str = get_auth("REDIS_AUTH") or password or REDIS_AUTH
port = port or REDIS_PORT
db: str = db or REDIS_DB
scheme: str = scheme or REDIS_SCHEME
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.5
current_version = 2.1.6
commit = True
tag = True

Expand Down

0 comments on commit 1f22c21

Please sign in to comment.