This patch adds support for XML validation with RelaxNG. The original S3 schema is available at http://doc.s3.amazonaws.com/2006-03-01/AmazonS3.xsd, but I write a schema for swift3 from scratch. It is because: - The original schema does not support all of the latest S3 API. Even if we use it, we have to update and maintain it in either way. - The original schema is written with XML Schema, but the language is not enough to describe some of the latest S3 API. For example, the Multi-Object Delete operation sends an XML document, which can interleave a Quiet element with Object elements. XML Schema cannot define such kinds of XML documents. This patch includes both RelaxNG (rng) and RelaxNG compact syntax files (rnc) for validation. What I wrote are only rnc files, and rng files are automatically generated from rnc with trang, the most well-known schema converter. If possible, I'd like to use only rnc schemas since rng files are complicated and not so human-readable. However, lxml doesn't support RelaxNG compact syntax currently, unfortunately. After lxml supports compact syntax, let's remove all of the rng files. This patch also fixes some XML errors detected by RelaxNG validator, and some helper methods to convert strings between camel-case name and snake-case name. Change-Id: I4513345a6b981efc5d5f5e8cf528aba84ac1bdad
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
# Copyright (c) 2010-2014 OpenStack Foundation.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from simplejson import loads
|
|
|
|
from swift3.controllers.base import Controller
|
|
from swift3.etree import Element, SubElement, tostring
|
|
from swift3.response import HTTPOk
|
|
|
|
|
|
class ServiceController(Controller):
|
|
"""
|
|
Handles account level requests.
|
|
"""
|
|
def GET(self, req):
|
|
"""
|
|
Handle GET Service request
|
|
"""
|
|
resp = req.get_response(self.app, query={'format': 'json'})
|
|
|
|
containers = loads(resp.body)
|
|
# we don't keep the creation time of a backet (s3cmd doesn't
|
|
# work without that) so we use something bogus.
|
|
elem = Element('ListAllMyBucketsResult')
|
|
|
|
owner = SubElement(elem, 'Owner')
|
|
SubElement(owner, 'ID').text = req.user_id
|
|
SubElement(owner, 'DisplayName').text = req.user_id
|
|
|
|
buckets = SubElement(elem, 'Buckets')
|
|
for c in containers:
|
|
bucket = SubElement(buckets, 'Bucket')
|
|
SubElement(bucket, 'Name').text = c['name']
|
|
SubElement(bucket, 'CreationDate').text = \
|
|
'2009-02-03T16:45:09.000Z'
|
|
|
|
body = tostring(elem)
|
|
|
|
return HTTPOk(content_type='application/xml', body=body)
|