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,49 @@
# -*- 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.
"""The main command group for cloud source command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
@base.DefaultUniverseOnly
class Source(base.Group):
"""Cloud git repository commands.
The {command} group lets you manipulate git repositories within a Google
Cloud project.
"""
category = base.SDK_TOOLS_CATEGORY
def Filter(self, context, args):
"""Initialize context for source commands.
Args:
context: The current context.
args: The argparse namespace that was specified on the CLI or API.
Returns:
The updated context.
"""
# gcloud source only accepts project ID, not number.
base.RequireProjectID(args)
base.DisableUserProjectQuota()

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""gcloud source project-configs command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA, base.ReleaseTrack.GA
)
@base.DefaultUniverseOnly
class ProjectConfigs(base.Group):
"""Manage Cloud Source Repositories configuration of a project."""

View File

@@ -0,0 +1,16 @@
- help_text:
brief: Show details about the configuration of a project.
description: Show details about the configuration of a project.
examples: |
To show the current configuration of the current project run:
$ {command}
request:
collection: sourcerepo.projects
method: getConfig
arguments:
resource:
help_text: The project.
spec: !REF googlecloudsdk.command_lib.source.resources:project

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""`gcloud source project-configs update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.source import project_configs
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.source import flags
from googlecloudsdk.command_lib.source import util
@base.DefaultUniverseOnly
class Update(base.Command):
r"""Update the Cloud Source Repositories configuration of the current project.
## EXAMPLES
To enable PushBlock for all repositories under current project, run:
$ {command} --enable-pushblock
To associate a Cloud Pub/Sub topic to receive repository update notifications,
run:
$ {command} --add-topic=TOPIC_NAME --service-account=SERVICE_ACCOUNT_EMAIL \
--message-format=json
"""
_ENABLE_KEY_UPDATE_MASK = 'enablePrivateKeyCheck'
_PUBSUB_CONFIGS_UPDATE_MASK = 'pubsubConfigs'
@staticmethod
def Args(parser):
flags.AddProjectConfigUpdateArgs(parser)
def Run(self, args):
client = project_configs.ProjectConfig()
if args.enable_pushblock or args.disable_pushblock:
updated_project_config = util.ParseProjectConfigWithPushblock(args)
return client.Update(updated_project_config, self._ENABLE_KEY_UPDATE_MASK)
project_ref = util.CreateProjectResource(args)
project_config = client.Get(project_ref)
updated_project_config = util.ParseProjectConfigWithModifiedTopic(
args, project_config)
return client.Update(updated_project_config,
self._PUBSUB_CONFIGS_UPDATE_MASK)

View File

@@ -0,0 +1,26 @@
# -*- 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.
"""gcloud source repos command group."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.DefaultUniverseOnly
class Repos(base.Group):
"""Manage cloud source repositories."""

View File

