rest_api.py 34.6 KB
Newer Older
Stavros Sachtouris's avatar
Stavros Sachtouris committed
1
# Copyright 2012-2013 GRNET S.A. All rights reserved.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
#   1. Redistributions of source code must retain the above
#      copyright notice, this list of conditions and the following
#      disclaimer.
#
#   2. Redistributions in binary form must reproduce the above
#      copyright notice, this list of conditions and the following
#      disclaimer in the documentation and/or other materials
#      provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

34
from kamaki.clients.storage import StorageClient
35
from kamaki.clients.utils import path4url
36

37

38
class PithosRestClient(StorageClient):
39
    service_type = 'object-store'
40

41
42
43
44
45
46
    def account_head(
            self,
            until=None,
            if_modified_since=None,
            if_unmodified_since=None,
            *args, **kwargs):
47
        """ Full Pithos+ HEAD at account level
48

49
        --- request parameters ---
50
51
52
53
54
55
56
57
58
59
60
61

        :param until: (string) optional timestamp

        --- request headers ---

        :param if_modified_since: (string) Retrieve if account has changed
            since provided timestamp

        :param if_unmodified_since: (string) Retrieve if account has not
            change since provided timestamp

        :returns: ConnectionResponse
62
        """
63
64
        self.response_headers = ['Last-Modified', ]
        self.response_header_prefices = ['X-Account-', ]
65

66
        self._assert_account()
67
68
        path = path4url(self.account)

69
        self.set_param('until', until, iff=until)
70
71
72
73
        self.set_header('If-Modified-Since', if_modified_since)
        self.set_header('If-Unmodified-Since', if_unmodified_since)

        success = kwargs.pop('success', 204)
74
75
76
77
78
        r = self.head(path, *args, success=success, **kwargs)
        self._unquote_header_keys(
            r.headers,
            ('x-account-group-', 'x-account-policy-', 'x-account-meta-'))
        return r
79

80
81
82
83
84
85
    def account_get(
            self,
            limit=None,
            marker=None,
            format='json',
            show_only_shared=False,
86
            public=False,
87
88
89
90
            until=None,
            if_modified_since=None,
            if_unmodified_since=None,
            *args, **kwargs):
91
        """  Full Pithos+ GET at account level
92

93
        --- request parameters ---
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

        :param limit: (integer) The amount of results requested
            (server will use default value if None)

        :param marker: string Return containers with name
            lexicographically after marker

        :param format: (string) reply format can be json or xml
            (default: json)

        :param shared: (bool) If true, only shared containers will be
            included in results

        :param until: (string) optional timestamp

        --- request headers ---

        :param if_modified_since: (string) Retrieve if account has changed
            since provided timestamp

        :param if_unmodified_since: (string) Retrieve if account has not
            changed since provided timestamp

        :returns: ConnectionResponse
118
        """
119
        self._assert_account()
120
121
        self.response_headers = ['Last-Modified', ]
        self.response_header_prefices = ['X-Account-', ]
122

123
124
        self.set_param('limit', limit, iff=limit)
        self.set_param('marker', marker, iff=marker)
125
        self.set_param('format', format, iff=format)
126
        self.set_param('shared', iff=show_only_shared)
127
        self.set_param('public', iff=public)
128
        self.set_param('until', until, iff=until)
129
130
131
132
133
134

        self.set_header('If-Modified-Since', if_modified_since)
        self.set_header('If-Unmodified-Since', if_unmodified_since)

        path = path4url(self.account)
        success = kwargs.pop('success', (200, 204))
135
        return self.get(path, *args, success=success, **kwargs)
136

137
138
139
140
141
142
143
144
    def account_post(
            self,
            update=True,
            groups={},
            metadata=None,
            quota=None,
            versioning=None,
            *args, **kwargs):
