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,104 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Declarative hooks for `gcloud dialogflow agent`."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import base64
from googlecloudsdk.api_lib.storage import storage_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.util import files
def AddSessionPrefix(session):
project = properties.VALUES.core.project.GetOrFail()
return 'projects/{}/agent/sessions/{}'.format(project, session)
def SetQueryLanguage(unused_instance_ref, args, request):
query_input = request.googleCloudDialogflowV2DetectIntentRequest.queryInput
if args.IsSpecified('query_text'):
query_input.text.languageCode = args.language
elif args.IsSpecified('query_audio_file'):
query_input.audioConfig.languageCode = args.language
return request
def LogTrainSuccess(unused_response, unused_args):
log.status.Print('Successfully trained agent.')
def IsBucketUri(path):
return path.startswith(storage_util.GSUTIL_BUCKET_PREFIX)
def SetAgentUri(unused_instance_ref, args, request):
dest = args.destination
if IsBucketUri(dest) and storage_util.ValidateBucketUrl:
request.googleCloudDialogflowV2ExportAgentRequest = {'agentUri': dest}
return request
def SaveAgentToFile(response, args):
dest = args.destination
if not IsBucketUri(dest):
props = response.additionalProperties
agent_content = next(prop for prop in props if prop.key == 'agentContent')
agent_content_bin = base64.b64decode(agent_content.value.string_value)
log.WriteToFileOrStdout(dest, agent_content_bin, binary=True)
if dest != '-':
log.status.Print('Wrote agent to [{}].'.format(dest))
return response
def ChooseImportOrRestoreMethod(unused_instance_ref, args):
if args.replace_all:
return 'restore'
return 'import'
def _GetAgentRequestBody(source):
if source.startswith('gs://'):
return {'agentUri': source}
else:
return {'agentContent': files.ReadBinaryFileContents(source)}
def ModifyImportOrRestoreRequest(unused_instance_ref, args, request):
body = _GetAgentRequestBody(args.source)
if args.replace_all:
request.googleCloudDialogflowV2RestoreAgentRequest = body
else:
request.googleCloudDialogflowV2ImportAgentRequest = body
return request
def LogImportSuccess(response, args):
path = args.source
if not args.async_:
if path != '-':
log.status.Print('Successfully imported agent from [{}].'.format(path))
else:
log.status.Print('Successfully imported agent.')
if args.replace_all:
log.status.Print('Replaced all existing resources.')
return response

View File

@@ -0,0 +1,121 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Declarative hooks for `gcloud dialogflow entity-types`."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import exceptions
import six
def EntitiesType(entities):
"""Validates entities input and turns it into an entities dict.
Valid entities inputs are:
str of comma separated entities
list of entities
map from entities to synonyms
Args:
entities: entities input
Returns:
dict mapping from entities to synonyms
Raises:
InvalidArgumentException: If the entities input is invalid.
"""
if isinstance(entities, six.text_type):
entities = arg_parsers.ArgList()(entities)
if isinstance(entities, list):
for entity in entities:
if not isinstance(entity, six.text_type):
break
else:
return [{'value': entity, 'synonyms': [entity]} for entity in entities]
if isinstance(entities, dict):
for entity, synonyms in entities.items():
if not isinstance(synonyms, list):
break
else:
return [{'value': entity, 'synonyms': synonyms}
for entity, synonyms in entities.items()]
raise exceptions.InvalidArgumentException(
'Entities must be a list of entities or a map from entities to a list of'
'synonyms.')
def PatchEntityType(unused_instance_ref, args, update_request):
"""Update entities based on clear/remove/add-entities flags."""
entities = update_request.googleCloudDialogflowV2EntityType.entities
if args.IsSpecified('clear_entities'):
entities = []
if args.IsSpecified('remove_entities'):
to_remove = set(args.remove_entities or [])
entities = [e for e in entities if e.value not in to_remove]
if args.IsSpecified('add_entities'):
entities += args.add_entities
update_request.googleCloudDialogflowV2EntityType.entities = entities
return update_request
def SetUpdateMask(unused_instance_ref, args, update_request):
"""Set the update mask on the update request based on the args.
Args:
unused_instance_ref: unused.
args: The argparse namespace.
update_request: The update request to modify.
Returns:
The update request.
Raises:
InvalidArgumentException: If no fields are specified to update.
"""
update_mask = []
if (args.IsSpecified('add_entities') or args.IsSpecified('remove_entities')
or args.IsSpecified('clear_entities')):
update_mask.append('entities')
if args.IsSpecified('add_entities'):
update_mask.append('kind')
if args.IsSpecified('display_name'):
update_mask.append('displayName')
if args.IsSpecified('auto_expand'):
update_mask.append('autoExpansionMode')
if not update_mask:
raise exceptions.InvalidArgumentException(
'Must specify at least one valid entity type parameter to update.')
update_request.updateMask = ','.join(update_mask)
return update_request
def AddEntityTypeKind(unused_instance_ref, unused_args, request):
entities = request.googleCloudDialogflowV2EntityType.entities
enum = request.googleCloudDialogflowV2EntityType.KindValueValuesEnum
kind = enum.KIND_LIST
for entity in entities:
if entity.synonyms != [entity.value]:
kind = enum.KIND_MAP
request.googleCloudDialogflowV2EntityType.kind = kind
return request

View File

@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Declarative hooks for `gcloud dialogflow intents`."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import encoding
def TrainingPhrasesType(training_phrase):
return {
'parts': [{'text': training_phrase}],
'type': 'EXAMPLE'
}
def ResponseToMessage(response):
return {'text': {'text': [response]}}
def AddOtherPropertiesToRequest(unused_instance_ref, args, request):
intent = encoding.MessageToDict(request.googleCloudDialogflowV2Intent)
if args.IsSpecified('other_properties'):
intent.update(args.other_properties)
request.googleCloudDialogflowV2Intent = encoding.DictToMessage(
intent, type(request.googleCloudDialogflowV2Intent))
return request

View File

@@ -0,0 +1,35 @@
project:
name: project
collection: dialogflow.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: Cloud project for the {resource}.
property: core/project
agent:
name: agent
collection: dialogflow.projects.agent
attributes:
- *project
entityType:
name: entityType
collection: dialogflow.projects.agent.entityTypes
attributes:
- *project
- &entityType
parameter_name: entityTypesId
attribute_name: entity_type
help: Dialogflow entity type for the {resource}.
intent:
name: intent
collection: dialogflow.projects.agent.intents
attributes:
- *project
- &intent
parameter_name: intentsId
attribute_name: intent
help: Dialogflow intent for the {resource}.