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,53 @@
# -*- 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.
"""Request hooks for Cloud Media Asset's asset transformation."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import json
from apitools.base.py import encoding
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.command_lib.media.asset import utils
def AddParentInfoToAnnotationRequests(ref, args, req):
"""Python hook for yaml commands to wildcard the parent parameter in annotation requests."""
del ref # Unused
project = utils.GetProject()
location = utils.GetLocation(args)
req.parent = utils.GetAnnotationParentTemplate(project, location,
args.asset_type, args.asset,
args.annotation_set)
return req
def ParseAnnotationRequest(ref, args, req):
"""Prepare the annotation for create and update requests."""
del ref # Unused
messages = apis.GetMessagesModule('mediaasset', 'v1alpha')
# In update case, request's annotation is nill
if req.annotation is None:
req.annotation = encoding.DictToMessage({}, messages.Annotation)
if args.IsKnownAndSpecified('labels'):
req.annotation.labels = encoding.DictToMessage(
args.labels, messages.Annotation.LabelsValue)
if args.IsKnownAndSpecified('annotation_data_file'):
annotation_data = json.loads(args.annotation_data_file)
req.annotation.data = encoding.DictToMessage(annotation_data,
messages.Annotation.DataValue)
return req

View File

@@ -0,0 +1,109 @@
# -*- 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.
"""Create hooks for Cloud Media Asset's asset type."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import json
from apitools.base.py import encoding
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.command_lib.media.asset import utils
from googlecloudsdk.core import exceptions
from googlecloudsdk.core import resources
def ParseCreateConfigFile(ref, args, req):
"""Reads the json file of with the asset type configs and parse the content to the request message."""
del ref
messages = apis.GetMessagesModule('mediaasset', 'v1alpha')
message_class = messages.AssetType
if args.create_asset_type_config_file:
asset_type_configs = json.loads(args.create_asset_type_config_file)
at = encoding.DictToMessage(asset_type_configs, message_class)
utils.ValidateMediaAssetMessage(at)
req.assetType = at
if args.IsKnownAndSpecified('labels'):
req.assetType.labels = encoding.DictToMessage(
args.labels, messages.AssetType.LabelsValue)
return req
def ParseUpdateConfigFile(ref, args, req):
"""Reads the json file with asset type configs and update mask, then parse the cotent to the request message."""
del ref
update_file_config = json.loads(args.update_asset_type_config_file)
messages = apis.GetMessagesModule('mediaasset', 'v1alpha')
# validate input file.
if 'assetType' not in update_file_config:
raise exceptions.Error('assetType needs to be included in the config file.')
if 'updateMask' not in update_file_config:
raise exceptions.Error(
'updateMask needs to be included in the config file.')
update_mask = update_file_config['updateMask']
asset_type = update_file_config['assetType']
if not isinstance(update_mask, list):
raise exceptions.Error('updateMask needs to be a list.')
if len(update_mask) != len(asset_type):
raise exceptions.Error('updated assetType does not match with updateMask.')
for update in update_mask:
if update not in asset_type:
raise exceptions.Error(
'updated assetType does not match with updateMask.')
# set request parameters.
at = encoding.DictToMessage(asset_type, messages.AssetType)
utils.ValidateMediaAssetMessage(at)
req.assetType = at
req.updateMask = ','.join(update_mask)
return req
def GetExistingResource(api_version, request_message):
"""Get the modified resource.
Args:
api_version: the request's release track.
request_message: request message type in the python client.
Returns:
The modified resource.
"""
return utils.GetClient(api_version).projects_locations_assetTypes.Get(
request_message)
def ProcessOutput(response, args):
"""Wait for operations to finish and return the resource."""
api_version = utils.GetApiVersionFromArgs(args)
utils.WaitForOperation(response, api_version)
project = utils.GetProject()
location = utils.GetLocation(args)
resource_ref = resources.REGISTRY.Create(
'mediaasset.projects.locations.assetTypes',
projectsId=project,
locationsId=location,
assetTypesId=args.asset_type)
if 'delete' in args.command_path:
# No need to send another get request to check for the deleted complex type.
return response
request_message = utils.GetApiMessage(
api_version).MediaassetProjectsLocationsAssetTypesGetRequest(
name=resource_ref.RelativeName())
return GetExistingResource(api_version, request_message)

View File

