def check_copy_source(self, app): """ check_copy_source checks the copy source existence :return : last modified str if copy-source header exist otherwise None """ if 'X-Amz-Copy-Source' in self.headers: src_path = self.headers['X-Amz-Copy-Source'] src_path = src_path if src_path.startswith('/') else \ ('/' + src_path) src_bucket, src_obj = split_path(src_path, 0, 2, True) headers = swob.HeaderKeyDict() headers.update(self._copy_source_headers()) src_resp = self.get_response(app, 'HEAD', src_bucket, src_obj, headers=headers) if src_resp.status_int == 304: # pylint: disable-msg=E1101 raise PreconditionFailed() return src_resp.last_modified.isoformat()[:-6] return None
def check_copy_source(self, app): """ check_copy_source checks the copy source existence and if copying an object to itself, for illegal request parameters :returns: the source HEAD response """ try: src_path = self.headers['X-Amz-Copy-Source'] except KeyError: return None if '?' in src_path: src_path, qs = src_path.split('?', 1) query = parse_qsl(qs, True) if not query: pass # ignore it elif len(query) > 1 or query[0][0] != 'versionId': raise InvalidArgument('X-Amz-Copy-Source', self.headers['X-Amz-Copy-Source'], 'Unsupported copy source parameter.') elif query[0][1] != 'null': # TODO: once we support versioning, we'll need to translate # src_path to the proper location in the versions container raise S3NotImplemented('Versioning is not yet supported') self.headers['X-Amz-Copy-Source'] = src_path src_path = unquote(src_path) src_path = src_path if src_path.startswith('/') else ('/' + src_path) src_bucket, src_obj = split_path(src_path, 0, 2, True) headers = swob.HeaderKeyDict() headers.update(self._copy_source_headers()) src_resp = self.get_response(app, 'HEAD', src_bucket, src_obj, headers=headers) if src_resp.status_int == 304: # pylint: disable-msg=E1101 raise PreconditionFailed() self.headers['X-Amz-Copy-Source'] = \ '/' + self.headers['X-Amz-Copy-Source'].lstrip('/') source_container, source_obj = \ split_path(self.headers['X-Amz-Copy-Source'], 1, 2, True) if (self.container_name == source_container and self.object_name == source_obj and self.headers.get('x-amz-metadata-directive', 'COPY') == 'COPY'): raise InvalidRequest("This copy request is illegal " "because it is trying to copy an " "object to itself without " "changing the object's metadata, " "storage class, website redirect " "location or encryption " "attributes.") return src_resp
def check_copy_source(self, app): if 'X-Amz-Copy-Source' in self.headers: src_path = self.headers['X-Amz-Copy-Source'] src_path = src_path if src_path.startswith('/') else \ ('/' + src_path) src_bucket, src_obj = split_path(src_path, 0, 2, True) headers = swob.HeaderKeyDict() headers.update(self._copy_source_headers()) src_resp = self.get_response(app, 'HEAD', src_bucket, src_obj, headers=headers) if src_resp.status_int == 304: # pylint: disable-msg=E1101 raise PreconditionFailed()
def check_copy_source(self, app): """ check_copy_source checks the copy source existence and if copying an object to itself, for illegal request parameters :returns: the source HEAD response """ if 'X-Amz-Copy-Source' not in self.headers: return None src_path = unquote(self.headers['X-Amz-Copy-Source']) src_path = src_path if src_path.startswith('/') else \ ('/' + src_path) src_bucket, src_obj = split_path(src_path, 0, 2, True) headers = swob.HeaderKeyDict() headers.update(self._copy_source_headers()) src_resp = self.get_response(app, 'HEAD', src_bucket, src_obj, headers=headers) if src_resp.status_int == 304: # pylint: disable-msg=E1101 raise PreconditionFailed() self.headers['X-Amz-Copy-Source'] = \ '/' + self.headers['X-Amz-Copy-Source'].lstrip('/') source_container, source_obj = \ split_path(self.headers['X-Amz-Copy-Source'], 1, 2, True) if (self.container_name == source_container and self.object_name == source_obj and self.headers.get( 'x-amz-metadata-directive', 'COPY') == 'COPY'): raise InvalidRequest("This copy request is illegal " "because it is trying to copy an " "object to itself without " "changing the object's metadata, " "storage class, website redirect " "location or encryption " "attributes.") return src_resp