145
        """ Full Pithos+ POST at account level
146

147
        --- request parameters ---
148
149
150

        :param update: (bool) if True, Do not replace metadata/groups

151
        --- request headers ---
152
153
154
155
156
157
158
159
160
161
162
163
164
165

        :param groups: (dict) Optional user defined groups in the form
            { 'group1':['user1', 'user2', ...],
            'group2':['userA', 'userB', ...], }

        :param metadata: (dict) Optional user defined metadata in the form
            { 'name1': 'value1', 'name2': 'value2', ... }

        :param quota: (integer) If supported, sets the Account quota

        :param versioning: (string) If supported, sets the Account versioning
            to 'auto' or some other supported versioning string

        :returns: ConnectionResponse
166
        """
167
        self._assert_account()
168

169
        self.set_param('update', '', iff=update)
170

171
172
173
174
175
176
177
178
        if groups:
            for group, usernames in groups.items():
                userstr = ''
                dlm = ''
                for user in usernames:
                    userstr = userstr + dlm + user
                    dlm = ','
                self.set_header('X-Account-Group-' + group, userstr)
179
        if metadata:
180
            for metaname, metaval in metadata.items():
181
                self.set_header('X-Account-Meta-' + metaname, metaval)
182
183
        self.set_header('X-Account-Policy-Quota', quota)
        self.set_header('X-Account-Policy-Versioning', versioning)
184
185
        self._quote_header_keys(
            self.headers, ('x-account-group-', 'x-account-meta'))
186
187
188
189
190

        path = path4url(self.account)
        success = kwargs.pop('success', 202)
        return self.post(path, *args, success=success, **kwargs)

191
192
193
194
195
196
    def container_head(
            self,
            until=None,
            if_modified_since=None,
            if_unmodified_since=None,
            *args, **kwargs):
197
        """ Full Pithos+ HEAD at container level
198

199
        --- request params ---
200
201
202
203
204
205
206
207
208
209
210
211

        :param until: (string) optional timestamp

        --- request headers ---

        :param if_modified_since: (string) Retrieve if account has changed
            since provided timestamp

        :param if_unmodified_since: (string) Retrieve if account has not
            changed since provided timestamp

        :returns: ConnectionResponse
212
        """
213
        self._assert_container()
214
215
        self.response_headers = ['Last-Modified', ]
        self.response_header_prefices = ['X-Container-', ]
216

217
        self.set_param('until', until, iff=until)
218
219
220
221
222
223

        self.set_header('If-Modified-Since', if_modified_since)
        self.set_header('If-Unmodified-Since', if_unmodified_since)

        path = path4url(self.account, self.container)
        success = kwargs.pop('success', 204)
224
225
226
227
        r = self.head(path, *args, success=success, **kwargs)
        self._unquote_header_keys(
            r.headers, ('x-container-policy-', 'x-container-meta-'))
        return r
228

229
230
231
232
233
234
235
236
237
238
    def container_get(
            self,
            limit=None,
            marker=None,
            prefix=None,
            delimiter=None,
            path=None,
            format='json',
            meta=[],
            show_only_shared=False,
239
            public=False,
240
241
242
243
            until=None,
            if_modified_since=None,
            if_unmodified_since=None,
            *args, **kwargs):
244
        """ Full Pithos+ GET at container level
245

246
        --- request parameters ---
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267

        :param limit: (integer) The amount of results requested
            (server will use default value if None)

        :param marker: (string) Return containers with name lexicographically
            after marker

        :param prefix: (string) Return objects starting with prefix

        :param delimiter: (string) Return objects up to the delimiter

        :param path: (string) assume prefix = path and delimiter = /
            (overwrites prefix and delimiter)

        :param format: (string) reply format can be json or xml (default:json)

        :param meta: (list) Return objects that satisfy the key queries in
            the specified comma separated list (use <key>, !<key> for
            existence queries, <key><op><value> for value queries, where <op>
            can be one of =, !=, <=, >=, <, >)

268
269
        :param show_only_shared: (bool) If true, only shared containers will
            be included in results
270
271
272
273
274
275
276
277
278
279
280
281

        :param until: (string) optional timestamp

        --- request headers ---

        :param if_modified_since: (string) Retrieve if account has changed
            since provided timestamp

        :param if_unmodified_since: (string) Retrieve if account has not
            changed since provided timestamp

        :returns: ConnectionResponse
282
        """