@@ -0,0 +1,89 @@
# -*- 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.
"""Create hooks for Cloud Media Asset's asset type."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import json
from apitools.base.py import encoding
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.command_lib.media.asset import utils
from googlecloudsdk.core import resources
def AddParentInfoToAssetRequests(ref, args, req):
"""Python hook for yaml commands to wildcard the parent parameter in asset requests."""
del ref # Unused
project = utils.GetProject()
location = utils.GetLocation(args)
req.parent = utils.GetAssetTypeParentTemplate(project, location,
args.asset_type)
return req
def ParseAssetConfigFile(ref, args, req):
"""Prepare the asset for create and update requests."""
del ref # Unused
messages = apis.GetMessagesModule('mediaasset', 'v1alpha')
if args.IsKnownAndSpecified('asset_config_file'):
asset_data = json.loads(args.asset_config_file)
asset = encoding.DictToMessage(asset_data, messages.Asset)
utils.ValidateMediaAssetMessage(asset)
req.asset = asset
if args.IsKnownAndSpecified('labels'):
req.asset.labels = encoding.DictToMessage(args.labels,
messages.Asset.LabelsValue)
return req
def GetExistingResource(api_version, request_message):
"""Get the modified resource.
Args:
api_version: the request's release track.
request_message: request message type in the python client.
Returns:
The modified resource.
"""
return utils.GetClient(api_version).projects_locations_assetTypes_assets.Get(
request_message)
def ProcessOutput(response, args):
"""Wait for operations to finish and return the resource."""
api_version = utils.GetApiVersionFromArgs(args)
utils.WaitForOperation(response, api_version)
project = utils.GetProject()
location = utils.GetLocation(args)
resource_ref = resources.REGISTRY.Create(
'mediaasset.projects.locations.assetTypes.assets',
projectsId=project,
locationsId=location,
assetTypesId=args.asset_type,
assetsId=args.asset)
if 'delete' in args.command_path:
# No need to send another get request to check for the deleted asset.
return response
request_message = utils.GetApiMessage(
api_version).MediaassetProjectsLocationsAssetTypesAssetsGetRequest(
name=resource_ref.RelativeName())
return GetExistingResource(api_version, request_message)

View File

@@ -0,0 +1,94 @@
# -*- 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.
"""Hooks function for Cloud Media Asset's complex type."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import json
from apitools.base.py import encoding
from googlecloudsdk.command_lib.media.asset import utils
from googlecloudsdk.core import exceptions
from googlecloudsdk.core import resources
def ParseComplexTypeConfigFile(ref, args, req):
"""Reads the json with complex type configuration and set the content in the request."""
del ref
complex_type_dict = []
if args.complex_type_config_file:
complex_type_dict = json.loads(args.complex_type_config_file)
messages = utils.GetApiMessage(utils.GetApiVersionFromArgs(args))
ct = encoding.DictToMessage(complex_type_dict, messages.ComplexType)
utils.ValidateMediaAssetMessage(ct)
req.complexType = ct
if 'update' in args.command_path:
ValidateUpdateMask(args, complex_type_dict)
return req
def ValidateUpdateMask(args, complex_type_dict):
"""Validate the update mask in update complex type requests."""
update_masks = list(args.update_mask.split(','))
for mask in update_masks:
# walk the path in the dictionary to ensure it's correct
mask_path = mask.split('.')
mask_path_index = 0
complex_type_walker = complex_type_dict
while mask_path_index < len(mask_path):
if mask_path[mask_path_index] not in complex_type_walker:
raise exceptions.Error(
'unrecognized field in update_mask: {0}.'.format(mask))
complex_type_walker = complex_type_walker[mask_path[mask_path_index]]
mask_path_index += 1
def GetExistingResource(api_version, request_message):
"""Get the modified resource.
Args:
api_version: The request release track.
request_message: request message type in the python client.
Returns:
The modified resource.
"""
return utils.GetClient(api_version).projects_locations_complexTypes.Get(
request_message)
def ProcessOutput(response, args):
"""Wait for operations to finish and return the resource."""
api_version = utils.GetApiVersionFromArgs(args)
utils.WaitForOperation(response, api_version)
project = utils.GetProject()
location = utils.GetLocation(args)
resource_ref = resources.REGISTRY.Create(
'mediaasset.projects.locations.complexTypes',
projectsId=project,
locationsId=location,
complexTypesId=args.complex_type)
if 'delete' in args.command_path:
# No need to send another get request to check for the deleted complex type.
return response
request_message = utils.GetApiMessage(
api_version).MediaassetProjectsLocationsComplexTypesGetRequest(
name=resource_ref.RelativeName())
return GetExistingResource(api_version, request_message)

View File

