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,20 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Package marker file."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

View File

@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Shared resource flags for datafusion commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.core.console import console_io
def ParsePolicyFile(policy_file_path, policy_message_type):
"""Constructs an IAM Policy message from a JSON/YAML formatted file.
Args:
policy_file_path: Path to the JSON or YAML IAM policy file.
policy_message_type: Policy message type to convert JSON or YAML to.
Returns:
a protorpc.Message of type policy_message_type filled in from the JSON or
YAML policy file.
Raises:
BadFileException if the JSON or YAML file is malformed.
"""
policy, unused_mask = iam_util.ParseYamlOrJsonPolicyFile(
policy_file_path,
policy_message_type)
if not policy.etag:
msg = ('The specified policy does not contain an "etag" field '
'identifying a specific version to replace. Changing a '
'policy without an "etag" can overwrite concurrent policy '
'changes.')
console_io.PromptContinue(
message=msg, prompt_string='Replace existing policy', cancel_on_no=True)
return policy
def DoSetIamPolicy(instance_ref,
namespace,
new_iam_policy,
messages,
client):
"""Sets IAM policy for a given instance or a namespace."""
if namespace:
policy_request = messages.DatafusionProjectsLocationsInstancesNamespacesSetIamPolicyRequest(
resource='%s/namespaces/%s' % (instance_ref.RelativeName(), namespace),
setIamPolicyRequest=messages.SetIamPolicyRequest(
policy=new_iam_policy))
return client.projects_locations_instances_namespaces.SetIamPolicy(
policy_request)
else:
policy_request = messages.DatafusionProjectsLocationsInstancesSetIamPolicyRequest(
resource=instance_ref.RelativeName(),
setIamPolicyRequest=messages.SetIamPolicyRequest(
policy=new_iam_policy))
return client.projects_locations_instances.SetIamPolicy(policy_request)
def AddPolicyFileArg(parser):
parser.add_argument(
'policy_file',
metavar='POLICY_FILE',
help="""\
Path to a local JSON or YAML file containing a valid policy.
The output of the `get-iam-policy` command is a valid file, as is any
JSON or YAML file conforming to the structure of a
[Policy](https://cloud.google.com/iam/reference/rest/v1/Policy).
""")

View File

