-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose all resources on a service resource. #60
Changes from 1 commit
20fd57d
a0b77ec
19a6c69
b9e8ae9
e2d3706
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,6 +312,66 @@ def batch_actions(self): | |
|
||
return actions | ||
|
||
def _get_has_definition(self): | ||
""" | ||
Get a ``has`` relationship definition from a model, where the | ||
service resource model is treated special in that it contains | ||
a relationship to every resource defined for the service. This | ||
allows things like ``s3.Object('bucket-name', 'key')`` to | ||
work even though the JSON doesn't define it explicitly. | ||
|
||
@rtype: dict | ||
@return: Mapping of names to subresource and reference | ||
definitions. | ||
""" | ||
if self.name not in self._resource_defs: | ||
# This is the service resource, so let us expose all of | ||
# the defined resources as subresources. | ||
definition = {} | ||
|
||
for name, resource_def in self._resource_defs.items(): | ||
# It's possible for the service to have renamed a | ||
# resource, so we need to take that into account and | ||
# search for the same resource type. | ||
has_items = self._definition.get('has', {}).items() | ||
for has_name, has_def in has_items: | ||
if has_def.get('resource', {}).get('type') == name: | ||
definition[has_name] = has_def | ||
break | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this else coming from? It does not look in line with any if statement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's from the |
||
# Create a relationship definition and attach it | ||
# to the model, such that all identifiers must be | ||
# supplied by the user. It will look something like: | ||
# | ||
# { | ||
# 'resource': { | ||
# 'type': 'ResourceName', | ||
# 'identifiers': [ | ||
# {'target': 'Name1', 'source': 'input'}, | ||
# {'target': 'Name2', 'source': 'input'}, | ||
# ... | ||
# ] | ||
# } | ||
# } | ||
# | ||
fake_has = { | ||
'resource': { | ||
'type': name, | ||
'identifiers': [] | ||
} | ||
} | ||
|
||
for identifier in resource_def.get('identifiers', []): | ||
fake_has['resource']['identifiers'].append({ | ||
'target': identifier['name'], 'source': 'input' | ||
}) | ||
|
||
definition[name] = fake_has | ||
else: | ||
definition = self._definition.get('has', {}) | ||
|
||
return definition | ||
|
||
def _get_related_resources(self, subresources): | ||
""" | ||
Get a list of sub-resources or references. | ||
|
@@ -323,7 +383,7 @@ def _get_related_resources(self, subresources): | |
""" | ||
resources = [] | ||
|
||
for name, definition in self._definition.get('has', {}).items(): | ||
for name, definition in self._get_has_definition().items(): | ||
action = Action(name, definition, self._resource_defs) | ||
|
||
data_required = False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's with the @rtype: notation?