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,26 @@
# -*- 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 command group for configs variables component."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Variables(base.Group):
"""Manage variable resources."""

View File

@@ -0,0 +1,44 @@
# -*- 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 configs variables describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.runtime_config import util
from googlecloudsdk.command_lib.runtime_config import base_commands
class Describe(base_commands.VariableRetrieverCommand):
"""Describe variable resources.
This command displays information about the variable resource with the
specified name.
"""
detailed_help = {
'EXAMPLES': """\
To describe a variable named "my-var", run:
$ {command} --config-name=my-config my-var
""",
}
def Run(self, args):
result = super(Describe, self).Run(args)
# Describe always returns the value.
return util.FormatVariable(result, True)

View File

@@ -0,0 +1,49 @@
# -*- 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 configs variables get-value command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.runtime_config import base_commands
from googlecloudsdk.core import log
class GetValue(base_commands.VariableRetrieverCommand):
"""Output values of variable resources.
This command prints only the value of the variable resource with the
specified name, and does not append a trailing newline character.
It can be used as part of shell expansions.
"""
detailed_help = {
'EXAMPLES': """\
To print the value of a variable named "my-var", run:
$ {command} --config-name=my-config my-var
Values will be automatically base64-decoded.
""",
}
def Display(self, args, variable):
# Server guarantees that only one of those will be set.
if variable.value:
log.out.write(variable.value)
else:
log.out.write(variable.text)

View File

