-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starting redis integration for get configuration
- Loading branch information
Showing
10 changed files
with
101 additions
and
17 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
File renamed without changes.
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,37 @@ | ||
|
||
from typing import Tuple | ||
from xmlrpc.client import Boolean | ||
import redis | ||
from globals import env | ||
|
||
|
||
def check_conf_server( | ||
host_param: str = None, | ||
port_param: str = None) -> Tuple: | ||
"""Check if the Redis configuration endpoint is alive. | ||
If host and/or port aren't provided, pull values from REDIS_HOST and REDIS_port | ||
environment variables | ||
Arguments: | ||
host_param (Optional): the Redis endpoint (.e.g, 'redis://localhost' or '127.0.0.1') | ||
port_param (Optional): the Redis port | ||
Return: | ||
(status_code, r) tuple where status_code is boolean for the check success, | ||
and r is the Redis handle if successful | ||
""" | ||
|
||
if not host_param: | ||
host_param = env['REDIS_HOST'] | ||
if not port_param: | ||
port_param = env['REDIS_PORT'] | ||
|
||
try: | ||
r = redis.StrictRedis(host=host_param, port=port_param, decode_responses=True ) | ||
if r.ping(): | ||
return True, r | ||
return False, None | ||
|
||
except redis.ConnectionError: | ||
return False, None | ||
|
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,14 +1,42 @@ | ||
# Configuration GET | ||
|
||
from fastapi import Response, status | ||
from globals import env | ||
from ast import Dict | ||
from internal.check_conf_server import check_conf_server | ||
|
||
def get( | ||
response: Response, | ||
instance_param: str = None, | ||
section_param: str = None | ||
) -> Dict: | ||
"""Implement GET method for | ||
/v1/configuration | ||
/v1/configuration/{instance} | ||
/v1/configuration/{instance}/{section} | ||
Args: | ||
response (Response): pass through for setting specific status | ||
instance_param (str, optional): Name of the instance. Defaults to None. | ||
section_param (str, optional): Name of the configuration section. Defaults to None. | ||
Returns: | ||
Dict: response from the operation | ||
HTTP Status Codes: | ||
424: Redis failure | ||
""" | ||
return_dict = {'instance': instance_param, 'section': section_param} | ||
|
||
# redis code goes here | ||
# do we have a working Redis connection? | ||
redis_status, r = check_conf_server() | ||
if not redis_status: | ||
response.status_code = status.HTTP_424_FAILED_DEPENDENCY | ||
return { 'message': 'redis connection failed' } | ||
# we have a working redis connection | ||
|
||
# do something useful with redis | ||
|
||
return return_dict |
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