283

284
        self._assert_container()
285
286
        self.response_headers = ['Last-Modified', ]
        self.response_header_prefices = ['X-Container-', ]
287

288
289
290
291
292
        self.set_param('limit', limit, iff=limit)
        self.set_param('marker', marker, iff=marker)
        if not path:
            self.set_param('prefix', prefix, iff=prefix)
            self.set_param('delimiter', delimiter, iff=delimiter)
293
294
        else:
            self.set_param('path', path)
295
        self.set_param('format', format, iff=format)
296
        self.set_param('shared', iff=show_only_shared)
297
        self.set_param('public', iff=public)
298
299
        if meta:
            self.set_param('meta',  ','.join(meta))
300
        self.set_param('until', until, iff=until)
301
302
303
304
305
306
307
308

        self.set_header('If-Modified-Since', if_modified_since)
        self.set_header('If-Unmodified-Since', if_unmodified_since)

        path = path4url(self.account, self.container)
        success = kwargs.pop('success', 200)
        return self.get(path, *args, success=success, **kwargs)

309
310
    def container_put(
            self,
311
            quota=None, versioning=None, project=None, metadata=None,
312
            *args, **kwargs):
313
        """ Full Pithos+ PUT at container level
314

315
        --- request headers ---
316
317
318
319
320
321
322
323
324

        :param quota: (integer) Size limit in KB

        :param versioning: (string) 'auto' or other string supported by server

        :param metadata: (dict) Optional user defined metadata in the form
            { 'name1': 'value1', 'name2': 'value2', ... }

        :returns: ConnectionResponse
325
        """
326
        self._assert_container()
327

328
329
        self.set_header('X-Container-Policy-Quota', quota)
        self.set_header('X-Container-Policy-Versioning', versioning)
330
331
332
        if project:
            self.set_header('X-Container-Policy-project', project)

333
        if metadata:
334
            for metaname, metaval in metadata.items():
335
                self.set_header('X-Container-Meta-' + metaname, metaval)
336
337
        self._quote_header_keys(
            self.headers, ('x-container-policy-', 'x-container-meta-'))
338
339

        path = path4url(self.account, self.container)
340
        success = kwargs.pop('success', (201, 202))
341
342
        return self.put(path, *args, success=success, **kwargs)

343
344
345
346
347
348
    def container_post(
            self,
            update=True,
            format='json',
            quota=None,
            versioning=None,
349
            project=None,
350
351
352
353
354
            metadata=None,
            content_type=None,
            content_length=None,
            transfer_encoding=None,
            *args, **kwargs):
355
        """ Full Pithos+ POST at container level
356

357
        --- request params ---
358
359
360
361
362

        :param update: (bool)  if True, Do not replace metadata/groups

        :param format: (string) json (default) or xml

363
        --- request headers ---
364
365
366
367
368
369
370
371
372
373
374
375

        :param quota: (integer) Size limit in KB

        :param versioning: (string) 'auto' or other string supported by server

        :param metadata: (dict) Optional user defined metadata in the form
            { 'name1': 'value1', 'name2': 'value2', ... }

        :param content_type: (string) set a custom content type

        :param content_length: (string) set a custrom content length

376
        :param transfer_encoding: (string) set a custom transfer encoding
377
378

        :returns: ConnectionResponse
379
        """
380
        self._assert_container()
381

382
        self.set_param('update', '', iff=update)
383
        self.set_param('format', format, iff=format)
384

385
386
        self.set_header('X-Container-Policy-Quota', quota)
        self.set_header('X-Container-Policy-Versioning', versioning)
387
388
389
        if project:
            self.set_header('X-Container-Policy-project', project)

390
        if metadata:
391
            for metaname, metaval in metadata.items():
392
                self.set_header('X-Container-Meta-' + metaname, metaval)