@@ -0,0 +1,41 @@
create-asset-type-config-file:
arg_name: create-asset-type-config-file
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
help_text: |-
File path to a config file in JSON format.
update-asset-type-config-file:
arg_name: update-asset-type-config-file
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
required: true
help_text: |-
File path to a config file in JSON format. It must containe the asset type updated fields and update_mask
complex-type-config-file:
arg_name: complex-type-config-file
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
required: false
help_text: |-
File path to a config file in JSON format. It must containe the asset type updated fields and update_mask
create-transformer-configs-file:
arg_name: create-transformer-configs-file
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
required: false
help_text: |-
File path to a config file in JSON format.
annotation-data-file:
arg_name: annotation-data-file
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
required: true
help_text: |-
File path to a file contains annotation data in JSON format.
asset-config-file:
arg_name: asset-config-file
required: false
type: "googlecloudsdk.calliope.arg_parsers:FileContents:"
help_text: |-
File path to an asset content file in JSON format.

View File

@@ -0,0 +1,30 @@
# -*- 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.
"""Create hooks for Cloud Media Asset."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.media.asset import utils
def AddDefaultParentInfoToAssetTypeRequests(ref, args, req):
"""Python hook for yaml commands to wildcard the location in asset type requests."""
del ref # Unused
project = utils.GetProject()
location = utils.GetLocation(args)
req.parent = utils.GetParentTemplate(project, location)
return req

View File

@@ -0,0 +1,107 @@
project:
name: project
collection: mediaasset.projects
attributes:
- &project
parameter_name: projectsId
attribute_name: project
help: Cloud Project name.
property: core/project
location:
name: location
collection: mediaasset.projects.locations
attributes:
- *project
- &location
parameter_name: locationsId
attribute_name: location
property: media_asset/location
help: Google Cloud location.
operation:
name: operation
collection: mediaasset.projects.locations.operations
attributes:
- *project
- *location
- &operation
parameter_name: operationsId
attribute_name: operation
help: Cloud Media Asset Operation.
asset_type:
name: asset_type
collection: mediaasset.projects.locations.assetTypes
request_id_field: assetTypeId
attributes:
- *project
- *location
- &asset_type
parameter_name: assetTypesId
attribute_name: asset_type
help: Google Cloud Media Asset asset type.
asset:
name: asset
collection: mediaasset.projects.locations.assetTypes.assets
request_id_field: assetId
attributes:
- *project
- *location
- *asset_type
- &asset
parameter_name: assetsId
attribute_name: asset
help: Google Cloud Media Asset asset.
complex_type:
name: complex_type
collection: mediaasset.projects.locations.complexTypes
request_id_field: complexTypeId
attributes:
- *project
- *location
- &complex_type
parameter_name: complexTypesId
attribute_name: complex_type
help: Google Cloud Media Asset complex type.
transformer:
name: transformer
collection: mediaasset.projects.locations.transformers
request_id_field: transformerId
attributes:
- *project
- *location
- &transformer
parameter_name: transformersId
attribute_name: transformer
help: Google Cloud Media Asset transformer.
annotation_set:
name: annotation_set
collection: mediaasset.projects.locations.assetTypes.assets.annotationSets
attributes:
- *project
- *location
- *asset_type
- *asset
- &annotation_set
parameter_name: annotationSetsId
attribute_name: annotation_set
help: Google Cloud Media Asset annotation set
annotation:
name: annotation
collection: mediaasset.projects.locations.assetTypes.assets.annotationSets.annotations
attributes:
- *project
- *location
- *asset_type
- *asset
- *annotation_set
- &annotation
parameter_name: annotationsId
attribute_name: annotation
help: Google Cloud Media Asset annotation

View File

@@ -0,0 +1,79 @@
# -*- 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.
"""Hooks function for Cloud Media Asset's transformers."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import json
from apitools.base.py import encoding
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.command_lib.media.asset import utils
from googlecloudsdk.core import resources
def ParseTransformerConfigFile(ref, args, req):
"""Reads the json file of with the transformer configs and parse the content to the request message."""
del ref
messages = apis.GetMessagesModule('mediaasset', 'v1alpha')
message_class = messages.Transformer
if args.create_transformer_configs_file:
transformer_configs = json.loads(args.create_transformer_configs_file)
transformer = encoding.DictToMessage(transformer_configs, message_class)
utils.ValidateMediaAssetMessage(transformer)
req.transformer = transformer
if args.IsKnownAndSpecified('labels'):
req.transformer.labels = encoding.DictToMessage(
args.labels, messages.Transformer.LabelsValue)
return req
def GetExistingResource(api_version, request_message):
"""Get the modified resource.
Args:
api_version: The request release track.
request_message: request message type in the python client.
Returns:
The modified resource.
"""
return utils.GetClient(api_version).projects_locations_transformers.Get(
request_message)
def ProcessOutput(response, args):
"""Wait for operations to finish and return the resource."""
api_version = utils.GetApiVersionFromArgs(args)
utils.WaitForOperation(response, api_version)
project = utils.GetProject()
location = utils.GetLocation(args)
resource_ref = resources.REGISTRY.Create(
'mediaasset.projects.locations.transformers',
projectsId=project,
locationsId=location,
transformersId=args.transformer)
if 'delete' in args.command_path:
# No need to send another get request to check for the deleted complex type.
return response
request_message = utils.GetApiMessage(
api_version).MediaassetProjectsLocationsTransformersGetRequest(
name=resource_ref.RelativeName())
return GetExistingResource(api_version, request_message)