@@ -0,0 +1,166 @@
# -*- 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.
"""Clone Google Cloud Platform git repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.source import git
from googlecloudsdk.api_lib.source import sourcerepo
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions as c_exc
from googlecloudsdk.core import log
from googlecloudsdk.core.credentials import store as c_store
@base.ReleaseTracks(base.ReleaseTrack.GA)
@base.DefaultUniverseOnly
class CloneGA(base.Command):
"""Clone a cloud source repository."""
detailed_help = {
'DESCRIPTION': """\
This command clones a git repository from the currently active
Google Cloud project into the specified directory or into the current
directory if no target directory is specified.
Each Google Cloud project can have zero or more git repositories
associated with it. To see the available repositories, run:
$ {parent_command} list
The clone operation configures the local clone to use your gcloud
credentials to authenticate future git operations. This command emits a
warning if the cloud source repository is a mirror.
""",
'EXAMPLES': """\
The example commands below show a sample workflow.
$ gcloud init
$ {command} REPOSITORY_NAME DIRECTORY_NAME
$ cd DIRECTORY_NAME
... create/edit files and create one or more commits ...
$ git push origin main
""",
}
@staticmethod
def Args(parser):
parser.add_argument(
'--dry-run',
action='store_true',
help=('If provided, prints the command that would be run to standard '
'out instead of executing it.'))
parser.add_argument(
'src', metavar='REPOSITORY_NAME', help='Name of the repository.')
parser.add_argument(
'dst',
metavar='DIRECTORY_NAME',
nargs='?',
help=('Directory name for the cloned repo. Defaults to the repository '
'name.'))
def UseFullGcloudPath(self, args):
"""Always false because --use-full-gcloud-path argument is not in GA."""
return False
def ActionIfMirror(self, project, repo, mirror_url):
"""Prints a warning if the repository is a mirror."""
message = ('Repository "{repo}" in project "{prj}" is a mirror. Pushing to '
'this clone will have no effect. Instead, clone the '
'mirrored repository directly with \n$ git clone '
'{url}'.format(repo=repo, prj=project, url=mirror_url))
log.warning(message)
def Run(self, args):
"""Clone a GCP repository to the current directory.
Args:
args: argparse.Namespace, the arguments this command is run with.
Returns:
The path to the new git repository.
"""
# Ensure that we're logged in.
c_store.Load(use_google_auth=True)
res = sourcerepo.ParseRepo(args.src)
source_handler = sourcerepo.Source()
repo = source_handler.GetRepo(res)
if hasattr(repo, 'mirrorConfig') and repo.mirrorConfig:
mirror_url = repo.mirrorConfig.url
self.ActionIfMirror(
project=res.projectsId, repo=args.src, mirror_url=mirror_url)
# do the actual clone
git_helper = git.Git(res.projectsId, args.src, uri=repo.url)
path = git_helper.Clone(
destination_path=args.dst or args.src,
dry_run=args.dry_run,
full_path=self.UseFullGcloudPath(args))
if path and not args.dry_run:
log.status.write('Project [{prj}] repository [{repo}] was cloned '
'to [{path}].\n'.format(
prj=res.projectsId, path=path, repo=args.src))
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class CloneAlpha(CloneGA):
"""Clone a cloud source repository.
This command clones a git repository for the currently active
Google Cloud Platform project into the specified directory or into
the current directory if no target directory is specified. This command
gives an error if the cloud source repository is a mirror.
The clone operation configures the local clone to use your gcloud
credentials to authenticate future git operations.
## EXAMPLES
The example commands below show a sample workflow.
$ gcloud init
$ {command} REPOSITORY_NAME DIRECTORY_NAME
$ cd DIRECTORY_NAME
... create/edit files and create one or more commits ...
$ git push origin main
"""
@staticmethod
def Args(parser):
CloneGA.Args(parser)
parser.add_argument(
'--use-full-gcloud-path',
action='store_true',
help=
('If provided, use the full gcloud path for the git credential.helper. '
'Using the full path means that gcloud does not need to be in '
'the path for future git operations on the repository.'))
def UseFullGcloudPath(self, args):
"""Use value of --use-full-gcloud-path argument in beta and alpha."""
return args.use_full_gcloud_path
def ActionIfMirror(self, project, repo, mirror_url):
"""Raises an exception if the repository is a mirror."""
message = ('Repository "{repo}" in project "{prj}" is a mirror. Clone the '
'mirrored repository directly with \n$ git clone '
'{url}'.format(repo=repo, prj=project, url=mirror_url))
raise c_exc.InvalidArgumentException('REPOSITORY_NAME', message)

View File

@@ -0,0 +1,27 @@
# -*- 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.
"""Command group for managing Cloud Source repo configurations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.DefaultUniverseOnly
class Config(base.Group):
"""Manage Cloud Source repo configurations."""

View File