393
394
395
        self.set_header('Content-Type', content_type)
        self.set_header('Content-Length', content_length)
        self.set_header('Transfer-Encoding', transfer_encoding)
396
397
        self._quote_header_keys(
            self.headers, ('x-container-policy-', 'x-container-meta-'))
398
399
400
401
402
403
404

        path = path4url(self.account, self.container)
        success = kwargs.pop('success', 202)
        return self.post(path, *args, success=success, **kwargs)

    def container_delete(self, until=None, delimiter=None, *args, **kwargs):
        """ Full Pithos+ DELETE at container level
405

406
        --- request parameters ---
407
408
409
410
411

        :param until: (timestamp string) if defined, container is purged up to
            that time

        :returns: ConnectionResponse
412
        """
413

414
        self._assert_container()
415

416
417
        self.set_param('until', until, iff=until)
        self.set_param('delimiter', delimiter, iff=delimiter)
418

419
        path = path4url(self.account, self.container)
420
        success = kwargs.pop('success', 204)
421
        return self.delete(path, *args, success=success, **kwargs)
422

423
    def object_head(
424
            self, obj,
425
426
427
428
429
430
            version=None,
            if_etag_match=None,
            if_etag_not_match=None,
            if_modified_since=None,
            if_unmodified_since=None,
            *args, **kwargs):
431
        """ Full Pithos+ HEAD at object level
432

433
        --- request parameters ---
434
435
436

        :param version: (string) optional version identified

437
        --- request headers ---
438
439
440
441
442
443
444
445
446
447
448
449
450
451

        :param if_etag_match: (string) if provided, return only results
            with etag matching with this

        :param if_etag_not_match: (string) if provided, return only results
            with etag not matching with this

        :param if_modified_since: (string) Retrieve if account has changed
            since provided timestamp

        :param if_unmodified_since: (string) Retrieve if account has not
            changed since provided timestamp

        :returns: ConnectionResponse
452
        """
453
        self._assert_container()
454
455
456
457
458
459
460
461
462
        self.response_headers = [
            'ETag',
            'Content-Length',
            'Content-Type',
            'Last-Modified',
            'Content-Encoding',
            'Content-Disposition',
        ]
        self.response_header_prefices = ['X-Object-', ]
463

464
        self.set_param('version', version, iff=version)
465
466
467
468
469
470

        self.set_header('If-Match', if_etag_match)
        self.set_header('If-None-Match', if_etag_not_match)
        self.set_header('If-Modified-Since', if_modified_since)
        self.set_header('If-Unmodified-Since', if_unmodified_since)

471
        path = path4url(self.account, self.container, obj)
472
        success = kwargs.pop('success', 200)
473
474
475
        r = self.head(path, *args, success=success, **kwargs)
        self._unquote_header_keys(r.headers, 'x-object-meta-')
        return r
476

477
    def object_get(
478
            self, obj,
479
480
481
482
483
484
485
486
487
488
            format='json',
            hashmap=False,
            version=None,
            data_range=None,
            if_range=False,
            if_etag_match=None,
            if_etag_not_match=None,
            if_modified_since=None,
            if_unmodified_since=None,
            *args, **kwargs):
489
        """ Full Pithos+ GET at object level
490

491
        --- request parameters ---
492
493
494
495
496
497
498

        :param format: (string) json (default) or xml

        :param hashmap: (bool) Optional request for hashmap

        :param version: (string) optional version identified

499
        --- request headers ---
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

        :param data_range: (string) Optional range of data to retrieve

        :param if_range: (bool)

        :param if_etag_match: (string) if provided, return only results
            with etag matching with this

        :param if_etag_not_match: (string) if provided, return only results
            with etag not matching with this

        :param if_modified_since: (string) Retrieve if account has changed
            since provided timestamp

        :param if_unmodified_since: (string) Retrieve if account has not
            changed since provided timestamp

        :returns: ConnectionResponse
518
        """
519
        self._assert_container()