View File

@@ -0,0 +1,125 @@
# -*- 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.
"""Create hooks for Cloud Media Asset's asset type."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import encoding
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.core import exceptions
from googlecloudsdk.core import properties
from googlecloudsdk.core import resources
import six
MEDIA_ASSET_API = 'mediaasset'
OPERATIONS_COLLECTION = 'mediaasset.projects.locations.operations'
PARENT_TEMPLATE = 'projects/{}/locations/{}'
ASSET_TYPE_PARENT_TEMPLATE = 'projects/{}/locations/{}/assetTypes/{}'
ASSET_PARENT_TEMPLATE = 'projects/{}/locations/{}/assetTypes/{}/assets/{}'
ANNOTATION_PARENT_TEMPLATE = ASSET_PARENT_TEMPLATE + '/annotationSets/{}'
def GetApiMessage(api_version):
return apis.GetMessagesModule(MEDIA_ASSET_API, api_version)
def GetClient(api_version):
return apis.GetClientInstance(MEDIA_ASSET_API, api_version)
def GetProject():
return properties.VALUES.core.project.Get(required=True)
def GetLocation(args):
return args.location or properties.VALUES.media_asset.location.Get(
required=True)
def GetParentTemplate(project, location):
return PARENT_TEMPLATE.format(project, location)
def GetAssetTypeParentTemplate(project, location, asset_type):
return ASSET_TYPE_PARENT_TEMPLATE.format(project, location, asset_type)
def GetAssetParentTemplate(project, location, asset_type, asset):
return ASSET_PARENT_TEMPLATE.format(project, location, asset_type, asset)
def GetAnnotationParentTemplate(project, location, asset_type, asset,
annotation_set):
return ANNOTATION_PARENT_TEMPLATE.format(project, location, asset_type, asset,
annotation_set)
class UnsupportedReleaseTrackError(Exception):
"""Raised when calling an api with a unsupported release track."""
def GetApiVersionFromArgs(args):
"""Return API version based on args.
Update this whenever there is a new version.
Args:
args: The argparse namespace.
Returns:
API version (e.g. v1alpha or v1beta).
Raises:
UnsupportedReleaseTrackError: If invalid release track from args.
"""
release_track = args.calliope_command.ReleaseTrack()
if release_track == base.ReleaseTrack.ALPHA:
return 'v1alpha'
if release_track == base.ReleaseTrack.BETA:
return 'v1beta'
if release_track == base.ReleaseTrack.GA:
return 'v1'
raise UnsupportedReleaseTrackError(release_track)
def ValidateMediaAssetMessage(message):
"""Validate all parsed message from file are valid."""
errors = encoding.UnrecognizedFieldIter(message)
unrecognized_field_paths = []
for edges_to_message, field_names in errors:
message_field_path = '.'.join(six.text_type(e) for e in edges_to_message)
for field_name in field_names:
unrecognized_field_paths.append('{}.{}'.format(message_field_path,
field_name))
if unrecognized_field_paths:
error_msg_lines = [
'Invalid schema, the following fields are unrecognized:'
] + unrecognized_field_paths
raise exceptions.Error('\n'.join(error_msg_lines))
def WaitForOperation(response, api_version):
"""Wait for an operation to finish."""
operation_ref = resources.REGISTRY.ParseRelativeName(
response.name, collection=OPERATIONS_COLLECTION)
return waiter.WaitFor(
waiter.CloudOperationPollerNoResources(
GetClient(api_version).projects_locations_operations), operation_ref,
'Waiting for [{0}] to finish'.format(operation_ref.Name()))