feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The group for the Cloud Folders CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
# @base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class Folders(base.Group):
"""Manage Cloud Folders.
Commands to query and update your Cloud Folders.
"""
@staticmethod
def Args(parser):
parser.display_info.AddUriFunc(folders.GetUri)

View File

@@ -0,0 +1,33 @@
release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Add IAM policy binding for a folder.
description: |
Adds a policy binding to the IAM policy of a folder, given a folder ID and the binding. One
binding consists of a member, a role, and an optional condition.
examples: |
To add an IAM policy binding for the role of 'roles/editor' for the user 'test-user@gmail.com'
on the folder 'folder-id', run:
$ {command} folder-id --member='user:test-user@gmail.com' --role='roles/editor'
To add an IAM policy binding which expires at the end of the year 2018 for the role of
'roles/storage.objectAdmin' and the user 'test-user@gmail.com' on the folder 'folder-id', run:
$ {command} folder-id --member='user:test-user@gmail.com' --role='roles/storage.objectAdmin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: cloudresourcemanager.folders
api_version: v2
arguments:
resource:
help_text: The ID of the folder to add the IAM binding.
spec: !REF googlecloudsdk.command_lib.resource_manager.resources:folder
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion

View File

@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to create a new folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.api_lib.resource_manager import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.resource_manager import flags
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Create a new folder.
Creates a new folder in the given parent folder or organization.
## EXAMPLES
The following command creates a folder with the name `abc` into a
folder with the ID `2345`:
$ {command} --display-name=abc --folder=2345
The following command creates a folder with the name `abc` into an
organization with ID `1234`:
$ {command} --display-name=abc --organization=1234
"""
@staticmethod
def Args(parser):
flags.AddParentFlagsToParser(parser)
flags.OperationAsyncFlag().AddToParser(parser)
base.Argument(
'--display-name',
required=True,
help='Friendly display name to use for the new folder.',
).AddToParser(parser)
flags.TagsFlag().AddToParser(parser)
def Run(self, args):
flags.CheckParentFlags(args)
messages = folders.FoldersMessages()
tags = flags.GetTagsFromFlags(args, messages.Folder.TagsValue)
operation = folders.FoldersService().Create(
messages.CloudresourcemanagerFoldersCreateRequest(
parent=flags.GetParentFromFlags(args),
folder=messages.Folder(displayName=args.display_name, tags=tags),
)
)
if args.async_:
return operation
else:
finished_operation = operations.WaitForOperation(operation)
result = operations.ExtractOperationResponse(finished_operation,
messages.Folder)
log.CreatedResource(result)
return result

View File

@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to delete a folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.resource_manager import flags
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Delete a folder.
Delete a folder, given a valid folder ID.
This command can fail for the following reasons:
* There is no folder with the given ID.
* The active account does not have permission to delete the given folder.
* The folder to be deleted is not empty.
## EXAMPLES
The following command deletes a folder with the ID `123456789`:
$ {command} 123456789
"""
@staticmethod
def Args(parser):
flags.FolderIdArg('you want to delete.').AddToParser(parser)
def Run(self, args):
service = folders.FoldersService()
messages = folders.FoldersMessages()
result = service.Delete(
messages.CloudresourcemanagerFoldersDeleteRequest(foldersId=args.id))
log.DeletedResource(result)

View File