520
521
522
523
524
525
526
527
528
529
        self.response_headers = [
            'ETag',
            'Content-Length',
            'Content-Type',
            'Last-Modified',
            'Content-Encoding',
            'Content-Disposition',
            'Content-Range',
        ]
        self.response_header_prefices = ['X-Object-', ]
530

531
        self.set_param('format', format, iff=format)
532
        self.set_param('hashmap', hashmap, iff=hashmap)
533
        self.set_param('version', version, iff=version)
534
535

        self.set_header('Range', data_range)
536
        self.set_header('If-Range', '', if_range and data_range)
537
538
539
540
541
        self.set_header('If-Match', if_etag_match, )
        self.set_header('If-None-Match', if_etag_not_match)
        self.set_header('If-Modified-Since', if_modified_since)
        self.set_header('If-Unmodified-Since', if_unmodified_since)

542
        path = path4url(self.account, self.container, obj)
543
        success = kwargs.pop('success', 200)
544
545
546
        r = self.get(path, *args, success=success, **kwargs)
        self._unquote_header_keys(r.headers, ('x-object-meta-'))
        return r
547

548
    def object_put(
549
            self, obj,
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
            format='json',
            hashmap=False,
            delimiter=None,
            if_etag_match=None,
            if_etag_not_match=None,
            etag=None,
            content_length=None,
            content_type=None,
            transfer_encoding=None,
            copy_from=None,
            move_from=None,
            source_account=None,
            source_version=None,
            content_encoding=None,
            content_disposition=None,
            manifest=None,
            permissions=None,
567
            public=None,
568
569
            metadata=None,
            *args, **kwargs):
570
        """ Full Pithos+ PUT at object level
571

572
        --- request parameters ---
573
574
575
576
577

        :param format: (string) json (default) or xml

        :param hashmap: (bool) Optional hashmap provided instead of data

578
        --- request headers ---
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617

        :param if_etag_match: (string) if provided, return only results
            with etag matching with this

        :param if_etag_not_match: (string) if provided, return only results
            with etag not matching with this

        :param etag: (string) The MD5 hash of the object (optional to check
            written data)

        :param content_length: (integer) The size of the data written

        :param content_type: (string) The MIME content type of the object

        :param transfer_encoding: (string) Set to chunked to specify
            incremental uploading (if used, Content-Length is ignored)

        :param copy_from: (string) The source path in the form
            /<container>/<object>

        :param move_from: (string) The source path in the form
            /<container>/<object>

        :param source_account: (string) The source account to copy/move from

        :param source_version: (string) The source version to copy from

        :param conent_encoding: (string) The encoding of the object

        :param content_disposition: (string) Presentation style of the object

        :param manifest: (string) Object parts prefix in
            /<container>/<object> form

        :param permissions: (dict) Object permissions in the form (all fields
            are optional)
            { 'read':[user1, group1, user2, ...],
            'write':['user3, group2, group3, ...] }

618
        :param public: (bool) If true, Object is published, False, unpublished
619
620
621
622
623

        :param metadata: (dict) Optional user defined metadata in the form
            {'meta-key-1':'meta-value-1', 'meta-key-2':'meta-value-2', ...}

        :returns: ConnectionResponse
624
        """
625
        self._assert_container()
626
        self.response_headers = ['ETag', 'X-Object-Version']
627

628
        self.set_param('format', format, iff=format)
629
        self.set_param('hashmap', hashmap, iff=hashmap)
630
        self.set_param('delimiter', delimiter, iff=delimiter)
631
632
633
634
635
636
637
638
639
640
641
642
643
644

        self.set_header('If-Match', if_etag_match)
        self.set_header('If-None-Match', if_etag_not_match)
        self.set_header('ETag', etag)
        self.set_header('Content-Length', content_length)
        self.set_header('Content-Type', content_type)
        self.set_header('Transfer-Encoding', transfer_encoding)
        self.set_header('X-Copy-From', copy_from)
        self.set_header('X-Move-From', move_from)
        self.set_header('X-Source-Account', source_account)
        self.set_header('X-Source-Version', source_version)
        self.set_header('Content-Encoding', content_encoding)
        self.set_header('Content-Disposition', content_disposition)
        self.set_header('X-Object-Manifest', manifest)
