Skip to content

Commit

Permalink
do not use str(url) to stringify a URL for subsequent use
Browse files Browse the repository at this point in the history
The str(url) function in SQLAlchemy hides the password.
For a URL string that is to be re-used, use
render_as_string(hide_password=False).

this also replaces usege of falcon resp.body to resp.text [1]

[1] falconry/falcon#1578

Change-Id: Ib8a393fd626f5515ef92632a5236120c3ccbde05
  • Loading branch information
noonedeadpunk committed Dec 1, 2024
1 parent c0ed772 commit c826b3a
Show file tree
Hide file tree
Showing 24 changed files with 154 additions and 169 deletions.
13 changes: 0 additions & 13 deletions freezer_api/api/common/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import webob.dec
import webob.exc

from oslo_serialization import jsonutils as json

from freezer_api.common import exceptions as freezer_api_exc
from freezer_api import context

Expand Down Expand Up @@ -137,17 +135,6 @@ def process_request(self, req, resp):
href='http://docs.examples.com/api/json')


class JSONTranslator(HookableMiddlewareMixin, object):
def process_response(self, req, resp, resource, req_succeeded=True):
if not hasattr(resp, 'body'):
return
if isinstance(resp.data, dict):
resp.data = json.dumps(resp.data)

if isinstance(resp.body, dict):
resp.body = json.dumps(resp.body)


class BaseContextMiddleware(Middleware):
def process_response(self, response):
try:
Expand Down
12 changes: 6 additions & 6 deletions freezer_api/api/v1/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def on_get(self, req, resp):
search = self.json_body(req)
obj_list = self.db.search_action(user_id=user_id, offset=offset,
limit=limit, search=search)
resp.body = {'actions': obj_list}
resp.media = {'actions': obj_list}

@policy.enforce('actions:create')
def on_post(self, req, resp):
Expand All @@ -50,7 +50,7 @@ def on_post(self, req, resp):
user_id = req.get_header('X-User-ID')
action_id = self.db.add_action(user_id=user_id, doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'action_id': action_id}
resp.media = {'action_id': action_id}


class ActionsResource(resource.BaseResource):
Expand All @@ -68,7 +68,7 @@ def on_get(self, req, resp, action_id):
user_id = req.get_header('X-User-ID') or ''
obj = self.db.get_action(user_id=user_id, action_id=action_id)
if obj:
resp.body = obj
resp.media = obj
else:
resp.status = falcon.HTTP_404

Expand All @@ -84,7 +84,7 @@ def on_delete(self, req, resp, action_id):
format(action_id))
else:
self.db.delete_action(user_id=user_id, action_id=action_id)
resp.body = {'action_id': action_id}
resp.media = {'action_id': action_id}
resp.status = falcon.HTTP_204

@policy.enforce('actions:update')
Expand All @@ -95,7 +95,7 @@ def on_patch(self, req, resp, action_id):
new_version = self.db.update_action(user_id=user_id,
action_id=action_id,
patch_doc=doc)
resp.body = {'action_id': action_id, 'version': new_version}
resp.media = {'action_id': action_id, 'version': new_version}

@policy.enforce('actions:replace')
def on_post(self, req, resp, action_id):
Expand All @@ -106,4 +106,4 @@ def on_post(self, req, resp, action_id):
action_id=action_id,
doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'action_id': action_id, 'version': new_version}
resp.media = {'action_id': action_id, 'version': new_version}
8 changes: 4 additions & 4 deletions freezer_api/api/v1/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def on_get(self, req, resp):
search = self.json_body(req)
obj_list = self.db.search_backup(user_id=user_id, offset=offset,
limit=limit, search=search)
resp.body = {'backups': obj_list}
resp.media = {'backups': obj_list}

@policy.enforce('backups:create')
def on_post(self, req, resp):
Expand All @@ -52,7 +52,7 @@ def on_post(self, req, resp):
backup_id = self.db.add_backup(
user_id=user_id, user_name=user_name, doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'backup_id': backup_id}
resp.media = {'backup_id': backup_id}


class BackupsResource(resource.BaseResource):
Expand All @@ -68,7 +68,7 @@ def on_get(self, req, resp, backup_id):
user_id = req.get_header('X-User-ID')
obj = self.db.get_backup(user_id=user_id, backup_id=backup_id)
if obj:
resp.body = obj
resp.media = obj
else:
resp.status = falcon.HTTP_404

Expand All @@ -85,5 +85,5 @@ def on_delete(self, req, resp, backup_id):
else:
self.db.delete_backup(
user_id=user_id, backup_id=backup_id)
resp.body = {'backup_id': backup_id}
resp.media = {'backup_id': backup_id}
resp.status = falcon.HTTP_204
8 changes: 4 additions & 4 deletions freezer_api/api/v1/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def on_get(self, req, resp):
search = self.json_body(req)
obj_list = self.db.get_client(user_id=user_id, offset=offset,
limit=limit, search=search)
resp.body = {'clients': obj_list}
resp.media = {'clients': obj_list}

