MediaStore delete container and list tags endpoints implemented (#3938)

* Add delete container and list tags endpoints to MediaStore

* Black reformat

* Fixed Lint problems

* Check if dictionary was deleted effectively

* lint fix

Co-authored-by: av <arcovoltaico@gmail.com>
This commit is contained in:
Jordi Alhambra 2021-05-20 16:17:31 +01:00 committed by GitHub
commit 7f49cd0ed6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 6 deletions

View file

@ -1,4 +1,5 @@
from __future__ import unicode_literals
from moto.core.exceptions import JsonRESTError
@ -6,6 +7,15 @@ class MediaStoreClientError(JsonRESTError):
code = 400
class ContainerNotFoundException(MediaStoreClientError):
def __init__(self, msg=None):
self.code = 400
super(ContainerNotFoundException, self).__init__(
"ContainerNotFoundException",
msg or "The specified container does not exist",
)
class ResourceNotFoundException(MediaStoreClientError):
def __init__(self, msg=None):
self.code = 400

View file

@ -1,9 +1,16 @@
from __future__ import unicode_literals
from boto3 import Session
from moto.core import BaseBackend, BaseModel
from collections import OrderedDict
from datetime import date
from .exceptions import ResourceNotFoundException, PolicyNotFoundException
from boto3 import Session
from moto.core import BaseBackend, BaseModel
from .exceptions import (
ContainerNotFoundException,
ResourceNotFoundException,
PolicyNotFoundException,
)
class Container(BaseModel):
@ -16,6 +23,7 @@ class Container(BaseModel):
self.lifecycle_policy = None
self.policy = None
self.metric_policy = None
self.tags = kwargs.get("tags")
def to_dict(self, exclude=None):
data = {
@ -24,6 +32,7 @@ class Container(BaseModel):
"Endpoint": self.endpoint,
"Status": self.status,
"CreationTime": self.creation_time,
"Tags": self.tags,
}
if exclude:
for key in exclude:
@ -50,10 +59,17 @@ class MediaStoreBackend(BaseBackend):
endpoint="/{}".format(name),
status="CREATING",
creation_time=date.today().strftime("%m/%d/%Y, %H:%M:%S"),
tags=tags,
)
self._containers[name] = container
return container
def delete_container(self, name):
if name not in self._containers:
raise ContainerNotFoundException()
del self._containers[name]
return {}
def describe_container(self, name):
if name not in self._containers:
raise ResourceNotFoundException()
@ -66,6 +82,10 @@ class MediaStoreBackend(BaseBackend):
response_containers = [c.to_dict() for c in containers]
return response_containers, None
def list_tags_for_resource(self, name):
tags = self._containers[name].tags
return tags
def put_lifecycle_policy(self, container_name, lifecycle_policy):
if container_name not in self._containers:
raise ResourceNotFoundException()

View file

@ -1,7 +1,9 @@
from __future__ import unicode_literals
import json
from moto.core.responses import BaseResponse
from .models import mediastore_backends
import json
class MediaStoreResponse(BaseResponse):
@ -17,6 +19,11 @@ class MediaStoreResponse(BaseResponse):
container = self.mediastore_backend.create_container(name=name, tags=tags)
return json.dumps(dict(Container=container.to_dict()))
def delete_container(self):
name = self._get_param("ContainerName")
result = self.mediastore_backend.delete_container(name=name)
return json.dumps(result)
def describe_container(self):
name = self._get_param("ContainerName")
container = self.mediastore_backend.describe_container(name=name)
@ -30,6 +37,11 @@ class MediaStoreResponse(BaseResponse):
)
return json.dumps(dict(dict(Containers=containers), NextToken=next_token))
def list_tags_for_resource(self):
name = self._get_param("Resource")
tags = self.mediastore_backend.list_tags_for_resource(name)
return json.dumps(dict(Tags=tags))
def put_lifecycle_policy(self):
container_name = self._get_param("ContainerName")
lifecycle_policy = self._get_param("LifecyclePolicy")