645
        if permissions:
646
647
648
649
650
651
652
653
654
            perms = None
            if permissions:
                for perm_type, perm_list in permissions.items():
                    if not perms:
                        perms = ''  # Remove permissions
                    if perm_list:
                        perms += ';' if perms else ''
                        perms += '%s=%s' % (perm_type, ','.join(perm_list))
            self.set_header('X-Object-Sharing', perms)
655
        self.set_header('X-Object-Public', public, public is not None)
656
        if metadata:
657
            for key, val in metadata.items():
658
                self.set_header('X-Object-Meta-' + key, val)
659
        self._quote_header_keys(self.headers, ('x-object-meta-', ))
660

661
        path = path4url(self.account, self.container, obj)
662
663
664
        success = kwargs.pop('success', 201)
        return self.put(path, *args, success=success, **kwargs)

665
    def object_copy(
666
            self, obj, destination,
667
668
669
670
671
672
673
674
675
676
            format='json',
            ignore_content_type=False,
            if_etag_match=None,
            if_etag_not_match=None,
            destination_account=None,
            content_type=None,
            content_encoding=None,
            content_disposition=None,
            source_version=None,
            permissions=None,
677
            public=None,
678
679
            metadata=None,
            *args, **kwargs):
680
        """ Full Pithos+ COPY at object level
681

682
        --- request parameters ---
683
684
685
686
687

        :param format: (string) json (default) or xml

        :param ignore_content_type: (bool) Ignore the supplied Content-Type

688
        --- request headers ---
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

        :param if_etag_match: (string) if provided, copy only results
            with etag matching with this

        :param if_etag_not_match: (string) if provided, copy only results
            with etag not matching with this

        :param destination: (string) The destination path in the form
            /<container>/<object>

        :param destination_account: (string) The destination account to copy to

        :param content_type: (string) The MIME content type of the object

        :param content_encoding: (string) The encoding of the object

        :param content_disposition: (string) Object resentation style

        :param source_version: (string) The source version to copy from

        :param permissions: (dict) Object permissions in the form
            (all fields are optional)
            { 'read':[user1, group1, user2, ...],
            'write':['user3, group2, group3, ...] }

714
        :param public: (bool) If true, Object is published, False, unpublished
715
716
717
718
719
720
721

        :param metadata: (dict) Optional user defined metadata in the form
            {'meta-key-1':'meta-value-1', 'meta-key-2':'meta-value-2', ...}
            Metadata are appended to the source metadata. In case of same
            keys, they replace the old metadata

        :returns: ConnectionResponse
722
        """
723
        self._assert_container()
724
725
726
727
728
729
730
731
732
733
734
        self.response_headers = [
            'If-Match',
            'If-None-Match',
            'Destination',
            'Destination-Account',
            'Content-Type',
            'Content-Encoding',
            'Content-Disposition',
            'X-Source-Version',
        ]
        self.response_header_prefices = ['X-Object-', ]
735

736
        self.set_param('format', format, iff=format)
737
738
739
740
741
742
743
744
745
746
        self.set_param('ignore_content_type', iff=ignore_content_type)

        self.set_header('If-Match', if_etag_match)
        self.set_header('If-None-Match', if_etag_not_match)
        self.set_header('Destination', destination)
        self.set_header('Destination-Account', destination_account)
        self.set_header('Content-Type', content_type)
        self.set_header('Content-Encoding', content_encoding)
        self.set_header('Content-Disposition', content_disposition)
        self.set_header('X-Source-Version', source_version)
747
        if permissions:
748
749
            perms = ''
            for perm_type, perm_list in permissions.items():
750
                if not perms:
751
                    perms = ''  # Remove permissions
752
753
754
755
                if perm_list:
                    perms += ';' if perms else ''
                    perms += '%s=%s' % (perm_type, ','.join(perm_list))
            self.set_header('X-Object-Sharing', perms)