@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to show metadata for a specified folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.resource_manager import flags
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Show metadata for a folder.
Shows metadata for a folder, given a valid folder ID.
This command can fail for the following reasons:
* The folder specified does not exist.
* The active account does not have permission to access the given
folder.
## EXAMPLES
The following command prints metadata for a folder with the ID `3589215982`:
$ {command} 3589215982
"""
@staticmethod
def Args(parser):
flags.FolderIdArg('you want to describe.').AddToParser(parser)
def Run(self, args):
return folders.GetFolder(args.id)

View File

@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to get IAM policy for a folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import policies_flags
from googlecloudsdk.command_lib.resource_manager import flags
class GetIamPolicy(base.ListCommand):
"""Get IAM policies for a folder and its ancestors.
Get IAM policies for a folder and its ancestors, given a folder ID.
## EXAMPLES
To get IAM policies for folder ``3589215982'' and its ancestors, run:
$ {command} 3589215982
"""
@staticmethod
def Args(parser):
flags.GetFolderResourceArg('get IAM policy for.').AddToParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
policies_flags.AddIncludeDenyFlag(parser)
def Run(self, args):
return folders.GetAncestorsIamPolicy(args.folder_id, args.include_deny,
self.ReleaseTrack())

View File

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to get IAM policy for a folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.resource_manager import flags
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.GA)
class GetIamPolicy(base.ListCommand):
"""Get IAM policy for a folder.
Gets the IAM policy for a folder, given a folder ID.
## EXAMPLES
The following command prints the IAM policy for a folder with the ID
`3589215982`:
$ {command} 3589215982
"""
@staticmethod
def Args(parser):
flags.FolderIdArg('whose policy you want to get.').AddToParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
return folders.GetIamPolicy(args.id)

View File

@@ -0,0 +1,28 @@
- release_tracks: [ALPHA]
help_text:
brief: Get the IAM policy for a folder.
description: |
*{command}* displays the IAM policy associated with a folder.
If formatted as JSON, the output can be edited and used as
a policy file for *set-iam-policy*. The output includes an "etag"
field identifying the version emitted and allowing detection of
concurrent policy updates; see
$ {parent} set-iam-policy for additional details.
examples: |
To print the IAM policy for a given folder, run:
$ {command} my-folder
request:
collection: cloudresourcemanager.folders
api_version: v2
arguments:
resource:
help_text: The ID of the folder for which to display the IAM policy.
spec: !REF googlecloudsdk.command_lib.resource_manager.resources:folder
iam:
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion

View File

@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to list all folder IDs associated with the active user."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.resource_manager import flags
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class ListBeta(base.ListCommand):
r"""List folders accessible by the active account.
List all folders to which the user has access under the specified
parent (either an Organization or a Folder). Exactly one of --folder
or --organization must be provided.
## EXAMPLES
The following command lists folders under org with ID `123456789`:
$ {command} --organization=123456789
The following command lists folders under folder with ID `123456789`:
$ {command} --folder=123456789
The following command lists all the folders including the delete requested
ones under the folder with ID `123456789`:
$ {command} --folder=123456789 --show-deleted
The following command lists only the deleted folders under folder with
ID `123456789`:
$ {command} --folder=123456789 --show-deleted \
--filter='lifecycleState:DELETE_REQUESTED':
"""
@staticmethod
def Args(parser):
flags.FolderIdFlag('to list folders under').AddToParser(parser)
flags.OrganizationIdFlag('to list folders under').AddToParser(parser)
parser.add_argument(
'--show-deleted',
action='store_true',
help="""\
Put --show-deleted flag to include folders
for which delete is requested.
""")
parser.display_info.AddFormat("""
table(
displayName:label=DISPLAY_NAME,
parent:label=PARENT_NAME,
name.segment():label=ID:align=right:sort=1,
lifecycleState
)
""")
def Run(self, args):
"""Run the list command."""
flags.CheckParentFlags(args)
return list_pager.YieldFromList(
folders.FoldersService(),
folders.FoldersMessages().CloudresourcemanagerFoldersListRequest(
parent=flags.GetParentFromFlags(args),
showDeleted=args.show_deleted),
limit=args.limit,
batch_size_attribute='pageSize',
batch_size=args.page_size,
field='folders')
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""List folders accessible by the active account.
List all folders to which the user has access under the specified
parent (either an Organization or a Folder). Exactly one of --folder
or --organization must be provided.
## EXAMPLES
The following command lists folders under org with ID `123456789`:
$ {command} --organization=123456789
The following command lists folders under folder with ID `123456789`:
$ {command} --folder=123456789
"""
@staticmethod
def Args(parser):
flags.FolderIdFlag('to list folders under').AddToParser(parser)
flags.OrganizationIdFlag('to list folders under').AddToParser(parser)
parser.display_info.AddFormat("""
table(
displayName:label=DISPLAY_NAME,
parent:label=PARENT_NAME,
name.segment():label=ID:align=right:sort=1
)
""")
def Run(self, args):
"""Run the list command."""
flags.CheckParentFlags(args)
return list_pager.YieldFromList(
folders.FoldersService(),
folders.FoldersMessages().CloudresourcemanagerFoldersListRequest(
parent=flags.GetParentFromFlags(args)),
limit=args.limit,
batch_size_attribute='pageSize',
batch_size=args.page_size,
field='folders')

