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,30 @@
# -*- 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 group for Identity Service Feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base as calliope_base
@calliope_base.ReleaseTracks(calliope_base.ReleaseTrack.ALPHA,
calliope_base.ReleaseTrack.BETA,
calliope_base.ReleaseTrack.GA)
class Identityservice(calliope_base.Group):
"""Manage Identity Service Feature."""
category = calliope_base.COMPUTE_CATEGORY

View File

@@ -0,0 +1,159 @@
# -*- 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.
"""The command to update Identity Service Feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.anthos.common import file_parsers
from googlecloudsdk.command_lib.container.fleet import resources
from googlecloudsdk.command_lib.container.fleet.features import base
from googlecloudsdk.command_lib.container.fleet.identity_service import utils
from googlecloudsdk.core import exceptions
from googlecloudsdk.core.util import retry
# Pull out the example text so the example command can be one line without the
# py linter complaining. The docgen tool properly breaks it into multiple lines.
EXAMPLES = """\
To apply an Identity Service configuration to a membership, run:
$ {command} --membership=MEMBERSHIP_NAME --config=/path/to/identity-service.yaml
To create or modify a fleet-level default membership configuration, run:
$ {command} --fleet-default-member-config=/path/to/identity-service.yaml
To apply an existing fleet-level default membership configuration to a membership, run:
$ {command} --origin=fleet --membership=MEMBERSHIP_NAME
"""
class Apply(base.UpdateCommand):
"""Update the Identity Service Feature.
This command updates the Identity Service Feature in a fleet.
"""
detailed_help = {'EXAMPLES': EXAMPLES}
feature_name = 'identityservice'
@classmethod
def Args(cls, parser):
command_args = parser.add_group(required=True, mutex=False)
command_args.add_argument(
'--fleet-default-member-config',
type=str,
help='The path to an identity-service.yaml configuration file.',
required=False,
)
per_member_config_args = command_args.add_group(required=False, mutex=False)
resources.AddMembershipResourceArg(per_member_config_args)
per_member_config_source = per_member_config_args.add_group(
mutex=True, required=True
)
per_member_config_source.add_argument(
'--config',
type=str,
help='The path to an identity-service.yaml configuration file.',
)
per_member_config_source.add_argument(
'--origin',
choices=['fleet'],
type=str,
help=(
'Applies the fleet-level default membership configuration to a'
' membership.'
),
)
def Run(self, args):
patch = self.messages.Feature()
update_mask = []
if args.config or args.origin:
self.preparePerMemberConfigPatch(args, patch, update_mask)
if args.fleet_default_member_config:
self.prepareFleetDefaultMemberConfigPatch(args, patch, update_mask)
try:
max_wait_ms = 60000 # 60 secs
retryer = retry.Retryer(
max_wait_ms=max_wait_ms, exponential_sleep_multiplier=1.1
)
retryer.RetryOnException(
self.Update, args=(update_mask, patch), sleep_ms=1000
)
except retry.MaxRetrialsException:
raise exceptions.Error(
'Retry limit exceeded while waiting for the {} feature to update'
.format(self.feature.display_name)
)
def prepareFleetDefaultMemberConfigPatch(self, args, patch, update_mask):
# Load the config YAML file.
loaded_config = file_parsers.YamlConfigFile(
file_path=args.fleet_default_member_config,
item_type=file_parsers.LoginConfigObject,
)
# Create a new identity service feature spec.
member_config = utils.parse_config(loaded_config, self.messages)
# Add the fleet default member config to the feature patch and update
# `update mask`.
patch.fleetDefaultMemberConfig = (
self.messages.CommonFleetDefaultMemberConfigSpec(
identityservice=member_config
)
)
update_mask.append('fleet_default_member_config')
def preparePerMemberConfigPatch(self, args, patch, update_mask):
# Get the membership the user is attempting to apply the configuration to.
# If no membership is specified, and there is a single membership available
# in the fleet, it would be automatically selected.
# If no membership is specified, and there are multiple memberships
# available in the fleet, the user would be prompted to select
# one from the ones available in the fleet.
membership = base.ParseMembership(
args, prompt=True, autoselect=True, search=True
)
membership_spec = self.messages.MembershipFeatureSpec()
if args.origin:
membership_spec.origin = self.messages.Origin(
type=self.messages.Origin.TypeValueValuesEnum('FLEET')
)
else:
# Load the config YAML file.
loaded_config = file_parsers.YamlConfigFile(
file_path=args.config, item_type=file_parsers.LoginConfigObject
)
# Create a new identity service feature spec.
member_config = utils.parse_config(loaded_config, self.messages)
membership_spec.identityservice = member_config
# Add the newly prepared membershipSpec to the feature patch and update
# `update mask`.
patch.membershipSpecs = self.hubclient.ToMembershipSpecs(
{membership: membership_spec}
)
update_mask.append('membership_specs')

View File

@@ -0,0 +1,86 @@
# -*- 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.
"""The command to update Config Management Feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.container.fleet import resources
from googlecloudsdk.command_lib.container.fleet.features import base
class Delete(base.UpdateCommand):
"""Delete a resource from the Identity Service Feature.
Deletes a resource from the Identity Service Feature.
## EXAMPLES
To delete the Identity Service configuration from a membership, run:
$ {command} --membership=MEMBERSHIP_NAME
To delete the fleet-level default membership configuration, run:
$ {command} --fleet-default-member-config
"""
feature_name = 'identityservice'
@classmethod
def Args(cls, parser):
resources.AddMembershipResourceArg(
parser, membership_help='Membership name provided during registration.')
parser.add_argument(
'--fleet-default-member-config',
action='store_true',
help="""If specified, deletes the default membership
configuration present in your fleet.
To delete the default membership configuration present in your
fleet, run:
$ {command} --fleet-default-member-config""",
)
def Run(self, args):
update_mask = []
patch = self.messages.Feature()
if args.fleet_default_member_config:
update_mask.append('fleet_default_member_config')
if not args.membership:
# TODO: b/307330225) - Figure out a way to get rid of this.
# This is currently necessary because the Hub CLH doesn't currently
# allow updates with an empty FeatureSpec object. `spec` isn't actually
# going to get updated as it isn't present in the update mask.
patch.spec = self.messages.CommonFeatureSpec()
self.Update(update_mask, patch)
return
self.preparePerMemberConfigDeletion(args, update_mask, patch)
self.Update(update_mask, patch)
def preparePerMemberConfigDeletion(self, args, mask, patch):
# Get the membership the user is trying to delete a config from.
membership = base.ParseMembership(
args, prompt=True, autoselect=True, search=True)
patch.membershipSpecs = self.hubclient.ToMembershipSpecs(
{membership: self.messages.MembershipFeatureSpec()}
)
mask.append('membership_specs')

