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,37 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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.
"""Configurations command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Configurations(base.Group):
"""Manage the set of gcloud named configurations."""
detailed_help = {
'DESCRIPTION': """\
{description}
The current configuration can be managed via the
CLOUDSDK_ACTIVE_CONFIG_NAME environment variable or a configuration
property. See `gcloud topic configurations` for an overview of named
configurations.
""",
}

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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 to activate named configuration."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.config import completers
from googlecloudsdk.command_lib.config import config_validators
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.configurations import named_configs
@base.UniverseCompatible
class Activate(base.SilentCommand):
"""Activates an existing named configuration."""
detailed_help = {
'DESCRIPTION': """\
{description}
See `gcloud topic configurations` for an overview of named
configurations.
""",
'EXAMPLES': """\
To activate an existing configuration named `my-config`, run:
$ {command} my-config
To list all properties in the activated configuration, run:
$ gcloud config list --all
""",
}
@staticmethod
def Args(parser):
"""Adds args for this command."""
parser.add_argument(
'configuration_name',
completer=completers.NamedConfigCompleter,
help='Name of the configuration to activate')
def Run(self, args):
named_configs.ConfigurationStore.ActivateConfig(args.configuration_name)
log.status.write('Activated [{0}].\n'.format(args.configuration_name))
project_id = properties.VALUES.core.project.Get()
if project_id:
# Warning if current project does not match the one in ADC
config_validators.WarnIfSettingProjectWhenAdcExists(project_id)
projects_util.PrintEnvironmentTagMessage(project_id)
return args.configuration_name

View File

@@ -0,0 +1,111 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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 to create named configuration."""
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.config import config_validators
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.configurations import named_configs
from googlecloudsdk.core.universe_descriptor import universe_descriptor
@base.UniverseCompatible
class Create(base.SilentCommand):
"""Creates a new named configuration."""
detailed_help = {
'DESCRIPTION': """\
{description}
Except for special cases (NONE), configuration names start with a
lower case letter and contain only lower case letters a-z, digits 0-9,
and hyphens '-'.
See `gcloud topic configurations` for an overview of named
configurations.
""",
'EXAMPLES': """\
To create a new named configuration, run:
$ {command} my-config
""",
}
@staticmethod
def Args(parser):
"""Adds args for this command."""
parser.add_argument(
'configuration_name', help='Name of the configuration to create'
)
parser.add_argument(
'--activate',
action='store_true',
default=True,
help='If true, activate this configuration upon create.',
)
parser.add_argument(
'--universe-domain',
type=str,
hidden=True,
help=(
'If set, creates the configuration with the specified'
' [core/universe_domain].'
),
)
def Run(self, args):
created_config = named_configs.ConfigurationStore.CreateConfig(
args.configuration_name
)
log.CreatedResource(args.configuration_name)
if args.activate:
named_configs.ConfigurationStore.ActivateConfig(args.configuration_name)
log.status.Print('Activated [{0}].'.format(args.configuration_name))
project_id = properties.VALUES.core.project.Get()
if project_id:
projects_util.PrintEnvironmentTagMessage(
project_id
)
else:
log.status.Print(
'To use this configuration, activate it by running:\n'
' $ gcloud config configurations activate {name}\n\n'.format(
name=args.configuration_name
)
)
if args.universe_domain:
config_validators.WarnIfSettingUniverseDomainWithNoDescriptorData(
args.universe_domain
)
universe_descriptor_obj = universe_descriptor.UniverseDescriptor()
_, is_deprecated_and_switched = (
universe_descriptor_obj.UpdateDescriptorFromUniverseDomain(
args.universe_domain
)
)
# Avoid setting back the universe domain property if args.universe_domain
# is deprecated.
if not is_deprecated_and_switched:
created_config.PersistProperty(
'core', 'universe_domain', args.universe_domain
)
else:
log.status.Print('Domain is switched to primary.')
log.status.Print('Updated property [core/universe_domain].')
return args.configuration_name

View File

