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,31 @@
# -*- 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 Artifact Registry packages."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
class Go(base.Group):
"""Manage Artifact Registry Go modules."""
category = base.CI_CD_CATEGORY

View File

@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 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.
"""Implements commands for the GOAUTH environment variable."""
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.artifacts import endpoint_util
from googlecloudsdk.command_lib.artifacts import go_util
from googlecloudsdk.core import log
@base.DefaultUniverseOnly
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Auth(base.Command):
"""Print authentication commands for the GOAUTH environment variable.
This command implements the GOAUTH credential provider command introduced in
Go 1.24. For more details about the GOAUTH environment variable, see
https://pkg.go.dev/cmd/go#hdr-GOAUTH_environment_variable. When you configure
the GOAUTH environment variable for repositories, Artifact Registry looks for
credentials in the following order:
* Application Default Credentials (ADC)
* Credentials provided by the Google Cloud CLI, including user credentials
from the command `gcloud auth application-default login`.
"""
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To configure the GOAUTH environment variable for repositories in `us-central1` and use your credentials:
$ export GOAUTH="{command} --location=us-central1"
To configure the GOAUTH environment variable for repositories in `us-central1` and use the credentials from a service account:
$ export GOAUTH="{command} --location=us-central1 --json-key=path/to/key.json"
""",
}
@staticmethod
def Args(parser):
"""Set up arguements for this command.
Args:
parser: An argparse.ArgumentPaser.
"""
# Go may or may not pass the URL to authenticate against, so we need
# to support an optional positional argument. This argument is currently
# unused.
parser.add_argument(
'url',
nargs='*',
help='A URL generated by Go to set up authentication.',
)
parser.add_argument(
'--location',
metavar='LOCATION',
required=True,
help='The location of the repository to print commands for.',
)
parser.add_argument(
'--json-key',
metavar='JSON_KEY',
help=(
'The path to the JSON key file to use for authentication. If not'
' specified, the authentication commands printed will use the token'
' from the logged in user.'
),
)
def Run(self, args):
"""Run the go goauth command."""
# TODO(b/399155579): Add support for regional endpoints.
url_line = endpoint_util.ArtifactRegistryDomainEndpoint(
args.location, 'go', rep=False, protocol='https'
)
header_line = go_util.AuthorizationHeader(args.json_key)
log.out.Print(url_line)
log.out.Print('')
log.out.Print(header_line)
log.out.Print('')

View File

@@ -0,0 +1,121 @@
# -*- 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.
"""Implements the command to upload Go modules to a repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import os
import tempfile
from apitools.base.py import transfer
from googlecloudsdk.api_lib.artifacts import exceptions
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.artifacts import flags
from googlecloudsdk.command_lib.artifacts import go_util
from googlecloudsdk.core import resources
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA,
base.ReleaseTrack.GA)
class Upload(base.Command):
"""Upload a Go module to an artifact repository."""
api_version = 'v1'
detailed_help = {
'DESCRIPTION':
'{description}',
'EXAMPLES':
"""\
To upload version v0.1.0 of a Go module located in /path/to/code/ to a repository in "us-central1":
$ {command} --location=us-central1 --project=myproject --repository=myrepo \
--module-path=the/module/path --version=v0.1.0 --source=/path/to/code
""",
}
@staticmethod
def Args(parser):
"""Set up arguements for this command.
Args:
parser: An argparse.ArgumentPaser.
"""
flags.GetRequiredRepoFlag().AddToParser(parser)
base.ASYNC_FLAG.AddToParser(parser)
parser.add_argument(
'--source',
metavar='SOURCE',
required=False,
default='.',
help='The root directory of the go module source code, '
'defaults to the current directory.')
parser.add_argument(
'--module-path',
metavar='MODULE_PATH',
required=True,
help='The module path of the Go module.')
parser.add_argument(
'--version',
metavar='VERSION',
required=True,
help='The version of the Go module.')
def Run(self, args):
"""Run the go module upload command."""
client = apis.GetClientInstance('artifactregistry', self.api_version)
client.additional_http_headers['X-Goog-Upload-Protocol'] = 'multipart'
messages = client.MESSAGES_MODULE
tempdir = tempfile.mkdtemp()
# Create the go.zip file.
zip_path = os.path.join(tempdir, 'go.zip')
pack = go_util.PackOperation()
pack_result = pack(
module_path=args.module_path,
version=args.version,
source=args.source,
output=zip_path)
if pack_result.exit_code:
raise exceptions.InvalidGoModuleError(
'failed to package the go module: ' + pack_result.stderr)
# Upload the go.zip.
repo_ref = args.CONCEPTS.repository.Parse()
request = messages.ArtifactregistryProjectsLocationsRepositoriesGoModulesUploadRequest(
uploadGoModuleRequest=messages.UploadGoModuleRequest(),
parent=repo_ref.RelativeName())
upload = transfer.Upload.FromFile(zip_path, mime_type='application/zip')
op_obj = client.projects_locations_repositories_goModules.Upload(
request, upload=upload)
op = op_obj.operation
op_ref = resources.REGISTRY.ParseRelativeName(
op.name, collection='artifactregistry.projects.locations.operations')
# Handle the operation.
if args.async_:
return op_ref
else:
result = waiter.WaitFor(
waiter.CloudOperationPollerNoResources(
client.projects_locations_operations), op_ref,
'Uploading package')
return result