View File

@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to move a folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.api_lib.resource_manager import operations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.resource_manager import flags
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Move(base.UpdateCommand):
"""Move a folder to a new position within the same organization.
Move the given folder under a new parent folder or under the organization.
Exactly one of --folder or --organization must be provided.
This command can fail for the following reasons:
* There is no folder with the given ID.
* There is no parent with the given type and ID.
* The new parent is not in the same organization of the given folder.
* Permission missing for performing this move.
## EXAMPLES
The following command moves a folder with the ID `123456789` into a
folder with the ID `2345`:
$ {command} 123456789 --folder=2345
The following command moves a folder with the ID `123456789` into an
organization with ID `1234`:
$ {command} 123456789 --organization=1234
"""
@staticmethod
def Args(parser):
flags.FolderIdArg('you want to move.').AddToParser(parser)
flags.OperationAsyncFlag().AddToParser(parser)
flags.AddParentFlagsToParser(parser)
def Run(self, args):
flags.CheckParentFlags(args)
messages = folders.FoldersMessages()
move_request = messages.CloudresourcemanagerFoldersMoveRequest(
foldersId=args.id,
moveFolderRequest=messages.MoveFolderRequest(
destinationParent=flags.GetParentFromFlags(args)))
operation = folders.FoldersService().Move(move_request)
if args.async_:
return operation
else:
if operation.done and not operation.name:
log.status.Print('No changes necessary.')
return
finished_op = operations.WaitForOperation(operation)
result = operations.ExtractOperationResponse(finished_op, messages.Folder)
log.UpdatedResource(result)

View File

