1#!/usr/bin/env python 2"""CLI for storage, version v1.""" 3# NOTE: This file is autogenerated and should not be edited by hand. 4 5import code 6import os 7import platform 8import sys 9 10import protorpc 11from protorpc import message_types 12from protorpc import messages 13 14from google.apputils import appcommands 15import gflags as flags 16 17import apitools.base.py as apitools_base 18from apitools.base.py import cli as apitools_base_cli 19import storage_v1_client as client_lib 20import storage_v1_messages as messages 21 22 23def _DeclareStorageFlags(): 24 """Declare global flags in an idempotent way.""" 25 if 'api_endpoint' in flags.FLAGS: 26 return 27 flags.DEFINE_string( 28 'api_endpoint', 29 u'https://www.googleapis.com/storage/v1/', 30 'URL of the API endpoint to use.', 31 short_name='storage_url') 32 flags.DEFINE_string( 33 'history_file', 34 u'~/.storage.v1.history', 35 'File with interactive shell history.') 36 flags.DEFINE_multistring( 37 'add_header', [], 38 'Additional http headers (as key=value strings). ' 39 'Can be specified multiple times.') 40 flags.DEFINE_string( 41 'service_account_json_keyfile', '', 42 'Filename for a JSON service account key downloaded' 43 ' from the Developer Console.') 44 flags.DEFINE_enum( 45 'alt', 46 u'json', 47 [u'json'], 48 u'Data format for the response.') 49 flags.DEFINE_string( 50 'fields', 51 None, 52 u'Selector specifying which fields to include in a partial response.') 53 flags.DEFINE_string( 54 'key', 55 None, 56 u'API key. Your API key identifies your project and provides you with ' 57 u'API access, quota, and reports. Required unless you provide an OAuth ' 58 u'2.0 token.') 59 flags.DEFINE_string( 60 'oauth_token', 61 None, 62 u'OAuth 2.0 token for the current user.') 63 flags.DEFINE_boolean( 64 'prettyPrint', 65 'True', 66 u'Returns response with indentations and line breaks.') 67 flags.DEFINE_string( 68 'quotaUser', 69 None, 70 u'Available to use for quota purposes for server-side applications. Can' 71 u' be any arbitrary string assigned to a user, but should not exceed 40' 72 u' characters. Overrides userIp if both are provided.') 73 flags.DEFINE_string( 74 'trace', 75 None, 76 'A tracing token of the form "token:<tokenid>" to include in api ' 77 'requests.') 78 flags.DEFINE_string( 79 'userIp', 80 None, 81 u'IP address of the site where the request originates. Use this if you ' 82 u'want to enforce per-user limits.') 83 84 85FLAGS = flags.FLAGS 86apitools_base_cli.DeclareBaseFlags() 87_DeclareStorageFlags() 88 89 90def GetGlobalParamsFromFlags(): 91 """Return a StandardQueryParameters based on flags.""" 92 result = messages.StandardQueryParameters() 93 if FLAGS['alt'].present: 94 result.alt = messages.StandardQueryParameters.AltValueValuesEnum(FLAGS.alt) 95 if FLAGS['fields'].present: 96 result.fields = FLAGS.fields.decode('utf8') 97 if FLAGS['key'].present: 98 result.key = FLAGS.key.decode('utf8') 99 if FLAGS['oauth_token'].present: 100 result.oauth_token = FLAGS.oauth_token.decode('utf8') 101 if FLAGS['prettyPrint'].present: 102 result.prettyPrint = FLAGS.prettyPrint 103 if FLAGS['quotaUser'].present: 104 result.quotaUser = FLAGS.quotaUser.decode('utf8') 105 if FLAGS['trace'].present: 106 result.trace = FLAGS.trace.decode('utf8') 107 if FLAGS['userIp'].present: 108 result.userIp = FLAGS.userIp.decode('utf8') 109 return result 110 111 112def GetClientFromFlags(): 113 """Return a client object, configured from flags.""" 114 log_request = FLAGS.log_request or FLAGS.log_request_response 115 log_response = FLAGS.log_response or FLAGS.log_request_response 116 api_endpoint = apitools_base.NormalizeApiEndpoint(FLAGS.api_endpoint) 117 additional_http_headers = dict(x.split('=', 1) for x in FLAGS.add_header) 118 credentials_args = { 119 'service_account_json_keyfile': os.path.expanduser(FLAGS.service_account_json_keyfile) 120 } 121 try: 122 client = client_lib.StorageV1( 123 api_endpoint, log_request=log_request, 124 log_response=log_response, 125 credentials_args=credentials_args, 126 additional_http_headers=additional_http_headers) 127 except apitools_base.CredentialsError as e: 128 print 'Error creating credentials: %s' % e 129 sys.exit(1) 130 return client 131 132 133class PyShell(appcommands.Cmd): 134 135 def Run(self, _): 136 """Run an interactive python shell with the client.""" 137 client = GetClientFromFlags() 138 params = GetGlobalParamsFromFlags() 139 for field in params.all_fields(): 140 value = params.get_assigned_value(field.name) 141 if value != field.default: 142 client.AddGlobalParam(field.name, value) 143 banner = """ 144 == storage interactive console == 145 client: a storage client 146 apitools_base: base apitools module 147 messages: the generated messages module 148 """ 149 local_vars = { 150 'apitools_base': apitools_base, 151 'client': client, 152 'client_lib': client_lib, 153 'messages': messages, 154 } 155 if platform.system() == 'Linux': 156 console = apitools_base_cli.ConsoleWithReadline( 157 local_vars, histfile=FLAGS.history_file) 158 else: 159 console = code.InteractiveConsole(local_vars) 160 try: 161 console.interact(banner) 162 except SystemExit as e: 163 return e.code 164 165 166class BucketAccessControlsDelete(apitools_base_cli.NewCmd): 167 """Command wrapping bucketAccessControls.Delete.""" 168 169 usage = """bucketAccessControls_delete <bucket> <entity>""" 170 171 def __init__(self, name, fv): 172 super(BucketAccessControlsDelete, self).__init__(name, fv) 173 174 def RunWithArgs(self, bucket, entity): 175 """Permanently deletes the ACL entry for the specified entity on the 176 specified bucket. 177 178 Args: 179 bucket: Name of a bucket. 180 entity: The entity holding the permission. Can be user-userId, user- 181 emailAddress, group-groupId, group-emailAddress, allUsers, or 182 allAuthenticatedUsers. 183 """ 184 client = GetClientFromFlags() 185 global_params = GetGlobalParamsFromFlags() 186 request = messages.StorageBucketAccessControlsDeleteRequest( 187 bucket=bucket.decode('utf8'), 188 entity=entity.decode('utf8'), 189 ) 190 result = client.bucketAccessControls.Delete( 191 request, global_params=global_params) 192 print apitools_base_cli.FormatOutput(result) 193 194 195class BucketAccessControlsGet(apitools_base_cli.NewCmd): 196 """Command wrapping bucketAccessControls.Get.""" 197 198 usage = """bucketAccessControls_get <bucket> <entity>""" 199 200 def __init__(self, name, fv): 201 super(BucketAccessControlsGet, self).__init__(name, fv) 202 203 def RunWithArgs(self, bucket, entity): 204 """Returns the ACL entry for the specified entity on the specified bucket. 205 206 Args: 207 bucket: Name of a bucket. 208 entity: The entity holding the permission. Can be user-userId, user- 209 emailAddress, group-groupId, group-emailAddress, allUsers, or 210 allAuthenticatedUsers. 211 """ 212 client = GetClientFromFlags() 213 global_params = GetGlobalParamsFromFlags() 214 request = messages.StorageBucketAccessControlsGetRequest( 215 bucket=bucket.decode('utf8'), 216 entity=entity.decode('utf8'), 217 ) 218 result = client.bucketAccessControls.Get( 219 request, global_params=global_params) 220 print apitools_base_cli.FormatOutput(result) 221 222 223class BucketAccessControlsInsert(apitools_base_cli.NewCmd): 224 """Command wrapping bucketAccessControls.Insert.""" 225 226 usage = """bucketAccessControls_insert <bucket>""" 227 228 def __init__(self, name, fv): 229 super(BucketAccessControlsInsert, self).__init__(name, fv) 230 flags.DEFINE_string( 231 'domain', 232 None, 233 u'The domain associated with the entity, if any.', 234 flag_values=fv) 235 flags.DEFINE_string( 236 'email', 237 None, 238 u'The email address associated with the entity, if any.', 239 flag_values=fv) 240 flags.DEFINE_string( 241 'entity', 242 None, 243 u'The entity holding the permission, in one of the following forms: ' 244 u'- user-userId - user-email - group-groupId - group-email - ' 245 u'domain-domain - project-team-projectId - allUsers - ' 246 u'allAuthenticatedUsers Examples: - The user liz@example.com would ' 247 u'be user-liz@example.com. - The group example@googlegroups.com ' 248 u'would be group-example@googlegroups.com. - To refer to all members' 249 u' of the Google Apps for Business domain example.com, the entity ' 250 u'would be domain-example.com.', 251 flag_values=fv) 252 flags.DEFINE_string( 253 'entityId', 254 None, 255 u'The ID for the entity, if any.', 256 flag_values=fv) 257 flags.DEFINE_string( 258 'etag', 259 None, 260 u'HTTP 1.1 Entity tag for the access-control entry.', 261 flag_values=fv) 262 flags.DEFINE_string( 263 'id', 264 None, 265 u'The ID of the access-control entry.', 266 flag_values=fv) 267 flags.DEFINE_string( 268 'kind', 269 u'storage#bucketAccessControl', 270 u'The kind of item this is. For bucket access control entries, this ' 271 u'is always storage#bucketAccessControl.', 272 flag_values=fv) 273 flags.DEFINE_string( 274 'projectTeam', 275 None, 276 u'The project team associated with the entity, if any.', 277 flag_values=fv) 278 flags.DEFINE_string( 279 'role', 280 None, 281 u'The access permission for the entity. Can be READER, WRITER, or ' 282 u'OWNER.', 283 flag_values=fv) 284 flags.DEFINE_string( 285 'selfLink', 286 None, 287 u'The link to this access-control entry.', 288 flag_values=fv) 289 290 def RunWithArgs(self, bucket): 291 """Creates a new ACL entry on the specified bucket. 292 293 Args: 294 bucket: The name of the bucket. 295 296 Flags: 297 domain: The domain associated with the entity, if any. 298 email: The email address associated with the entity, if any. 299 entity: The entity holding the permission, in one of the following 300 forms: - user-userId - user-email - group-groupId - group-email - 301 domain-domain - project-team-projectId - allUsers - 302 allAuthenticatedUsers Examples: - The user liz@example.com would be 303 user-liz@example.com. - The group example@googlegroups.com would be 304 group-example@googlegroups.com. - To refer to all members of the 305 Google Apps for Business domain example.com, the entity would be 306 domain-example.com. 307 entityId: The ID for the entity, if any. 308 etag: HTTP 1.1 Entity tag for the access-control entry. 309 id: The ID of the access-control entry. 310 kind: The kind of item this is. For bucket access control entries, this 311 is always storage#bucketAccessControl. 312 projectTeam: The project team associated with the entity, if any. 313 role: The access permission for the entity. Can be READER, WRITER, or 314 OWNER. 315 selfLink: The link to this access-control entry. 316 """ 317 client = GetClientFromFlags() 318 global_params = GetGlobalParamsFromFlags() 319 request = messages.BucketAccessControl( 320 bucket=bucket.decode('utf8'), 321 ) 322 if FLAGS['domain'].present: 323 request.domain = FLAGS.domain.decode('utf8') 324 if FLAGS['email'].present: 325 request.email = FLAGS.email.decode('utf8') 326 if FLAGS['entity'].present: 327 request.entity = FLAGS.entity.decode('utf8') 328 if FLAGS['entityId'].present: 329 request.entityId = FLAGS.entityId.decode('utf8') 330 if FLAGS['etag'].present: 331 request.etag = FLAGS.etag.decode('utf8') 332 if FLAGS['id'].present: 333 request.id = FLAGS.id.decode('utf8') 334 if FLAGS['kind'].present: 335 request.kind = FLAGS.kind.decode('utf8') 336 if FLAGS['projectTeam'].present: 337 request.projectTeam = apitools_base.JsonToMessage(messages.BucketAccessControl.ProjectTeamValue, FLAGS.projectTeam) 338 if FLAGS['role'].present: 339 request.role = FLAGS.role.decode('utf8') 340 if FLAGS['selfLink'].present: 341 request.selfLink = FLAGS.selfLink.decode('utf8') 342 result = client.bucketAccessControls.Insert( 343 request, global_params=global_params) 344 print apitools_base_cli.FormatOutput(result) 345 346 347class BucketAccessControlsList(apitools_base_cli.NewCmd): 348 """Command wrapping bucketAccessControls.List.""" 349 350 usage = """bucketAccessControls_list <bucket>""" 351 352 def __init__(self, name, fv): 353 super(BucketAccessControlsList, self).__init__(name, fv) 354 355 def RunWithArgs(self, bucket): 356 """Retrieves ACL entries on the specified bucket. 357 358 Args: 359 bucket: Name of a bucket. 360 """ 361 client = GetClientFromFlags() 362 global_params = GetGlobalParamsFromFlags() 363 request = messages.StorageBucketAccessControlsListRequest( 364 bucket=bucket.decode('utf8'), 365 ) 366 result = client.bucketAccessControls.List( 367 request, global_params=global_params) 368 print apitools_base_cli.FormatOutput(result) 369 370 371class BucketAccessControlsPatch(apitools_base_cli.NewCmd): 372 """Command wrapping bucketAccessControls.Patch.""" 373 374 usage = """bucketAccessControls_patch <bucket> <entity>""" 375 376 def __init__(self, name, fv): 377 super(BucketAccessControlsPatch, self).__init__(name, fv) 378 flags.DEFINE_string( 379 'domain', 380 None, 381 u'The domain associated with the entity, if any.', 382 flag_values=fv) 383 flags.DEFINE_string( 384 'email', 385 None, 386 u'The email address associated with the entity, if any.', 387 flag_values=fv) 388 flags.DEFINE_string( 389 'entityId', 390 None, 391 u'The ID for the entity, if any.', 392 flag_values=fv) 393 flags.DEFINE_string( 394 'etag', 395 None, 396 u'HTTP 1.1 Entity tag for the access-control entry.', 397 flag_values=fv) 398 flags.DEFINE_string( 399 'id', 400 None, 401 u'The ID of the access-control entry.', 402 flag_values=fv) 403 flags.DEFINE_string( 404 'kind', 405 u'storage#bucketAccessControl', 406 u'The kind of item this is. For bucket access control entries, this ' 407 u'is always storage#bucketAccessControl.', 408 flag_values=fv) 409 flags.DEFINE_string( 410 'projectTeam', 411 None, 412 u'The project team associated with the entity, if any.', 413 flag_values=fv) 414 flags.DEFINE_string( 415 'role', 416 None, 417 u'The access permission for the entity. Can be READER, WRITER, or ' 418 u'OWNER.', 419 flag_values=fv) 420 flags.DEFINE_string( 421 'selfLink', 422 None, 423 u'The link to this access-control entry.', 424 flag_values=fv) 425 426 def RunWithArgs(self, bucket, entity): 427 """Updates an ACL entry on the specified bucket. This method supports 428 patch semantics. 429 430 Args: 431 bucket: The name of the bucket. 432 entity: The entity holding the permission, in one of the following 433 forms: - user-userId - user-email - group-groupId - group-email - 434 domain-domain - project-team-projectId - allUsers - 435 allAuthenticatedUsers Examples: - The user liz@example.com would be 436 user-liz@example.com. - The group example@googlegroups.com would be 437 group-example@googlegroups.com. - To refer to all members of the 438 Google Apps for Business domain example.com, the entity would be 439 domain-example.com. 440 441 Flags: 442 domain: The domain associated with the entity, if any. 443 email: The email address associated with the entity, if any. 444 entityId: The ID for the entity, if any. 445 etag: HTTP 1.1 Entity tag for the access-control entry. 446 id: The ID of the access-control entry. 447 kind: The kind of item this is. For bucket access control entries, this 448 is always storage#bucketAccessControl. 449 projectTeam: The project team associated with the entity, if any. 450 role: The access permission for the entity. Can be READER, WRITER, or 451 OWNER. 452 selfLink: The link to this access-control entry. 453 """ 454 client = GetClientFromFlags() 455 global_params = GetGlobalParamsFromFlags() 456 request = messages.BucketAccessControl( 457 bucket=bucket.decode('utf8'), 458 entity=entity.decode('utf8'), 459 ) 460 if FLAGS['domain'].present: 461 request.domain = FLAGS.domain.decode('utf8') 462 if FLAGS['email'].present: 463 request.email = FLAGS.email.decode('utf8') 464 if FLAGS['entityId'].present: 465 request.entityId = FLAGS.entityId.decode('utf8') 466 if FLAGS['etag'].present: 467 request.etag = FLAGS.etag.decode('utf8') 468 if FLAGS['id'].present: 469 request.id = FLAGS.id.decode('utf8') 470 if FLAGS['kind'].present: 471 request.kind = FLAGS.kind.decode('utf8') 472 if FLAGS['projectTeam'].present: 473 request.projectTeam = apitools_base.JsonToMessage(messages.BucketAccessControl.ProjectTeamValue, FLAGS.projectTeam) 474 if FLAGS['role'].present: 475 request.role = FLAGS.role.decode('utf8') 476 if FLAGS['selfLink'].present: 477 request.selfLink = FLAGS.selfLink.decode('utf8') 478 result = client.bucketAccessControls.Patch( 479 request, global_params=global_params) 480 print apitools_base_cli.FormatOutput(result) 481 482 483class BucketAccessControlsUpdate(apitools_base_cli.NewCmd): 484 """Command wrapping bucketAccessControls.Update.""" 485 486 usage = """bucketAccessControls_update <bucket> <entity>""" 487 488 def __init__(self, name, fv): 489 super(BucketAccessControlsUpdate, self).__init__(name, fv) 490 flags.DEFINE_string( 491 'domain', 492 None, 493 u'The domain associated with the entity, if any.', 494 flag_values=fv) 495 flags.DEFINE_string( 496 'email', 497 None, 498 u'The email address associated with the entity, if any.', 499 flag_values=fv) 500 flags.DEFINE_string( 501 'entityId', 502 None, 503 u'The ID for the entity, if any.', 504 flag_values=fv) 505 flags.DEFINE_string( 506 'etag', 507 None, 508 u'HTTP 1.1 Entity tag for the access-control entry.', 509 flag_values=fv) 510 flags.DEFINE_string( 511 'id', 512 None, 513 u'The ID of the access-control entry.', 514 flag_values=fv) 515 flags.DEFINE_string( 516 'kind', 517 u'storage#bucketAccessControl', 518 u'The kind of item this is. For bucket access control entries, this ' 519 u'is always storage#bucketAccessControl.', 520 flag_values=fv) 521 flags.DEFINE_string( 522 'projectTeam', 523 None, 524 u'The project team associated with the entity, if any.', 525 flag_values=fv) 526 flags.DEFINE_string( 527 'role', 528 None, 529 u'The access permission for the entity. Can be READER, WRITER, or ' 530 u'OWNER.', 531 flag_values=fv) 532 flags.DEFINE_string( 533 'selfLink', 534 None, 535 u'The link to this access-control entry.', 536 flag_values=fv) 537 538 def RunWithArgs(self, bucket, entity): 539 """Updates an ACL entry on the specified bucket. 540 541 Args: 542 bucket: The name of the bucket. 543 entity: The entity holding the permission, in one of the following 544 forms: - user-userId - user-email - group-groupId - group-email - 545 domain-domain - project-team-projectId - allUsers - 546 allAuthenticatedUsers Examples: - The user liz@example.com would be 547 user-liz@example.com. - The group example@googlegroups.com would be 548 group-example@googlegroups.com. - To refer to all members of the 549 Google Apps for Business domain example.com, the entity would be 550 domain-example.com. 551 552 Flags: 553 domain: The domain associated with the entity, if any. 554 email: The email address associated with the entity, if any. 555 entityId: The ID for the entity, if any. 556 etag: HTTP 1.1 Entity tag for the access-control entry. 557 id: The ID of the access-control entry. 558 kind: The kind of item this is. For bucket access control entries, this 559 is always storage#bucketAccessControl. 560 projectTeam: The project team associated with the entity, if any. 561 role: The access permission for the entity. Can be READER, WRITER, or 562 OWNER. 563 selfLink: The link to this access-control entry. 564 """ 565 client = GetClientFromFlags() 566 global_params = GetGlobalParamsFromFlags() 567 request = messages.BucketAccessControl( 568 bucket=bucket.decode('utf8'), 569 entity=entity.decode('utf8'), 570 ) 571 if FLAGS['domain'].present: 572 request.domain = FLAGS.domain.decode('utf8') 573 if FLAGS['email'].present: 574 request.email = FLAGS.email.decode('utf8') 575 if FLAGS['entityId'].present: 576 request.entityId = FLAGS.entityId.decode('utf8') 577 if FLAGS['etag'].present: 578 request.etag = FLAGS.etag.decode('utf8') 579 if FLAGS['id'].present: 580 request.id = FLAGS.id.decode('utf8') 581 if FLAGS['kind'].present: 582 request.kind = FLAGS.kind.decode('utf8') 583 if FLAGS['projectTeam'].present: 584 request.projectTeam = apitools_base.JsonToMessage(messages.BucketAccessControl.ProjectTeamValue, FLAGS.projectTeam) 585 if FLAGS['role'].present: 586 request.role = FLAGS.role.decode('utf8') 587 if FLAGS['selfLink'].present: 588 request.selfLink = FLAGS.selfLink.decode('utf8') 589 result = client.bucketAccessControls.Update( 590 request, global_params=global_params) 591 print apitools_base_cli.FormatOutput(result) 592 593 594class BucketsDelete(apitools_base_cli.NewCmd): 595 """Command wrapping buckets.Delete.""" 596 597 usage = """buckets_delete <bucket>""" 598 599 def __init__(self, name, fv): 600 super(BucketsDelete, self).__init__(name, fv) 601 flags.DEFINE_string( 602 'ifMetagenerationMatch', 603 None, 604 u'If set, only deletes the bucket if its metageneration matches this ' 605 u'value.', 606 flag_values=fv) 607 flags.DEFINE_string( 608 'ifMetagenerationNotMatch', 609 None, 610 u'If set, only deletes the bucket if its metageneration does not ' 611 u'match this value.', 612 flag_values=fv) 613 614 def RunWithArgs(self, bucket): 615 """Permanently deletes an empty bucket. 616 617 Args: 618 bucket: Name of a bucket. 619 620 Flags: 621 ifMetagenerationMatch: If set, only deletes the bucket if its 622 metageneration matches this value. 623 ifMetagenerationNotMatch: If set, only deletes the bucket if its 624 metageneration does not match this value. 625 """ 626 client = GetClientFromFlags() 627 global_params = GetGlobalParamsFromFlags() 628 request = messages.StorageBucketsDeleteRequest( 629 bucket=bucket.decode('utf8'), 630 ) 631 if FLAGS['ifMetagenerationMatch'].present: 632 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 633 if FLAGS['ifMetagenerationNotMatch'].present: 634 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 635 result = client.buckets.Delete( 636 request, global_params=global_params) 637 print apitools_base_cli.FormatOutput(result) 638 639 640class BucketsGet(apitools_base_cli.NewCmd): 641 """Command wrapping buckets.Get.""" 642 643 usage = """buckets_get <bucket>""" 644 645 def __init__(self, name, fv): 646 super(BucketsGet, self).__init__(name, fv) 647 flags.DEFINE_string( 648 'ifMetagenerationMatch', 649 None, 650 u'Makes the return of the bucket metadata conditional on whether the ' 651 u"bucket's current metageneration matches the given value.", 652 flag_values=fv) 653 flags.DEFINE_string( 654 'ifMetagenerationNotMatch', 655 None, 656 u'Makes the return of the bucket metadata conditional on whether the ' 657 u"bucket's current metageneration does not match the given value.", 658 flag_values=fv) 659 flags.DEFINE_enum( 660 'projection', 661 u'full', 662 [u'full', u'noAcl'], 663 u'Set of properties to return. Defaults to noAcl.', 664 flag_values=fv) 665 666 def RunWithArgs(self, bucket): 667 """Returns metadata for the specified bucket. 668 669 Args: 670 bucket: Name of a bucket. 671 672 Flags: 673 ifMetagenerationMatch: Makes the return of the bucket metadata 674 conditional on whether the bucket's current metageneration matches the 675 given value. 676 ifMetagenerationNotMatch: Makes the return of the bucket metadata 677 conditional on whether the bucket's current metageneration does not 678 match the given value. 679 projection: Set of properties to return. Defaults to noAcl. 680 """ 681 client = GetClientFromFlags() 682 global_params = GetGlobalParamsFromFlags() 683 request = messages.StorageBucketsGetRequest( 684 bucket=bucket.decode('utf8'), 685 ) 686 if FLAGS['ifMetagenerationMatch'].present: 687 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 688 if FLAGS['ifMetagenerationNotMatch'].present: 689 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 690 if FLAGS['projection'].present: 691 request.projection = messages.StorageBucketsGetRequest.ProjectionValueValuesEnum(FLAGS.projection) 692 result = client.buckets.Get( 693 request, global_params=global_params) 694 print apitools_base_cli.FormatOutput(result) 695 696 697class BucketsInsert(apitools_base_cli.NewCmd): 698 """Command wrapping buckets.Insert.""" 699 700 usage = """buckets_insert <project>""" 701 702 def __init__(self, name, fv): 703 super(BucketsInsert, self).__init__(name, fv) 704 flags.DEFINE_string( 705 'bucket', 706 None, 707 u'A Bucket resource to be passed as the request body.', 708 flag_values=fv) 709 flags.DEFINE_enum( 710 'predefinedAcl', 711 u'authenticatedRead', 712 [u'authenticatedRead', u'private', u'projectPrivate', u'publicRead', u'publicReadWrite'], 713 u'Apply a predefined set of access controls to this bucket.', 714 flag_values=fv) 715 flags.DEFINE_enum( 716 'predefinedDefaultObjectAcl', 717 u'authenticatedRead', 718 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 719 u'Apply a predefined set of default object access controls to this ' 720 u'bucket.', 721 flag_values=fv) 722 flags.DEFINE_enum( 723 'projection', 724 u'full', 725 [u'full', u'noAcl'], 726 u'Set of properties to return. Defaults to noAcl, unless the bucket ' 727 u'resource specifies acl or defaultObjectAcl properties, when it ' 728 u'defaults to full.', 729 flag_values=fv) 730 731 def RunWithArgs(self, project): 732 """Creates a new bucket. 733 734 Args: 735 project: A valid API project identifier. 736 737 Flags: 738 bucket: A Bucket resource to be passed as the request body. 739 predefinedAcl: Apply a predefined set of access controls to this bucket. 740 predefinedDefaultObjectAcl: Apply a predefined set of default object 741 access controls to this bucket. 742 projection: Set of properties to return. Defaults to noAcl, unless the 743 bucket resource specifies acl or defaultObjectAcl properties, when it 744 defaults to full. 745 """ 746 client = GetClientFromFlags() 747 global_params = GetGlobalParamsFromFlags() 748 request = messages.StorageBucketsInsertRequest( 749 project=project.decode('utf8'), 750 ) 751 if FLAGS['bucket'].present: 752 request.bucket = apitools_base.JsonToMessage(messages.Bucket, FLAGS.bucket) 753 if FLAGS['predefinedAcl'].present: 754 request.predefinedAcl = messages.StorageBucketsInsertRequest.PredefinedAclValueValuesEnum(FLAGS.predefinedAcl) 755 if FLAGS['predefinedDefaultObjectAcl'].present: 756 request.predefinedDefaultObjectAcl = messages.StorageBucketsInsertRequest.PredefinedDefaultObjectAclValueValuesEnum(FLAGS.predefinedDefaultObjectAcl) 757 if FLAGS['projection'].present: 758 request.projection = messages.StorageBucketsInsertRequest.ProjectionValueValuesEnum(FLAGS.projection) 759 result = client.buckets.Insert( 760 request, global_params=global_params) 761 print apitools_base_cli.FormatOutput(result) 762 763 764class BucketsList(apitools_base_cli.NewCmd): 765 """Command wrapping buckets.List.""" 766 767 usage = """buckets_list <project>""" 768 769 def __init__(self, name, fv): 770 super(BucketsList, self).__init__(name, fv) 771 flags.DEFINE_integer( 772 'maxResults', 773 None, 774 u'Maximum number of buckets to return.', 775 flag_values=fv) 776 flags.DEFINE_string( 777 'pageToken', 778 None, 779 u'A previously-returned page token representing part of the larger ' 780 u'set of results to view.', 781 flag_values=fv) 782 flags.DEFINE_string( 783 'prefix', 784 None, 785 u'Filter results to buckets whose names begin with this prefix.', 786 flag_values=fv) 787 flags.DEFINE_enum( 788 'projection', 789 u'full', 790 [u'full', u'noAcl'], 791 u'Set of properties to return. Defaults to noAcl.', 792 flag_values=fv) 793 794 def RunWithArgs(self, project): 795 """Retrieves a list of buckets for a given project. 796 797 Args: 798 project: A valid API project identifier. 799 800 Flags: 801 maxResults: Maximum number of buckets to return. 802 pageToken: A previously-returned page token representing part of the 803 larger set of results to view. 804 prefix: Filter results to buckets whose names begin with this prefix. 805 projection: Set of properties to return. Defaults to noAcl. 806 """ 807 client = GetClientFromFlags() 808 global_params = GetGlobalParamsFromFlags() 809 request = messages.StorageBucketsListRequest( 810 project=project.decode('utf8'), 811 ) 812 if FLAGS['maxResults'].present: 813 request.maxResults = FLAGS.maxResults 814 if FLAGS['pageToken'].present: 815 request.pageToken = FLAGS.pageToken.decode('utf8') 816 if FLAGS['prefix'].present: 817 request.prefix = FLAGS.prefix.decode('utf8') 818 if FLAGS['projection'].present: 819 request.projection = messages.StorageBucketsListRequest.ProjectionValueValuesEnum(FLAGS.projection) 820 result = client.buckets.List( 821 request, global_params=global_params) 822 print apitools_base_cli.FormatOutput(result) 823 824 825class BucketsPatch(apitools_base_cli.NewCmd): 826 """Command wrapping buckets.Patch.""" 827 828 usage = """buckets_patch <bucket>""" 829 830 def __init__(self, name, fv): 831 super(BucketsPatch, self).__init__(name, fv) 832 flags.DEFINE_string( 833 'bucketResource', 834 None, 835 u'A Bucket resource to be passed as the request body.', 836 flag_values=fv) 837 flags.DEFINE_string( 838 'ifMetagenerationMatch', 839 None, 840 u'Makes the return of the bucket metadata conditional on whether the ' 841 u"bucket's current metageneration matches the given value.", 842 flag_values=fv) 843 flags.DEFINE_string( 844 'ifMetagenerationNotMatch', 845 None, 846 u'Makes the return of the bucket metadata conditional on whether the ' 847 u"bucket's current metageneration does not match the given value.", 848 flag_values=fv) 849 flags.DEFINE_enum( 850 'predefinedAcl', 851 u'authenticatedRead', 852 [u'authenticatedRead', u'private', u'projectPrivate', u'publicRead', u'publicReadWrite'], 853 u'Apply a predefined set of access controls to this bucket.', 854 flag_values=fv) 855 flags.DEFINE_enum( 856 'predefinedDefaultObjectAcl', 857 u'authenticatedRead', 858 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 859 u'Apply a predefined set of default object access controls to this ' 860 u'bucket.', 861 flag_values=fv) 862 flags.DEFINE_enum( 863 'projection', 864 u'full', 865 [u'full', u'noAcl'], 866 u'Set of properties to return. Defaults to full.', 867 flag_values=fv) 868 869 def RunWithArgs(self, bucket): 870 """Updates a bucket. This method supports patch semantics. 871 872 Args: 873 bucket: Name of a bucket. 874 875 Flags: 876 bucketResource: A Bucket resource to be passed as the request body. 877 ifMetagenerationMatch: Makes the return of the bucket metadata 878 conditional on whether the bucket's current metageneration matches the 879 given value. 880 ifMetagenerationNotMatch: Makes the return of the bucket metadata 881 conditional on whether the bucket's current metageneration does not 882 match the given value. 883 predefinedAcl: Apply a predefined set of access controls to this bucket. 884 predefinedDefaultObjectAcl: Apply a predefined set of default object 885 access controls to this bucket. 886 projection: Set of properties to return. Defaults to full. 887 """ 888 client = GetClientFromFlags() 889 global_params = GetGlobalParamsFromFlags() 890 request = messages.StorageBucketsPatchRequest( 891 bucket=bucket.decode('utf8'), 892 ) 893 if FLAGS['bucketResource'].present: 894 request.bucketResource = apitools_base.JsonToMessage(messages.Bucket, FLAGS.bucketResource) 895 if FLAGS['ifMetagenerationMatch'].present: 896 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 897 if FLAGS['ifMetagenerationNotMatch'].present: 898 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 899 if FLAGS['predefinedAcl'].present: 900 request.predefinedAcl = messages.StorageBucketsPatchRequest.PredefinedAclValueValuesEnum(FLAGS.predefinedAcl) 901 if FLAGS['predefinedDefaultObjectAcl'].present: 902 request.predefinedDefaultObjectAcl = messages.StorageBucketsPatchRequest.PredefinedDefaultObjectAclValueValuesEnum(FLAGS.predefinedDefaultObjectAcl) 903 if FLAGS['projection'].present: 904 request.projection = messages.StorageBucketsPatchRequest.ProjectionValueValuesEnum(FLAGS.projection) 905 result = client.buckets.Patch( 906 request, global_params=global_params) 907 print apitools_base_cli.FormatOutput(result) 908 909 910class BucketsUpdate(apitools_base_cli.NewCmd): 911 """Command wrapping buckets.Update.""" 912 913 usage = """buckets_update <bucket>""" 914 915 def __init__(self, name, fv): 916 super(BucketsUpdate, self).__init__(name, fv) 917 flags.DEFINE_string( 918 'bucketResource', 919 None, 920 u'A Bucket resource to be passed as the request body.', 921 flag_values=fv) 922 flags.DEFINE_string( 923 'ifMetagenerationMatch', 924 None, 925 u'Makes the return of the bucket metadata conditional on whether the ' 926 u"bucket's current metageneration matches the given value.", 927 flag_values=fv) 928 flags.DEFINE_string( 929 'ifMetagenerationNotMatch', 930 None, 931 u'Makes the return of the bucket metadata conditional on whether the ' 932 u"bucket's current metageneration does not match the given value.", 933 flag_values=fv) 934 flags.DEFINE_enum( 935 'predefinedAcl', 936 u'authenticatedRead', 937 [u'authenticatedRead', u'private', u'projectPrivate', u'publicRead', u'publicReadWrite'], 938 u'Apply a predefined set of access controls to this bucket.', 939 flag_values=fv) 940 flags.DEFINE_enum( 941 'predefinedDefaultObjectAcl', 942 u'authenticatedRead', 943 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 944 u'Apply a predefined set of default object access controls to this ' 945 u'bucket.', 946 flag_values=fv) 947 flags.DEFINE_enum( 948 'projection', 949 u'full', 950 [u'full', u'noAcl'], 951 u'Set of properties to return. Defaults to full.', 952 flag_values=fv) 953 954 def RunWithArgs(self, bucket): 955 """Updates a bucket. 956 957 Args: 958 bucket: Name of a bucket. 959 960 Flags: 961 bucketResource: A Bucket resource to be passed as the request body. 962 ifMetagenerationMatch: Makes the return of the bucket metadata 963 conditional on whether the bucket's current metageneration matches the 964 given value. 965 ifMetagenerationNotMatch: Makes the return of the bucket metadata 966 conditional on whether the bucket's current metageneration does not 967 match the given value. 968 predefinedAcl: Apply a predefined set of access controls to this bucket. 969 predefinedDefaultObjectAcl: Apply a predefined set of default object 970 access controls to this bucket. 971 projection: Set of properties to return. Defaults to full. 972 """ 973 client = GetClientFromFlags() 974 global_params = GetGlobalParamsFromFlags() 975 request = messages.StorageBucketsUpdateRequest( 976 bucket=bucket.decode('utf8'), 977 ) 978 if FLAGS['bucketResource'].present: 979 request.bucketResource = apitools_base.JsonToMessage(messages.Bucket, FLAGS.bucketResource) 980 if FLAGS['ifMetagenerationMatch'].present: 981 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 982 if FLAGS['ifMetagenerationNotMatch'].present: 983 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 984 if FLAGS['predefinedAcl'].present: 985 request.predefinedAcl = messages.StorageBucketsUpdateRequest.PredefinedAclValueValuesEnum(FLAGS.predefinedAcl) 986 if FLAGS['predefinedDefaultObjectAcl'].present: 987 request.predefinedDefaultObjectAcl = messages.StorageBucketsUpdateRequest.PredefinedDefaultObjectAclValueValuesEnum(FLAGS.predefinedDefaultObjectAcl) 988 if FLAGS['projection'].present: 989 request.projection = messages.StorageBucketsUpdateRequest.ProjectionValueValuesEnum(FLAGS.projection) 990 result = client.buckets.Update( 991 request, global_params=global_params) 992 print apitools_base_cli.FormatOutput(result) 993 994 995class ChannelsStop(apitools_base_cli.NewCmd): 996 """Command wrapping channels.Stop.""" 997 998 usage = """channels_stop""" 999 1000 def __init__(self, name, fv): 1001 super(ChannelsStop, self).__init__(name, fv) 1002 flags.DEFINE_string( 1003 'address', 1004 None, 1005 u'The address where notifications are delivered for this channel.', 1006 flag_values=fv) 1007 flags.DEFINE_string( 1008 'expiration', 1009 None, 1010 u'Date and time of notification channel expiration, expressed as a ' 1011 u'Unix timestamp, in milliseconds. Optional.', 1012 flag_values=fv) 1013 flags.DEFINE_string( 1014 'id', 1015 None, 1016 u'A UUID or similar unique string that identifies this channel.', 1017 flag_values=fv) 1018 flags.DEFINE_string( 1019 'kind', 1020 u'api#channel', 1021 u'Identifies this as a notification channel used to watch for changes' 1022 u' to a resource. Value: the fixed string "api#channel".', 1023 flag_values=fv) 1024 flags.DEFINE_string( 1025 'params', 1026 None, 1027 u'Additional parameters controlling delivery channel behavior. ' 1028 u'Optional.', 1029 flag_values=fv) 1030 flags.DEFINE_boolean( 1031 'payload', 1032 None, 1033 u'A Boolean value to indicate whether payload is wanted. Optional.', 1034 flag_values=fv) 1035 flags.DEFINE_string( 1036 'resourceId', 1037 None, 1038 u'An opaque ID that identifies the resource being watched on this ' 1039 u'channel. Stable across different API versions.', 1040 flag_values=fv) 1041 flags.DEFINE_string( 1042 'resourceUri', 1043 None, 1044 u'A version-specific identifier for the watched resource.', 1045 flag_values=fv) 1046 flags.DEFINE_string( 1047 'token', 1048 None, 1049 u'An arbitrary string delivered to the target address with each ' 1050 u'notification delivered over this channel. Optional.', 1051 flag_values=fv) 1052 flags.DEFINE_string( 1053 'type', 1054 None, 1055 u'The type of delivery mechanism used for this channel.', 1056 flag_values=fv) 1057 1058 def RunWithArgs(self): 1059 """Stop watching resources through this channel 1060 1061 Flags: 1062 address: The address where notifications are delivered for this channel. 1063 expiration: Date and time of notification channel expiration, expressed 1064 as a Unix timestamp, in milliseconds. Optional. 1065 id: A UUID or similar unique string that identifies this channel. 1066 kind: Identifies this as a notification channel used to watch for 1067 changes to a resource. Value: the fixed string "api#channel". 1068 params: Additional parameters controlling delivery channel behavior. 1069 Optional. 1070 payload: A Boolean value to indicate whether payload is wanted. 1071 Optional. 1072 resourceId: An opaque ID that identifies the resource being watched on 1073 this channel. Stable across different API versions. 1074 resourceUri: A version-specific identifier for the watched resource. 1075 token: An arbitrary string delivered to the target address with each 1076 notification delivered over this channel. Optional. 1077 type: The type of delivery mechanism used for this channel. 1078 """ 1079 client = GetClientFromFlags() 1080 global_params = GetGlobalParamsFromFlags() 1081 request = messages.Channel( 1082 ) 1083 if FLAGS['address'].present: 1084 request.address = FLAGS.address.decode('utf8') 1085 if FLAGS['expiration'].present: 1086 request.expiration = int(FLAGS.expiration) 1087 if FLAGS['id'].present: 1088 request.id = FLAGS.id.decode('utf8') 1089 if FLAGS['kind'].present: 1090 request.kind = FLAGS.kind.decode('utf8') 1091 if FLAGS['params'].present: 1092 request.params = apitools_base.JsonToMessage(messages.Channel.ParamsValue, FLAGS.params) 1093 if FLAGS['payload'].present: 1094 request.payload = FLAGS.payload 1095 if FLAGS['resourceId'].present: 1096 request.resourceId = FLAGS.resourceId.decode('utf8') 1097 if FLAGS['resourceUri'].present: 1098 request.resourceUri = FLAGS.resourceUri.decode('utf8') 1099 if FLAGS['token'].present: 1100 request.token = FLAGS.token.decode('utf8') 1101 if FLAGS['type'].present: 1102 request.type = FLAGS.type.decode('utf8') 1103 result = client.channels.Stop( 1104 request, global_params=global_params) 1105 print apitools_base_cli.FormatOutput(result) 1106 1107 1108class DefaultObjectAccessControlsDelete(apitools_base_cli.NewCmd): 1109 """Command wrapping defaultObjectAccessControls.Delete.""" 1110 1111 usage = """defaultObjectAccessControls_delete <bucket> <entity>""" 1112 1113 def __init__(self, name, fv): 1114 super(DefaultObjectAccessControlsDelete, self).__init__(name, fv) 1115 1116 def RunWithArgs(self, bucket, entity): 1117 """Permanently deletes the default object ACL entry for the specified 1118 entity on the specified bucket. 1119 1120 Args: 1121 bucket: Name of a bucket. 1122 entity: The entity holding the permission. Can be user-userId, user- 1123 emailAddress, group-groupId, group-emailAddress, allUsers, or 1124 allAuthenticatedUsers. 1125 """ 1126 client = GetClientFromFlags() 1127 global_params = GetGlobalParamsFromFlags() 1128 request = messages.StorageDefaultObjectAccessControlsDeleteRequest( 1129 bucket=bucket.decode('utf8'), 1130 entity=entity.decode('utf8'), 1131 ) 1132 result = client.defaultObjectAccessControls.Delete( 1133 request, global_params=global_params) 1134 print apitools_base_cli.FormatOutput(result) 1135 1136 1137class DefaultObjectAccessControlsGet(apitools_base_cli.NewCmd): 1138 """Command wrapping defaultObjectAccessControls.Get.""" 1139 1140 usage = """defaultObjectAccessControls_get <bucket> <entity>""" 1141 1142 def __init__(self, name, fv): 1143 super(DefaultObjectAccessControlsGet, self).__init__(name, fv) 1144 1145 def RunWithArgs(self, bucket, entity): 1146 """Returns the default object ACL entry for the specified entity on the 1147 specified bucket. 1148 1149 Args: 1150 bucket: Name of a bucket. 1151 entity: The entity holding the permission. Can be user-userId, user- 1152 emailAddress, group-groupId, group-emailAddress, allUsers, or 1153 allAuthenticatedUsers. 1154 """ 1155 client = GetClientFromFlags() 1156 global_params = GetGlobalParamsFromFlags() 1157 request = messages.StorageDefaultObjectAccessControlsGetRequest( 1158 bucket=bucket.decode('utf8'), 1159 entity=entity.decode('utf8'), 1160 ) 1161 result = client.defaultObjectAccessControls.Get( 1162 request, global_params=global_params) 1163 print apitools_base_cli.FormatOutput(result) 1164 1165 1166class DefaultObjectAccessControlsInsert(apitools_base_cli.NewCmd): 1167 """Command wrapping defaultObjectAccessControls.Insert.""" 1168 1169 usage = """defaultObjectAccessControls_insert <bucket>""" 1170 1171 def __init__(self, name, fv): 1172 super(DefaultObjectAccessControlsInsert, self).__init__(name, fv) 1173 flags.DEFINE_string( 1174 'domain', 1175 None, 1176 u'The domain associated with the entity, if any.', 1177 flag_values=fv) 1178 flags.DEFINE_string( 1179 'email', 1180 None, 1181 u'The email address associated with the entity, if any.', 1182 flag_values=fv) 1183 flags.DEFINE_string( 1184 'entity', 1185 None, 1186 u'The entity holding the permission, in one of the following forms: ' 1187 u'- user-userId - user-email - group-groupId - group-email - ' 1188 u'domain-domain - project-team-projectId - allUsers - ' 1189 u'allAuthenticatedUsers Examples: - The user liz@example.com would ' 1190 u'be user-liz@example.com. - The group example@googlegroups.com ' 1191 u'would be group-example@googlegroups.com. - To refer to all members' 1192 u' of the Google Apps for Business domain example.com, the entity ' 1193 u'would be domain-example.com.', 1194 flag_values=fv) 1195 flags.DEFINE_string( 1196 'entityId', 1197 None, 1198 u'The ID for the entity, if any.', 1199 flag_values=fv) 1200 flags.DEFINE_string( 1201 'etag', 1202 None, 1203 u'HTTP 1.1 Entity tag for the access-control entry.', 1204 flag_values=fv) 1205 flags.DEFINE_string( 1206 'generation', 1207 None, 1208 u'The content generation of the object.', 1209 flag_values=fv) 1210 flags.DEFINE_string( 1211 'id', 1212 None, 1213 u'The ID of the access-control entry.', 1214 flag_values=fv) 1215 flags.DEFINE_string( 1216 'kind', 1217 u'storage#objectAccessControl', 1218 u'The kind of item this is. For object access control entries, this ' 1219 u'is always storage#objectAccessControl.', 1220 flag_values=fv) 1221 flags.DEFINE_string( 1222 'object', 1223 None, 1224 u'The name of the object.', 1225 flag_values=fv) 1226 flags.DEFINE_string( 1227 'projectTeam', 1228 None, 1229 u'The project team associated with the entity, if any.', 1230 flag_values=fv) 1231 flags.DEFINE_string( 1232 'role', 1233 None, 1234 u'The access permission for the entity. Can be READER or OWNER.', 1235 flag_values=fv) 1236 flags.DEFINE_string( 1237 'selfLink', 1238 None, 1239 u'The link to this access-control entry.', 1240 flag_values=fv) 1241 1242 def RunWithArgs(self, bucket): 1243 """Creates a new default object ACL entry on the specified bucket. 1244 1245 Args: 1246 bucket: The name of the bucket. 1247 1248 Flags: 1249 domain: The domain associated with the entity, if any. 1250 email: The email address associated with the entity, if any. 1251 entity: The entity holding the permission, in one of the following 1252 forms: - user-userId - user-email - group-groupId - group-email - 1253 domain-domain - project-team-projectId - allUsers - 1254 allAuthenticatedUsers Examples: - The user liz@example.com would be 1255 user-liz@example.com. - The group example@googlegroups.com would be 1256 group-example@googlegroups.com. - To refer to all members of the 1257 Google Apps for Business domain example.com, the entity would be 1258 domain-example.com. 1259 entityId: The ID for the entity, if any. 1260 etag: HTTP 1.1 Entity tag for the access-control entry. 1261 generation: The content generation of the object. 1262 id: The ID of the access-control entry. 1263 kind: The kind of item this is. For object access control entries, this 1264 is always storage#objectAccessControl. 1265 object: The name of the object. 1266 projectTeam: The project team associated with the entity, if any. 1267 role: The access permission for the entity. Can be READER or OWNER. 1268 selfLink: The link to this access-control entry. 1269 """ 1270 client = GetClientFromFlags() 1271 global_params = GetGlobalParamsFromFlags() 1272 request = messages.ObjectAccessControl( 1273 bucket=bucket.decode('utf8'), 1274 ) 1275 if FLAGS['domain'].present: 1276 request.domain = FLAGS.domain.decode('utf8') 1277 if FLAGS['email'].present: 1278 request.email = FLAGS.email.decode('utf8') 1279 if FLAGS['entity'].present: 1280 request.entity = FLAGS.entity.decode('utf8') 1281 if FLAGS['entityId'].present: 1282 request.entityId = FLAGS.entityId.decode('utf8') 1283 if FLAGS['etag'].present: 1284 request.etag = FLAGS.etag.decode('utf8') 1285 if FLAGS['generation'].present: 1286 request.generation = int(FLAGS.generation) 1287 if FLAGS['id'].present: 1288 request.id = FLAGS.id.decode('utf8') 1289 if FLAGS['kind'].present: 1290 request.kind = FLAGS.kind.decode('utf8') 1291 if FLAGS['object'].present: 1292 request.object = FLAGS.object.decode('utf8') 1293 if FLAGS['projectTeam'].present: 1294 request.projectTeam = apitools_base.JsonToMessage(messages.ObjectAccessControl.ProjectTeamValue, FLAGS.projectTeam) 1295 if FLAGS['role'].present: 1296 request.role = FLAGS.role.decode('utf8') 1297 if FLAGS['selfLink'].present: 1298 request.selfLink = FLAGS.selfLink.decode('utf8') 1299 result = client.defaultObjectAccessControls.Insert( 1300 request, global_params=global_params) 1301 print apitools_base_cli.FormatOutput(result) 1302 1303 1304class DefaultObjectAccessControlsList(apitools_base_cli.NewCmd): 1305 """Command wrapping defaultObjectAccessControls.List.""" 1306 1307 usage = """defaultObjectAccessControls_list <bucket>""" 1308 1309 def __init__(self, name, fv): 1310 super(DefaultObjectAccessControlsList, self).__init__(name, fv) 1311 flags.DEFINE_string( 1312 'ifMetagenerationMatch', 1313 None, 1314 u"If present, only return default ACL listing if the bucket's current" 1315 u' metageneration matches this value.', 1316 flag_values=fv) 1317 flags.DEFINE_string( 1318 'ifMetagenerationNotMatch', 1319 None, 1320 u"If present, only return default ACL listing if the bucket's current" 1321 u' metageneration does not match the given value.', 1322 flag_values=fv) 1323 1324 def RunWithArgs(self, bucket): 1325 """Retrieves default object ACL entries on the specified bucket. 1326 1327 Args: 1328 bucket: Name of a bucket. 1329 1330 Flags: 1331 ifMetagenerationMatch: If present, only return default ACL listing if 1332 the bucket's current metageneration matches this value. 1333 ifMetagenerationNotMatch: If present, only return default ACL listing if 1334 the bucket's current metageneration does not match the given value. 1335 """ 1336 client = GetClientFromFlags() 1337 global_params = GetGlobalParamsFromFlags() 1338 request = messages.StorageDefaultObjectAccessControlsListRequest( 1339 bucket=bucket.decode('utf8'), 1340 ) 1341 if FLAGS['ifMetagenerationMatch'].present: 1342 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 1343 if FLAGS['ifMetagenerationNotMatch'].present: 1344 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 1345 result = client.defaultObjectAccessControls.List( 1346 request, global_params=global_params) 1347 print apitools_base_cli.FormatOutput(result) 1348 1349 1350class DefaultObjectAccessControlsPatch(apitools_base_cli.NewCmd): 1351 """Command wrapping defaultObjectAccessControls.Patch.""" 1352 1353 usage = """defaultObjectAccessControls_patch <bucket> <entity>""" 1354 1355 def __init__(self, name, fv): 1356 super(DefaultObjectAccessControlsPatch, self).__init__(name, fv) 1357 flags.DEFINE_string( 1358 'domain', 1359 None, 1360 u'The domain associated with the entity, if any.', 1361 flag_values=fv) 1362 flags.DEFINE_string( 1363 'email', 1364 None, 1365 u'The email address associated with the entity, if any.', 1366 flag_values=fv) 1367 flags.DEFINE_string( 1368 'entityId', 1369 None, 1370 u'The ID for the entity, if any.', 1371 flag_values=fv) 1372 flags.DEFINE_string( 1373 'etag', 1374 None, 1375 u'HTTP 1.1 Entity tag for the access-control entry.', 1376 flag_values=fv) 1377 flags.DEFINE_string( 1378 'generation', 1379 None, 1380 u'The content generation of the object.', 1381 flag_values=fv) 1382 flags.DEFINE_string( 1383 'id', 1384 None, 1385 u'The ID of the access-control entry.', 1386 flag_values=fv) 1387 flags.DEFINE_string( 1388 'kind', 1389 u'storage#objectAccessControl', 1390 u'The kind of item this is. For object access control entries, this ' 1391 u'is always storage#objectAccessControl.', 1392 flag_values=fv) 1393 flags.DEFINE_string( 1394 'object', 1395 None, 1396 u'The name of the object.', 1397 flag_values=fv) 1398 flags.DEFINE_string( 1399 'projectTeam', 1400 None, 1401 u'The project team associated with the entity, if any.', 1402 flag_values=fv) 1403 flags.DEFINE_string( 1404 'role', 1405 None, 1406 u'The access permission for the entity. Can be READER or OWNER.', 1407 flag_values=fv) 1408 flags.DEFINE_string( 1409 'selfLink', 1410 None, 1411 u'The link to this access-control entry.', 1412 flag_values=fv) 1413 1414 def RunWithArgs(self, bucket, entity): 1415 """Updates a default object ACL entry on the specified bucket. This method 1416 supports patch semantics. 1417 1418 Args: 1419 bucket: The name of the bucket. 1420 entity: The entity holding the permission, in one of the following 1421 forms: - user-userId - user-email - group-groupId - group-email - 1422 domain-domain - project-team-projectId - allUsers - 1423 allAuthenticatedUsers Examples: - The user liz@example.com would be 1424 user-liz@example.com. - The group example@googlegroups.com would be 1425 group-example@googlegroups.com. - To refer to all members of the 1426 Google Apps for Business domain example.com, the entity would be 1427 domain-example.com. 1428 1429 Flags: 1430 domain: The domain associated with the entity, if any. 1431 email: The email address associated with the entity, if any. 1432 entityId: The ID for the entity, if any. 1433 etag: HTTP 1.1 Entity tag for the access-control entry. 1434 generation: The content generation of the object. 1435 id: The ID of the access-control entry. 1436 kind: The kind of item this is. For object access control entries, this 1437 is always storage#objectAccessControl. 1438 object: The name of the object. 1439 projectTeam: The project team associated with the entity, if any. 1440 role: The access permission for the entity. Can be READER or OWNER. 1441 selfLink: The link to this access-control entry. 1442 """ 1443 client = GetClientFromFlags() 1444 global_params = GetGlobalParamsFromFlags() 1445 request = messages.ObjectAccessControl( 1446 bucket=bucket.decode('utf8'), 1447 entity=entity.decode('utf8'), 1448 ) 1449 if FLAGS['domain'].present: 1450 request.domain = FLAGS.domain.decode('utf8') 1451 if FLAGS['email'].present: 1452 request.email = FLAGS.email.decode('utf8') 1453 if FLAGS['entityId'].present: 1454 request.entityId = FLAGS.entityId.decode('utf8') 1455 if FLAGS['etag'].present: 1456 request.etag = FLAGS.etag.decode('utf8') 1457 if FLAGS['generation'].present: 1458 request.generation = int(FLAGS.generation) 1459 if FLAGS['id'].present: 1460 request.id = FLAGS.id.decode('utf8') 1461 if FLAGS['kind'].present: 1462 request.kind = FLAGS.kind.decode('utf8') 1463 if FLAGS['object'].present: 1464 request.object = FLAGS.object.decode('utf8') 1465 if FLAGS['projectTeam'].present: 1466 request.projectTeam = apitools_base.JsonToMessage(messages.ObjectAccessControl.ProjectTeamValue, FLAGS.projectTeam) 1467 if FLAGS['role'].present: 1468 request.role = FLAGS.role.decode('utf8') 1469 if FLAGS['selfLink'].present: 1470 request.selfLink = FLAGS.selfLink.decode('utf8') 1471 result = client.defaultObjectAccessControls.Patch( 1472 request, global_params=global_params) 1473 print apitools_base_cli.FormatOutput(result) 1474 1475 1476class DefaultObjectAccessControlsUpdate(apitools_base_cli.NewCmd): 1477 """Command wrapping defaultObjectAccessControls.Update.""" 1478 1479 usage = """defaultObjectAccessControls_update <bucket> <entity>""" 1480 1481 def __init__(self, name, fv): 1482 super(DefaultObjectAccessControlsUpdate, self).__init__(name, fv) 1483 flags.DEFINE_string( 1484 'domain', 1485 None, 1486 u'The domain associated with the entity, if any.', 1487 flag_values=fv) 1488 flags.DEFINE_string( 1489 'email', 1490 None, 1491 u'The email address associated with the entity, if any.', 1492 flag_values=fv) 1493 flags.DEFINE_string( 1494 'entityId', 1495 None, 1496 u'The ID for the entity, if any.', 1497 flag_values=fv) 1498 flags.DEFINE_string( 1499 'etag', 1500 None, 1501 u'HTTP 1.1 Entity tag for the access-control entry.', 1502 flag_values=fv) 1503 flags.DEFINE_string( 1504 'generation', 1505 None, 1506 u'The content generation of the object.', 1507 flag_values=fv) 1508 flags.DEFINE_string( 1509 'id', 1510 None, 1511 u'The ID of the access-control entry.', 1512 flag_values=fv) 1513 flags.DEFINE_string( 1514 'kind', 1515 u'storage#objectAccessControl', 1516 u'The kind of item this is. For object access control entries, this ' 1517 u'is always storage#objectAccessControl.', 1518 flag_values=fv) 1519 flags.DEFINE_string( 1520 'object', 1521 None, 1522 u'The name of the object.', 1523 flag_values=fv) 1524 flags.DEFINE_string( 1525 'projectTeam', 1526 None, 1527 u'The project team associated with the entity, if any.', 1528 flag_values=fv) 1529 flags.DEFINE_string( 1530 'role', 1531 None, 1532 u'The access permission for the entity. Can be READER or OWNER.', 1533 flag_values=fv) 1534 flags.DEFINE_string( 1535 'selfLink', 1536 None, 1537 u'The link to this access-control entry.', 1538 flag_values=fv) 1539 1540 def RunWithArgs(self, bucket, entity): 1541 """Updates a default object ACL entry on the specified bucket. 1542 1543 Args: 1544 bucket: The name of the bucket. 1545 entity: The entity holding the permission, in one of the following 1546 forms: - user-userId - user-email - group-groupId - group-email - 1547 domain-domain - project-team-projectId - allUsers - 1548 allAuthenticatedUsers Examples: - The user liz@example.com would be 1549 user-liz@example.com. - The group example@googlegroups.com would be 1550 group-example@googlegroups.com. - To refer to all members of the 1551 Google Apps for Business domain example.com, the entity would be 1552 domain-example.com. 1553 1554 Flags: 1555 domain: The domain associated with the entity, if any. 1556 email: The email address associated with the entity, if any. 1557 entityId: The ID for the entity, if any. 1558 etag: HTTP 1.1 Entity tag for the access-control entry. 1559 generation: The content generation of the object. 1560 id: The ID of the access-control entry. 1561 kind: The kind of item this is. For object access control entries, this 1562 is always storage#objectAccessControl. 1563 object: The name of the object. 1564 projectTeam: The project team associated with the entity, if any. 1565 role: The access permission for the entity. Can be READER or OWNER. 1566 selfLink: The link to this access-control entry. 1567 """ 1568 client = GetClientFromFlags() 1569 global_params = GetGlobalParamsFromFlags() 1570 request = messages.ObjectAccessControl( 1571 bucket=bucket.decode('utf8'), 1572 entity=entity.decode('utf8'), 1573 ) 1574 if FLAGS['domain'].present: 1575 request.domain = FLAGS.domain.decode('utf8') 1576 if FLAGS['email'].present: 1577 request.email = FLAGS.email.decode('utf8') 1578 if FLAGS['entityId'].present: 1579 request.entityId = FLAGS.entityId.decode('utf8') 1580 if FLAGS['etag'].present: 1581 request.etag = FLAGS.etag.decode('utf8') 1582 if FLAGS['generation'].present: 1583 request.generation = int(FLAGS.generation) 1584 if FLAGS['id'].present: 1585 request.id = FLAGS.id.decode('utf8') 1586 if FLAGS['kind'].present: 1587 request.kind = FLAGS.kind.decode('utf8') 1588 if FLAGS['object'].present: 1589 request.object = FLAGS.object.decode('utf8') 1590 if FLAGS['projectTeam'].present: 1591 request.projectTeam = apitools_base.JsonToMessage(messages.ObjectAccessControl.ProjectTeamValue, FLAGS.projectTeam) 1592 if FLAGS['role'].present: 1593 request.role = FLAGS.role.decode('utf8') 1594 if FLAGS['selfLink'].present: 1595 request.selfLink = FLAGS.selfLink.decode('utf8') 1596 result = client.defaultObjectAccessControls.Update( 1597 request, global_params=global_params) 1598 print apitools_base_cli.FormatOutput(result) 1599 1600 1601class ObjectAccessControlsDelete(apitools_base_cli.NewCmd): 1602 """Command wrapping objectAccessControls.Delete.""" 1603 1604 usage = """objectAccessControls_delete <bucket> <object> <entity>""" 1605 1606 def __init__(self, name, fv): 1607 super(ObjectAccessControlsDelete, self).__init__(name, fv) 1608 flags.DEFINE_string( 1609 'generation', 1610 None, 1611 u'If present, selects a specific revision of this object (as opposed ' 1612 u'to the latest version, the default).', 1613 flag_values=fv) 1614 1615 def RunWithArgs(self, bucket, object, entity): 1616 """Permanently deletes the ACL entry for the specified entity on the 1617 specified object. 1618 1619 Args: 1620 bucket: Name of a bucket. 1621 object: Name of the object. 1622 entity: The entity holding the permission. Can be user-userId, user- 1623 emailAddress, group-groupId, group-emailAddress, allUsers, or 1624 allAuthenticatedUsers. 1625 1626 Flags: 1627 generation: If present, selects a specific revision of this object (as 1628 opposed to the latest version, the default). 1629 """ 1630 client = GetClientFromFlags() 1631 global_params = GetGlobalParamsFromFlags() 1632 request = messages.StorageObjectAccessControlsDeleteRequest( 1633 bucket=bucket.decode('utf8'), 1634 object=object.decode('utf8'), 1635 entity=entity.decode('utf8'), 1636 ) 1637 if FLAGS['generation'].present: 1638 request.generation = int(FLAGS.generation) 1639 result = client.objectAccessControls.Delete( 1640 request, global_params=global_params) 1641 print apitools_base_cli.FormatOutput(result) 1642 1643 1644class ObjectAccessControlsGet(apitools_base_cli.NewCmd): 1645 """Command wrapping objectAccessControls.Get.""" 1646 1647 usage = """objectAccessControls_get <bucket> <object> <entity>""" 1648 1649 def __init__(self, name, fv): 1650 super(ObjectAccessControlsGet, self).__init__(name, fv) 1651 flags.DEFINE_string( 1652 'generation', 1653 None, 1654 u'If present, selects a specific revision of this object (as opposed ' 1655 u'to the latest version, the default).', 1656 flag_values=fv) 1657 1658 def RunWithArgs(self, bucket, object, entity): 1659 """Returns the ACL entry for the specified entity on the specified object. 1660 1661 Args: 1662 bucket: Name of a bucket. 1663 object: Name of the object. 1664 entity: The entity holding the permission. Can be user-userId, user- 1665 emailAddress, group-groupId, group-emailAddress, allUsers, or 1666 allAuthenticatedUsers. 1667 1668 Flags: 1669 generation: If present, selects a specific revision of this object (as 1670 opposed to the latest version, the default). 1671 """ 1672 client = GetClientFromFlags() 1673 global_params = GetGlobalParamsFromFlags() 1674 request = messages.StorageObjectAccessControlsGetRequest( 1675 bucket=bucket.decode('utf8'), 1676 object=object.decode('utf8'), 1677 entity=entity.decode('utf8'), 1678 ) 1679 if FLAGS['generation'].present: 1680 request.generation = int(FLAGS.generation) 1681 result = client.objectAccessControls.Get( 1682 request, global_params=global_params) 1683 print apitools_base_cli.FormatOutput(result) 1684 1685 1686class ObjectAccessControlsInsert(apitools_base_cli.NewCmd): 1687 """Command wrapping objectAccessControls.Insert.""" 1688 1689 usage = """objectAccessControls_insert <bucket> <object>""" 1690 1691 def __init__(self, name, fv): 1692 super(ObjectAccessControlsInsert, self).__init__(name, fv) 1693 flags.DEFINE_string( 1694 'generation', 1695 None, 1696 u'If present, selects a specific revision of this object (as opposed ' 1697 u'to the latest version, the default).', 1698 flag_values=fv) 1699 flags.DEFINE_string( 1700 'objectAccessControl', 1701 None, 1702 u'A ObjectAccessControl resource to be passed as the request body.', 1703 flag_values=fv) 1704 1705 def RunWithArgs(self, bucket, object): 1706 """Creates a new ACL entry on the specified object. 1707 1708 Args: 1709 bucket: Name of a bucket. 1710 object: Name of the object. 1711 1712 Flags: 1713 generation: If present, selects a specific revision of this object (as 1714 opposed to the latest version, the default). 1715 objectAccessControl: A ObjectAccessControl resource to be passed as the 1716 request body. 1717 """ 1718 client = GetClientFromFlags() 1719 global_params = GetGlobalParamsFromFlags() 1720 request = messages.StorageObjectAccessControlsInsertRequest( 1721 bucket=bucket.decode('utf8'), 1722 object=object.decode('utf8'), 1723 ) 1724 if FLAGS['generation'].present: 1725 request.generation = int(FLAGS.generation) 1726 if FLAGS['objectAccessControl'].present: 1727 request.objectAccessControl = apitools_base.JsonToMessage(messages.ObjectAccessControl, FLAGS.objectAccessControl) 1728 result = client.objectAccessControls.Insert( 1729 request, global_params=global_params) 1730 print apitools_base_cli.FormatOutput(result) 1731 1732 1733class ObjectAccessControlsList(apitools_base_cli.NewCmd): 1734 """Command wrapping objectAccessControls.List.""" 1735 1736 usage = """objectAccessControls_list <bucket> <object>""" 1737 1738 def __init__(self, name, fv): 1739 super(ObjectAccessControlsList, self).__init__(name, fv) 1740 flags.DEFINE_string( 1741 'generation', 1742 None, 1743 u'If present, selects a specific revision of this object (as opposed ' 1744 u'to the latest version, the default).', 1745 flag_values=fv) 1746 1747 def RunWithArgs(self, bucket, object): 1748 """Retrieves ACL entries on the specified object. 1749 1750 Args: 1751 bucket: Name of a bucket. 1752 object: Name of the object. 1753 1754 Flags: 1755 generation: If present, selects a specific revision of this object (as 1756 opposed to the latest version, the default). 1757 """ 1758 client = GetClientFromFlags() 1759 global_params = GetGlobalParamsFromFlags() 1760 request = messages.StorageObjectAccessControlsListRequest( 1761 bucket=bucket.decode('utf8'), 1762 object=object.decode('utf8'), 1763 ) 1764 if FLAGS['generation'].present: 1765 request.generation = int(FLAGS.generation) 1766 result = client.objectAccessControls.List( 1767 request, global_params=global_params) 1768 print apitools_base_cli.FormatOutput(result) 1769 1770 1771class ObjectAccessControlsPatch(apitools_base_cli.NewCmd): 1772 """Command wrapping objectAccessControls.Patch.""" 1773 1774 usage = """objectAccessControls_patch <bucket> <object> <entity>""" 1775 1776 def __init__(self, name, fv): 1777 super(ObjectAccessControlsPatch, self).__init__(name, fv) 1778 flags.DEFINE_string( 1779 'generation', 1780 None, 1781 u'If present, selects a specific revision of this object (as opposed ' 1782 u'to the latest version, the default).', 1783 flag_values=fv) 1784 flags.DEFINE_string( 1785 'objectAccessControl', 1786 None, 1787 u'A ObjectAccessControl resource to be passed as the request body.', 1788 flag_values=fv) 1789 1790 def RunWithArgs(self, bucket, object, entity): 1791 """Updates an ACL entry on the specified object. This method supports 1792 patch semantics. 1793 1794 Args: 1795 bucket: Name of a bucket. 1796 object: Name of the object. 1797 entity: The entity holding the permission. Can be user-userId, user- 1798 emailAddress, group-groupId, group-emailAddress, allUsers, or 1799 allAuthenticatedUsers. 1800 1801 Flags: 1802 generation: If present, selects a specific revision of this object (as 1803 opposed to the latest version, the default). 1804 objectAccessControl: A ObjectAccessControl resource to be passed as the 1805 request body. 1806 """ 1807 client = GetClientFromFlags() 1808 global_params = GetGlobalParamsFromFlags() 1809 request = messages.StorageObjectAccessControlsPatchRequest( 1810 bucket=bucket.decode('utf8'), 1811 object=object.decode('utf8'), 1812 entity=entity.decode('utf8'), 1813 ) 1814 if FLAGS['generation'].present: 1815 request.generation = int(FLAGS.generation) 1816 if FLAGS['objectAccessControl'].present: 1817 request.objectAccessControl = apitools_base.JsonToMessage(messages.ObjectAccessControl, FLAGS.objectAccessControl) 1818 result = client.objectAccessControls.Patch( 1819 request, global_params=global_params) 1820 print apitools_base_cli.FormatOutput(result) 1821 1822 1823class ObjectAccessControlsUpdate(apitools_base_cli.NewCmd): 1824 """Command wrapping objectAccessControls.Update.""" 1825 1826 usage = """objectAccessControls_update <bucket> <object> <entity>""" 1827 1828 def __init__(self, name, fv): 1829 super(ObjectAccessControlsUpdate, self).__init__(name, fv) 1830 flags.DEFINE_string( 1831 'generation', 1832 None, 1833 u'If present, selects a specific revision of this object (as opposed ' 1834 u'to the latest version, the default).', 1835 flag_values=fv) 1836 flags.DEFINE_string( 1837 'objectAccessControl', 1838 None, 1839 u'A ObjectAccessControl resource to be passed as the request body.', 1840 flag_values=fv) 1841 1842 def RunWithArgs(self, bucket, object, entity): 1843 """Updates an ACL entry on the specified object. 1844 1845 Args: 1846 bucket: Name of a bucket. 1847 object: Name of the object. 1848 entity: The entity holding the permission. Can be user-userId, user- 1849 emailAddress, group-groupId, group-emailAddress, allUsers, or 1850 allAuthenticatedUsers. 1851 1852 Flags: 1853 generation: If present, selects a specific revision of this object (as 1854 opposed to the latest version, the default). 1855 objectAccessControl: A ObjectAccessControl resource to be passed as the 1856 request body. 1857 """ 1858 client = GetClientFromFlags() 1859 global_params = GetGlobalParamsFromFlags() 1860 request = messages.StorageObjectAccessControlsUpdateRequest( 1861 bucket=bucket.decode('utf8'), 1862 object=object.decode('utf8'), 1863 entity=entity.decode('utf8'), 1864 ) 1865 if FLAGS['generation'].present: 1866 request.generation = int(FLAGS.generation) 1867 if FLAGS['objectAccessControl'].present: 1868 request.objectAccessControl = apitools_base.JsonToMessage(messages.ObjectAccessControl, FLAGS.objectAccessControl) 1869 result = client.objectAccessControls.Update( 1870 request, global_params=global_params) 1871 print apitools_base_cli.FormatOutput(result) 1872 1873 1874class ObjectsCompose(apitools_base_cli.NewCmd): 1875 """Command wrapping objects.Compose.""" 1876 1877 usage = """objects_compose <destinationBucket> <destinationObject>""" 1878 1879 def __init__(self, name, fv): 1880 super(ObjectsCompose, self).__init__(name, fv) 1881 flags.DEFINE_string( 1882 'composeRequest', 1883 None, 1884 u'A ComposeRequest resource to be passed as the request body.', 1885 flag_values=fv) 1886 flags.DEFINE_enum( 1887 'destinationPredefinedAcl', 1888 u'authenticatedRead', 1889 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 1890 u'Apply a predefined set of access controls to the destination ' 1891 u'object.', 1892 flag_values=fv) 1893 flags.DEFINE_string( 1894 'ifGenerationMatch', 1895 None, 1896 u"Makes the operation conditional on whether the object's current " 1897 u'generation matches the given value.', 1898 flag_values=fv) 1899 flags.DEFINE_string( 1900 'ifMetagenerationMatch', 1901 None, 1902 u"Makes the operation conditional on whether the object's current " 1903 u'metageneration matches the given value.', 1904 flag_values=fv) 1905 flags.DEFINE_string( 1906 'download_filename', 1907 '', 1908 'Filename to use for download.', 1909 flag_values=fv) 1910 flags.DEFINE_boolean( 1911 'overwrite', 1912 'False', 1913 'If True, overwrite the existing file when downloading.', 1914 flag_values=fv) 1915 1916 def RunWithArgs(self, destinationBucket, destinationObject): 1917 """Concatenates a list of existing objects into a new object in the same 1918 bucket. 1919 1920 Args: 1921 destinationBucket: Name of the bucket in which to store the new object. 1922 destinationObject: Name of the new object. 1923 1924 Flags: 1925 composeRequest: A ComposeRequest resource to be passed as the request 1926 body. 1927 destinationPredefinedAcl: Apply a predefined set of access controls to 1928 the destination object. 1929 ifGenerationMatch: Makes the operation conditional on whether the 1930 object's current generation matches the given value. 1931 ifMetagenerationMatch: Makes the operation conditional on whether the 1932 object's current metageneration matches the given value. 1933 download_filename: Filename to use for download. 1934 overwrite: If True, overwrite the existing file when downloading. 1935 """ 1936 client = GetClientFromFlags() 1937 global_params = GetGlobalParamsFromFlags() 1938 request = messages.StorageObjectsComposeRequest( 1939 destinationBucket=destinationBucket.decode('utf8'), 1940 destinationObject=destinationObject.decode('utf8'), 1941 ) 1942 if FLAGS['composeRequest'].present: 1943 request.composeRequest = apitools_base.JsonToMessage(messages.ComposeRequest, FLAGS.composeRequest) 1944 if FLAGS['destinationPredefinedAcl'].present: 1945 request.destinationPredefinedAcl = messages.StorageObjectsComposeRequest.DestinationPredefinedAclValueValuesEnum(FLAGS.destinationPredefinedAcl) 1946 if FLAGS['ifGenerationMatch'].present: 1947 request.ifGenerationMatch = int(FLAGS.ifGenerationMatch) 1948 if FLAGS['ifMetagenerationMatch'].present: 1949 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 1950 download = None 1951 if FLAGS.download_filename: 1952 download = apitools_base.Download.FromFile(FLAGS.download_filename, overwrite=FLAGS.overwrite, 1953 progress_callback=apitools_base.DownloadProgressPrinter, 1954 finish_callback=apitools_base.DownloadCompletePrinter) 1955 result = client.objects.Compose( 1956 request, global_params=global_params, download=download) 1957 print apitools_base_cli.FormatOutput(result) 1958 1959 1960class ObjectsCopy(apitools_base_cli.NewCmd): 1961 """Command wrapping objects.Copy.""" 1962 1963 usage = """objects_copy <sourceBucket> <sourceObject> <destinationBucket> <destinationObject>""" 1964 1965 def __init__(self, name, fv): 1966 super(ObjectsCopy, self).__init__(name, fv) 1967 flags.DEFINE_enum( 1968 'destinationPredefinedAcl', 1969 u'authenticatedRead', 1970 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 1971 u'Apply a predefined set of access controls to the destination ' 1972 u'object.', 1973 flag_values=fv) 1974 flags.DEFINE_string( 1975 'ifGenerationMatch', 1976 None, 1977 u"Makes the operation conditional on whether the destination object's" 1978 u' current generation matches the given value.', 1979 flag_values=fv) 1980 flags.DEFINE_string( 1981 'ifGenerationNotMatch', 1982 None, 1983 u"Makes the operation conditional on whether the destination object's" 1984 u' current generation does not match the given value.', 1985 flag_values=fv) 1986 flags.DEFINE_string( 1987 'ifMetagenerationMatch', 1988 None, 1989 u"Makes the operation conditional on whether the destination object's" 1990 u' current metageneration matches the given value.', 1991 flag_values=fv) 1992 flags.DEFINE_string( 1993 'ifMetagenerationNotMatch', 1994 None, 1995 u"Makes the operation conditional on whether the destination object's" 1996 u' current metageneration does not match the given value.', 1997 flag_values=fv) 1998 flags.DEFINE_string( 1999 'ifSourceGenerationMatch', 2000 None, 2001 u"Makes the operation conditional on whether the source object's " 2002 u'generation matches the given value.', 2003 flag_values=fv) 2004 flags.DEFINE_string( 2005 'ifSourceGenerationNotMatch', 2006 None, 2007 u"Makes the operation conditional on whether the source object's " 2008 u'generation does not match the given value.', 2009 flag_values=fv) 2010 flags.DEFINE_string( 2011 'ifSourceMetagenerationMatch', 2012 None, 2013 u"Makes the operation conditional on whether the source object's " 2014 u'current metageneration matches the given value.', 2015 flag_values=fv) 2016 flags.DEFINE_string( 2017 'ifSourceMetagenerationNotMatch', 2018 None, 2019 u"Makes the operation conditional on whether the source object's " 2020 u'current metageneration does not match the given value.', 2021 flag_values=fv) 2022 flags.DEFINE_string( 2023 'object', 2024 None, 2025 u'A Object resource to be passed as the request body.', 2026 flag_values=fv) 2027 flags.DEFINE_enum( 2028 'projection', 2029 u'full', 2030 [u'full', u'noAcl'], 2031 u'Set of properties to return. Defaults to noAcl, unless the object ' 2032 u'resource specifies the acl property, when it defaults to full.', 2033 flag_values=fv) 2034 flags.DEFINE_string( 2035 'sourceGeneration', 2036 None, 2037 u'If present, selects a specific revision of the source object (as ' 2038 u'opposed to the latest version, the default).', 2039 flag_values=fv) 2040 flags.DEFINE_string( 2041 'download_filename', 2042 '', 2043 'Filename to use for download.', 2044 flag_values=fv) 2045 flags.DEFINE_boolean( 2046 'overwrite', 2047 'False', 2048 'If True, overwrite the existing file when downloading.', 2049 flag_values=fv) 2050 2051 def RunWithArgs(self, sourceBucket, sourceObject, destinationBucket, destinationObject): 2052 """Copies a source object to a destination object. Optionally overrides 2053 metadata. 2054 2055 Args: 2056 sourceBucket: Name of the bucket in which to find the source object. 2057 sourceObject: Name of the source object. 2058 destinationBucket: Name of the bucket in which to store the new object. 2059 Overrides the provided object metadata's bucket value, if any. 2060 destinationObject: Name of the new object. Required when the object 2061 metadata is not otherwise provided. Overrides the object metadata's 2062 name value, if any. 2063 2064 Flags: 2065 destinationPredefinedAcl: Apply a predefined set of access controls to 2066 the destination object. 2067 ifGenerationMatch: Makes the operation conditional on whether the 2068 destination object's current generation matches the given value. 2069 ifGenerationNotMatch: Makes the operation conditional on whether the 2070 destination object's current generation does not match the given 2071 value. 2072 ifMetagenerationMatch: Makes the operation conditional on whether the 2073 destination object's current metageneration matches the given value. 2074 ifMetagenerationNotMatch: Makes the operation conditional on whether the 2075 destination object's current metageneration does not match the given 2076 value. 2077 ifSourceGenerationMatch: Makes the operation conditional on whether the 2078 source object's generation matches the given value. 2079 ifSourceGenerationNotMatch: Makes the operation conditional on whether 2080 the source object's generation does not match the given value. 2081 ifSourceMetagenerationMatch: Makes the operation conditional on whether 2082 the source object's current metageneration matches the given value. 2083 ifSourceMetagenerationNotMatch: Makes the operation conditional on 2084 whether the source object's current metageneration does not match the 2085 given value. 2086 object: A Object resource to be passed as the request body. 2087 projection: Set of properties to return. Defaults to noAcl, unless the 2088 object resource specifies the acl property, when it defaults to full. 2089 sourceGeneration: If present, selects a specific revision of the source 2090 object (as opposed to the latest version, the default). 2091 download_filename: Filename to use for download. 2092 overwrite: If True, overwrite the existing file when downloading. 2093 """ 2094 client = GetClientFromFlags() 2095 global_params = GetGlobalParamsFromFlags() 2096 request = messages.StorageObjectsCopyRequest( 2097 sourceBucket=sourceBucket.decode('utf8'), 2098 sourceObject=sourceObject.decode('utf8'), 2099 destinationBucket=destinationBucket.decode('utf8'), 2100 destinationObject=destinationObject.decode('utf8'), 2101 ) 2102 if FLAGS['destinationPredefinedAcl'].present: 2103 request.destinationPredefinedAcl = messages.StorageObjectsCopyRequest.DestinationPredefinedAclValueValuesEnum(FLAGS.destinationPredefinedAcl) 2104 if FLAGS['ifGenerationMatch'].present: 2105 request.ifGenerationMatch = int(FLAGS.ifGenerationMatch) 2106 if FLAGS['ifGenerationNotMatch'].present: 2107 request.ifGenerationNotMatch = int(FLAGS.ifGenerationNotMatch) 2108 if FLAGS['ifMetagenerationMatch'].present: 2109 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 2110 if FLAGS['ifMetagenerationNotMatch'].present: 2111 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 2112 if FLAGS['ifSourceGenerationMatch'].present: 2113 request.ifSourceGenerationMatch = int(FLAGS.ifSourceGenerationMatch) 2114 if FLAGS['ifSourceGenerationNotMatch'].present: 2115 request.ifSourceGenerationNotMatch = int(FLAGS.ifSourceGenerationNotMatch) 2116 if FLAGS['ifSourceMetagenerationMatch'].present: 2117 request.ifSourceMetagenerationMatch = int(FLAGS.ifSourceMetagenerationMatch) 2118 if FLAGS['ifSourceMetagenerationNotMatch'].present: 2119 request.ifSourceMetagenerationNotMatch = int(FLAGS.ifSourceMetagenerationNotMatch) 2120 if FLAGS['object'].present: 2121 request.object = apitools_base.JsonToMessage(messages.Object, FLAGS.object) 2122 if FLAGS['projection'].present: 2123 request.projection = messages.StorageObjectsCopyRequest.ProjectionValueValuesEnum(FLAGS.projection) 2124 if FLAGS['sourceGeneration'].present: 2125 request.sourceGeneration = int(FLAGS.sourceGeneration) 2126 download = None 2127 if FLAGS.download_filename: 2128 download = apitools_base.Download.FromFile(FLAGS.download_filename, overwrite=FLAGS.overwrite, 2129 progress_callback=apitools_base.DownloadProgressPrinter, 2130 finish_callback=apitools_base.DownloadCompletePrinter) 2131 result = client.objects.Copy( 2132 request, global_params=global_params, download=download) 2133 print apitools_base_cli.FormatOutput(result) 2134 2135 2136class ObjectsDelete(apitools_base_cli.NewCmd): 2137 """Command wrapping objects.Delete.""" 2138 2139 usage = """objects_delete <bucket> <object>""" 2140 2141 def __init__(self, name, fv): 2142 super(ObjectsDelete, self).__init__(name, fv) 2143 flags.DEFINE_string( 2144 'generation', 2145 None, 2146 u'If present, permanently deletes a specific revision of this object ' 2147 u'(as opposed to the latest version, the default).', 2148 flag_values=fv) 2149 flags.DEFINE_string( 2150 'ifGenerationMatch', 2151 None, 2152 u"Makes the operation conditional on whether the object's current " 2153 u'generation matches the given value.', 2154 flag_values=fv) 2155 flags.DEFINE_string( 2156 'ifGenerationNotMatch', 2157 None, 2158 u"Makes the operation conditional on whether the object's current " 2159 u'generation does not match the given value.', 2160 flag_values=fv) 2161 flags.DEFINE_string( 2162 'ifMetagenerationMatch', 2163 None, 2164 u"Makes the operation conditional on whether the object's current " 2165 u'metageneration matches the given value.', 2166 flag_values=fv) 2167 flags.DEFINE_string( 2168 'ifMetagenerationNotMatch', 2169 None, 2170 u"Makes the operation conditional on whether the object's current " 2171 u'metageneration does not match the given value.', 2172 flag_values=fv) 2173 2174 def RunWithArgs(self, bucket, object): 2175 """Deletes an object and its metadata. Deletions are permanent if 2176 versioning is not enabled for the bucket, or if the generation parameter 2177 is used. 2178 2179 Args: 2180 bucket: Name of the bucket in which the object resides. 2181 object: Name of the object. 2182 2183 Flags: 2184 generation: If present, permanently deletes a specific revision of this 2185 object (as opposed to the latest version, the default). 2186 ifGenerationMatch: Makes the operation conditional on whether the 2187 object's current generation matches the given value. 2188 ifGenerationNotMatch: Makes the operation conditional on whether the 2189 object's current generation does not match the given value. 2190 ifMetagenerationMatch: Makes the operation conditional on whether the 2191 object's current metageneration matches the given value. 2192 ifMetagenerationNotMatch: Makes the operation conditional on whether the 2193 object's current metageneration does not match the given value. 2194 """ 2195 client = GetClientFromFlags() 2196 global_params = GetGlobalParamsFromFlags() 2197 request = messages.StorageObjectsDeleteRequest( 2198 bucket=bucket.decode('utf8'), 2199 object=object.decode('utf8'), 2200 ) 2201 if FLAGS['generation'].present: 2202 request.generation = int(FLAGS.generation) 2203 if FLAGS['ifGenerationMatch'].present: 2204 request.ifGenerationMatch = int(FLAGS.ifGenerationMatch) 2205 if FLAGS['ifGenerationNotMatch'].present: 2206 request.ifGenerationNotMatch = int(FLAGS.ifGenerationNotMatch) 2207 if FLAGS['ifMetagenerationMatch'].present: 2208 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 2209 if FLAGS['ifMetagenerationNotMatch'].present: 2210 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 2211 result = client.objects.Delete( 2212 request, global_params=global_params) 2213 print apitools_base_cli.FormatOutput(result) 2214 2215 2216class ObjectsGet(apitools_base_cli.NewCmd): 2217 """Command wrapping objects.Get.""" 2218 2219 usage = """objects_get <bucket> <object>""" 2220 2221 def __init__(self, name, fv): 2222 super(ObjectsGet, self).__init__(name, fv) 2223 flags.DEFINE_string( 2224 'generation', 2225 None, 2226 u'If present, selects a specific revision of this object (as opposed ' 2227 u'to the latest version, the default).', 2228 flag_values=fv) 2229 flags.DEFINE_string( 2230 'ifGenerationMatch', 2231 None, 2232 u"Makes the operation conditional on whether the object's generation " 2233 u'matches the given value.', 2234 flag_values=fv) 2235 flags.DEFINE_string( 2236 'ifGenerationNotMatch', 2237 None, 2238 u"Makes the operation conditional on whether the object's generation " 2239 u'does not match the given value.', 2240 flag_values=fv) 2241 flags.DEFINE_string( 2242 'ifMetagenerationMatch', 2243 None, 2244 u"Makes the operation conditional on whether the object's current " 2245 u'metageneration matches the given value.', 2246 flag_values=fv) 2247 flags.DEFINE_string( 2248 'ifMetagenerationNotMatch', 2249 None, 2250 u"Makes the operation conditional on whether the object's current " 2251 u'metageneration does not match the given value.', 2252 flag_values=fv) 2253 flags.DEFINE_enum( 2254 'projection', 2255 u'full', 2256 [u'full', u'noAcl'], 2257 u'Set of properties to return. Defaults to noAcl.', 2258 flag_values=fv) 2259 flags.DEFINE_string( 2260 'download_filename', 2261 '', 2262 'Filename to use for download.', 2263 flag_values=fv) 2264 flags.DEFINE_boolean( 2265 'overwrite', 2266 'False', 2267 'If True, overwrite the existing file when downloading.', 2268 flag_values=fv) 2269 2270 def RunWithArgs(self, bucket, object): 2271 """Retrieves an object or its metadata. 2272 2273 Args: 2274 bucket: Name of the bucket in which the object resides. 2275 object: Name of the object. 2276 2277 Flags: 2278 generation: If present, selects a specific revision of this object (as 2279 opposed to the latest version, the default). 2280 ifGenerationMatch: Makes the operation conditional on whether the 2281 object's generation matches the given value. 2282 ifGenerationNotMatch: Makes the operation conditional on whether the 2283 object's generation does not match the given value. 2284 ifMetagenerationMatch: Makes the operation conditional on whether the 2285 object's current metageneration matches the given value. 2286 ifMetagenerationNotMatch: Makes the operation conditional on whether the 2287 object's current metageneration does not match the given value. 2288 projection: Set of properties to return. Defaults to noAcl. 2289 download_filename: Filename to use for download. 2290 overwrite: If True, overwrite the existing file when downloading. 2291 """ 2292 client = GetClientFromFlags() 2293 global_params = GetGlobalParamsFromFlags() 2294 request = messages.StorageObjectsGetRequest( 2295 bucket=bucket.decode('utf8'), 2296 object=object.decode('utf8'), 2297 ) 2298 if FLAGS['generation'].present: 2299 request.generation = int(FLAGS.generation) 2300 if FLAGS['ifGenerationMatch'].present: 2301 request.ifGenerationMatch = int(FLAGS.ifGenerationMatch) 2302 if FLAGS['ifGenerationNotMatch'].present: 2303 request.ifGenerationNotMatch = int(FLAGS.ifGenerationNotMatch) 2304 if FLAGS['ifMetagenerationMatch'].present: 2305 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 2306 if FLAGS['ifMetagenerationNotMatch'].present: 2307 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 2308 if FLAGS['projection'].present: 2309 request.projection = messages.StorageObjectsGetRequest.ProjectionValueValuesEnum(FLAGS.projection) 2310 download = None 2311 if FLAGS.download_filename: 2312 download = apitools_base.Download.FromFile(FLAGS.download_filename, overwrite=FLAGS.overwrite, 2313 progress_callback=apitools_base.DownloadProgressPrinter, 2314 finish_callback=apitools_base.DownloadCompletePrinter) 2315 result = client.objects.Get( 2316 request, global_params=global_params, download=download) 2317 print apitools_base_cli.FormatOutput(result) 2318 2319 2320class ObjectsInsert(apitools_base_cli.NewCmd): 2321 """Command wrapping objects.Insert.""" 2322 2323 usage = """objects_insert <bucket>""" 2324 2325 def __init__(self, name, fv): 2326 super(ObjectsInsert, self).__init__(name, fv) 2327 flags.DEFINE_string( 2328 'contentEncoding', 2329 None, 2330 u'If set, sets the contentEncoding property of the final object to ' 2331 u'this value. Setting this parameter is equivalent to setting the ' 2332 u'contentEncoding metadata property. This can be useful when ' 2333 u'uploading an object with uploadType=media to indicate the encoding ' 2334 u'of the content being uploaded.', 2335 flag_values=fv) 2336 flags.DEFINE_string( 2337 'ifGenerationMatch', 2338 None, 2339 u"Makes the operation conditional on whether the object's current " 2340 u'generation matches the given value.', 2341 flag_values=fv) 2342 flags.DEFINE_string( 2343 'ifGenerationNotMatch', 2344 None, 2345 u"Makes the operation conditional on whether the object's current " 2346 u'generation does not match the given value.', 2347 flag_values=fv) 2348 flags.DEFINE_string( 2349 'ifMetagenerationMatch', 2350 None, 2351 u"Makes the operation conditional on whether the object's current " 2352 u'metageneration matches the given value.', 2353 flag_values=fv) 2354 flags.DEFINE_string( 2355 'ifMetagenerationNotMatch', 2356 None, 2357 u"Makes the operation conditional on whether the object's current " 2358 u'metageneration does not match the given value.', 2359 flag_values=fv) 2360 flags.DEFINE_string( 2361 'name', 2362 None, 2363 u'Name of the object. Required when the object metadata is not ' 2364 u"otherwise provided. Overrides the object metadata's name value, if " 2365 u'any.', 2366 flag_values=fv) 2367 flags.DEFINE_string( 2368 'object', 2369 None, 2370 u'A Object resource to be passed as the request body.', 2371 flag_values=fv) 2372 flags.DEFINE_enum( 2373 'predefinedAcl', 2374 u'authenticatedRead', 2375 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 2376 u'Apply a predefined set of access controls to this object.', 2377 flag_values=fv) 2378 flags.DEFINE_enum( 2379 'projection', 2380 u'full', 2381 [u'full', u'noAcl'], 2382 u'Set of properties to return. Defaults to noAcl, unless the object ' 2383 u'resource specifies the acl property, when it defaults to full.', 2384 flag_values=fv) 2385 flags.DEFINE_string( 2386 'upload_filename', 2387 '', 2388 'Filename to use for upload.', 2389 flag_values=fv) 2390 flags.DEFINE_string( 2391 'upload_mime_type', 2392 '', 2393 'MIME type to use for the upload. Only needed if the extension on ' 2394 '--upload_filename does not determine the correct (or any) MIME ' 2395 'type.', 2396 flag_values=fv) 2397 flags.DEFINE_string( 2398 'download_filename', 2399 '', 2400 'Filename to use for download.', 2401 flag_values=fv) 2402 flags.DEFINE_boolean( 2403 'overwrite', 2404 'False', 2405 'If True, overwrite the existing file when downloading.', 2406 flag_values=fv) 2407 2408 def RunWithArgs(self, bucket): 2409 """Stores a new object and metadata. 2410 2411 Args: 2412 bucket: Name of the bucket in which to store the new object. Overrides 2413 the provided object metadata's bucket value, if any. 2414 2415 Flags: 2416 contentEncoding: If set, sets the contentEncoding property of the final 2417 object to this value. Setting this parameter is equivalent to setting 2418 the contentEncoding metadata property. This can be useful when 2419 uploading an object with uploadType=media to indicate the encoding of 2420 the content being uploaded. 2421 ifGenerationMatch: Makes the operation conditional on whether the 2422 object's current generation matches the given value. 2423 ifGenerationNotMatch: Makes the operation conditional on whether the 2424 object's current generation does not match the given value. 2425 ifMetagenerationMatch: Makes the operation conditional on whether the 2426 object's current metageneration matches the given value. 2427 ifMetagenerationNotMatch: Makes the operation conditional on whether the 2428 object's current metageneration does not match the given value. 2429 name: Name of the object. Required when the object metadata is not 2430 otherwise provided. Overrides the object metadata's name value, if 2431 any. 2432 object: A Object resource to be passed as the request body. 2433 predefinedAcl: Apply a predefined set of access controls to this object. 2434 projection: Set of properties to return. Defaults to noAcl, unless the 2435 object resource specifies the acl property, when it defaults to full. 2436 upload_filename: Filename to use for upload. 2437 upload_mime_type: MIME type to use for the upload. Only needed if the 2438 extension on --upload_filename does not determine the correct (or any) 2439 MIME type. 2440 download_filename: Filename to use for download. 2441 overwrite: If True, overwrite the existing file when downloading. 2442 """ 2443 client = GetClientFromFlags() 2444 global_params = GetGlobalParamsFromFlags() 2445 request = messages.StorageObjectsInsertRequest( 2446 bucket=bucket.decode('utf8'), 2447 ) 2448 if FLAGS['contentEncoding'].present: 2449 request.contentEncoding = FLAGS.contentEncoding.decode('utf8') 2450 if FLAGS['ifGenerationMatch'].present: 2451 request.ifGenerationMatch = int(FLAGS.ifGenerationMatch) 2452 if FLAGS['ifGenerationNotMatch'].present: 2453 request.ifGenerationNotMatch = int(FLAGS.ifGenerationNotMatch) 2454 if FLAGS['ifMetagenerationMatch'].present: 2455 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 2456 if FLAGS['ifMetagenerationNotMatch'].present: 2457 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 2458 if FLAGS['name'].present: 2459 request.name = FLAGS.name.decode('utf8') 2460 if FLAGS['object'].present: 2461 request.object = apitools_base.JsonToMessage(messages.Object, FLAGS.object) 2462 if FLAGS['predefinedAcl'].present: 2463 request.predefinedAcl = messages.StorageObjectsInsertRequest.PredefinedAclValueValuesEnum(FLAGS.predefinedAcl) 2464 if FLAGS['projection'].present: 2465 request.projection = messages.StorageObjectsInsertRequest.ProjectionValueValuesEnum(FLAGS.projection) 2466 upload = None 2467 if FLAGS.upload_filename: 2468 upload = apitools_base.Upload.FromFile( 2469 FLAGS.upload_filename, FLAGS.upload_mime_type, 2470 progress_callback=apitools_base.UploadProgressPrinter, 2471 finish_callback=apitools_base.UploadCompletePrinter) 2472 download = None 2473 if FLAGS.download_filename: 2474 download = apitools_base.Download.FromFile(FLAGS.download_filename, overwrite=FLAGS.overwrite, 2475 progress_callback=apitools_base.DownloadProgressPrinter, 2476 finish_callback=apitools_base.DownloadCompletePrinter) 2477 result = client.objects.Insert( 2478 request, global_params=global_params, upload=upload, download=download) 2479 print apitools_base_cli.FormatOutput(result) 2480 2481 2482class ObjectsList(apitools_base_cli.NewCmd): 2483 """Command wrapping objects.List.""" 2484 2485 usage = """objects_list <bucket>""" 2486 2487 def __init__(self, name, fv): 2488 super(ObjectsList, self).__init__(name, fv) 2489 flags.DEFINE_string( 2490 'delimiter', 2491 None, 2492 u'Returns results in a directory-like mode. items will contain only ' 2493 u'objects whose names, aside from the prefix, do not contain ' 2494 u'delimiter. Objects whose names, aside from the prefix, contain ' 2495 u'delimiter will have their name, truncated after the delimiter, ' 2496 u'returned in prefixes. Duplicate prefixes are omitted.', 2497 flag_values=fv) 2498 flags.DEFINE_integer( 2499 'maxResults', 2500 None, 2501 u'Maximum number of items plus prefixes to return. As duplicate ' 2502 u'prefixes are omitted, fewer total results may be returned than ' 2503 u'requested. The default value of this parameter is 1,000 items.', 2504 flag_values=fv) 2505 flags.DEFINE_string( 2506 'pageToken', 2507 None, 2508 u'A previously-returned page token representing part of the larger ' 2509 u'set of results to view.', 2510 flag_values=fv) 2511 flags.DEFINE_string( 2512 'prefix', 2513 None, 2514 u'Filter results to objects whose names begin with this prefix.', 2515 flag_values=fv) 2516 flags.DEFINE_enum( 2517 'projection', 2518 u'full', 2519 [u'full', u'noAcl'], 2520 u'Set of properties to return. Defaults to noAcl.', 2521 flag_values=fv) 2522 flags.DEFINE_boolean( 2523 'versions', 2524 None, 2525 u'If true, lists all versions of an object as distinct results. The ' 2526 u'default is false. For more information, see Object Versioning.', 2527 flag_values=fv) 2528 2529 def RunWithArgs(self, bucket): 2530 """Retrieves a list of objects matching the criteria. 2531 2532 Args: 2533 bucket: Name of the bucket in which to look for objects. 2534 2535 Flags: 2536 delimiter: Returns results in a directory-like mode. items will contain 2537 only objects whose names, aside from the prefix, do not contain 2538 delimiter. Objects whose names, aside from the prefix, contain 2539 delimiter will have their name, truncated after the delimiter, 2540 returned in prefixes. Duplicate prefixes are omitted. 2541 maxResults: Maximum number of items plus prefixes to return. As 2542 duplicate prefixes are omitted, fewer total results may be returned 2543 than requested. The default value of this parameter is 1,000 items. 2544 pageToken: A previously-returned page token representing part of the 2545 larger set of results to view. 2546 prefix: Filter results to objects whose names begin with this prefix. 2547 projection: Set of properties to return. Defaults to noAcl. 2548 versions: If true, lists all versions of an object as distinct results. 2549 The default is false. For more information, see Object Versioning. 2550 """ 2551 client = GetClientFromFlags() 2552 global_params = GetGlobalParamsFromFlags() 2553 request = messages.StorageObjectsListRequest( 2554 bucket=bucket.decode('utf8'), 2555 ) 2556 if FLAGS['delimiter'].present: 2557 request.delimiter = FLAGS.delimiter.decode('utf8') 2558 if FLAGS['maxResults'].present: 2559 request.maxResults = FLAGS.maxResults 2560 if FLAGS['pageToken'].present: 2561 request.pageToken = FLAGS.pageToken.decode('utf8') 2562 if FLAGS['prefix'].present: 2563 request.prefix = FLAGS.prefix.decode('utf8') 2564 if FLAGS['projection'].present: 2565 request.projection = messages.StorageObjectsListRequest.ProjectionValueValuesEnum(FLAGS.projection) 2566 if FLAGS['versions'].present: 2567 request.versions = FLAGS.versions 2568 result = client.objects.List( 2569 request, global_params=global_params) 2570 print apitools_base_cli.FormatOutput(result) 2571 2572 2573class ObjectsPatch(apitools_base_cli.NewCmd): 2574 """Command wrapping objects.Patch.""" 2575 2576 usage = """objects_patch <bucket> <object>""" 2577 2578 def __init__(self, name, fv): 2579 super(ObjectsPatch, self).__init__(name, fv) 2580 flags.DEFINE_string( 2581 'generation', 2582 None, 2583 u'If present, selects a specific revision of this object (as opposed ' 2584 u'to the latest version, the default).', 2585 flag_values=fv) 2586 flags.DEFINE_string( 2587 'ifGenerationMatch', 2588 None, 2589 u"Makes the operation conditional on whether the object's current " 2590 u'generation matches the given value.', 2591 flag_values=fv) 2592 flags.DEFINE_string( 2593 'ifGenerationNotMatch', 2594 None, 2595 u"Makes the operation conditional on whether the object's current " 2596 u'generation does not match the given value.', 2597 flag_values=fv) 2598 flags.DEFINE_string( 2599 'ifMetagenerationMatch', 2600 None, 2601 u"Makes the operation conditional on whether the object's current " 2602 u'metageneration matches the given value.', 2603 flag_values=fv) 2604 flags.DEFINE_string( 2605 'ifMetagenerationNotMatch', 2606 None, 2607 u"Makes the operation conditional on whether the object's current " 2608 u'metageneration does not match the given value.', 2609 flag_values=fv) 2610 flags.DEFINE_string( 2611 'objectResource', 2612 None, 2613 u'A Object resource to be passed as the request body.', 2614 flag_values=fv) 2615 flags.DEFINE_enum( 2616 'predefinedAcl', 2617 u'authenticatedRead', 2618 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 2619 u'Apply a predefined set of access controls to this object.', 2620 flag_values=fv) 2621 flags.DEFINE_enum( 2622 'projection', 2623 u'full', 2624 [u'full', u'noAcl'], 2625 u'Set of properties to return. Defaults to full.', 2626 flag_values=fv) 2627 2628 def RunWithArgs(self, bucket, object): 2629 """Updates an object's metadata. This method supports patch semantics. 2630 2631 Args: 2632 bucket: Name of the bucket in which the object resides. 2633 object: Name of the object. 2634 2635 Flags: 2636 generation: If present, selects a specific revision of this object (as 2637 opposed to the latest version, the default). 2638 ifGenerationMatch: Makes the operation conditional on whether the 2639 object's current generation matches the given value. 2640 ifGenerationNotMatch: Makes the operation conditional on whether the 2641 object's current generation does not match the given value. 2642 ifMetagenerationMatch: Makes the operation conditional on whether the 2643 object's current metageneration matches the given value. 2644 ifMetagenerationNotMatch: Makes the operation conditional on whether the 2645 object's current metageneration does not match the given value. 2646 objectResource: A Object resource to be passed as the request body. 2647 predefinedAcl: Apply a predefined set of access controls to this object. 2648 projection: Set of properties to return. Defaults to full. 2649 """ 2650 client = GetClientFromFlags() 2651 global_params = GetGlobalParamsFromFlags() 2652 request = messages.StorageObjectsPatchRequest( 2653 bucket=bucket.decode('utf8'), 2654 object=object.decode('utf8'), 2655 ) 2656 if FLAGS['generation'].present: 2657 request.generation = int(FLAGS.generation) 2658 if FLAGS['ifGenerationMatch'].present: 2659 request.ifGenerationMatch = int(FLAGS.ifGenerationMatch) 2660 if FLAGS['ifGenerationNotMatch'].present: 2661 request.ifGenerationNotMatch = int(FLAGS.ifGenerationNotMatch) 2662 if FLAGS['ifMetagenerationMatch'].present: 2663 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 2664 if FLAGS['ifMetagenerationNotMatch'].present: 2665 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 2666 if FLAGS['objectResource'].present: 2667 request.objectResource = apitools_base.JsonToMessage(messages.Object, FLAGS.objectResource) 2668 if FLAGS['predefinedAcl'].present: 2669 request.predefinedAcl = messages.StorageObjectsPatchRequest.PredefinedAclValueValuesEnum(FLAGS.predefinedAcl) 2670 if FLAGS['projection'].present: 2671 request.projection = messages.StorageObjectsPatchRequest.ProjectionValueValuesEnum(FLAGS.projection) 2672 result = client.objects.Patch( 2673 request, global_params=global_params) 2674 print apitools_base_cli.FormatOutput(result) 2675 2676 2677class ObjectsRewrite(apitools_base_cli.NewCmd): 2678 """Command wrapping objects.Rewrite.""" 2679 2680 usage = """objects_rewrite <sourceBucket> <sourceObject> <destinationBucket> <destinationObject>""" 2681 2682 def __init__(self, name, fv): 2683 super(ObjectsRewrite, self).__init__(name, fv) 2684 flags.DEFINE_enum( 2685 'destinationPredefinedAcl', 2686 u'authenticatedRead', 2687 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 2688 u'Apply a predefined set of access controls to the destination ' 2689 u'object.', 2690 flag_values=fv) 2691 flags.DEFINE_string( 2692 'ifGenerationMatch', 2693 None, 2694 u"Makes the operation conditional on whether the destination object's" 2695 u' current generation matches the given value.', 2696 flag_values=fv) 2697 flags.DEFINE_string( 2698 'ifGenerationNotMatch', 2699 None, 2700 u"Makes the operation conditional on whether the destination object's" 2701 u' current generation does not match the given value.', 2702 flag_values=fv) 2703 flags.DEFINE_string( 2704 'ifMetagenerationMatch', 2705 None, 2706 u"Makes the operation conditional on whether the destination object's" 2707 u' current metageneration matches the given value.', 2708 flag_values=fv) 2709 flags.DEFINE_string( 2710 'ifMetagenerationNotMatch', 2711 None, 2712 u"Makes the operation conditional on whether the destination object's" 2713 u' current metageneration does not match the given value.', 2714 flag_values=fv) 2715 flags.DEFINE_string( 2716 'ifSourceGenerationMatch', 2717 None, 2718 u"Makes the operation conditional on whether the source object's " 2719 u'generation matches the given value.', 2720 flag_values=fv) 2721 flags.DEFINE_string( 2722 'ifSourceGenerationNotMatch', 2723 None, 2724 u"Makes the operation conditional on whether the source object's " 2725 u'generation does not match the given value.', 2726 flag_values=fv) 2727 flags.DEFINE_string( 2728 'ifSourceMetagenerationMatch', 2729 None, 2730 u"Makes the operation conditional on whether the source object's " 2731 u'current metageneration matches the given value.', 2732 flag_values=fv) 2733 flags.DEFINE_string( 2734 'ifSourceMetagenerationNotMatch', 2735 None, 2736 u"Makes the operation conditional on whether the source object's " 2737 u'current metageneration does not match the given value.', 2738 flag_values=fv) 2739 flags.DEFINE_string( 2740 'maxBytesRewrittenPerCall', 2741 None, 2742 u'The maximum number of bytes that will be rewritten per rewrite ' 2743 u"request. Most callers shouldn't need to specify this parameter - it" 2744 u' is primarily in place to support testing. If specified the value ' 2745 u'must be an integral multiple of 1 MiB (1048576). Also, this only ' 2746 u'applies to requests where the source and destination span locations' 2747 u' and/or storage classes. Finally, this value must not change across' 2748 u" rewrite calls else you'll get an error that the rewriteToken is " 2749 u'invalid.', 2750 flag_values=fv) 2751 flags.DEFINE_string( 2752 'object', 2753 None, 2754 u'A Object resource to be passed as the request body.', 2755 flag_values=fv) 2756 flags.DEFINE_enum( 2757 'projection', 2758 u'full', 2759 [u'full', u'noAcl'], 2760 u'Set of properties to return. Defaults to noAcl, unless the object ' 2761 u'resource specifies the acl property, when it defaults to full.', 2762 flag_values=fv) 2763 flags.DEFINE_string( 2764 'rewriteToken', 2765 None, 2766 u'Include this field (from the previous rewrite response) on each ' 2767 u'rewrite request after the first one, until the rewrite response ' 2768 u"'done' flag is true. Calls that provide a rewriteToken can omit all" 2769 u' other request fields, but if included those fields must match the ' 2770 u'values provided in the first rewrite request.', 2771 flag_values=fv) 2772 flags.DEFINE_string( 2773 'sourceGeneration', 2774 None, 2775 u'If present, selects a specific revision of the source object (as ' 2776 u'opposed to the latest version, the default).', 2777 flag_values=fv) 2778 2779 def RunWithArgs(self, sourceBucket, sourceObject, destinationBucket, destinationObject): 2780 """Rewrites a source object to a destination object. Optionally overrides 2781 metadata. 2782 2783 Args: 2784 sourceBucket: Name of the bucket in which to find the source object. 2785 sourceObject: Name of the source object. 2786 destinationBucket: Name of the bucket in which to store the new object. 2787 Overrides the provided object metadata's bucket value, if any. 2788 destinationObject: Name of the new object. Required when the object 2789 metadata is not otherwise provided. Overrides the object metadata's 2790 name value, if any. 2791 2792 Flags: 2793 destinationPredefinedAcl: Apply a predefined set of access controls to 2794 the destination object. 2795 ifGenerationMatch: Makes the operation conditional on whether the 2796 destination object's current generation matches the given value. 2797 ifGenerationNotMatch: Makes the operation conditional on whether the 2798 destination object's current generation does not match the given 2799 value. 2800 ifMetagenerationMatch: Makes the operation conditional on whether the 2801 destination object's current metageneration matches the given value. 2802 ifMetagenerationNotMatch: Makes the operation conditional on whether the 2803 destination object's current metageneration does not match the given 2804 value. 2805 ifSourceGenerationMatch: Makes the operation conditional on whether the 2806 source object's generation matches the given value. 2807 ifSourceGenerationNotMatch: Makes the operation conditional on whether 2808 the source object's generation does not match the given value. 2809 ifSourceMetagenerationMatch: Makes the operation conditional on whether 2810 the source object's current metageneration matches the given value. 2811 ifSourceMetagenerationNotMatch: Makes the operation conditional on 2812 whether the source object's current metageneration does not match the 2813 given value. 2814 maxBytesRewrittenPerCall: The maximum number of bytes that will be 2815 rewritten per rewrite request. Most callers shouldn't need to specify 2816 this parameter - it is primarily in place to support testing. If 2817 specified the value must be an integral multiple of 1 MiB (1048576). 2818 Also, this only applies to requests where the source and destination 2819 span locations and/or storage classes. Finally, this value must not 2820 change across rewrite calls else you'll get an error that the 2821 rewriteToken is invalid. 2822 object: A Object resource to be passed as the request body. 2823 projection: Set of properties to return. Defaults to noAcl, unless the 2824 object resource specifies the acl property, when it defaults to full. 2825 rewriteToken: Include this field (from the previous rewrite response) on 2826 each rewrite request after the first one, until the rewrite response 2827 'done' flag is true. Calls that provide a rewriteToken can omit all 2828 other request fields, but if included those fields must match the 2829 values provided in the first rewrite request. 2830 sourceGeneration: If present, selects a specific revision of the source 2831 object (as opposed to the latest version, the default). 2832 """ 2833 client = GetClientFromFlags() 2834 global_params = GetGlobalParamsFromFlags() 2835 request = messages.StorageObjectsRewriteRequest( 2836 sourceBucket=sourceBucket.decode('utf8'), 2837 sourceObject=sourceObject.decode('utf8'), 2838 destinationBucket=destinationBucket.decode('utf8'), 2839 destinationObject=destinationObject.decode('utf8'), 2840 ) 2841 if FLAGS['destinationPredefinedAcl'].present: 2842 request.destinationPredefinedAcl = messages.StorageObjectsRewriteRequest.DestinationPredefinedAclValueValuesEnum(FLAGS.destinationPredefinedAcl) 2843 if FLAGS['ifGenerationMatch'].present: 2844 request.ifGenerationMatch = int(FLAGS.ifGenerationMatch) 2845 if FLAGS['ifGenerationNotMatch'].present: 2846 request.ifGenerationNotMatch = int(FLAGS.ifGenerationNotMatch) 2847 if FLAGS['ifMetagenerationMatch'].present: 2848 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 2849 if FLAGS['ifMetagenerationNotMatch'].present: 2850 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 2851 if FLAGS['ifSourceGenerationMatch'].present: 2852 request.ifSourceGenerationMatch = int(FLAGS.ifSourceGenerationMatch) 2853 if FLAGS['ifSourceGenerationNotMatch'].present: 2854 request.ifSourceGenerationNotMatch = int(FLAGS.ifSourceGenerationNotMatch) 2855 if FLAGS['ifSourceMetagenerationMatch'].present: 2856 request.ifSourceMetagenerationMatch = int(FLAGS.ifSourceMetagenerationMatch) 2857 if FLAGS['ifSourceMetagenerationNotMatch'].present: 2858 request.ifSourceMetagenerationNotMatch = int(FLAGS.ifSourceMetagenerationNotMatch) 2859 if FLAGS['maxBytesRewrittenPerCall'].present: 2860 request.maxBytesRewrittenPerCall = int(FLAGS.maxBytesRewrittenPerCall) 2861 if FLAGS['object'].present: 2862 request.object = apitools_base.JsonToMessage(messages.Object, FLAGS.object) 2863 if FLAGS['projection'].present: 2864 request.projection = messages.StorageObjectsRewriteRequest.ProjectionValueValuesEnum(FLAGS.projection) 2865 if FLAGS['rewriteToken'].present: 2866 request.rewriteToken = FLAGS.rewriteToken.decode('utf8') 2867 if FLAGS['sourceGeneration'].present: 2868 request.sourceGeneration = int(FLAGS.sourceGeneration) 2869 result = client.objects.Rewrite( 2870 request, global_params=global_params) 2871 print apitools_base_cli.FormatOutput(result) 2872 2873 2874class ObjectsUpdate(apitools_base_cli.NewCmd): 2875 """Command wrapping objects.Update.""" 2876 2877 usage = """objects_update <bucket> <object>""" 2878 2879 def __init__(self, name, fv): 2880 super(ObjectsUpdate, self).__init__(name, fv) 2881 flags.DEFINE_string( 2882 'generation', 2883 None, 2884 u'If present, selects a specific revision of this object (as opposed ' 2885 u'to the latest version, the default).', 2886 flag_values=fv) 2887 flags.DEFINE_string( 2888 'ifGenerationMatch', 2889 None, 2890 u"Makes the operation conditional on whether the object's current " 2891 u'generation matches the given value.', 2892 flag_values=fv) 2893 flags.DEFINE_string( 2894 'ifGenerationNotMatch', 2895 None, 2896 u"Makes the operation conditional on whether the object's current " 2897 u'generation does not match the given value.', 2898 flag_values=fv) 2899 flags.DEFINE_string( 2900 'ifMetagenerationMatch', 2901 None, 2902 u"Makes the operation conditional on whether the object's current " 2903 u'metageneration matches the given value.', 2904 flag_values=fv) 2905 flags.DEFINE_string( 2906 'ifMetagenerationNotMatch', 2907 None, 2908 u"Makes the operation conditional on whether the object's current " 2909 u'metageneration does not match the given value.', 2910 flag_values=fv) 2911 flags.DEFINE_string( 2912 'objectResource', 2913 None, 2914 u'A Object resource to be passed as the request body.', 2915 flag_values=fv) 2916 flags.DEFINE_enum( 2917 'predefinedAcl', 2918 u'authenticatedRead', 2919 [u'authenticatedRead', u'bucketOwnerFullControl', u'bucketOwnerRead', u'private', u'projectPrivate', u'publicRead'], 2920 u'Apply a predefined set of access controls to this object.', 2921 flag_values=fv) 2922 flags.DEFINE_enum( 2923 'projection', 2924 u'full', 2925 [u'full', u'noAcl'], 2926 u'Set of properties to return. Defaults to full.', 2927 flag_values=fv) 2928 flags.DEFINE_string( 2929 'download_filename', 2930 '', 2931 'Filename to use for download.', 2932 flag_values=fv) 2933 flags.DEFINE_boolean( 2934 'overwrite', 2935 'False', 2936 'If True, overwrite the existing file when downloading.', 2937 flag_values=fv) 2938 2939 def RunWithArgs(self, bucket, object): 2940 """Updates an object's metadata. 2941 2942 Args: 2943 bucket: Name of the bucket in which the object resides. 2944 object: Name of the object. 2945 2946 Flags: 2947 generation: If present, selects a specific revision of this object (as 2948 opposed to the latest version, the default). 2949 ifGenerationMatch: Makes the operation conditional on whether the 2950 object's current generation matches the given value. 2951 ifGenerationNotMatch: Makes the operation conditional on whether the 2952 object's current generation does not match the given value. 2953 ifMetagenerationMatch: Makes the operation conditional on whether the 2954 object's current metageneration matches the given value. 2955 ifMetagenerationNotMatch: Makes the operation conditional on whether the 2956 object's current metageneration does not match the given value. 2957 objectResource: A Object resource to be passed as the request body. 2958 predefinedAcl: Apply a predefined set of access controls to this object. 2959 projection: Set of properties to return. Defaults to full. 2960 download_filename: Filename to use for download. 2961 overwrite: If True, overwrite the existing file when downloading. 2962 """ 2963 client = GetClientFromFlags() 2964 global_params = GetGlobalParamsFromFlags() 2965 request = messages.StorageObjectsUpdateRequest( 2966 bucket=bucket.decode('utf8'), 2967 object=object.decode('utf8'), 2968 ) 2969 if FLAGS['generation'].present: 2970 request.generation = int(FLAGS.generation) 2971 if FLAGS['ifGenerationMatch'].present: 2972 request.ifGenerationMatch = int(FLAGS.ifGenerationMatch) 2973 if FLAGS['ifGenerationNotMatch'].present: 2974 request.ifGenerationNotMatch = int(FLAGS.ifGenerationNotMatch) 2975 if FLAGS['ifMetagenerationMatch'].present: 2976 request.ifMetagenerationMatch = int(FLAGS.ifMetagenerationMatch) 2977 if FLAGS['ifMetagenerationNotMatch'].present: 2978 request.ifMetagenerationNotMatch = int(FLAGS.ifMetagenerationNotMatch) 2979 if FLAGS['objectResource'].present: 2980 request.objectResource = apitools_base.JsonToMessage(messages.Object, FLAGS.objectResource) 2981 if FLAGS['predefinedAcl'].present: 2982 request.predefinedAcl = messages.StorageObjectsUpdateRequest.PredefinedAclValueValuesEnum(FLAGS.predefinedAcl) 2983 if FLAGS['projection'].present: 2984 request.projection = messages.StorageObjectsUpdateRequest.ProjectionValueValuesEnum(FLAGS.projection) 2985 download = None 2986 if FLAGS.download_filename: 2987 download = apitools_base.Download.FromFile(FLAGS.download_filename, overwrite=FLAGS.overwrite, 2988 progress_callback=apitools_base.DownloadProgressPrinter, 2989 finish_callback=apitools_base.DownloadCompletePrinter) 2990 result = client.objects.Update( 2991 request, global_params=global_params, download=download) 2992 print apitools_base_cli.FormatOutput(result) 2993 2994 2995class ObjectsWatchAll(apitools_base_cli.NewCmd): 2996 """Command wrapping objects.WatchAll.""" 2997 2998 usage = """objects_watchAll <bucket>""" 2999 3000 def __init__(self, name, fv): 3001 super(ObjectsWatchAll, self).__init__(name, fv) 3002 flags.DEFINE_string( 3003 'channel', 3004 None, 3005 u'A Channel resource to be passed as the request body.', 3006 flag_values=fv) 3007 flags.DEFINE_string( 3008 'delimiter', 3009 None, 3010 u'Returns results in a directory-like mode. items will contain only ' 3011 u'objects whose names, aside from the prefix, do not contain ' 3012 u'delimiter. Objects whose names, aside from the prefix, contain ' 3013 u'delimiter will have their name, truncated after the delimiter, ' 3014 u'returned in prefixes. Duplicate prefixes are omitted.', 3015 flag_values=fv) 3016 flags.DEFINE_integer( 3017 'maxResults', 3018 None, 3019 u'Maximum number of items plus prefixes to return. As duplicate ' 3020 u'prefixes are omitted, fewer total results may be returned than ' 3021 u'requested. The default value of this parameter is 1,000 items.', 3022 flag_values=fv) 3023 flags.DEFINE_string( 3024 'pageToken', 3025 None, 3026 u'A previously-returned page token representing part of the larger ' 3027 u'set of results to view.', 3028 flag_values=fv) 3029 flags.DEFINE_string( 3030 'prefix', 3031 None, 3032 u'Filter results to objects whose names begin with this prefix.', 3033 flag_values=fv) 3034 flags.DEFINE_enum( 3035 'projection', 3036 u'full', 3037 [u'full', u'noAcl'], 3038 u'Set of properties to return. Defaults to noAcl.', 3039 flag_values=fv) 3040 flags.DEFINE_boolean( 3041 'versions', 3042 None, 3043 u'If true, lists all versions of an object as distinct results. The ' 3044 u'default is false. For more information, see Object Versioning.', 3045 flag_values=fv) 3046 3047 def RunWithArgs(self, bucket): 3048 """Watch for changes on all objects in a bucket. 3049 3050 Args: 3051 bucket: Name of the bucket in which to look for objects. 3052 3053 Flags: 3054 channel: A Channel resource to be passed as the request body. 3055 delimiter: Returns results in a directory-like mode. items will contain 3056 only objects whose names, aside from the prefix, do not contain 3057 delimiter. Objects whose names, aside from the prefix, contain 3058 delimiter will have their name, truncated after the delimiter, 3059 returned in prefixes. Duplicate prefixes are omitted. 3060 maxResults: Maximum number of items plus prefixes to return. As 3061 duplicate prefixes are omitted, fewer total results may be returned 3062 than requested. The default value of this parameter is 1,000 items. 3063 pageToken: A previously-returned page token representing part of the 3064 larger set of results to view. 3065 prefix: Filter results to objects whose names begin with this prefix. 3066 projection: Set of properties to return. Defaults to noAcl. 3067 versions: If true, lists all versions of an object as distinct results. 3068 The default is false. For more information, see Object Versioning. 3069 """ 3070 client = GetClientFromFlags() 3071 global_params = GetGlobalParamsFromFlags() 3072 request = messages.StorageObjectsWatchAllRequest( 3073 bucket=bucket.decode('utf8'), 3074 ) 3075 if FLAGS['channel'].present: 3076 request.channel = apitools_base.JsonToMessage(messages.Channel, FLAGS.channel) 3077 if FLAGS['delimiter'].present: 3078 request.delimiter = FLAGS.delimiter.decode('utf8') 3079 if FLAGS['maxResults'].present: 3080 request.maxResults = FLAGS.maxResults 3081 if FLAGS['pageToken'].present: 3082 request.pageToken = FLAGS.pageToken.decode('utf8') 3083 if FLAGS['prefix'].present: 3084 request.prefix = FLAGS.prefix.decode('utf8') 3085 if FLAGS['projection'].present: 3086 request.projection = messages.StorageObjectsWatchAllRequest.ProjectionValueValuesEnum(FLAGS.projection) 3087 if FLAGS['versions'].present: 3088 request.versions = FLAGS.versions 3089 result = client.objects.WatchAll( 3090 request, global_params=global_params) 3091 print apitools_base_cli.FormatOutput(result) 3092 3093 3094def main(_): 3095 appcommands.AddCmd('pyshell', PyShell) 3096 appcommands.AddCmd('bucketAccessControls_delete', BucketAccessControlsDelete) 3097 appcommands.AddCmd('bucketAccessControls_get', BucketAccessControlsGet) 3098 appcommands.AddCmd('bucketAccessControls_insert', BucketAccessControlsInsert) 3099 appcommands.AddCmd('bucketAccessControls_list', BucketAccessControlsList) 3100 appcommands.AddCmd('bucketAccessControls_patch', BucketAccessControlsPatch) 3101 appcommands.AddCmd('bucketAccessControls_update', BucketAccessControlsUpdate) 3102 appcommands.AddCmd('buckets_delete', BucketsDelete) 3103 appcommands.AddCmd('buckets_get', BucketsGet) 3104 appcommands.AddCmd('buckets_insert', BucketsInsert) 3105 appcommands.AddCmd('buckets_list', BucketsList) 3106 appcommands.AddCmd('buckets_patch', BucketsPatch) 3107 appcommands.AddCmd('buckets_update', BucketsUpdate) 3108 appcommands.AddCmd('channels_stop', ChannelsStop) 3109 appcommands.AddCmd('defaultObjectAccessControls_delete', DefaultObjectAccessControlsDelete) 3110 appcommands.AddCmd('defaultObjectAccessControls_get', DefaultObjectAccessControlsGet) 3111 appcommands.AddCmd('defaultObjectAccessControls_insert', DefaultObjectAccessControlsInsert) 3112 appcommands.AddCmd('defaultObjectAccessControls_list', DefaultObjectAccessControlsList) 3113 appcommands.AddCmd('defaultObjectAccessControls_patch', DefaultObjectAccessControlsPatch) 3114 appcommands.AddCmd('defaultObjectAccessControls_update', DefaultObjectAccessControlsUpdate) 3115 appcommands.AddCmd('objectAccessControls_delete', ObjectAccessControlsDelete) 3116 appcommands.AddCmd('objectAccessControls_get', ObjectAccessControlsGet) 3117 appcommands.AddCmd('objectAccessControls_insert', ObjectAccessControlsInsert) 3118 appcommands.AddCmd('objectAccessControls_list', ObjectAccessControlsList) 3119 appcommands.AddCmd('objectAccessControls_patch', ObjectAccessControlsPatch) 3120 appcommands.AddCmd('objectAccessControls_update', ObjectAccessControlsUpdate) 3121 appcommands.AddCmd('objects_compose', ObjectsCompose) 3122 appcommands.AddCmd('objects_copy', ObjectsCopy) 3123 appcommands.AddCmd('objects_delete', ObjectsDelete) 3124 appcommands.AddCmd('objects_get', ObjectsGet) 3125 appcommands.AddCmd('objects_insert', ObjectsInsert) 3126 appcommands.AddCmd('objects_list', ObjectsList) 3127 appcommands.AddCmd('objects_patch', ObjectsPatch) 3128 appcommands.AddCmd('objects_rewrite', ObjectsRewrite) 3129 appcommands.AddCmd('objects_update', ObjectsUpdate) 3130 appcommands.AddCmd('objects_watchAll', ObjectsWatchAll) 3131 3132 apitools_base_cli.SetupLogger() 3133 if hasattr(appcommands, 'SetDefaultCommand'): 3134 appcommands.SetDefaultCommand('pyshell') 3135 3136 3137run_main = apitools_base_cli.run_main 3138 3139if __name__ == '__main__': 3140 appcommands.Run() 3141