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,32 @@
# -*- 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.
"""Cloud Storage HMAC commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.UniverseCompatible
class Hmac(base.Group):
"""Manage Cloud Storage service account HMAC keys."""
def Filter(self, context, args):
# TODO(b/190541521): Determine if command group works with project number
base.RequireProjectID(args)
del context, args

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.
"""Implementation of create command for HMAC."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.storage import api_factory
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import storage_url
@base.UniverseCompatible
class Create(base.Command):
"""Add a service account HMAC."""
detailed_help = {
'DESCRIPTION': """
*{command}* command creates an HMAC key for the specified service
account. The secret key material is only available upon creation, so be
sure to store the returned secret along with the access_id.
""",
'EXAMPLES': """
To create an HMAC key for
``test.service.account@test_project.iam.gserviceaccount.com'':
$ {command} test.service.account@test_project.iam.gserviceaccount.com
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'service_account', type=str, help='The service account email.')
def Run(self, args):
service_account = args.service_account
api = api_factory.get_api(storage_url.ProviderPrefix.GCS)
response = api.create_hmac_key(service_account)
return response.metadata

View File

@@ -0,0 +1,59 @@
# -*- 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.
"""Implementation of delete command for HMAC."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.storage import api_factory
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import storage_url
@base.UniverseCompatible
class Delete(base.Command):
"""Remove a service account HMAC."""
detailed_help = {
'DESCRIPTION': """
*{command}* permanently deletes the specified HMAC key. Note that keys
must be updated to be in the ``INACTIVE'' state before they can be
deleted.
""",
'EXAMPLES': """
To delete a specific HMAC key:
$ {command} GOOG56JBMFZX6PMPTQ62VD2
To be prompted for HMAC keys to delete:
$ {command}
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'access_id',
help=textwrap.dedent("""\
Access ID for HMAC key to delete."""))
def Run(self, args):
api = api_factory.get_api(storage_url.ProviderPrefix.GCS)
response = api.delete_hmac_key(args.access_id)
return response

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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.
"""Implementation of describe command for HMAC key."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.storage import api_factory
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import storage_url
@base.UniverseCompatible
class Describe(base.DescribeCommand):
"""Describes a service account HMAC key."""
detailed_help = {
'DESCRIPTION': """
*{command}* retrieves the specified HMAC key's metadata. Note that there
is no option to retrieve a key's secret material after it has
been created.
""",
'EXAMPLES': """
The following command retrieves the HMAC key's metadata:
$ {command} GOOG56JBMFZX6PMPTQ62VD2
Note `GOOG56JBMFZX6PMPTQ62VD2` is the `ACCESS_ID` of the HMAC key.
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'access_id',
type=str,
help=(
'The [Access ID](https://cloud.google.com/'
'storage/docs/authentication/hmackeys#overview) of the HMAC key'
),
)
def Run(self, args):
hmac_resource = api_factory.get_api(
storage_url.ProviderPrefix.GCS
).get_hmac_key(args.access_id)
return hmac_resource.metadata

View File

@@ -0,0 +1,80 @@
# -*- 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.
"""Implementation of list command for HMAC."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.storage import api_factory
from googlecloudsdk.api_lib.storage import cloud_api
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import storage_url
@base.UniverseCompatible
class List(base.ListCommand):
"""List service account HMAC keys."""
detailed_help = {
'DESCRIPTION': """
*{command}* lists the HMAC key metadata for keys in the current project.
""",
'EXAMPLES': """
To show metadata for all keys, including recently deleted keys:
$ {command} --all --long
To list only HMAC keys belonging to the service account
``test.sa@test.iam.gserviceaccount.com'':
$ {command} --service-account=test.sa@test.iam.gserviceaccount.com
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'-a',
'--all',
action='store_true',
help='Shows all keys, including recently deleted keys.')
parser.add_argument(
'-l',
'--long',
action='store_true',
help=textwrap.dedent("""\
Use long listing format, showing the full metadata for each key
excluding the secret."""))
parser.add_argument(
'-u',
'--service-account',
help='Filter keys for the provided service account email.')
def Run(self, args):
if args.long:
fields_scope = cloud_api.FieldsScope.FULL
else:
fields_scope = cloud_api.FieldsScope.SHORT
api = api_factory.get_api(storage_url.ProviderPrefix.GCS)
for hmac_key in api.list_hmac_keys(
service_account_email=args.service_account,
show_deleted_keys=args.all,
fields_scope=fields_scope
):
yield hmac_key.metadata

View File

@@ -0,0 +1,81 @@
# -*- 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.
"""Implementation of update command for HMAC."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import textwrap
from googlecloudsdk.api_lib.storage import api_factory
from googlecloudsdk.api_lib.storage import cloud_api
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.storage import storage_url
@base.UniverseCompatible
class Update(base.Command):
"""Change the status of a service account HMAC."""
detailed_help = {
'DESCRIPTION': """
*{command}* sets the state of the specified key. Valid state arguments
are ``ACTIVE'' and ``INACTIVE''. To set a key to state ``DELETED'', use
*{parent_command} delete* on an ``INACTIVE'' key. If an etag is set in
the command, it will only succeed if the provided etag matches the etag
of the stored key.
""",
'EXAMPLES': """
To activate an HMAC key:
$ {command} GOOG56JBMFZX6PMPTQ62VD2 --activate
To set the state of an HMAC key to ``INACTIVE'' provided its etag is
``M42da='':
$ {command} GOOG56JBMFZX6PMPTQ62VD2 --deactivate --etag=M42da=
""",
}
@staticmethod
def Args(parser):
parser.add_argument('access_id', help='Access ID for HMAC key to update.')
parser.add_argument(
'-e',
'--etag',
help=textwrap.dedent("""\
If provided, the update will only be performed if the specified etag
matches the etag of the stored key."""))
state_group = parser.add_mutually_exclusive_group(required=True)
state_group.add_argument(
'--activate',
action='store_true',
help='Sets the state of the specified key to ``ACTIVE\'\'.')
state_group.add_argument(
'--deactivate',
action='store_true',
help='Sets the state of the specified key to ``INACTIVE\'\'.')
def Run(self, args):
api = api_factory.get_api(storage_url.ProviderPrefix.GCS)
access_id = args.access_id
etag = args.etag
if args.activate:
state = cloud_api.HmacKeyState.ACTIVE
elif args.deactivate:
state = cloud_api.HmacKeyState.INACTIVE
response = api.patch_hmac_key(access_id, etag, state)
return response.metadata