@policy.enforce('clients:create')
def on_post(self, req, resp):
Expand All @@ -51,7 +51,7 @@ def on_post(self, req, resp):
client_id = self.db.add_client(
user_id=user_id, doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'client_id': client_id}
resp.media = {'client_id': client_id}


class ClientsResource(resource.BaseResource):
Expand All @@ -68,7 +68,7 @@ def on_get(self, req, resp, client_id):
user_id = req.get_header('X-User-ID') or ''
obj = self.db.get_client(user_id=user_id, client_id=client_id)
if obj:
resp.body = obj[0]
resp.media = obj[0]
else:
resp.status = falcon.HTTP_404

Expand All @@ -85,5 +85,5 @@ def on_delete(self, req, resp, client_id):
else:
self.db.delete_client(
user_id=user_id, client_id=client_id)
resp.body = {'client_id': client_id}
resp.media = {'client_id': client_id}
resp.status = falcon.HTTP_204
14 changes: 7 additions & 7 deletions freezer_api/api/v1/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def on_get(self, req, resp):
search = self.json_body(req)
obj_list = self.db.search_job(user_id=user_id, offset=offset,
limit=limit, search=search)
resp.body = {'jobs': obj_list}
resp.media = {'jobs': obj_list}

@policy.enforce('jobs:create')
def on_post(self, req, resp):
Expand All @@ -92,7 +92,7 @@ def on_post(self, req, resp):
self.update_actions_in_job(user_id, job.doc)
job_id = self.db.add_job(user_id=user_id, doc=job.doc)
resp.status = falcon.HTTP_201
resp.body = {'job_id': job_id}
resp.media = {'job_id': job_id}


class JobsResource(JobsBaseResource):
Expand All @@ -107,7 +107,7 @@ def on_get(self, req, resp, job_id):
user_id = req.get_header('X-User-ID') or ''
obj = self.db.get_job(user_id=user_id, job_id=job_id)
if obj:
resp.body = obj
resp.media = obj
else:
resp.status = falcon.HTTP_404

Expand All @@ -122,7 +122,7 @@ def on_delete(self, req, resp, job_id):
format(job_id))
else:
self.db.delete_job(user_id=user_id, job_id=job_id)
resp.body = {'job_id': job_id}
resp.media = {'job_id': job_id}
resp.status = falcon.HTTP_204

@policy.enforce('jobs:update')
Expand All @@ -134,7 +134,7 @@ def on_patch(self, req, resp, job_id):
new_version = self.db.update_job(user_id=user_id,
job_id=job_id,
patch_doc=job.doc)
resp.body = {'job_id': job_id, 'version': new_version}
resp.media = {'job_id': job_id, 'version': new_version}

@policy.enforce('jobs:create')
def on_post(self, req, resp, job_id):
Expand All @@ -146,7 +146,7 @@ def on_post(self, req, resp, job_id):
job_id=job_id,
doc=job.doc)
resp.status = falcon.HTTP_201
resp.body = {'job_id': job_id, 'version': new_version}
resp.media = {'job_id': job_id, 'version': new_version}


class JobsEvent(resource.BaseResource):
Expand Down Expand Up @@ -184,7 +184,7 @@ def on_post(self, req, resp, job_id):
job_id=job_id,
doc=job.doc)
resp.status = falcon.HTTP_202
resp.body = {'result': result}
resp.media = {'result': result}


class Action(object):
Expand Down
16 changes: 8 additions & 8 deletions freezer_api/api/v1/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def on_get(self, req, resp):
search = self.json_body(req)
obj_list = self.db.search_session(user_id=user_id, offset=offset,
limit=limit, search=search)
resp.body = {'sessions': obj_list}
resp.media = {'sessions': obj_list}

@policy.enforce('sessions:create')
def on_post(self, req, resp):
Expand All @@ -52,7 +52,7 @@ def on_post(self, req, resp):
user_id = req.get_header('X-User-ID')
session_id = self.db.add_session(user_id=user_id, doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'session_id': session_id}
resp.media = {'session_id': session_id}


class SessionsResource(resource.BaseResource):
Expand All @@ -70,7 +70,7 @@ def on_get(self, req, resp, session_id):
user_id = req.get_header('X-User-ID') or ''
obj = self.db.get_session(user_id=user_id, session_id=session_id)
if obj:
resp.body = obj
resp.media = obj
else:
resp.status = falcon.HTTP_404

Expand All @@ -86,7 +86,7 @@ def on_delete(self, req, resp, session_id):
format(session_id))
else:
self.db.delete_session(user_id=user_id, session_id=session_id)
resp.body = {'session_id': session_id}
resp.media = {'session_id': session_id}
resp.status = falcon.HTTP_204

@policy.enforce('sessions:update')
Expand All @@ -97,7 +97,7 @@ def on_patch(self, req, resp, session_id):
new_version = self.db.update_session(user_id=user_id,
session_id=session_id,
patch_doc=doc)
resp.body = {'session_id': session_id, 'version': new_version}
resp.media = {'session_id': session_id, 'version': new_version}

