fix #2392 Add validation for shadow version,when update_thing_shadow() has called
This commit is contained in:
parent
3a5d857a60
commit
778fc47c21
3 changed files with 17 additions and 0 deletions
|
|
@ -21,3 +21,11 @@ class InvalidRequestException(IoTDataPlaneClientError):
|
|||
super(InvalidRequestException, self).__init__(
|
||||
"InvalidRequestException", message
|
||||
)
|
||||
|
||||
|
||||
class ConflictException(IoTDataPlaneClientError):
|
||||
def __init__(self, message):
|
||||
self.code = 409
|
||||
super(ConflictException, self).__init__(
|
||||
"ConflictException", message
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import jsondiff
|
|||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.iot import iot_backends
|
||||
from .exceptions import (
|
||||
ConflictException,
|
||||
ResourceNotFoundException,
|
||||
InvalidRequestException
|
||||
)
|
||||
|
|
@ -161,6 +162,8 @@ class IoTDataPlaneBackend(BaseBackend):
|
|||
if any(_ for _ in payload['state'].keys() if _ not in ['desired', 'reported']):
|
||||
raise InvalidRequestException('State contains an invalid node')
|
||||
|
||||
if 'version' in payload and thing.thing_shadow.version != payload['version']:
|
||||
raise ConflictException('Version conflict')
|
||||
new_shadow = FakeShadow.create_from_previous_version(thing.thing_shadow, payload)
|
||||
thing.thing_shadow = new_shadow
|
||||
return thing.thing_shadow
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue