Implement Tags for S3 bucket
Use the metadata to hold the tags. Change-Id: I52d8bb9429a90529431622c72ff2484e6c38c58e
This commit is contained in:
parent
5fb5bf7289
commit
b044fa8096
|
@ -30,6 +30,12 @@ class S3Bucket(resource.Resource):
|
|||
'ErrorDocument': {
|
||||
'Type': 'String',
|
||||
'Description': _('The name of the error document.')}}
|
||||
tags_schema = {'Key': {'Type': 'String',
|
||||
'Description': _('The tag key name.'),
|
||||
'Required': True},
|
||||
'Value': {'Type': 'String',
|
||||
'Description': _('The tag value.'),
|
||||
'Required': True}}
|
||||
|
||||
properties_schema = {
|
||||
'AccessControl': {
|
||||
|
@ -47,6 +53,11 @@ class S3Bucket(resource.Resource):
|
|||
'Schema': website_schema,
|
||||
'Description': _('Information used to configure the bucket as '
|
||||
'a static website.')},
|
||||
'Tags': {
|
||||
'Type': 'List',
|
||||
'Schema': {'Type': 'Map', 'Schema': tags_schema},
|
||||
'Required': False,
|
||||
'Description': _('Tags to attach to the bucket.')},
|
||||
}
|
||||
attributes_schema = {
|
||||
'DomainName': _('The DNS name of the specified bucket.'),
|
||||
|
@ -62,10 +73,17 @@ class S3Bucket(resource.Resource):
|
|||
return {'Error':
|
||||
'S3 services unavailable because of missing swiftclient.'}
|
||||
|
||||
def tags_to_headers(self):
|
||||
if self.properties['Tags'] is None:
|
||||
return {}
|
||||
return dict(
|
||||
('X-Container-Meta-S3-Tag-' + tm['Key'], tm['Value'])
|
||||
for tm in self.properties['Tags'])
|
||||
|
||||
def handle_create(self):
|
||||
"""Create a bucket."""
|
||||
container = self.physical_resource_name()
|
||||
headers = {}
|
||||
headers = self.tags_to_headers()
|
||||
logger.debug('S3Bucket create container %s with headers %s' %
|
||||
(container, headers))
|
||||
if self.properties['WebsiteConfiguration'] is not None:
|
||||
|
|
|
@ -55,6 +55,13 @@ swift_template = '''
|
|||
"Properties" : {
|
||||
"AccessControl" : "Private"
|
||||
}
|
||||
},
|
||||
"S3Bucket_with_tags" : {
|
||||
"Type" : "AWS::S3::Bucket",
|
||||
"Properties" : {
|
||||
"Tags" : [{"Key": "greeting", "Value": "hello"},
|
||||
{"Key": "location", "Value": "here"}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,6 +146,26 @@ class s3Test(HeatTestCase):
|
|||
scheduler.TaskRunner(rsrc.delete)()
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_tags(self):
|
||||
clients.OpenStackClients.keystone().AndReturn(
|
||||
fakes.FakeKeystoneClient())
|
||||
container_name = utils.PhysName('test_stack', 'test_resource')
|
||||
swiftclient.Connection.put_container(
|
||||
utils.PhysName('test_stack', 'test_resource'),
|
||||
{'X-Container-Write': 'test_tenant:test_username',
|
||||
'X-Container-Read': 'test_tenant:test_username',
|
||||
'X-Container-Meta-S3-Tag-greeting': 'hello',
|
||||
'X-Container-Meta-S3-Tag-location': 'here'}).AndReturn(None)
|
||||
swiftclient.Connection.delete_container(
|
||||
container_name).AndReturn(None)
|
||||
|
||||
self.m.ReplayAll()
|
||||
t = template_format.parse(swift_template)
|
||||
stack = utils.parse_stack(t)
|
||||
rsrc = self.create_resource(t, stack, 'S3Bucket_with_tags')
|
||||
scheduler.TaskRunner(rsrc.delete)()
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_public_read_write(self):
|
||||
clients.OpenStackClients.keystone().AndReturn(
|
||||
fakes.FakeKeystoneClient())
|
||||
|
|
Loading…
Reference in New Issue