756
        self.set_header('X-Object-Public', public, public is not None)
757
        if metadata:
758
            for key, val in metadata.items():
759
                self.set_header('X-Object-Meta-' + key, val)
760
        self._unquote_header_keys(self.headers, 'x-object-meta-')
761

762
        path = path4url(self.account, self.container, obj)
763
764
765
        success = kwargs.pop('success', 201)
        return self.copy(path, *args, success=success, **kwargs)

766
767
768
769
770
771
772
773
774
775
776
777
    def object_move(
            self, object,
            format='json',
            ignore_content_type=False,
            if_etag_match=None,
            if_etag_not_match=None,
            destination=None,
            destination_account=None,
            content_type=None,
            content_encoding=None,
            content_disposition=None,
            permissions={},
778
            public=None,
779
780
            metadata={},
            *args, **kwargs):
781
        """ Full Pithos+ COPY at object level
782

783
        --- request parameters ---
784
785
786
787
788

        :param format: (string) json (default) or xml

        :param ignore_content_type: (bool) Ignore the supplied Content-Type

789
        --- request headers ---
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814

        :param if_etag_match: (string) if provided, return only results
            with etag matching with this

        :param if_etag_not_match: (string) if provided, return only results
            with etag not matching with this

        :param destination: (string) The destination path in the form
            /<container>/<object>

        :param destination_account: (string) The destination account to copy to

        :param content_type: (string) The MIME content type of the object

        :param content_encoding: (string) The encoding of the object

        :param content_disposition: (string) Object presentation style

        :param source_version: (string) The source version to copy from

        :param permissions: (dict) Object permissions in the form
            (all fields are optional)
            { 'read':[user1, group1, user2, ...],
            'write':['user3, group2, group3, ...] }

815
        :param public: (bool) If true, Object is published, False, unpublished
816
817
818
819
820

        :param metadata: (dict) Optional user defined metadata in the form
            {'meta-key-1':'meta-value-1', 'meta-key-2':'meta-value-2', ...}

        :returns: ConnectionResponse
821
        """
822
        self._assert_container()
823
824
825
826
827
828
829
830
831
832
833
        self.response_headers = [
            'If-Match',
            'If-None-Match',
            'Destination',
            'Destination-Account',
            'Content-Type',
            'Content-Encoding',
            'Content-Disposition',
            'X-Source-Version',
        ]
        self.response_header_prefices = ['X-Object-', ]
834

835
        self.set_param('format', format, iff=format)
836
837
838
839
840
841
842
843
844
        self.set_param('ignore_content_type', iff=ignore_content_type)

        self.set_header('If-Match', if_etag_match)
        self.set_header('If-None-Match', if_etag_not_match)
        self.set_header('Destination', destination)
        self.set_header('Destination-Account', destination_account)
        self.set_header('Content-Type', content_type)
        self.set_header('Content-Encoding', content_encoding)
        self.set_header('Content-Disposition', content_disposition)
845
846
847
848
        perms = ';'.join(
            ['%s=%s' % (k, ','.join(v)) for k, v in permissions.items() if (
                v)]) if (permissions) else ''
        self.set_header('X-Object-Sharing', perms, iff=permissions)
849
        self.set_header('X-Object-Public', public, public is not None)
850
851
852
        if metadata:
            for key, val in metadata.items():
                self.set_header('X-Object-Meta-' + key, val)
853
        self._unquote_header_keys(self.headers, 'x-object-meta-')
854
855
856
857
858

        path = path4url(self.account, self.container, object)
        success = kwargs.pop('success', 201)
        return self.move(path, *args, success=success, **kwargs)

859
    def object_post(
860
            self, obj,
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
            format='json',
            update=True,
            if_etag_match=None,
            if_etag_not_match=None,
            content_length=None,
            content_type=None,
            content_range=None,
            transfer_encoding=None,
            content_encoding=None,
            content_disposition=None,
            source_object=None,
            source_account=None,
            source_version=None,
            object_bytes=None,
            manifest=None,
            permissions={},
877
            public=None,
878
879
            metadata={},
            *args, **kwargs):
