Skip to content

Commit

Permalink
added command in settings to control console output, defaulted to tru…
Browse files Browse the repository at this point in the history
…e for now. #14
  • Loading branch information
miguel-bermudo committed Feb 12, 2024
1 parent f1abe05 commit f7addf6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 4 additions & 2 deletions silence/server/default_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def login():
# and return it with the logged user's info
logger.debug("Login OK")

logger.info(log_utils.format_custom_record('api', 'yellow', f'PARAMS {form}'))
if(settings.DISPLAY_BODY_PARAMS_CLI):
logger.info(log_utils.format_custom_record('api', 'yellow', f'PARAMS {form}'))

token = create_token(user)
del user[PASSWORD_FIELD]
Expand Down Expand Up @@ -125,7 +126,8 @@ def register():
# and return it with the logged user's info
logger.debug("Register OK")

logger.info(log_utils.format_custom_record('api', 'yellow', f'PARAMS {form}'))
if(settings.DISPLAY_BODY_PARAMS_CLI):
logger.info(log_utils.format_custom_record('api', 'yellow', f'PARAMS {form}'))

token = create_token(user)
del user[PASSWORD_FIELD]
Expand Down
16 changes: 13 additions & 3 deletions silence/server/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def route_handler(*args, **kwargs):
else: # POST/PUT/DELETE operations
#Construct a dict for all params expected in the request body, setting them to None if they have not been provided
form = request.json if request.is_json else request.form

# TODO: maybe instead of getting putting a none put the default value.
# SELECT DISTINCT DEFAULT(name) FROM departments
# take into account that the default value if none is specified is NULL.

# request_body_params[param] if param in request_body_params else find_default(tabla, columna)

body_params = {param: form.get(param, None) for param in request_body_params}


Expand All @@ -119,12 +126,15 @@ def route_handler(*args, **kwargs):
for param in url_params:
body_params[param] = request_url_params_dict[param]

# print(f"\n\n body paramters:\n {body_params} \n\n request url params dict:\n {request_url_params_dict} \n\n")

logger.info(log_utils.format_custom_record('api', 'yellow', f'PARAMS {body_params}'))
if(settings.DISPLAY_BODY_PARAMS_CLI):
logger.info(log_utils.format_custom_record('api', 'yellow', f'PARAMS {body_params}'))

# TODO: if the tuple recieves a none, but the database has an explicit default,
# replace that none with the specific default value.
param_tuple = tuple(body_params[param] for param in sql_params)

# print(f"\n\n body paramters:\n {body_params} \n\n request url params dict:\n {request_url_params_dict} \n\n form:\n {form} \n\n param tuple: \n {param_tuple}\n\n query string: \n {query_string}")

# Run the execute query
res = dal.api_safe_update(query_string, param_tuple)

Expand Down
5 changes: 4 additions & 1 deletion silence/settings/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@
CHECK_FOR_UPDATES = True

# Enables the createapi command
ENABLE_ENDPOINT_AUTO_GENERATION = True
ENABLE_ENDPOINT_AUTO_GENERATION = True

# Displaying the POST/UPDATE/DELETE request body parameters in the CLI console.
DISPLAY_BODY_PARAMS_CLI = True

0 comments on commit f7addf6

Please sign in to comment.