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,28 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 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 group for Dataplex Content Resource."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Content(base.Group):
"""Manage Dataplex Content."""
category = base.DATA_ANALYTICS_CATEGORY

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google Inc. 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.
"""`gcloud dataplex environments add-iam-policy-binding` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataplex import content
from googlecloudsdk.api_lib.util import exceptions as gcloud_exception
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataplex import resource_args
from googlecloudsdk.command_lib.iam import iam_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class AddIamPolicyBinding(base.Command):
"""Adds IAM policy binding to a Dataplex Content."""
detailed_help = {
'EXAMPLES':
"""\
To add an IAM policy binding for the role of `roles/dataplex.viewer`
for the user 'testuser@gmail.com' to content `test-content` within lake
`test-lake` in location `us-central`, run:
$ {command} test-content --project=test-project --location=us-central1 --lake=test-lake --role=roles/dataplex.viewer --member=user:testuser@gmail.com
See https://cloud.google.com/dataplex/docs/iam-roles for details of
policy role and member types.
""",
}
@staticmethod
def Args(parser):
resource_args.AddContentitemResourceArg(parser,
'to add IAM policy binding to.')
iam_util.AddArgsForAddIamPolicyBinding(parser)
@gcloud_exception.CatchHTTPErrorRaiseHTTPException(
'Status code: {status_code}. {status_message}.')
def Run(self, args):
content_ref = args.CONCEPTS.content.Parse()
result = content.AddIamPolicyBinding(content_ref, args.member,
args.role)
return result

View File

@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google Inc. 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.
"""`gcloud dataplex content create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataplex import content
from googlecloudsdk.api_lib.dataplex import util as dataplex_util
from googlecloudsdk.api_lib.util import exceptions as gcloud_exception
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataplex import resource_args
from googlecloudsdk.command_lib.util.apis import arg_utils
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Create(base.Command):
"""Creating a content."""
detailed_help = {
'EXAMPLES':
"""\
To create a Dataplex content `test-content` of type notebook within lake `test-lake` in location `us-central1`.
$ {command} --project=test-project --location=us-central1 --lake=test-lake --kernel-type=PYTHON3 --data-text='' --path='test-content'
""",
}
@staticmethod
def Args(parser):
"""Register flags for this command.
Args:
parser: argparse.Parser: Parser object for command line inputs.
"""
# Content resource does not take a Content ID and auto-generates it.
# Hence we add Lake Resource Args here and not Content Resource args.
resource_args.AddLakeResourceArg(
parser, 'to create a Content to.', positional=False)
parser.add_argument('--description', help='Description of the Content')
parser.add_argument(
'--data-text', help='Content data in string format', required=True)
parser.add_argument(
'--path',
help='The path for the Content file, represented as directory structure',
required=True)
sqlscript_or_notebook = parser.add_group(
required=True,
mutex=True,
help='Sql script or notebook related configurations.')
notebook = sqlscript_or_notebook.add_group(
required=False, help='Notebook related configurations.')
notebook.add_argument(
'--kernel-type',
choices={'PYTHON3': 'python3'},
type=arg_utils.ChoiceToEnumName,
help='Kernel Type of the notebook.',
required=True)
sql_script = sqlscript_or_notebook.add_group(
required=False, help='Sql script related configurations.')
sql_script.add_argument(
'--query-engine',
choices={'SPARK': 'spark'},
type=arg_utils.ChoiceToEnumName,
help='Query Engine to be used for the Sql Query.',
required=True)
parser.add_argument(
'--validate-only',
action='store_true',
default=False,
help='Validate the create action, but don\'t actually perform it.')
labels_util.AddCreateLabelsFlags(parser)
@gcloud_exception.CatchHTTPErrorRaiseHTTPException(
'Status code: {status_code}. {status_message}.')
def Run(self, args):
"""Constructs and sends request.
Args:
args: argparse.Namespace, An object that contains the values for the
arguments specified in the .Args() method.
"""
# We extract lake reference, instead of content reference as content id
# is not provided at the time of create content and is auto-generated
# and returned in response.
lake_ref = args.CONCEPTS.lake.Parse()
dataplex_client = dataplex_util.GetClientInstance()
content_response = dataplex_client.projects_locations_lakes_contentitems.Create(
dataplex_util.GetMessageModule(
).DataplexProjectsLocationsLakesContentitemsCreateRequest(
parent=lake_ref.RelativeName(),
validateOnly=args.validate_only,
googleCloudDataplexV1Content=content
.GenerateContentForCreateRequest(args)))
validate_only = getattr(args, 'validate_only', False)
if validate_only:
log.status.Print('Validation complete.')
return
log.CreatedResource(
content_response.name,
details='Content created in lake [{0}] in project [{1}] with location [{2}]'
.format(lake_ref.lakesId, lake_ref.projectsId, lake_ref.locationsId))

View File

@@ -0,0 +1,20 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
Delete a Dataplex Content Resource.
description: |
Delete a Dataplex Content resource based on project, location, lake, and content.
examples: |
To delete a content `test-content` in lake `test-lake` under location `us-central1` inside project `test-project`, run :
$ {command} --project=test-project --location=us-central1 --lake=test-lake test-content
request:
ALPHA:
api_version: v1
collection: dataplex.projects.locations.lakes.contentitems
arguments:
resource:
help_text: |
Arguments and flags that define the Dataplex Content you want to delete.
spec: !REF googlecloudsdk.command_lib.dataplex.resources:content

View File

@@ -0,0 +1,36 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
Retrieve a Dataplex Content Resource.
description: |
Get a Dataplex Content resource based on project, location, lake, and content.
examples: |
To describe a Dataplex Content `test-content` in project `test-project` under loaction `us-central1` inside project `test-project`, run:
$ {command} test-content --project=test-project --location=us-central1 --lake=test-lake
request:
ALPHA:
api_version: v1
collection: dataplex.projects.locations.lakes.contentitems
method: get
arguments:
resource:
help_text: |
Arguments and flags that define the Dataplex Content you want to retrieve.
spec: !REF googlecloudsdk.command_lib.dataplex.resources:content
params:
- arg_name: view
api_field: view
help_text: |
There are two possible views, 'basic' and 'full'. The default view is 'basic'.
choices:
- enum_value: BASIC
arg_value: basic
help_text: |
Does not include the Content data in response.
- enum_value: FULL
arg_value: full
help_text: |
Includes the content data in response.
default: basic

View File

@@ -0,0 +1,18 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
Retrieve the IAM policy for a Dataplex Content.
description: |
Get a Dataplex Content Iam Policy based on project_id, location, lake_id, and contents_id.
examples: |
To get the IAM policy of a Dataplex Content `test-content` in project `test-project` under loaction `us-central1` inside lake `test-lake`, run:
$ {command} test-content --project=test-project --location=us-central1 --lake=test-lake
request:
collection: dataplex.projects.locations.lakes.contentitems
arguments:
resource:
help_text: |
Arguments and flags that define the Dataplex contents IAM policy you want to retrieve.
spec: !REF googlecloudsdk.command_lib.dataplex.resources:content

View File

@@ -0,0 +1,33 @@
- release_tracks: [ALPHA, GA]
help_text:
brief: |
List Dataplex Content Resources.
description: |
List Dataplex Content resource based on project, location, and lake. Currently list does not support project/{project_id}/.../ notation.
examples: |
To list all Dataplex Content resource in lake `test-lake` under location `us-central1` inside project `test-project`, run :
$ {command} --project=test-project --location=us-central1 --lake=test-lake
request:
ALPHA:
api_version: v1
collection: dataplex.projects.locations.lakes.contentitems
arguments:
resource:
help_text: |
Arguments and flags that define the Dataplex Content you want to list.
spec: !REF googlecloudsdk.command_lib.dataplex.resources:lake
response:
id_field: name
output:
format: |
table(
name.basename():label=NAME,
path:label=PATH,
notebook.kernel_type:label=NOTEBOOK_KERNEL,
sql_script.engine:label=SQL_SCRIPT_ENGINE,
labels:label=LABELS
)

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google Inc. 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.
"""`gcloud dataplex environment remove-iam-policy-binding` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataplex import content
from googlecloudsdk.api_lib.util import exceptions as gcloud_exception
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataplex import resource_args
from googlecloudsdk.command_lib.iam import iam_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class RemoveIamPolicyBinding(base.Command):
"""Removes IAM policy binding from a Dataplex Content."""
detailed_help = {
'EXAMPLES':
"""\
To remove an IAM policy binding for the role `roles/dataplex.viewer`
for the user `testuser@gmail.com` from a content `test-content` within lake
`test-lake` in location `us-central1`, run:
$ {command} test-content --project=test-project --location=us-central1 --lake=test-lake --role=roles/dataplex.viewer --member=user:testuser@gmail.com
See https://cloud.google.com/dataplex/docs/iam-roles for details of
policy role and member types.
""",
}
@staticmethod
def Args(parser):
resource_args.AddContentitemResourceArg(
parser, 'to remove IAM policy binding from ')
iam_util.AddArgsForRemoveIamPolicyBinding(parser)
@gcloud_exception.CatchHTTPErrorRaiseHTTPException(
'Status code: {status_code}. {status_message}.')
def Run(self, args):
content_ref = args.CONCEPTS.content.Parse()
result = content.RemoveIamPolicyBinding(content_ref, args.member,
args.role)
return result

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google Inc. 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.
"""`gcloud dataplex content set-iam-policy-binding` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataplex import content
from googlecloudsdk.api_lib.util import exceptions as gcloud_exception
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.dataplex import resource_args
from googlecloudsdk.command_lib.iam import iam_util
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class SetIamPolicy(base.Command):
"""Set the IAM policy to a Dataplex Content as defined in a JSON or YAML file.
See https://cloud.google.com/iam/docs/managing-policies for details of
the policy file format and contents.
"""
detailed_help = {
'EXAMPLES':
"""\
The following command will read an IAM policy defined in a JSON file
`policy.json` and set it for the Dataplex content `test-content` within
lake `test-lake` in location `us-central1` and :
$ {command} test-content --project=test-project --location=us-central1 --lake=test-lake policy.json
where policy.json is the relative path to the json file.
""",
}
@staticmethod
def Args(parser):
resource_args.AddContentitemResourceArg(parser, 'to set IAM policy to.')
iam_util.AddArgForPolicyFile(parser)
@gcloud_exception.CatchHTTPErrorRaiseHTTPException(
'Status code: {status_code}. {status_message}.')
def Run(self, args):
content_ref = args.CONCEPTS.content.Parse()
result = content.SetIamPolicyFromFile(content_ref, args.policy_file)
return result

View File

@@ -0,0 +1,111 @@
# -*- coding: utf-8 -*- #
# Copyright 2021 Google Inc. 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.
"""`gcloud dataplex content update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.dataplex import content
from googlecloudsdk.api_lib.dataplex import util as dataplex_util
from googlecloudsdk.api_lib.util import exceptions as gcloud_exception
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.command_lib.dataplex import resource_args
from googlecloudsdk.command_lib.util.apis import arg_utils
from googlecloudsdk.command_lib.util.args import labels_util
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.GA)
class Update(base.Command):
"""Update a Dataplex Content Resource with the given configurations."""
detailed_help = {
'EXAMPLES':
"""\
To update a Dataplex content `test-content` in project `test-project` within lake `test-lake` in location `us-central1` and
change the description to `Updated Description`, run:
$ {command} test-content --project=test-project --location=us-central1 --lake=test-lake --description='Updated Description'
""",
}
@staticmethod
def Args(parser):
resource_args.AddContentitemResourceArg(parser, 'to Update a Content to.')
parser.add_argument('--description', help='Description of the Content')
parser.add_argument('--data-text', help='Content data in string format')
parser.add_argument(
'--path',
help='The path for the Content file, represented as directory structure'
)
sqlscript_or_notebook = parser.add_group(
mutex=True, help='Sql script or notebook related configurations.')
notebook = sqlscript_or_notebook.add_group(
help='Notebook related configurations.')
notebook.add_argument(
'--kernel-type',
choices={'PYTHON3': 'python3'},
type=arg_utils.ChoiceToEnumName,
help='Kernel Type of the notebook.')
sql_script = sqlscript_or_notebook.add_group(
help='Sql script related configurations.')
sql_script.add_argument(
'--query-engine',
choices={'SPARK': 'spark'},
type=arg_utils.ChoiceToEnumName,
help='Query Engine to be used for the Sql Query.')
parser.add_argument(
'--validate-only',
action='store_true',
default=False,
help='Validate the update action, but don\'t actually perform it.')
labels_util.AddCreateLabelsFlags(parser)
@gcloud_exception.CatchHTTPErrorRaiseHTTPException(
'Status code: {status_code}. {status_message}.')
def Run(self, args):
update_mask = content.GenerateUpdateMask(args)
if len(update_mask) < 1:
raise exceptions.HttpException(
'Update commands must specify at least one additional parameter to change.'
)
content_ref = args.CONCEPTS.content.Parse()
dataplex_client = dataplex_util.GetClientInstance()
dataplex_client.projects_locations_lakes_contentitems.Patch(
dataplex_util.GetMessageModule(
).DataplexProjectsLocationsLakesContentitemsPatchRequest(
name=content_ref.RelativeName(),
validateOnly=args.validate_only,
updateMask=u','.join(update_mask),
googleCloudDataplexV1Content=content
.GenerateContentForUpdateRequest(args)))
validate_only = getattr(args, 'validate_only', False)
if validate_only:
log.status.Print('Validation complete.')
return
log.UpdatedResource(content_ref)