880
        """ Full Pithos+ POST at object level
881

882
        --- request parameters ---
883
884
885
886
887

        :param format: (string) json (default) or xml

        :param update: (bool) Do not replace metadata

888
        --- request headers ---
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924

        :param if_etag_match: (string) if provided, return only results
            with etag matching with this

        :param if_etag_not_match: (string) if provided, return only results
            with etag not matching with this

        :param content_length: (string) The size of the data written

        :param content_type: (string) The MIME content type of the object

        :param content_range: (string) The range of data supplied

        :param transfer_encoding: (string) Set to chunked to specify
            incremental uploading (if used, Content-Length is ignored)

        :param content_encoding: (string) The encoding of the object

        :param content_disposition: (string) Object presentation style

        :param source_object: (string) Update with data from the object at
            path /<container>/<object>

        :param source_account: (string) The source account to update from

        :param source_version: (string) The source version to copy from

        :param object_bytes: (integer) The updated objects final size

        :param manifest: (string) Object parts prefix as /<container>/<object>

        :param permissions: (dict) Object permissions in the form (all fields
            are optional)
            { 'read':[user1, group1, user2, ...],
            'write':['user3, group2, group3, ...] }

925
        :param public: (bool) If true, Object is published, False, unpublished
926
927
928
929
930

        :param metadata: (dict) Optional user defined metadata in the form
            {'meta-key-1':'meta-value-1', 'meta-key-2':'meta-value-2', ...}

        :returns: ConnectionResponse
931
        """
932
        self._assert_container()
933
        self.response_headers = ['ETag', 'X-Object-Version']
934

935
        self.set_param('format', format, iff=format)
936
        self.set_param('update', '', iff=update)
937
938
939

        self.set_header('If-Match', if_etag_match)
        self.set_header('If-None-Match', if_etag_not_match)
940
        self.set_header(
941
            'Content-Length', content_length, iff=not transfer_encoding)
942
943
944
945
946
947
948
949
950
951
        self.set_header('Content-Type', content_type)
        self.set_header('Content-Range', content_range)
        self.set_header('Transfer-Encoding', transfer_encoding)
        self.set_header('Content-Encoding', content_encoding)
        self.set_header('Content-Disposition', content_disposition)
        self.set_header('X-Source-Object', source_object)
        self.set_header('X-Source-Account', source_account)
        self.set_header('X-Source-Version', source_version)
        self.set_header('X-Object-Bytes', object_bytes)
        self.set_header('X-Object-Manifest', manifest)
952
953
954
955
        perms = ';'.join(
            ['%s=%s' % (k, ','.join(v)) for k, v in permissions.items() if (
                v)]) if (permissions) else ''
        self.set_header('X-Object-Sharing', perms, iff=permissions)
956
        self.set_header('X-Object-Public', public, public is not None)
957
        for key, val in metadata.items():
958
            self.set_header('X-Object-Meta-' + key, val)
959
        self._quote_header_keys(self.headers, ('x-object-meta-', ))
960

961
        path = path4url(self.account, self.container, obj)
962
        success = kwargs.pop('success', (202, 204))
963
        return self.post(path, *args, success=success, **kwargs)
964

965
966
967
968
    def object_delete(
            self, object,
            until=None, delimiter=None,
            *args, **kwargs):
969
        """ Full Pithos+ DELETE at object level
970

971
        --- request parameters ---
972
973
974
975

        :param until: (string) Optional timestamp

        :returns: ConnectionResponse
976
        """
977
        self._assert_container()
978

979
980
        self.set_param('until', until, iff=until)
        self.set_param('delimiter', delimiter, iff=delimiter)
981
982
983

        path = path4url(self.account, self.container, object)
        success = kwargs.pop('success', 204)
984
        return self.delete(path, *args, success=success, **kwargs)