@@ -0,0 +1,144 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 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.
"""Command utilities for maintenance."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.data_fusion import datafusion as df
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions
CLEAR_MAINTENANCE_WINDOW_FLAG = base.Argument(
'--clear-maintenance-window',
action='store_true',
help="""\
Clear the maintenance window for this Data Fusion instance.
""")
MAINTENANCE_WINDOW_START = base.Argument(
'--maintenance-window-start',
type=arg_parsers.Datetime.Parse,
help="""\
The start time of the maintenance window. Only the time of the day is
used as a reference for a starting time of the window with a provided
recurrence. This flag must be specified if any of the other arguments in
this group are specified. For example:
--maintenance_window_start=2024-01-01T01:00:00Z.
See $ gcloud topic datetimes for information on time formats.
""")
MAINTENANCE_WINDOW_END = base.Argument(
'--maintenance-window-end',
type=arg_parsers.Datetime.Parse,
help="""\
The end time of the maintenance window. Only the time of the day is
used as a reference for an ending time of the window with a provided
recurrence. This will be used in conjunction with start time, and
the difference will determine the length of a single maintenance
window. This flag must be specified if any of the other arguments in this
group are specified. For example:
--maintenance_window_end=2024-01-02T01:00:00Z.
See $ gcloud topic datetimes for information on time formats.
""")
MAINTENANCE_WINDOW_RECURRENCE = base.Argument(
'--maintenance-window-recurrence',
type=str,
help="""\
An RFC 5545 RRULE, specifying how the maintenance window will recur.
Only FREQ=WEEKLY format is supported. This flag must be specified if
any of the other arguments in this group are specified. For example:
--maintenance_window_recurrence="FREQ=WEEKLY;BYDAY=FR,SA,SU".
""")
MAINTENANCE_WINDOW_GROUP_DESCRIPTION = (
'Group of arguments for setting the maintenance window value.')
def CreateArgumentsGroup(parser):
"""Adds argument group for creating maintenance window.
Args:
parser: parser to which the group of flags should be added.
"""
group = parser.add_group(MAINTENANCE_WINDOW_GROUP_DESCRIPTION)
MAINTENANCE_WINDOW_START.AddToParser(group)
MAINTENANCE_WINDOW_END.AddToParser(group)
MAINTENANCE_WINDOW_RECURRENCE.AddToParser(group)
def UpdateArgumentsGroup(parser):
"""Adds argument group for updating maintenance window.
Args:
parser: parser to which the group of flags should be added.
"""
update_group = parser.add_mutually_exclusive_group()
maintenance_window_group = update_group.add_group(
MAINTENANCE_WINDOW_GROUP_DESCRIPTION)
MAINTENANCE_WINDOW_START.AddToParser(maintenance_window_group)
MAINTENANCE_WINDOW_END.AddToParser(maintenance_window_group)
MAINTENANCE_WINDOW_RECURRENCE.AddToParser(maintenance_window_group)
CLEAR_MAINTENANCE_WINDOW_FLAG.AddToParser(update_group)
def SetMaintenanceWindow(args, instance):
"""Validates maintenance window flags and sets the maintenance window value.
"""
maintenance_window_start = args.maintenance_window_start
maintenance_window_end = args.maintenance_window_end
maintenance_window_recurrence = args.maintenance_window_recurrence
if (maintenance_window_start or
maintenance_window_end or
maintenance_window_recurrence):
if not maintenance_window_start:
raise exceptions.RequiredArgumentException(
'--maintenance-window-start',
'must be specified.')
if not maintenance_window_end:
raise exceptions.RequiredArgumentException(
'--maintenance-window-end',
'must be specified.')
if not maintenance_window_recurrence:
raise exceptions.RequiredArgumentException(
'--maintenance-window-recurrence',
'must be specified.')
datafusion = df.Datafusion()
instance.maintenancePolicy = datafusion.messages.MaintenancePolicy(
maintenanceWindow=datafusion.messages.MaintenanceWindow(
recurringTimeWindow=datafusion.messages.RecurringTimeWindow(
window=datafusion.messages.TimeWindow(
startTime=maintenance_window_start.isoformat().
replace('+00:00', 'Z'),
endTime=maintenance_window_end.isoformat().
replace('+00:00', 'Z'),
),
recurrence=maintenance_window_recurrence,
),
)
)
def UpdateMaintenanceWindow(args, instance):
"""Validates maintenance window flags and sets the maintenance window value.
"""
if args.clear_maintenance_window:
instance.maintenancePolicy = None
else:
SetMaintenanceWindow(args, instance)

View File

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Operation Poller."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.data_fusion import datafusion as df
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.core import exceptions as core_exceptions
class OperationPoller(waiter.CloudOperationPollerNoResources):
"""Class for polling Data Fusion long running Operations."""
def __init__(self):
super(OperationPoller, self).__init__(
df.Datafusion().client.projects_locations_operations, lambda x: x)
def IsDone(self, operation):
if operation.done:
if operation.error:
raise OperationError(operation.name, operation.error.message)
return True
return False
class OperationError(core_exceptions.Error):
"""Class for errors raised when a polled operation completes with an error."""
def __init__(self, operation_name, description):
super(OperationError, self).__init__('Operation [{}] failed: {}'.format(
operation_name, description))

View File

@@ -0,0 +1,129 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Shared resource flags for datafusion commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope.concepts import concepts
from googlecloudsdk.calliope.concepts import deps
from googlecloudsdk.command_lib.util.concepts import concept_parsers
from googlecloudsdk.core import properties
import six
def LocationAttributeConfig():
fallthroughs = [
deps.PropertyFallthrough(properties.VALUES.datafusion.location)
]
return concepts.ResourceParameterAttributeConfig(
name='location',
help_text='Compute Engine region in which to create the {resource}.',
fallthroughs=fallthroughs)
def InstanceAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='instance',
help_text='Cloud Data Fusion instance for the {resource}.')
def OperationAttributeConfig():
return concepts.ResourceParameterAttributeConfig(
name='operation',
help_text='Cloud Data Fusion operation for the {resource}.')
def GetLocationResourceSpec():
return concepts.ResourceSpec(
'datafusion.projects.locations',
resource_name='location',
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
locationsId=LocationAttributeConfig())
def GetInstanceResourceSpec():
return concepts.ResourceSpec(
'datafusion.projects.locations.instances',
resource_name='instance',
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
locationsId=LocationAttributeConfig(),
instancesId=InstanceAttributeConfig())
def GetOperationResourceSpec():
return concepts.ResourceSpec(
'datafusion.projects.locations.operations',
resource_name='operation',
projectsId=concepts.DEFAULT_PROJECT_ATTRIBUTE_CONFIG,
locationsId=LocationAttributeConfig(),
operationsId=OperationAttributeConfig())
def AddLocationResourceArg(parser, description):
concept_parsers.ConceptParser.ForResource(
'--location', GetLocationResourceSpec(), description,
required=True).AddToParser(parser)
def GetTagsArg():
"""Makes the base.Argument for --tags flag."""
help_parts = [
'List of tags KEY=VALUE pairs to bind.',
'Each item must be specified in either ID',
'`<tag_Key_id>=<tag_value_id>`',
'or Namespaced format',
'`<tag-key-namespaced-name>=<tag-value-short-name>`.\n',
'Example: `123/environment=production,123/costCenter=marketing`\n',
]
return base.Argument(
'--tags',
metavar='KEY=VALUE',
type=arg_parsers.ArgDict(),
action=arg_parsers.UpdateAction,
help='\n'.join(help_parts),
)
def GetTagsFromArgs(args, tags_message, tags_arg_name='tags'):
"""Makes the tags message object."""
tags = getattr(args, tags_arg_name)
if not tags:
return None
# Sorted for test stability
return tags_message(
additionalProperties=[
tags_message.AdditionalProperty(key=key, value=value)
for key, value in sorted(six.iteritems(tags))
]
)
def AddInstanceResourceArg(parser, description):
concept_parsers.ConceptParser.ForResource(
'instance',
GetInstanceResourceSpec(),
description,
required=True,
plural=False).AddToParser(parser)
def AddOperationResourceArg(parser, description):
concept_parsers.ConceptParser.ForResource(
'operation', GetOperationResourceSpec(), description,
required=True).AddToParser(parser)