-
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.
- Loading branch information
Showing
12 changed files
with
135 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
REDIS_HOST=localhost | ||
REDIS_PORT=6379 | ||
REDIS_USER= | ||
REDIS_PASSWORD= | ||
VAST_API_KEY= |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
# distributaur/config.py | ||
|
||
from distributaur.utils import get_env_vars | ||
|
||
|
||
class Config: | ||
def __init__(self): | ||
self.settings = {} | ||
self.settings.update(get_env_vars()) | ||
|
||
def configure(self, **kwargs): | ||
self.settings.update(kwargs) | ||
|
||
def get(self, key, default=None): | ||
return self.settings.get(key, default) | ||
|
||
config = Config() |
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
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,49 +1,38 @@ | ||
# /Users/shawwalters/distributoor/distributaur/utils.py | ||
|
||
import os | ||
import redis | ||
from redis import ConnectionPool | ||
|
||
pool = None | ||
|
||
def get_redis_values(path=".env"): | ||
env_vars = get_env_vars(path) | ||
|
||
host = env_vars.get("REDIS_HOST", os.getenv("REDIS_HOST", "localhost")) | ||
password = env_vars.get("REDIS_PASSWORD", os.getenv("REDIS_PASSWORD", None)) | ||
port = env_vars.get("REDIS_PORT", os.getenv("REDIS_PORT", 6379)) | ||
username = env_vars.get("REDIS_USER", os.getenv("REDIS_USER", None)) | ||
def get_redis_values(config): | ||
print("config is", config) | ||
host = config.get("REDIS_HOST", "localhost") | ||
password = config.get("REDIS_PASSWORD", None) | ||
port = config.get("REDIS_PORT", 6379) | ||
username = config.get("REDIS_USER", None) | ||
if password is None: | ||
redis_url = f"redis://{host}:{port}" | ||
else: | ||
redis_url = f"redis://{username}:{password}@{host}:{port}" | ||
return redis_url | ||
|
||
def get_redis_connection(): | ||
def get_redis_connection(config): | ||
"""Retrieve Redis connection from the connection pool.""" | ||
global pool | ||
if pool is None: | ||
redis_url = get_redis_values() | ||
redis_url = get_redis_values(config) | ||
pool = ConnectionPool.from_url(redis_url) | ||
return redis.Redis(connection_pool=pool) | ||
|
||
def close_redis_connection(client): | ||
"""Close the Redis connection.""" | ||
client.close() | ||
|
||
def get_env_vars(path=".env"): | ||
# combine env vars from .env file and system environment | ||
|
||
def get_env_vars(path=".env.default"): | ||
env_vars = {} | ||
|
||
for key, value in os.environ.items(): | ||
env_vars[key] = value | ||
|
||
if not os.path.exists(path): | ||
return env_vars | ||
with open(path, "r") as f: | ||
for line in f: | ||
key, value = line.strip().split("=") | ||
env_vars[key] = value | ||
print('*** env vars are:', env_vars) | ||
if os.path.exists(path): | ||
with open(path, "r") as f: | ||
for line in f: | ||
key, value = line.strip().split("=") | ||
env_vars[key] = value | ||
return env_vars |
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
Oops, something went wrong.