Check parameters are strings on SWF endpoints
SWF endpoints raise a 400 Bad Request for non-string types, and boto
doesn't enforce it as of today, so better have some safety nets in moto
to avoid this common mistake.
Example exception raised by Boto:
SWFResponseError: SWFResponseError: 400 Bad Request
{u'Message': u'class java.lang.Short can not be converted to an String',
u'__type': u'com.amazon.coral.service#SerializationException'}
This commit is contained in:
parent
8e3fd6c7de
commit
5392978eaf
3 changed files with 44 additions and 6 deletions
|
|
@ -7,6 +7,7 @@ from .exceptions import (
|
|||
SWFUnknownResourceFault,
|
||||
SWFDomainAlreadyExistsFault,
|
||||
SWFDomainDeprecatedFault,
|
||||
SWFSerializationException,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -40,12 +41,21 @@ class SWFBackend(BaseBackend):
|
|||
return matching[0]
|
||||
return None
|
||||
|
||||
def _check_string(self, parameter):
|
||||
if not isinstance(parameter, basestring):
|
||||
raise SWFSerializationException()
|
||||
|
||||
def list_domains(self, status):
|
||||
self._check_string(status)
|
||||
return [domain for domain in self.domains
|
||||
if domain.status == status]
|
||||
|
||||
def register_domain(self, name, workflow_execution_retention_period_in_days,
|
||||
description=None):
|
||||
self._check_string(name)
|
||||
self._check_string(workflow_execution_retention_period_in_days)
|
||||
if description:
|
||||
self._check_string(description)
|
||||
if self._get_domain(name, ignore_empty=True):
|
||||
raise SWFDomainAlreadyExistsFault(name)
|
||||
domain = Domain(name, workflow_execution_retention_period_in_days,
|
||||
|
|
@ -53,12 +63,14 @@ class SWFBackend(BaseBackend):
|
|||
self.domains.append(domain)
|
||||
|
||||
def deprecate_domain(self, name):
|
||||
self._check_string(name)
|
||||
domain = self._get_domain(name)
|
||||
if domain.status == "DEPRECATED":
|
||||
raise SWFDomainDeprecatedFault(name)
|
||||
domain.status = "DEPRECATED"
|
||||
|
||||
def describe_domain(self, name):
|
||||
self._check_string(name)
|
||||
return self._get_domain(name)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue