Revision 023d5ada

b/docs/examplesdir/imageregister.rst
303 303

  
304 304
We can use the same idea to change the values of other metadata like disk
305 305
format, container format or status. On the other hand, we cannot modify the
306
id, owner, location, checksum and dates. e.g., to publish and unpublish:
306
id, owner, location, checksum and dates. e.g., to make an image public or
307
private:
307 308

  
308 309
.. code-block:: console
309 310

  
310
    kamaki image modify 7h1rd-1m4g3-1d --publish --name='Debian Base Gama'
311
    kamaki image modify 7h1rd-1m4g3-1d --unpublish
311
    kamaki image modify 7h1rd-1m4g3-1d --public --name='Debian Base Gama'
312
    kamaki image modify 7h1rd-1m4g3-1d --private
312 313

  
313 314
The first call publishes the image (set is-public to True) and also restores
314 315
the name to "Debian Base Gama". The second one unpublishes the image (set
b/docs/examplesdir/sharing.rst
55 55

  
56 56
.. code-block:: console
57 57

  
58
    $ kamaki file modify /pithos/info.txt --unpublish
59
    $ kamaki file modify /pithos/file2upload.txt --publish
58
    $ kamaki file unpublish /pithos/info.txt
59
    $ kamaki file publish /pithos/file2upload.txt
60 60
    https://example.com/pithos/public/43gdL2df02ld3
61 61

  
62 62
Modify permissions
b/kamaki/cli/argument/__init__.py
313 313
            self._value = self._calculate_limit(new_value)
314 314

  
315 315

  
316
class UserAccountArgument(ValueArgument):
317
    """A user UUID or name (if uuid does not exist)"""
318

  
319
    account_client = None
320

  
321
    @property
322
    def value(self):
323
        return super(UserAccountArgument, self).value
324

  
325
    @value.setter
326
    def value(self, uuid_or_name):
327
        if uuid_or_name and self.account_client:
328
            r = self.account_client.uuids2usernames([uuid_or_name, ])
329
            if r:
330
                self._value = uuid_or_name
331
            else:
332
                r = self.account_client.usernames2uuids([uuid_or_name])
333
                self._value = r.get(uuid_or_name) if r else None
334
            if not self._value:
335
                raise raiseCLIError('User name or UUID not found', details=[
336
                    '%s is not a known username or UUID' % uuid_or_name,
337
                    'Usage:  %s <USER_UUID | USERNAME>' % self.lvalue])
338

  
339

  
316 340
class DateArgument(ValueArgument):
317 341

  
318 342
    DATE_FORMAT = '%a %b %d %H:%M:%S %Y'
b/kamaki/cli/commands/image.py
326 326
        container_format=ValueArgument(
327 327
            'Change container format', '--container-format'),
328 328
        status=ValueArgument('Change status', '--status'),
329
        publish=FlagArgument('Publish the image', '--public'),
330
        unpublish=FlagArgument('Unpublish the image', '--private'),
329
        publish=FlagArgument('Make the image public', '--public'),
330
        unpublish=FlagArgument('Make the image private', '--private'),
331 331
        property_to_set=KeyValueArgument(
332 332
            'set property in key=value form (can be repeated)',
333 333
            ('-p', '--property-set')),
b/kamaki/cli/commands/pithos.py
48 48
    CLISyntaxError)
49 49
from kamaki.cli.argument import (
50 50
    FlagArgument, IntArgument, ValueArgument, DateArgument, KeyValueArgument,
51
    ProgressBarArgument, RepeatableArgument, DataSizeArgument)
51
    ProgressBarArgument, RepeatableArgument, DataSizeArgument,
52
    UserAccountArgument)
52 53
from kamaki.cli.utils import (
53 54
    format_size, bold, get_path_size, guess_mime_type)
54 55

  
......
119 120

  
120 121
    def __init__(self, arguments={}, auth_base=None, cloud=None):
121 122
        super(_pithos_account, self).__init__(arguments, auth_base, cloud)
122
        self['account'] = ValueArgument(
123
            'Use (a different) user uuid', ('-A', '--account'))
123
        self['account'] = UserAccountArgument(
124
            'A user UUID or name', ('-A', '--account'))
125
        self.arguments['account'].account_client = auth_base
124 126

  
125 127
    def print_objects(self, object_list):
126 128
        for index, obj in enumerate(object_list):
......
329 331
    """Modify the attributes of a file or directory object"""
330 332

  
331 333
    arguments = dict(
332
        publish=FlagArgument(
333
            'Make an object public (returns the public URL)', '--publish'),
334
        unpublish=FlagArgument(
335
            'Make an object unpublic', '--unpublish'),
336 334
        uuid_for_read_permission=RepeatableArgument(
337 335
            'Give read access to user/group (can be repeated, accumulative). '
338 336
            'Format for users: UUID . Format for groups: UUID:GROUP . '
......
349 347
            'Delete object metadata (can be repeated)', '--metadata-del'),
350 348
    )