@@ -0,0 +1,38 @@
release_tracks: [ALPHA]
command_type: CONFIG_EXPORT
help_text:
brief: Export the configuration for a Cloud Source repo.
description: |
*{command}* exports the configuration for a Cloud Source repo.
Repo configurations can be exported in
Kubernetes Resource Model (krm) or Terraform HCL formats. The
default format is `krm`.
Specifying `--all` allows you to export the configurations for all
repos within the project.
Specifying `--path` allows you to export the configuration(s) to
a local directory.
examples: |
To export the configuration for a repo, run:
$ {command} my-repo
To export the configuration for a repo to a file, run:
$ {command} my-repo --path=/path/to/dir/
To export the configuration for a repo in Terraform
HCL format, run:
$ {command} my-repo --resource-format=terraform
To export the configurations for all repos within a
project, run:
$ {command} --all
arguments:
resource:
help_text: Repo to export the configuration for.
spec: !REF googlecloudsdk.command_lib.source.resources:repo

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.
"""Create a Google Cloud Platform git repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import exceptions
from googlecloudsdk.api_lib.source import sourcerepo
from googlecloudsdk.calliope import base
from googlecloudsdk.calliope import exceptions as c_exc
from googlecloudsdk.command_lib.source import flags
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
from six import text_type
_ERROR_FORMAT = ('ResponseError: status=[{status_description}], '
'code=[{status_code}], message=[{message}]. '
'{details.message?\ndetails:\n{?}}')
_LINK_FORMAT = ('\nenable at: '
'https://console.cloud.google.com/apis/library/'
'sourcerepo.googleapis.com/?project={project}')
_BILLING_URL = 'https://cloud.google.com/source-repositories/docs/pricing'
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA
)
@base.DefaultUniverseOnly
class Create(base.CreateCommand):
"""Create a cloud source repository.
This command creates a named git repository for the currently
active Google Cloud Platform project.
## EXAMPLES
To create a named repository in the current project issue the
following commands:
$ gcloud init
$ {command} REPOSITORY_NAME
Once you push contents to it, they can be browsed in the
Developers Console.
"""
@staticmethod
def Args(parser):
parser.add_argument(
'repository_name',
help="""\
Name of the repository. May contain between 3 and 63 (inclusive)
lowercase letters, digits, and hyphens. Must start with a letter, and
may not end with a hyphen.
""")
def Run(self, args):
"""Create a GCP repository to the current directory.
Args:
args: argparse.Namespace, the arguments this command is run with.
Returns:
(sourcerepo_v1_messages.Repo) The created respository.
Raises:
sourcerepo.RepoResourceError: on resource initialization errors.
c_exc.HttpException: on missing billing account, and when the repo name is
already in use.
"""
res = sourcerepo.ParseRepo(args.repository_name)
# check that the name does not have forbidden characters.
# we'd like to do this by putting the validator in the flag type, but
# we cannot for now because it needs to work on the parsed name.
flags.REPO_NAME_VALIDATOR(res.Name())
source_handler = sourcerepo.Source()
try:
repo = source_handler.CreateRepo(res)
if repo:
log.CreatedResource(res.Name())
log.warning('You may be billed for this repository. '
'See {url} for details.'.format(url=_BILLING_URL))
return repo
except exceptions.HttpError as error:
exc = c_exc.HttpException(error)
exc.error_format = _ERROR_FORMAT
if 'API is not enabled' in text_type(exc):
link = _LINK_FORMAT.format(
project=properties.VALUES.core.project.GetOrFail())
exc.error_format += link
raise exc

View File

@@ -0,0 +1,87 @@
# -*- 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.
"""Delete Google Cloud Platform git repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.source import sourcerepo
from googlecloudsdk.calliope import actions
from googlecloudsdk.calliope import base
from googlecloudsdk.core import log
from googlecloudsdk.core.console import console_io
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA
)
@base.DefaultUniverseOnly
class Delete(base.DeleteCommand):
"""Delete a cloud source repository.
This command deletes a named git repository from the currently
active Google Cloud Platform project.
## EXAMPLES
To delete a named repository in the current project issue the
following commands:
$ gcloud init
$ {command} REPOSITORY_NAME
"""
@staticmethod
def Args(parser):
parser.add_argument('repository_name', help='Name of the repository.')
parser.add_argument(
'--force',
action=actions.DeprecationAction(
'--force',
error=('The {flag_name} option has been removed; use --quiet '
'to suppress prompting.'),
removed=True,
action='store_true'),
help='If provided, skip the delete confirmation prompt.')
def Run(self, args):
"""Delete a named GCP repository in the current project.
Args:
args: argparse.Namespace, the arguments this command is run with.
Returns:
The path to the deleted git repository.
Raises:
sourcerepo.RepoResourceError: on resource initialization errors.
apitools.base.py.exceptions.HttpError: on request errors.
"""
res = sourcerepo.ParseRepo(args.repository_name)
delete_warning = ('If {repo} is deleted, the name cannot be reused for up '
'to seven days.'.format(repo=res.Name()))
prompt_string = ('Delete "{repo}" in project "{prj}"'.format(
repo=res.Name(), prj=res.projectsId))
if console_io.PromptContinue(
message=delete_warning, prompt_string=prompt_string, default=True):
sourcerepo_handler = sourcerepo.Source()
# This returns an empty proto buffer as a response, so there's
# nothing to return.
sourcerepo_handler.DeleteRepo(res)
log.DeletedResource(res.Name())
return res.Name()

View File