@@ -0,0 +1,170 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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 to delete named configuration."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.config import completers
from googlecloudsdk.core import config
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from googlecloudsdk.core.configurations import named_configs
from googlecloudsdk.core.configurations import properties_file
from googlecloudsdk.core.console import console_io
from googlecloudsdk.core.resource import resource_printer
from googlecloudsdk.core.universe_descriptor import universe_descriptor
@base.UniverseCompatible
class Delete(base.SilentCommand):
"""Deletes a named configuration."""
detailed_help = {
'DESCRIPTION': """\
{description} You cannot delete a configuration that is active, even
when overridden with the --configuration flag. To delete the current
active configuration, first `gcloud config configurations activate`
another one.
See `gcloud topic configurations` for an overview of named
configurations.
""",
'EXAMPLES': """\
To delete an existing configuration named `my-config`, run:
$ {command} my-config
To delete more than one configuration, run:
$ {command} my-config1 my-config2
To list existing configurations, run:
$ gcloud config configurations list
""",
}
@staticmethod
def Args(parser):
"""Adds args for this command."""
parser.add_argument(
'configuration_names',
nargs='+',
completer=completers.NamedConfigCompleter,
help=(
'Name of the configuration to delete. '
'Cannot be currently active configuration.'
),
)
def _UniverseDomainSetInAnyConfig(self, universe_domain: str) -> bool:
"""Determines whether the universe domain is set in any other config.
Args:
universe_domain: The universe domain to check for in any other config.
Returns:
True if the universe domain is set in any other config, False otherwise.
"""
all_configs = named_configs.ConfigurationStore.AllConfigs()
for _, user_config in sorted(all_configs.items()):
props = properties.VALUES.AllValues(
list_unset=True,
include_hidden=True,
properties_file=properties_file.PropertiesFile(
[user_config.file_path]
),
only_file_contents=True,
)
if props['core'].get('universe_domain') == universe_domain:
return True
return False
def _DeleteUniverseDescriptor(self, universe_domain: str) -> None:
"""Deletes the universe descriptor if it is not used in any other config.
Args:
universe_domain: The universe domain of the descriptor to delete.
"""
universe_descriptor_obj = universe_descriptor.UniverseDescriptor()
if not self._UniverseDomainSetInAnyConfig(universe_domain):
universe_descriptor_obj.DeleteDescriptorFromUniverseDomain(
universe_domain
)
def _GetConfigurationUniverseDomain(self, config_name: str) -> str:
"""Returns the universe domain of the given configuration.
Args:
config_name: The name of the configuration to get the universe domain of.
Returns:
The universe domain of the given configuration or the default if not
found.
"""
all_named_configs = named_configs.ConfigurationStore.AllConfigs()
for _, user_config in sorted(all_named_configs.items()):
if user_config.name == config_name:
props = properties.VALUES.AllValues(
list_unset=True,
include_hidden=True,
properties_file=properties_file.PropertiesFile(
[user_config.file_path]
),
only_file_contents=True,
)
return (
props['core'].get('universe_domain')
or properties.VALUES.core.universe_domain.default
)
return properties.VALUES.core.universe_domain.default
def Run(self, args):
# Fail the delete operation when we're attempting to delete the
# active config.
active_config = named_configs.ConfigurationStore.ActiveConfig()
if active_config.name in args.configuration_names:
raise named_configs.NamedConfigError(
'Deleting named configuration failed because configuration '
'[{0}] is set as active. Use `gcloud config configurations '
'activate` to change the active configuration.'.format(
active_config.name
)
)
fmt = 'list[title="The following configurations will be deleted:"]'
resource_printer.Print(args.configuration_names, fmt, out=log.status)
console_io.PromptContinue(default=True, cancel_on_no=True)
for configuration_name in args.configuration_names:
delete_config_universe_domain = self._GetConfigurationUniverseDomain(
configuration_name
)
named_configs.ConfigurationStore.DeleteConfig(configuration_name)
config_store_to_delete = config.GetConfigStore(configuration_name)
config_store_to_delete.DeleteConfig()
try:
self._DeleteUniverseDescriptor(delete_config_universe_domain)
except universe_descriptor.UniverseDescriptorError as e:
log.warning(
'Failed to delete universe descriptor for universe domain %s: %s',
delete_config_universe_domain,
e,
)
log.DeletedResource(configuration_name)

View File

