Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
storage-service: Added optional secure parameter. (#15)
Browse files Browse the repository at this point in the history
There are times when other components will need to request secure
content from the storage service. This change adds a secure parameter to
on_get, on_save, and on_list which passes the bool to the model.
  • Loading branch information
ashcrow authored and mbarnes committed Oct 5, 2016
1 parent cd0ca30 commit 388a854
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/commissaire_service/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _build_model(self, model_type_name, model_kwargs):
model_type = self._model_types[model_type_name]
return model_type.new(**model_kwargs)

def on_save(self, message, model_type_name, model_json_data):
def on_save(self, message, model_type_name, model_json_data, secure=False):
"""
Handler for the "storage.save" routing key.
Expand All @@ -135,14 +135,16 @@ def on_save(self, message, model_type_name, model_json_data):
:type model_type_name: str
:param model_json_data: JSON representation of a model
:type model_json_data: str
:param secure: If the resulting dict should include secure content.
:type secure: bool
:returns: full dict representation of the model
:rtype: dict
"""
model_instance = self._build_model(model_type_name, model_json_data)
saved_model_instance = self._manager.save(model_instance)
return saved_model_instance.to_dict()
return saved_model_instance.to_dict(secure=secure)

def on_get(self, message, model_type_name, model_json_data):
def on_get(self, message, model_type_name, model_json_data, secure=False):
"""
Handler for the "storage.get" routing key.
Expand All @@ -155,12 +157,14 @@ def on_get(self, message, model_type_name, model_json_data):
:type model_type_name: str
:param model_json_data: JSON identification of a model
:type model_json_data: str
:param secure: If the resulting dict should include secure content.
:type secure: bool
:returns: full dict representation of the model
:rtype: dict
"""
model_instance = self._build_model(model_type_name, model_json_data)
full_model_instance = self._manager.get(model_instance)
return full_model_instance.to_dict()
return full_model_instance.to_dict(secure=secure)

def on_delete(self, message, model_type_name, model_json_data):
"""
Expand All @@ -179,7 +183,7 @@ def on_delete(self, message, model_type_name, model_json_data):
model_instance = self._build_model(model_type_name, model_json_data)
self._manager.delete(model_instance)

def on_list(self, message, model_type_name):
def on_list(self, message, model_type_name, secure=False):
"""
Handler for the "storage.list" routing key.
Expand All @@ -189,12 +193,15 @@ def on_list(self, message, model_type_name):
:type message: kombu.message.Message
:param model_type_name: Model type for the JSON data
:type model_type_name: str
:param secure: If the results should include secure content.
:type secure: bool
:returns: a list of model representations as dicts
:rtype: list
"""
model_type = self._model_types[model_type_name]
model_list = self._manager.list(model_type.new())
return [model_instance.to_dict() for model_instance in model_list]
return [model_instance.to_dict(secure=secure)
for model_instance in model_list]


def main(): # pragma: no cover
Expand Down

0 comments on commit 388a854

Please sign in to comment.