@@ -0,0 +1,65 @@
# -*- 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.
"""Describe Google Cloud Platform git repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.source import sourcerepo
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA
)
@base.DefaultUniverseOnly
class Describe(base.DescribeCommand):
"""Describe a cloud source repository.
This command describes a repository from the currently
active Google Cloud Platform project. The description includes the
full repository name (projects/<projectid>/repos/<reponame>), the size
(if non-zero), and the url.
## EXAMPLES
To describe a repository named example-repo in the current project
issue the following command:
$ {command} REPOSITORY_NAME
"""
@staticmethod
def Args(parser):
parser.add_argument('repository_name', help='Name of the repository.')
def Run(self, args):
"""Describe a named GCP repository in the current project.
Args:
args: argparse.Namespace, the arguments this command is run with.
Returns:
(sourcerepo_v1_messages.Repo) The named repository.
Raises:
sourcerepo.RepoResourceError: on resource initialization errors.
apitools.base.py.exceptions.HttpError: on request errors.
"""
res = sourcerepo.ParseRepo(args.repository_name)
sourcerepo_handler = sourcerepo.Source()
return sourcerepo_handler.GetRepo(res)

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Gets the IAM policy for the repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.source import sourcerepo
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA
)
@base.DefaultUniverseOnly
class GetIamPolicy(base.ListCommand):
"""Get the IAM policy for the named cloud source repository.
This command gets the IAM policy for the given repository.
## EXAMPLES
To get the IAM policy, issue the following command:
$ {command} REPOSITORY_NAME
"""
@staticmethod
def Args(parser):
parser.add_argument('repository_name', help='Name of the repository.')
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
"""Gets the IAM policy for the repository.
Args:
args: argparse.Namespace, the arguments this command is run with.
Returns:
(sourcerepo_v1_messages.Policy) The IAM policy.
Raises:
sourcerepo.RepoResourceError: on resource initialization errors.
apitools.base.py.exceptions.HttpError: on request errors.
"""
res = sourcerepo.ParseRepo(args.repository_name)
source = sourcerepo.Source()
return source.GetIamPolicy(res)

View File

@@ -0,0 +1,66 @@
# -*- 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.
"""List project repositories."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.source import sourcerepo
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA
)
@base.DefaultUniverseOnly
class List(base.ListCommand):
"""List the repositories the currently active project.
By default, repos in the current project are listed; this can be overridden
with the gcloud --project flag. The repository size is not returned, but
can be retrieved for a particular repository with the describe command.
## EXAMPLES
To list all repositories in the current project, run:
$ {command}
"""
@staticmethod
def Args(parser):
base.URI_FLAG.RemoveFromParser(parser)
# Here's some sample output (with the URL cut short)
# REPO_NAME PROJECT_ID URL
# ANewRepo kris-csr-test https://...
#
# The resource name looks like projects/<projectid>/repos/reponame
# We extract the project name as segment 1 and the repo name as segment 3
# and up.
parser.display_info.AddFormat("""
table(
name.split(/).slice(3:).join(/):label=REPO_NAME,
name.segment(1):label=PROJECT_ID,
firstof(mirror_config.url, url):label=URL
)
""")
def Run(self, args):
"""Run the list command."""
res = sourcerepo.GetDefaultProject()
source_handler = sourcerepo.Source()
return source_handler.ListRepos(
res, limit=args.limit, page_size=args.page_size)

View File

@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 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.
"""Sets the IAM policy for the repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.source import sourcerepo
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA
)
@base.DefaultUniverseOnly
class SetIamPolicy(base.UpdateCommand):
"""Set the IAM policy for the named repository.
This command sets the IAM policy for the given repository from the
policy in the provided file.
## EXAMPLES
To set the IAM policy, issue the following command:
$ {command} REPOSITORY_NAME POLICY_FILE
"""
@staticmethod
def Args(parser):
parser.add_argument(
'name', metavar='REPOSITORY_NAME', help='Name of the repository.')
parser.add_argument(
'policy_file',
help=('JSON or YAML file with IAM policy. '
'See https://cloud.google.com/resource-manager/'
'reference/rest/Shared.Types/Policy'))
parser.display_info.AddFormat('default')
def Run(self, args):
"""Sets the IAM policy for the repository.
Args:
args: argparse.Namespace, the arguments this command is run with.
Returns:
(sourcerepo_v1_messsages.Policy) The IAM policy.
Raises:
sourcerepo.RepoResourceError: on resource initialization errors.
iam_util.BadFileException: if the YAML or JSON file is malformed.
iam_util.IamEtagReadError: if the etag is badly formatted.
apitools.base.py.exceptions.HttpError: on request errors.
"""
res = sourcerepo.ParseRepo(args.name)
source = sourcerepo.Source()
policy, unused_mask = iam_util.ParseYamlOrJsonPolicyFile(
args.policy_file, source.messages.Policy)
result = source.SetIamPolicy(res, policy)
iam_util.LogSetIamPolicy(res.Name(), 'repo')
return result

View File

@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*- #
# Copyright 2018 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.
"""`gcloud source repos update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.source import sourcerepo
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.source import flags
from googlecloudsdk.command_lib.source import util
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA
)
@base.DefaultUniverseOnly
class Update(base.Command):
r"""Update the configuration of a Cloud Source Repository.
## EXAMPLES
To associate a Cloud Pub/Sub topic to receive repository update notifications,
run:
$ {command} REPO_NAME \
--add-topic=TOPIC_NAME \
--service-account=SERVICE_ACCOUNT_EMAIL \
--message-format=json
"""
@staticmethod
def Args(parser):
flags.AddRepoUpdateArgs(parser)
def Run(self, args):
client = sourcerepo.Source()
repo_ref = args.CONCEPTS.repo.Parse()
repo = client.GetRepo(repo_ref)
updated_repo = util.ParseSourceRepoWithModifiedTopic(args, repo)
return client.PatchRepo(updated_repo, 'pubsubConfigs')