@@ -0,0 +1,40 @@
release_tracks: [GA, BETA, ALPHA]
help_text:
brief: Remove IAM policy binding for a folder
description: |
Removes a policy binding to the IAM policy of a folder, given a folder ID and the binding. One
binding consists of a member, a role, and an optional condition.
examples: |
To remove an IAM policy binding for the role of 'roles/editor' for the user
'test-user@gmail.com' on the folder 'folder-id', run:
$ {command} folder-id --member='user:test-user@gmail.com' --role='roles/editor'
To remove an IAM policy binding with a condition of
expression='request.time < timestamp("2019-01-01T00:00:00Z")', title='expires_end_of_2018',
and description='Expires at midnight on 2018-12-31' for the role of 'roles/storage.objectAdmin'
for the user 'test-user@gmail.com' on the folder 'folder-id', run:
$ {command} folder-id --member='user:test-user@gmail.com' --role='roles/storage.objectAdmin' --condition='expression=request.time < timestamp("2019-01-01T00:00:00Z"),title=expires_end_of_2018,description=Expires at midnight on 2018-12-31'
To remove all IAM policy bindings regardless of the condition for the role of
'roles/storage.objectAdmin' and for the user 'test-user@gmail.com' on the folder 'folder-id', run:
$ {command} folder-id --member='user:test-user@gmail.com' --role='roles/storage.objectAdmin' --all
See https://cloud.google.com/iam/docs/managing-policies for details of
policy role and member types.
request:
collection: cloudresourcemanager.folders
api_version: v2
arguments:
resource:
help_text: The ID of the folder to remove the IAM binding.
spec: !REF googlecloudsdk.command_lib.resource_manager.resources:folder
iam:
enable_condition: true
policy_version: 3
get_iam_policy_version_path: getIamPolicyRequest.options.requestedPolicyVersion

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to search folders associated with the active user."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Search(base.Command):
"""Search folders matching the specified query.
You can specify the maximum number of folders to return in the result
using the `--limit`flag.
## EXAMPLES
The following command lists the folders that have been marked for deletion:
$ {command} --query='state:DELETE_REQUESTED'
Folders with their displayNames starting with sun like sunflower-folder,
sunburn-folder etc. can be listed using the below command
$ {command} --query='displayName:sun*'
"""
FOLDERS_API_VERSION = 'v3'
@staticmethod
def Args(parser):
parser.display_info.AddFormat("""
table(
displayName,
name,
parent,
state
)
""")
base.LIMIT_FLAG.AddToParser(parser)
base.SORT_BY_FLAG.AddToParser(parser)
parser.add_argument(
'--query',
help="""\
A boolean expression for the search criteria used to select the folders to return.
If no search criteria is specified then all accessible projects will be returned.
Query expressions can be used to restrict results based upon displayName, state
and parent, where the operators `=` (`:`) `NOT`, `AND` and `OR` can be used along
with the suffix wildcard symbol `*`. The `displayName` field in a query expression should
use escaped quotes for values that include whitespace to prevent unexpected behavior.
For more details and fields supported by the query expression please refer
query parameters section `[here]
(https://cloud.google.com/resource-manager/reference/rest/v3/folders/search#query-parameters)`
""")
parser.add_argument(
'--page-size',
type=arg_parsers.BoundedInt(1, sys.maxsize, unlimited=True),
require_coverage_in_tests=False,
category=base.LIST_COMMAND_FLAGS,
help="""\
This flag specifies the maximum number of folders per page.
""")
def Run(self, args):
"""Run the search command."""
return list_pager.YieldFromList(
folders.FoldersService(self.FOLDERS_API_VERSION),
folders.FoldersMessages(
self.FOLDERS_API_VERSION).CloudresourcemanagerFoldersSearchRequest(
query=args.query),
method='Search',
limit=args.limit,
batch_size_attribute='pageSize',
batch_size=args.page_size,
field='folders')

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to set IAM policy for a folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.resource_manager import flags
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class SetIamPolicy(base.Command):
"""Set IAM policy for a folder.
Sets the IAM policy for a folder, given a folder ID and a file encoded in
JSON or YAML that contains the IAM policy.
## EXAMPLES
The following command reads an IAM policy defined in a JSON file `policy.json`
and sets it for a folder with the ID `3589215982`:
$ {command} 3589215982 policy.json
"""
@staticmethod
def Args(parser):
flags.FolderIdArg('whose policy you want to set.').AddToParser(parser)
parser.add_argument(
'policy_file', help='JSON or YAML file with the IAM policy.')
def Run(self, args):
messages = folders.FoldersMessages()
policy, update_mask = iam_util.ParsePolicyFileWithUpdateMask(
args.policy_file, messages.Policy)
policy.version = iam_util.MAX_LIBRARY_IAM_SUPPORTED_VERSION
# To preserve the existing set-iam-policy behavior of always overwriting
# bindings and etag, add bindings and etag to update_mask.
if 'bindings' not in update_mask:
update_mask += ',bindings'
if 'etag' not in update_mask:
update_mask += ',etag'
result = folders.SetIamPolicy(args.id, policy, update_mask)
iam_util.LogSetIamPolicy(args.id, 'folder')
return result

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to undelete a folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.resource_manager import flags
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Undelete(base.CreateCommand):
"""Undelete a folder.
Undeletes the folder with the given folder ID.
This command can fail for the following reasons:
* There is no folder with the given ID.
* The active account does not have Owner or Editor permissions for the
given folder.
* When the folder to be undeleted has the same display name as an active
folder under this folder's parent.
## EXAMPLES
The following command undeletes the folder with the ID `3589215982`:
$ {command} 3589215982
"""
@staticmethod
def Args(parser):
flags.FolderIdArg('you want to undelete.').AddToParser(parser)
def Run(self, args):
service = folders.FoldersService()
messages = folders.FoldersMessages()
restored = service.Undelete(
messages.CloudresourcemanagerFoldersUndeleteRequest(
foldersId=args.id))
log.RestoredResource(restored)

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Command to update a folder."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.resource_manager import folders
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.resource_manager import flags
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Update the display name of a folder.
Updates the given folder with new folder name.
This command can fail for the following reasons:
* There is no folder with the given ID.
* The active account does not have permission to update the given
folder.
* The new display name is taken by another folder under this folder's
parent.
## EXAMPLES
The following command updates a folder with the ID `123456789` to have
the name "Foo Bar and Grill":
$ {command} 123456789 --display-name="Foo Bar and Grill"
"""
@staticmethod
def Args(parser):
flags.FolderIdArg('you want to update.').AddToParser(parser)
parser.add_argument(
'--display-name',
required=True,
help='New display name for the folder (unique under the same parent).')
def Run(self, args):
folder = folders.GetFolder(args.id)
folder.displayName = args.display_name
request = folders.FoldersMessages().CloudresourcemanagerFoldersPatchRequest(
folder=folder, foldersId=args.id, updateMask='display_name')
log.UpdatedResource(folders.FoldersService().Patch(request))