351 349
    required = [
352
        'publish', 'unpublish', 'uuid_for_read_permission', 'metadata_to_set',
350
        'uuid_for_read_permission', 'metadata_to_set',
353 351
        'uuid_for_write_permission', 'no_permissions',
354 352
        'metadata_key_to_delete']
355 353

  
......
358 356
    @errors.pithos.container
359 357
    @errors.pithos.object_path
360 358
    def _run(self):
361
        if self['publish']:
362
            self.writeln(self.client.publish_object(self.path))
363
        if self['unpublish']:
364
            self.client.unpublish_object(self.path)
365 359
        if self['uuid_for_read_permission'] or self[
366 360
                'uuid_for_write_permission']:
367 361
            perms = self.client.get_object_sharing(self.path)
......
398 392
        self._run()
399 393

  
400 394

  
395
@command(file_cmds)
396
class file_publish(_pithos_container):
397
    """Publish an object (creates a public URL)"""
398

  
399
    @errors.generic.all
400
    @errors.pithos.connection
401
    @errors.pithos.container
402
    @errors.pithos.object_path
403
    def _run(self):
404
        self.writeln(self.client.publish_object(self.path))
405

  
406
    def main(self, path_or_url):
407
        super(self.__class__, self)._run(path_or_url)
408
        self._run()
409

  
410

  
411
@command(file_cmds)
412
class file_unpublish(_pithos_container):
413
    """Unpublish an object"""
414

  
415
    @errors.generic.all
416
    @errors.pithos.connection
417
    @errors.pithos.container
418
    @errors.pithos.object_path
419
    def _run(self):
420
        self.client.unpublish_object(self.path)
421

  
422
    def main(self, path_or_url):
423
        super(self.__class__, self)._run(path_or_url)
424
        self._run()
425

  
426

  
401 427
def _assert_path(self, path_or_url):
402 428
    if not self.path:
403 429
        raiseCLIError(
......
488 514
class _source_destination(_pithos_container, _optional_output_cmd):
489 515

  
490 516
    sd_arguments = dict(
491
        destination_user_uuid=ValueArgument(
492
            'default: current user uuid', '--to-account'),
517
        destination_user=UserAccountArgument(
518
            'UUID or username, default: current user', '--to-account'),
493 519
        destination_container=ValueArgument(
494 520
            'default: pithos', '--to-container'),
495 521
        source_prefix=FlagArgument(
......
508 534
        self.arguments.update(self.sd_arguments)
509 535
        super(_source_destination, self).__init__(
510 536
            self.arguments, auth_base, cloud)
537
        self.arguments['destination_user'].account_client = self.auth_base
511 538

  
512 539
    def _report_transfer(self, src, dst, transfer_name):
513 540
        if not dst:
......
636 663
            base_url=self.client.base_url, token=self.client.token,
637 664
            container=self[
638 665
                'destination_container'] or dst_con or self.client.container,
639
            account=self[
640
                'destination_user_uuid'] or dst_acc or self.account)
666
            account=self['destination_user'] or dst_acc or self.account)
641 667
        self.dst_path = dst_path or self.path
642 668

  
643 669

  
......
1640 1666
    def _run(self):
1641 1667
        self._print(self.client.get_account_info(), self.print_dict)
1642 1668

  
1643
    def main(self, account_uuid=None):
1669
    def main(self, account_uuid_or_name=None):
1644 1670
        super(self.__class__, self)._run()
1645
        if account_uuid:
1646
            self.client.account, self.account = account_uuid, account_uuid
1671
        if account_uuid_or_name:
1672
            arg = UserAccountArgument('Check', ' ')
1673
            arg.account_client = self.auth_base
1674
            arg.value = account_uuid_or_name
1675
            self.client.account, self.account = arg.value, arg.value
1647 1676
        self._run()
1648 1677

  
1649 1678

  
......
1721 1750
    def main(self, groupname):
1722 1751
        super(self.__class__, self)._run()
1723 1752
        self._run(groupname)
1724

  
1725

  
1726
#  Deprecated commands
1727

  
1728
@command(file_cmds)
1729
class file_publish(_pithos_init):
1730
    """DEPRECATED, replaced by [kamaki] file modify OBJECT --publish"""
1731

  
1732
    def main(self, *args):
1733
        raise CLISyntaxError('DEPRECATED', details=[
1734
            'This command is replaced by:',
1735
            '  [kamaki] file modify OBJECT --publish'])
1736

  
1737

  
1738
@command(file_cmds)
1739
class file_unpublish(_pithos_init):
1740
    """DEPRECATED, replaced by [kamaki] file modify OBJECT --unpublish"""
1741

  
1742
    def main(self, *args):
1743
        raise CLISyntaxError('DEPRECATED', details=[
1744
            'This command is replaced by:',
1745
            '  [kamaki] file modify OBJECT --unpublish'])

Also available in: Unified diff