"Fossies" - the Fresh Open Source Software Archive

Member "swift-2.21.0/swift/common/middleware/s3api/controllers/s3_acl.py" (25 Mar 2019, 2082 Bytes) of package /linux/misc/openstack/swift-2.21.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "s3_acl.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.19.1_vs_2.21.0.

    1 # Copyright (c) 2014 OpenStack Foundation.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    4 # you may not use this file except in compliance with the License.
    5 # You may obtain a copy of the License at
    6 #
    7 #    http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS,
   11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   12 # implied.
   13 # See the License for the specific language governing permissions and
   14 # limitations under the License.
   15 
   16 from six.moves.urllib.parse import quote
   17 from swift.common.utils import public
   18 
   19 from swift.common.middleware.s3api.controllers.base import Controller
   20 from swift.common.middleware.s3api.s3response import HTTPOk
   21 from swift.common.middleware.s3api.etree import tostring
   22 
   23 
   24 class S3AclController(Controller):
   25     """
   26     Handles the following APIs:
   27 
   28     * GET Bucket acl
   29     * PUT Bucket acl
   30     * GET Object acl
   31     * PUT Object acl
   32 
   33     Those APIs are logged as ACL operations in the S3 server log.
   34     """
   35     @public
   36     def GET(self, req):
   37         """
   38         Handles GET Bucket acl and GET Object acl.
   39         """
   40         resp = req.get_response(self.app)
   41 
   42         acl = resp.object_acl if req.is_object_request else resp.bucket_acl
   43 
   44         resp = HTTPOk()
   45         resp.body = tostring(acl.elem())
   46 
   47         return resp
   48 
   49     @public
   50     def PUT(self, req):
   51         """
   52         Handles PUT Bucket acl and PUT Object acl.
   53         """
   54         if req.is_object_request:
   55             headers = {}
   56             src_path = '/%s/%s' % (req.container_name, req.object_name)
   57 
   58             # object-sysmeta' can be updated by 'Copy' method,
   59             # but can not be by 'POST' method.
   60             # So headers['X-Copy-From'] for copy request is added here.
   61             headers['X-Copy-From'] = quote(src_path)
   62             headers['Content-Length'] = 0
   63             req.get_response(self.app, 'PUT', headers=headers)
   64         else:
   65             req.get_response(self.app, 'POST')
   66 
   67         return HTTPOk()