Skip to content

Commit

Permalink
Changed how identifiers are handled (for better behavior on methods l…
Browse files Browse the repository at this point in the history
…ike ``.get(…)``).
  • Loading branch information
toastdriven committed Nov 28, 2013
1 parent 196bd44 commit e5694c2
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 205 deletions.
67 changes: 33 additions & 34 deletions boto3/core/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,36 +115,17 @@ def api_version(self):
return self._api_version

@property
def identifier_var_name(self):
def identifiers(self):
"""
Returns variable name of the identifier.
This should be the name the ``Resource`` should look for from the user
as the unique identifer for the resource server-side.
Returns the identifiers.
If the data has been previously accessed, a memoized version of the
variable name is returned.
:returns: The identifier's variable name (from Python)
:rtype: string
"""
return self.resource_data['identifier']['var_name']

@property
def identifier_api_name(self):
"""
Returns API name of the identifier.
This should be the name the ``Resource`` should look for from the API
(server-side) as the unique identifer for the resource.
If the data has been previously accessed, a memoized version of the
API name is returned.
:returns: The identifier's API name (from server-side)
:rtype: string
:returns: The identifiers
:rtype: dict
"""
return self.resource_data['identifier']['api_name']
return self.resource_data['identifiers']


class Resource(object):
Expand Down Expand Up @@ -227,25 +208,37 @@ def _update_docstrings(self):
conn_meth = getattr(self._connection, to_snake_case(api_name))
meth.__doc__ = conn_meth.__doc__

def get_identifier(self):
def get_identifiers(self):
"""
Returns the identifier (if present) from the instance data.
Returns the identifier(s) (if present) from the instance data.
This identifier name is determined from the ``ResourceDetails``
The identifier name(s) is/are determined from the ``ResourceDetails``
instance hanging off the class itself.
:returns: All the identifier information
:rtype: dict
"""
return self._data.get(self._details.identifier_var_name)
data = {}

for id_info in self._details.identifiers:
var_name = id_info['var_name']
data[var_name] = self._data.get(var_name)

def set_identifier(self, value):
return data

def set_identifiers(self, data):
"""
Sets the identifier within the instance data.
Sets the identifier(s) within the instance data.
This identifier name is determined from the ``ResourceDetails``
The identifier name(s) is/are determined from the ``ResourceDetails``
instance hanging off the class itself.
:param value: The value to be set.
:param data: The value(s) to be set.
:param data: dict
"""
self._data[self._details.identifier_var_name] = value
for id_info in self._details.identifiers:
var_name = id_info['var_name']
self._data[var_name] = data.get(var_name)

def full_update_params(self, conn_method_name, params):
"""
Expand Down Expand Up @@ -303,7 +296,7 @@ def update_params(self, conn_method_name, params):
"""
# By default, this just sets the identifier info.
# We use ``var_name`` instead of ``api_name``. Because botocore.
params[self._details.identifier_var_name] = self.get_identifier()
params.update(self.get_identifiers())
return params

def full_post_process(self, conn_method_name, result):
Expand Down Expand Up @@ -362,6 +355,12 @@ def post_process(self, conn_method_name, result):
# Mostly a hook for post-processing as needed.
return result

def post_process_get(self, result):
for key, value in result.items():
self._data[to_snake_case(key)] = value

return result


class ResourceFactory(object):
"""
Expand Down
20 changes: 12 additions & 8 deletions boto3/data/aws/resources/cloudsearch-2011-02-01.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
"resources": {
"Domain": {
"shape_name": "Domain",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"define_index_field": {
"api_name": "DefineIndexField"
Expand Down Expand Up @@ -84,10 +86,12 @@
},
"Document": {
"shape_name": "Document",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {},
"relations": {}
}
Expand Down
20 changes: 12 additions & 8 deletions boto3/data/aws/resources/dynamodb-2012-08-10.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
"resources": {
"Table": {
"shape_name": "Table",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"get": {
"api_name": "DescribeTable"
Expand All @@ -54,10 +56,12 @@
},
"Item": {
"shape_name": "Item",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"get": {
"api_name": "GetItem"
Expand Down
50 changes: 30 additions & 20 deletions boto3/data/aws/resources/elasticache-2013-06-15.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@
"resources": {
"CacheCluster": {
"shape_name": "CacheCluster",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"delete": {
"api_name": "DeleteCacheCluster"
Expand All @@ -96,10 +98,12 @@
},
"CacheParameterGroup": {
"shape_name": "CacheParameterGroup",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"delete": {
"api_name": "DeleteCacheParameterGroup"
Expand All @@ -118,10 +122,12 @@
},
"CacheSecurityGroup": {
"shape_name": "CacheSecurityGroup",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"authorize_ingress": {
"api_name": "AuthorizeCacheSecurityGroupIngress"
Expand All @@ -137,10 +143,12 @@
},
"CacheSubnetGroup": {
"shape_name": "CacheSubnetGroup",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"delete": {
"api_name": "DeleteCacheSubnetGroup"
Expand All @@ -153,10 +161,12 @@
},
"ReplicationGroup": {
"shape_name": "ReplicationGroup",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"delete": {
"api_name": "DeleteReplicationGroup"
Expand Down
30 changes: 18 additions & 12 deletions boto3/data/aws/resources/elastictranscoder-2012-09-25.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
"resources": {
"Pipeline": {
"shape_name": "Pipeline",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"get": {
"api_name": "ReadPipeline"
Expand All @@ -68,10 +70,12 @@
},
"Preset": {
"shape_name": "Preset",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"get": {
"api_name": "ReadPreset"
Expand All @@ -84,10 +88,12 @@
},
"Job": {
"shape_name": "Job",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"get": {
"api_name": "ReadJob"
Expand Down
40 changes: 24 additions & 16 deletions boto3/data/aws/resources/glacier-2012-06-01.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
"resources": {
"Vault": {
"shape_name": "Vault",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"get": {
"api_name": "DescribeVault"
Expand All @@ -70,10 +72,12 @@
},
"Archive": {
"shape_name": "Archive",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"delete": {
"api_name": "DeleteArchive"
Expand All @@ -83,10 +87,12 @@
},
"MultipartUpload": {
"shape_name": "MultipartUpload",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"abort": {
"api_name": "AbortMultipartUpload"
Expand All @@ -102,10 +108,12 @@
},
"Job": {
"shape_name": "Job",
"identifier": {
"var_name": "id",
"api_name": "$shape_name.Id"
},
"identifiers": [
{
"var_name": "id",
"api_name": "$shape_name.Id"
}
],
"operations": {
"get": {
"api_name": "GetJobOutput"
Expand Down
Loading

0 comments on commit e5694c2

Please sign in to comment.