@policy.enforce('sessions:replace')
def on_post(self, req, resp, session_id):
Expand All @@ -111,7 +111,7 @@ def on_post(self, req, resp, session_id):
session_id=session_id,
doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'session_id': session_id, 'version': new_version}
resp.media = {'session_id': session_id, 'version': new_version}


class SessionsAction(resource.BaseResource):
Expand Down Expand Up @@ -145,8 +145,8 @@ def on_post(self, req, resp, session_id):
session_id=session_id,
patch_doc=session.doc)
resp.status = falcon.HTTP_202
resp.body = {'result': session.action_result,
'session_tag': session.session_tag}
resp.media = {'result': session.action_result,
'session_tag': session.session_tag}


class Session(resource.BaseResource):
Expand Down
12 changes: 6 additions & 6 deletions freezer_api/api/v2/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def on_get(self, req, resp, project_id):
obj_list = self.db.search_action(project_id=project_id,
user_id=user_id, offset=offset,
limit=limit, search=search)
resp.body = {'actions': obj_list}
resp.media = {'actions': obj_list}

@policy.enforce('actions:create')
def on_post(self, req, resp, project_id):
Expand All @@ -53,7 +53,7 @@ def on_post(self, req, resp, project_id):
user_id=user_id,
doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'action_id': action_id}
resp.media = {'action_id': action_id}


class ActionsResource(resource.BaseResource):
Expand All @@ -74,7 +74,7 @@ def on_get(self, req, resp, project_id, action_id):
user_id=user_id,
action_id=action_id)
if obj:
resp.body = obj
resp.media = obj
else:
resp.status = falcon.HTTP_404

Expand All @@ -86,7 +86,7 @@ def on_delete(self, req, resp, project_id, action_id):
self.db.delete_action(project_id=project_id,
user_id=user_id,
action_id=action_id)
resp.body = {'action_id': action_id}
resp.media = {'action_id': action_id}
resp.status = falcon.HTTP_204

@policy.enforce('actions:update')
Expand All @@ -99,7 +99,7 @@ def on_patch(self, req, resp, project_id, action_id):
user_id=user_id,
action_id=action_id,
patch_doc=doc)
resp.body = {'action_id': action_id, 'version': new_version}
resp.media = {'action_id': action_id, 'version': new_version}

@policy.enforce('actions:replace')
def on_post(self, req, resp, project_id, action_id):
Expand All @@ -112,4 +112,4 @@ def on_post(self, req, resp, project_id, action_id):
action_id=action_id,
doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'action_id': action_id, 'version': new_version}
resp.media = {'action_id': action_id, 'version': new_version}
8 changes: 4 additions & 4 deletions freezer_api/api/v2/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def on_get(self, req, resp, project_id):
obj_list = self.db.search_backup(project_id=project_id,
user_id=user_id, offset=offset,
limit=limit, search=search)
resp.body = {'backups': obj_list}
resp.media = {'backups': obj_list}

@policy.enforce('backups:create')
def on_post(self, req, resp, project_id):
Expand All @@ -55,7 +55,7 @@ def on_post(self, req, resp, project_id):
user_name=user_name,
doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'backup_id': backup_id}
resp.media = {'backup_id': backup_id}


class BackupsResource(resource.BaseResource):
Expand All @@ -73,7 +73,7 @@ def on_get(self, req, resp, project_id, backup_id):
user_id=user_id,
backup_id=backup_id)
if obj:
resp.body = obj
resp.media = obj
else:
resp.status = falcon.HTTP_404

Expand All @@ -85,5 +85,5 @@ def on_delete(self, req, resp, project_id, backup_id):
self.db.delete_backup(project_id=project_id,
user_id=user_id,
backup_id=backup_id)
resp.body = {'backup_id': backup_id}
resp.media = {'backup_id': backup_id}
resp.status = falcon.HTTP_204
8 changes: 4 additions & 4 deletions freezer_api/api/v2/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def on_get(self, req, resp, project_id):
offset=offset,
limit=limit,
search=search)
resp.body = {'clients': obj_list}
resp.media = {'clients': obj_list}

@policy.enforce('clients:create')
def on_post(self, req, resp, project_id):
Expand All @@ -54,7 +54,7 @@ def on_post(self, req, resp, project_id):
client_id = self.db.add_client(
project_id=project_id, user_id=user_id, doc=doc)
resp.status = falcon.HTTP_201
resp.body = {'client_id': client_id}
resp.media = {'client_id': client_id}


class ClientsResource(resource.BaseResource):
Expand All @@ -73,7 +73,7 @@ def on_get(self, req, resp, project_id, client_id):
user_id=user_id,
client_id=client_id)
if obj:
resp.body = obj[0]
resp.media = obj[0]
else:
resp.status = falcon.HTTP_404

Expand All @@ -85,5 +85,5 @@ def on_delete(self, req, resp, project_id, client_id):
self.db.delete_client(project_id=project_id,
user_id=user_id,
client_id=client_id)
resp.body = {'client_id': client_id}
resp.media = {'client_id': client_id}
resp.status = falcon.HTTP_204
Loading

0 comments on commit c826b3a

Please sign in to comment.