@@ -0,0 +1,110 @@
# -*- 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 configs variables list command."""
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.runtime_config import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.runtime_config import flags
from googlecloudsdk.core import log
class List(base.ListCommand):
"""List variable resources within a configuration.
This command lists the variable resources within a specified configuration.
"""
DEFAULT_PAGE_SIZE = 100
detailed_help = {
'EXAMPLES': """\
To list all variables within the configuration named "my-config", run:
$ {command} --config-name=my-config
The --filter parameter can be used to filter results based on content.
For example, to list all variables under the path 'status/', run:
$ {command} --config-name=my-config --filter='name=status/*'
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
flags.AddRequiredConfigFlag(parser)
parser.add_argument(
'--values',
action='store_true',
help=('List the variables for which you have Get '
'IAM permission along with their values.'))
parser.display_info.AddFormat('table(name, updateTime, value:optional)')
def Run(self, args):
"""Run 'runtime-configs variables list'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Yields:
The list of variables.
Raises:
HttpException: An http error response was received while executing api
request.
"""
variable_client = util.VariableClient()
messages = util.Messages()
config_resource = util.ParseConfigName(util.ConfigName(args))
self._display_values = args.values
request = messages.RuntimeconfigProjectsConfigsVariablesListRequest(
parent=config_resource.RelativeName(),
returnValues=self._display_values)
page_size = args.page_size or self.DEFAULT_PAGE_SIZE
results = list_pager.YieldFromList(
variable_client, request, field='variables',
batch_size_attribute='pageSize', limit=args.limit,
batch_size=page_size
)
for result in results:
yield util.FormatVariable(result, self._display_values)
def Epilog(self, resources_were_displayed):
if resources_were_displayed and self._display_values:
log.status.Print("""\
With --values flag specified, only those variables for which you have Get IAM permission will be returned along with their values.
To see all the variables for which you have List IAM permission, please run the command without the --values flag.
""")

View File

@@ -0,0 +1,187 @@
# -*- 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 configs variables set command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import sys
from apitools.base.py import exceptions as apitools_exceptions
from googlecloudsdk.api_lib.runtime_config import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.runtime_config import flags
from googlecloudsdk.core import log
from googlecloudsdk.core.util import http_encoding
class Set(base.CreateCommand):
"""Create or update variable resources.
This command creates or updates a variable resource, setting its value to
the specified string or file contents.
"""
detailed_help = {
'EXAMPLES': """\
To create or update a variable named "my-var", run:
$ {command} --config-name=my-config my-var "my value"
To create or update a variable with a hierarchical name, such as
"results/task1", run:
$ {command} --config-name=my-config results/task1 "my value"
To create a variable, but fail if it already exists, run:
$ {command} --config-name=my-config my-var "my-value" --fail-if-present
To update a variable, but fail if it does not exist, run:
$ {command} --config-name=my-config my-var "my-value" --fail-if-absent
It is possible to provide --is-text flag if the value contains only
text (UTF-8 encoded). This affects how the variable is transmitted on
the wire and requires less quota on the backend.
$ {command} --config-name=my-config --is-text my-var "my value"
If the variable's value parameter is not specified, the value will be
read from standard input. This allows setting variables to large values
or values that contain non-printable characters. The variable value
will be automatically base64-encoded. For example, to set a variable's
value to the contents of a file, run:
$ cat my-file | {command} --config-name my-config my-var
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
flags.AddRequiredConfigFlag(parser)
fail_group = parser.add_mutually_exclusive_group()
fail_group.add_argument(
'--fail-if-present',
help='Fail if a variable with the specified name already exists.',
action='store_true')
fail_group.add_argument(
'--fail-if-absent',
help='Fail if a variable with the specified name does not exist.',
action='store_true')
parser.add_argument('name', help='The variable name.')
parser.add_argument(
'value',
nargs='?',
default=None,
help=(
'The variable value. If absent, the value will be read from stdin. '
'The value is automatically base64-encoded, '
'unless --is-text flag is set.'))
parser.add_argument('--is-text',
default=False,
required=False,
action='store_true',
help=('If True, send and store the value as text. Can '
'be used if the value contains only text '
'(UTF-8 encoded). This affects how the variable '
'is transmitted on the wire and requires less '
'quota on the backend.'))
def Run(self, args):
"""Run 'runtime-configs variables set'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
The new variable.
Raises:
HttpException: An http error response was received while executing api
request.
"""
var_resource = util.ParseVariableName(args.name, args)
if args.value is None:
log.status.Print('No value argument specified; reading value from stdin.')
value = sys.stdin.read()
else:
value = args.value
if args.fail_if_absent:
# Update case
return self._Update(args, var_resource, value)
else:
# Either create or create-or-update
try:
return self._Create(args, var_resource, value)
except apitools_exceptions.HttpConflictError:
# If --fail-if-present was not specified, and we got an
# Already Exists error, try updating instead.
if not args.fail_if_present:
return self._Update(args, var_resource, value)
# If --fail-if-present was specified re-raise the error.
raise
def _Create(self, args, var_resource, value):
variable_client = util.VariableClient()
messages = util.Messages()
project = var_resource.projectsId
config = var_resource.configsId
result = variable_client.Create(
messages.RuntimeconfigProjectsConfigsVariablesCreateRequest(
parent=util.ConfigPath(project, config),
variable=messages.Variable(
name=var_resource.RelativeName(),
value=http_encoding.Encode(value) if not args.is_text else None,
text=value if args.is_text else None,
)
)
)
log.CreatedResource(var_resource)
return util.FormatVariable(result)
def _Update(self, args, var_resource, value):
variable_client = util.VariableClient()
messages = util.Messages()
result = variable_client.Update(
messages.Variable(
name=var_resource.RelativeName(),
value=http_encoding.Encode(value) if not args.is_text else None,
text=value if args.is_text else None,
)
)
log.UpdatedResource(var_resource)
return util.FormatVariable(result)

View File

@@ -0,0 +1,107 @@
# -*- 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 configs variables unset command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions as apitools_exceptions
from googlecloudsdk.api_lib.runtime_config import util
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.runtime_config import flags
from googlecloudsdk.core import log
class Unset(base.DeleteCommand):
"""Delete variable resources.
This command deletes the variable resource with the specified name.
"""
detailed_help = {
'EXAMPLES': """\
To delete a variable named "my-var", run:
$ {command} --config-name=my-config my-var
To delete a variable, but fail if it does not exist, run:
$ {command} --config-name=my-config my-var --fail-if-absent
To recursively delete a parent variable and its children, run:
$ {command} --config-name=my-config my-parent-var --recursive
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
flags.AddRequiredConfigFlag(parser)
parser.add_argument(
'--fail-if-absent',
help='Fail if a variable with the specified name does not exist.',
action='store_true')
parser.add_argument(
'--recursive',
help='Delete a parent node and all of its children.',
action='store_true')
parser.add_argument('name', help='The variable name.')
def Run(self, args):
"""Run 'runtime-configs variables set'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
The new variable.
Raises:
HttpException: An http error response was received while executing api
request.
"""
variable_client = util.VariableClient()
messages = util.Messages()
var_resource = util.ParseVariableName(args.name, args)
try:
variable_client.Delete(
messages.RuntimeconfigProjectsConfigsVariablesDeleteRequest(
name=var_resource.RelativeName(),
recursive=args.recursive,
)
)
log.DeletedResource(var_resource)
except apitools_exceptions.HttpNotFoundError:
# Raise this failure if the user requested it.
if args.fail_if_absent:
raise

View File

@@ -0,0 +1,151 @@
# -*- 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 configs variables watch command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import socket
from apitools.base.py import exceptions as apitools_exceptions
from googlecloudsdk.api_lib.deployment_manager import exceptions
from googlecloudsdk.api_lib.runtime_config import util
from googlecloudsdk.calliope import arg_parsers
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.runtime_config import flags
from googlecloudsdk.core.console import progress_tracker
from googlecloudsdk.core.util import times
TIMEOUT_MESSAGE = 'The read operation timed out'
class Watch(base.Command):
"""Wait for a variable resources to change.
This command waits for the variable resource with the specified name to either
have its value changed or be deleted.
"""
detailed_help = {
'EXAMPLES': """
To wait for a variable to change or be deleted, run:
$ {command} my-var --config-name=my-config
This command will return after the variable changes,
is deleted, or a server-defined timeout elapses.
To wait for user-specified period of 20 seconds, run:
$ {command} my-var --config-name=my-config --max-wait=20
If a watch command returns due to a timeout, the command's exit value
will be 2. All other errors result in an exit value of 1. If the
watched variable changes prior to the timeout, the command will exit
successfully with a value of 0.
Optionally, a --newer-than parameter can be specified to wait only
if the variable hasn't changed since the specified time. If the
variable has changed since the time passed to --newer-than, the
command returns without waiting. For example:
$ {command} my-var --config-name=my-config --newer-than="2016-04-05T12:00:00Z"
""",
}
@staticmethod
def Args(parser):
"""Args is called by calliope to gather arguments for this command.
Args:
parser: An argparse parser that you can use to add arguments that go
on the command line after this command. Positional arguments are
allowed.
"""
flags.AddRequiredConfigFlag(parser)
parser.add_argument('--newer-than',
help="""Return immediately if the stored variable is
newer than this time. See $ gcloud topic datetimes
for information on time formats.""",
type=arg_parsers.Datetime.Parse)
parser.add_argument('--max-wait',
help="""\
An optional maximum time to wait. For example, "30s".
See $ gcloud topic datetimes for information on duration formats.""",
type=arg_parsers.Duration(lower_bound='1s',
upper_bound='60s'))
parser.add_argument('name', help='Variable name.')
def Run(self, args):
"""Run a command that watches a variable.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
The WatchVariable response.
Raises:
HttpException: An http error response was received while executing api
request.
"""
# Disable retries and configure the timeout.
variable_client = util.VariableClient(num_retries=0, timeout=args.max_wait)
messages = util.Messages()
var_resource = util.ParseVariableName(args.name, args)
if args.newer_than:
newer_than = times.FormatDateTime(args.newer_than)
else:
newer_than = None
with progress_tracker.ProgressTracker(
'Waiting for variable [{0}] to change'.format(var_resource.Name())):
try:
return util.FormatVariable(
variable_client.Watch(
messages.RuntimeconfigProjectsConfigsVariablesWatchRequest(
name=var_resource.RelativeName(),
watchVariableRequest=messages.WatchVariableRequest(
newerThan=newer_than,))))
except apitools_exceptions.HttpError as error:
# For deadline exceeded or bad gateway errors,
# we return a status code of 2.
# In some cases, the GFE will timeout before the backend
# responds with a 504 Gateway Timeout (DEADLINE_EXCEEDED).
# In that scenario, GFE responds first with a 502 BAD GATEWAY error.
if util.IsDeadlineExceededError(error) or util.IsBadGatewayError(error):
_RaiseTimeout()
raise
except socket.error as error:
if util.IsSocketTimeout(error):
_RaiseTimeout()
raise
def _RaiseTimeout():
raise exceptions.OperationTimeoutError(
'Variable did not change prior to timeout.', exit_code=2)