Skip to content

Commit

Permalink
IOT - delete_thing only when no certificates are attached (#4712)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers committed Dec 22, 2021
1 parent 80e3b35 commit c301f88
Show file tree
Hide file tree
Showing 13 changed files with 2,562 additions and 2,420 deletions.
9 changes: 9 additions & 0 deletions moto/iot/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ def __init__(self, name):
"VersionsLimitExceededException",
"The policy %s already has the maximum number of versions (5)" % name,
)


class ThingStillAttached(IoTClientError):
def __init__(self, name):
self.code = 409
super().__init__(
"InvalidRequestException",
f"Cannot delete. Thing {name} is still attached to one or more principals",
)
3 changes: 2 additions & 1 deletion moto/iot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
VersionConflictException,
ResourceAlreadyExistsException,
VersionsLimitExceededException,
ThingStillAttached,
)


Expand Down Expand Up @@ -697,7 +698,7 @@ def delete_thing(self, thing_name, expected_version):
# detach all principals
for k in list(self.principal_things.keys()):
if k[1] == thing_name:
del self.principal_things[k]
raise ThingStillAttached(thing_name)

del self.things[thing.arn]

Expand Down
Loading

0 comments on commit c301f88

Please sign in to comment.