View File

@@ -0,0 +1,84 @@
# -*- 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.
"""The command to describe the status of the Identity Service Feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import operator
from googlecloudsdk.api_lib.container.fleet import client
from googlecloudsdk.calliope import base as calliope_base
from googlecloudsdk.command_lib.container.fleet.features import base
from googlecloudsdk.core.util import times
class Describe(base.FeatureCommand, calliope_base.ListCommand):
"""Prints the status of all clusters with Identity Service installed.
Prints the status of the Identity Service Feature resource in a fleet.
## EXAMPLES
To describe the status of the Identity Service configuration, run:
$ {command}
"""
feature_name = 'identityservice'
@classmethod
def Args(cls, parser):
pass
def Run(self, args):
feature = self.GetFeature()
specs = client.HubClient.ToPyDict(feature.membershipSpecs)
for _, spec in specs.items():
self.FormatSessionDuration(spec, 'identityservice.identityServiceOptions')
feature.membershipSpecs = self.hubclient.ToMembershipSpecs(specs)
states = client.HubClient.ToPyDict(feature.membershipStates)
for _, state in states.items():
self.FormatSessionDuration(
state, 'identityservice.memberConfig.identityServiceOptions'
)
feature.membershipStates = self.hubclient.ToProtoMap(
self.messages.Feature.MembershipStatesValue, states
)
default_config = feature.fleetDefaultMemberConfig
self.FormatSessionDuration(
default_config, 'identityservice.identityServiceOptions'
)
return {'Identity Service Feature': feature}
def FormatSessionDuration(self, config, path):
try:
identity_service_options = operator.attrgetter(path)(config)
if identity_service_options.sessionDuration is not None:
session_duration_secs = times.ParseDuration(
identity_service_options.sessionDuration, default_suffix='s'
).total_seconds
session_duration_mins = int(session_duration_secs/60)
identity_service_options.sessionDuration = (
str(session_duration_mins) + ' mins'
)
except AttributeError:
pass

View File

@@ -0,0 +1,36 @@
# -*- 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.
"""The command to disable the Identity Service Feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.container.fleet.features import base
class Disable(base.DisableCommand):
"""Disable Identity Service Feature.
This command disables the Identity Service Feature in a fleet.
## EXAMPLES
To disable the Identity Service Feature, run:
$ {command}
"""
feature_name = 'identityservice'

View File

@@ -0,0 +1,82 @@
# -*- 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.
"""The command to enable Identity Service Feature."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.command_lib.anthos.common import file_parsers
from googlecloudsdk.command_lib.container.fleet.features import base
from googlecloudsdk.command_lib.container.fleet.identity_service import utils
# Pull out the example text so the example command can be one line without the
# py linter complaining. The docgen tool properly breaks it into multiple lines.
EXAMPLES = """\
To enable the Identity Service Feature, run:
$ {command}
To enable the Identity Service Feature with a fleet-level default membership configuration, run:
$ {command} --fleet-default-member-config=/path/to/identity-service.yaml
"""
class Enable(base.EnableCommand):
"""Enable the Identity Service Feature.
This command enables the Identity Service Feature in a fleet.
"""
detailed_help = {'EXAMPLES': EXAMPLES}
feature_name = 'identityservice'
@classmethod
def Args(cls, parser):
parser.add_argument(
'--fleet-default-member-config',
type=str,
help="""The path to an identity-service.yaml identity configuration
file. If specified, this configuration would be the default Identity
Service configuration for all memberships in your fleet. It could be
overridden with a membership-specific configuration by using the
the `Apply` command with the `--config` argument.
To enable the Identity Service Feature with a fleet-level default
membership configuration, run:
$ {command} --fleet-default-member-config=/path/to/identity-service.yaml""",
)
def Run(self, args):
if not args.fleet_default_member_config:
return self.Enable(self.messages.Feature())
# Load config YAML file.
loaded_config = file_parsers.YamlConfigFile(
file_path=args.fleet_default_member_config,
item_type=file_parsers.LoginConfigObject)
# Create new identity service feature spec.
member_config = utils.parse_config(loaded_config, self.messages)
# Create a feature object that has a default fleet identity service config
feature = self.messages.Feature(
fleetDefaultMemberConfig=self.messages
.CommonFleetDefaultMemberConfigSpec(identityservice=member_config))
return self.Enable(feature)