@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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 to describe named configuration."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.config import completers
from googlecloudsdk.core import properties
from googlecloudsdk.core.configurations import named_configs
from googlecloudsdk.core.configurations import properties_file
class Describe(base.DescribeCommand):
"""Describes a named configuration by listing its properties."""
detailed_help = {
'DESCRIPTION': """\
{description}
See `gcloud topic configurations` for an overview of named
configurations.
""",
'EXAMPLES': """\
To describe an existing configuration named `my-config`, run:
$ {command} my-config
This is similar to:
$ gcloud config configurations activate my-config
$ gcloud config list
""",
}
@staticmethod
def Args(parser):
"""Adds args for this command."""
parser.add_argument(
'configuration_name',
completer=completers.NamedConfigCompleter,
help='Name of the configuration to describe')
parser.add_argument(
'--all', action='store_true',
help='Include unset properties in output.')
def Run(self, args):
all_configs = named_configs.ConfigurationStore.AllConfigs(
include_none_config=True)
config = all_configs.get(args.configuration_name, None)
if not config:
raise named_configs.NamedConfigError(
'The configuration [{0}] does not exist.'
.format(args.configuration_name))
return {
'name': config.name,
'is_active': config.is_active,
'properties': properties.VALUES.AllValues(
list_unset=args.all,
properties_file=properties_file.PropertiesFile([config.file_path]),
only_file_contents=True),
}

View File

@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*- #
# Copyright 2015 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 to list named configuration."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.core import properties
from googlecloudsdk.core.configurations import named_configs
from googlecloudsdk.core.configurations import properties_file
import six
class List(base.ListCommand):
"""Lists existing named configurations."""
detailed_help = {
'DESCRIPTION': """\
{description}
Run `$ gcloud topic configurations` for an overview of named
configurations.
""",
'EXAMPLES': """\
To list all available configurations, run:
$ {command}
""",
}
@staticmethod
def Args(parser):
base.PAGE_SIZE_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
configs = named_configs.ConfigurationStore.AllConfigs()
table_format = """table(
name,
is_active,
properties.core.account,
properties.core.project,
properties.compute.zone:label=COMPUTE_DEFAULT_ZONE,
properties.compute.region:label=COMPUTE_DEFAULT_REGION)
"""
for _, config in sorted(six.iteritems(configs)):
props = properties.VALUES.AllValues(
list_unset=True,
include_hidden=True,
properties_file=properties_file.PropertiesFile([config.file_path]),
)
config_universe = props['core'].get('universe_domain')
if (
config_universe
and config_universe != properties.VALUES.core.universe_domain.default
):
table_format = """table(
name,
is_active,
properties.core.account,
properties.core.project,
properties.core.universe_domain,
properties.compute.zone:label=COMPUTE_DEFAULT_ZONE,
properties.compute.region:label=COMPUTE_DEFAULT_REGION)
"""
break
parser.display_info.AddFormat(table_format)
def Run(self, args):
configs = named_configs.ConfigurationStore.AllConfigs()
for _, config in sorted(six.iteritems(configs)):
props = properties.VALUES.AllValues(
list_unset=True,
properties_file=properties_file.PropertiesFile([config.file_path]),
only_file_contents=True)
yield {
'name': config.name,
'is_active': config.is_active,
'properties': props,
}

View File

@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 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 to rename named configuration."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.config import completers
from googlecloudsdk.core import log
from googlecloudsdk.core.configurations import named_configs
class Rename(base.SilentCommand):
"""Renames a named configuration."""
detailed_help = {
'DESCRIPTION': """\
{description}
See `gcloud topic configurations` for an overview of named
configurations.
""",
'EXAMPLES': """\
To rename an existing configuration named `my-config`, run:
$ {command} my-config --new-name=new-config
""",
}
@staticmethod
def Args(parser):
"""Adds args for this command."""
parser.add_argument(
'configuration_name',
completer=completers.NamedConfigCompleter,
help='Name of the configuration to rename')
parser.add_argument(
'--new-name',
required=True,
help='Specifies the new name of the configuration.')
def Run(self, args):
named_configs.ConfigurationStore.RenameConfig(args.configuration_name,
args.new_name)
log.status.Print('Renamed [{0}] to be [{1}].'.format(
args.configuration_name, args.new_name))
return args.new_name