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 2020 Google Inc. 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 Service Directory."""
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)
class ServiceDirectory(base.Group):
"""Command groups for Service Directory."""
category = base.NETWORKING_CATEGORY
def Filter(self, context, args):
del context, args

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 endpoints command group for Service Directory CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Endpoints(base.Group):
"""Manage Service Directory endpoints."""

View File

@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory endpoints create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import endpoints
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import flags
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.command_lib.service_directory import util
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'endpoint'
_ENDPOINT_LIMIT = 512
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Creates an endpoint."""
detailed_help = {
'EXAMPLES':
"""\
To create a Service Directory endpoint, run:
$ {command} my-endpoint --service=my-service --namespace=my-namespace --location=us-east1 --address=1.2.3.4 --port=5 --annotations=a=b,c=d --network=projects/123456789/locations/global/networks/default
""",
}
@staticmethod
def Args(parser):
resource_args.AddEndpointResourceArg(
parser,
"""to create. The endpoint id must be 1-63 characters long and match
the regular expression `[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?` which means
the first character must be a lowercase letter, and all following
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.""")
flags.AddAddressFlag(parser)
flags.AddPortFlag(parser)
flags.AddAnnotationsFlag(parser, _RESOURCE_TYPE, _ENDPOINT_LIMIT)
flags.AddNetworkFlag(parser)
def Run(self, args):
client = endpoints.EndpointsClient()
endpoint_ref = args.CONCEPTS.endpoint.Parse()
annotations = util.ParseAnnotationsArg(args.annotations, _RESOURCE_TYPE)
result = client.Create(endpoint_ref, args.address, args.port, annotations,
args.network)
log.CreatedResource(endpoint_ref.endpointsId, _RESOURCE_TYPE)
return result
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class CreateBeta(base.CreateCommand):
"""Creates an endpoint."""
detailed_help = {
'EXAMPLES':
"""\
To create a Service Directory endpoint, run:
$ {command} my-endpoint --service=my-service --namespace=my-namespace --location=us-east1 --address=1.2.3.4 --port=5 --metadata=a=b,c=d --network=projects/123456789/locations/global/networks/default
""",
}
@staticmethod
def Args(parser):
resource_args.AddEndpointResourceArg(
parser,
"""to create. The endpoint id must be 1-63 characters long and match
the regular expression `[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?` which means
the first character must be a lowercase letter, and all following
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.""")
flags.AddAddressFlag(parser)
flags.AddPortFlag(parser)
flags.AddMetadataFlag(parser, _RESOURCE_TYPE, _ENDPOINT_LIMIT)
flags.AddNetworkFlag(parser)
def Run(self, args):
client = endpoints.EndpointsClientBeta()
endpoint_ref = args.CONCEPTS.endpoint.Parse()
metadata = util.ParseMetadataArg(args.metadata, _RESOURCE_TYPE)
result = client.Create(endpoint_ref, args.address, args.port, metadata,
args.network)
log.CreatedResource(endpoint_ref.endpointsId, _RESOURCE_TYPE)
return result

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory endpoints delete` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import endpoints
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'endpoint'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Deletes an endpoint."""
detailed_help = {
'EXAMPLES':
"""\
To delete a Service Directory endpoint, run:
$ {command} my-endpoint --service=my-service --namespace=my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddEndpointResourceArg(parser, 'to delete.')
def Run(self, args):
client = endpoints.EndpointsClient(self.GetReleaseTrack())
endpoint_ref = args.CONCEPTS.endpoint.Parse()
result = client.Delete(endpoint_ref)
log.DeletedResource(endpoint_ref.endpointsId, _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DeleteBeta(Delete):
"""Deletes an endpoint."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory endpoints describe` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import endpoints
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describes an endpoint."""
detailed_help = {
'EXAMPLES':
"""\
To describe a Service Directory endpoint, run:
$ {command} my-endpoint --service=my-service --namespace=my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddEndpointResourceArg(parser, 'to describe.')
def Run(self, args):
client = endpoints.EndpointsClient(self.GetReleaseTrack())
endpoint_ref = args.CONCEPTS.endpoint.Parse()
return client.Describe(endpoint_ref)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DescribeBeta(Describe):
"""Describes an endpoint."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory endpoints list` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import endpoints
from googlecloudsdk.api_lib.util import common_args
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""Lists endpoints."""
detailed_help = {
'EXAMPLES':
"""\
To list Service Directory endpoints, run:
$ {command} --service=my-service --namespace=my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(parser, 'to list', positional=False)
base.LIMIT_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
client = endpoints.EndpointsClient(self.GetReleaseTrack())
service_ref = args.CONCEPTS.service.Parse()
order_by = common_args.ParseSortByArg(args.sort_by)
return client.List(service_ref, args.filter, order_by, args.page_size)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class ListBeta(List):
"""Lists endpoints."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,91 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory endpoints update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import endpoints
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import flags
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.command_lib.service_directory import util
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'endpoint'
_ENDPOINT_LIMIT = 512
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Updates an endpoint."""
detailed_help = {
'EXAMPLES':
"""\
To update a Service Directory endpoint, run:
$ {command} my-endpoint --service=my-service --namespace=my-namespace --location=us-east1 --address=1.2.3.4 --port=5 --annotations=a=b,c=d
""",
}
@staticmethod
def Args(parser):
resource_args.AddEndpointResourceArg(parser, 'to update.')
flags.AddAddressFlag(parser)
flags.AddPortFlag(parser)
flags.AddAnnotationsFlag(parser, _RESOURCE_TYPE, _ENDPOINT_LIMIT)
def Run(self, args):
client = endpoints.EndpointsClient()
endpoint_ref = args.CONCEPTS.endpoint.Parse()
annotations = util.ParseAnnotationsArg(args.annotations, _RESOURCE_TYPE)
result = client.Update(endpoint_ref, args.address, args.port, annotations)
log.UpdatedResource(endpoint_ref.endpointsId, _RESOURCE_TYPE)
return result
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class UpdateBeta(base.UpdateCommand):
"""Updates an endpoint."""
detailed_help = {
'EXAMPLES':
"""\
To update a Service Directory endpoint, run:
$ {command} my-endpoint --service=my-service --namespace=my-namespace --location=us-east1 --address=1.2.3.4 --port=5 --metadata=a=b,c=d
""",
}
@staticmethod
def Args(parser):
resource_args.AddEndpointResourceArg(parser, 'to update.')
flags.AddAddressFlag(parser)
flags.AddPortFlag(parser)
flags.AddMetadataFlag(parser, _RESOURCE_TYPE, _ENDPOINT_LIMIT)
def Run(self, args):
client = endpoints.EndpointsClientBeta()
endpoint_ref = args.CONCEPTS.endpoint.Parse()
metadata = util.ParseMetadataArg(args.metadata, _RESOURCE_TYPE)
result = client.Update(endpoint_ref, args.address, args.port, metadata)
log.UpdatedResource(endpoint_ref.endpointsId, _RESOURCE_TYPE)
return result

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 locations command group for Service Directory CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Locations(base.Group):
"""Manage Service Directory locations."""

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory locations describe` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import locations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describes a location."""
detailed_help = {
'EXAMPLES':
"""\
To describe a Service Directory location, run:
$ {command} location us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddLocationResourceArg(parser, 'to describe.')
def Run(self, args):
client = locations.LocationsClient(self.GetReleaseTrack())
location_ref = args.CONCEPTS.location.Parse()
return client.Describe(location_ref)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DescribeBeta(Describe):
"""Describes a location."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory locations list` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import locations
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.Command):
"""Lists locations."""
detailed_help = {
'EXAMPLES':
"""\
To describe a Service Directory location, run:
$ {command}
""",
}
@staticmethod
def Args(parser):
resource_args.AddProjectResourceArg(parser, 'to list', positional=False)
def Run(self, args):
client = locations.LocationsClient(self.GetReleaseTrack())
project_ref = args.CONCEPTS.project.Parse()
return client.List(project_ref)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class ListBeta(List):
"""Lists locations."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 services command group for Service Directory CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Services(base.Group):
"""Manage Service Directory namespaces."""

View File

@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces add-iam-policy-binding` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.service_directory import resource_args
_RESOURCE_TYPE = 'namespace'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class AddIamPolicyBinding(base.Command):
"""Adds IAM policy binding to a namespace."""
detailed_help = {
'EXAMPLES':
"""\
To add an IAM policy binding to a Service Directory namespace, run:
$ {command} my-namespace --location=us-east1 --role=roles/owner --member=user:foo@gmail.com
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(parser,
'to add IAM policy binding to.')
iam_util.AddArgsForAddIamPolicyBinding(parser)
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
result = client.AddIamPolicyBinding(namespace_ref, args.member, args.role)
iam_util.LogSetIamPolicy(namespace_ref.Name(), _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class AddIamPolicyBindingBeta(AddIamPolicyBinding):
"""Adds IAM policy binding to a namespace."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import flags
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.command_lib.service_directory import util
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'namespace'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Creates a namespace."""
detailed_help = {
'EXAMPLES':
"""\
To create a Service Directory namespace, run:
$ {command} my-namespace --location=us-east1 --labels=a=b,c=d
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(
parser,
"""to create. The namespace id must be 1-63 characters long and match
the regular expression `[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?` which means
the first character must be a lowercase letter, and all following
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.""")
flags.AddLabelsFlag(parser, _RESOURCE_TYPE)
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
labels = util.ParseLabelsArg(args.labels, self.GetReleaseTrack())
result = client.Create(namespace_ref, labels)
log.CreatedResource(namespace_ref.namespacesId, _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class CreateBeta(Create):
"""Creates a namespace."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces delete` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'namespace'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Deletes a namespace."""
detailed_help = {
'EXAMPLES':
"""\
To delete a Service Directory namespace, run:
$ {command} my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(parser, 'to delete.')
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
result = client.Delete(namespace_ref)
log.DeletedResource(namespace_ref.namespacesId, _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DeleteBeta(Delete):
"""Deletes a namespace."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces describe` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describes a namespace."""
detailed_help = {
'EXAMPLES':
"""\
To describe a Service Directory namespace, run:
$ {command} my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(parser, 'to describe.')
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
return client.Describe(namespace_ref)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DescribeBeta(Describe):
"""Describes a namespace."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces get-iam-policy` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
_RESOURCE_TYPE = 'namespace'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class GetIamPolicy(base.ListCommand):
"""Gets IAM policy for a namespace."""
detailed_help = {
'EXAMPLES':
"""\
To get an IAM policy to a Service Directory namespace, run:
$ {command} my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(
parser,
"""for which to get IAM policy.""")
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
return client.GetIamPolicy(namespace_ref)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class GetIamPolicyBeta(GetIamPolicy):
"""Gets IAM policy for a namespace."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces list` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.api_lib.util import common_args
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""Lists namespaces."""
detailed_help = {
'EXAMPLES':
"""\
To list Service Directory namespaces, run:
$ {command} --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddLocationResourceArg(parser, 'to list.', positional=False)
base.LIMIT_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
location_ref = args.CONCEPTS.location.Parse()
order_by = common_args.ParseSortByArg(args.sort_by)
return client.List(location_ref, args.filter, order_by, args.page_size)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class ListBeta(List):
"""Lists namespaces."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces remove-iam-policy-binding` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.service_directory import resource_args
_RESOURCE_TYPE = 'namespace'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class RemoveIamPolicyBinding(base.Command):
"""Removes IAM policy binding from a namespace."""
detailed_help = {
'EXAMPLES':
"""\
To remove an IAM policy binding to a Service Directory namespace, run:
$ {command} my-namespace --location=us-east1 --role=roles/owner --member=user:foo@gmail.com
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(
parser,
"""to remove IAM policy binding from.""")
iam_util.AddArgsForRemoveIamPolicyBinding(parser)
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
result = client.RemoveIamPolicyBinding(namespace_ref, args.member,
args.role)
iam_util.LogSetIamPolicy(namespace_ref.Name(), _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class RemoveIamPolicyBindingBeta(RemoveIamPolicyBinding):
"""Removes IAM policy binding from a namespace."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces set-iam-policy` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.service_directory import resource_args
_RESOURCE_TYPE = 'namespace'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class SetIamPolicy(base.Command):
"""Sets IAM policy for a namespace."""
detailed_help = {
'EXAMPLES':
"""\
To set an IAM policy to a Service Directory namespace, run:
$ {command} my-namespace --location=us-east1 policy.json
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(
parser,
"""to add IAM policy binding to.""")
iam_util.AddArgForPolicyFile(parser)
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
policy = iam_util.ParsePolicyFile(args.policy_file, client.msgs.Policy)
result = client.SetIamPolicy(namespace_ref, policy)
iam_util.LogSetIamPolicy(namespace_ref.Name(), _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class SetIamPolicyBeta(SetIamPolicy):
"""Sets IAM policy for a namespace."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory namespaces update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import namespaces
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import flags
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.command_lib.service_directory import util
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'namespace'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Updates a namespace."""
detailed_help = {
'EXAMPLES':
"""\
To update a Service Directory namespace, run:
$ {command} my-namespace --location=us-east1 --labels=a=b,c=d
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(parser, 'to update.')
flags.AddLabelsFlag(parser, _RESOURCE_TYPE)
def Run(self, args):
client = namespaces.NamespacesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
labels = util.ParseLabelsArg(args.labels, self.GetReleaseTrack())
result = client.Update(namespace_ref, labels)
log.UpdatedResource(namespace_ref.namespacesId, _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class UpdateBeta(Update):
"""Updates a namespace."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 services command group for Service Directory CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Services(base.Group):
"""Manage Service Directory services."""

View File

@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services add-iam-policy-binding` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.service_directory import resource_args
_RESOURCE_TYPE = 'service'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class AddIamPolicyBinding(base.Command):
"""Adds IAM policy binding to a service."""
detailed_help = {
'EXAMPLES':
"""\
To add an IAM policy binding to a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1 --role=roles/owner --member=user:foo@gmail.com
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(parser, 'to add IAM policy binding to.')
iam_util.AddArgsForAddIamPolicyBinding(parser)
def Run(self, args):
client = services.ServicesClient(self.GetReleaseTrack())
service_ref = args.CONCEPTS.service.Parse()
result = client.AddIamPolicyBinding(service_ref, args.member, args.role)
iam_util.LogSetIamPolicy(service_ref.Name(), _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class AddIamPolicyBindingBeta(AddIamPolicyBinding):
"""Adds IAM policy binding to a service."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import flags
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.command_lib.service_directory import util
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'service'
_SERVICE_LIMIT = 2000
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Create(base.CreateCommand):
"""Creates a service."""
detailed_help = {
'EXAMPLES':
"""\
To create a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1 --annotations=a=b,c=d
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(
parser,
"""to create. The service id must be 1-63 characters long and match
the regular expression `[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?` which means
the first character must be a lowercase letter, and all following
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.""")
flags.AddAnnotationsFlag(parser, _RESOURCE_TYPE, _SERVICE_LIMIT)
def Run(self, args):
client = services.ServicesClient()
service_ref = args.CONCEPTS.service.Parse()
annotations = util.ParseAnnotationsArg(args.annotations, _RESOURCE_TYPE)
result = client.Create(service_ref, annotations)
log.CreatedResource(service_ref.servicesId, _RESOURCE_TYPE)
return result
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class CreateBeta(base.CreateCommand):
"""Creates a service."""
detailed_help = {
'EXAMPLES':
"""\
To create a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1 --metadata=a=b,c=d
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(
parser,
"""to create. The service id must be 1-63 characters long and match
the regular expression `[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?` which means
the first character must be a lowercase letter, and all following
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.""")
flags.AddMetadataFlag(parser, _RESOURCE_TYPE, _SERVICE_LIMIT)
def Run(self, args):
client = services.ServicesClientBeta()
service_ref = args.CONCEPTS.service.Parse()
metadata = util.ParseMetadataArg(args.metadata, _RESOURCE_TYPE)
result = client.Create(service_ref, metadata)
log.CreatedResource(service_ref.servicesId, _RESOURCE_TYPE)
return result

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services delete` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'service'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Delete(base.DeleteCommand):
"""Deletes a service."""
detailed_help = {
'EXAMPLES':
"""\
To delete a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(parser, 'to delete.')
def Run(self, args):
client = services.ServicesClient(self.GetReleaseTrack())
service_ref = args.CONCEPTS.service.Parse()
result = client.Delete(service_ref)
log.DeletedResource(service_ref.servicesId, _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DeleteBeta(Delete):
"""Deletes a service."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services describe` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Describe(base.DescribeCommand):
"""Describes a service."""
detailed_help = {
'EXAMPLES':
"""\
To describe a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(parser, 'to describe.')
def Run(self, args):
client = services.ServicesClient(self.GetReleaseTrack())
service_ref = args.CONCEPTS.service.Parse()
return client.Describe(service_ref)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class DescribeBeta(Describe):
"""Describes a service."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services get-iam-policy` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
_RESOURCE_TYPE = 'service'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class GetIamPolicy(base.ListCommand):
"""Gets IAM policy for a service."""
detailed_help = {
'EXAMPLES':
"""\
To get an IAM policy to a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(
parser,
"""for which to get IAM policy.""")
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
client = services.ServicesClient(self.GetReleaseTrack())
service_ref = args.CONCEPTS.service.Parse()
return client.GetIamPolicy(service_ref)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class GetIamPolicyBeta(GetIamPolicy):
"""Gets IAM policy for a service."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services list` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.api_lib.util import common_args
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class List(base.ListCommand):
"""Lists services."""
detailed_help = {
'EXAMPLES':
"""\
To list Service Directory services, run:
$ {command} --namespace=my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddNamespaceResourceArg(parser, 'to list.', positional=False)
base.LIMIT_FLAG.RemoveFromParser(parser)
base.URI_FLAG.RemoveFromParser(parser)
def Run(self, args):
client = services.ServicesClient(self.GetReleaseTrack())
namespace_ref = args.CONCEPTS.namespace.Parse()
order_by = common_args.ParseSortByArg(args.sort_by)
return client.List(namespace_ref, args.filter, order_by, args.page_size)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class ListBeta(List):
"""Lists services."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services remove-iam-policy-binding` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.service_directory import resource_args
_RESOURCE_TYPE = 'service'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class RemoveIamPolicyBinding(base.Command):
"""Removes IAM policy binding from a service."""
detailed_help = {
'EXAMPLES':
"""\
To remove an IAM policy binding to a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1 --role=roles/owner --member=user:foo@gmail.com
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(
parser,
"""to remove IAM policy binding from.""")
iam_util.AddArgsForRemoveIamPolicyBinding(parser)
def Run(self, args):
client = services.ServicesClient(self.GetReleaseTrack())
service_ref = args.CONCEPTS.service.Parse()
result = client.RemoveIamPolicyBinding(service_ref, args.member, args.role)
iam_util.LogSetIamPolicy(service_ref.Name(), _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class RemoveIamPolicyBindingBeta(RemoveIamPolicyBinding):
"""Removes IAM policy binding from a service."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services resolve` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import flags
from googlecloudsdk.command_lib.service_directory import resource_args
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Resolve(base.Command):
"""Resolves a service."""
detailed_help = {
'EXAMPLES':
"""\
To resolve Service Directory services, run:
$ {command} my-service --namespace=my-namespace --location=us-east1
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(parser, 'to resolve.')
flags.AddMaxEndpointsFlag(parser)
flags.AddEndpointFilterFlag(parser)
def Run(self, args):
client = services.ServicesClient(self.GetReleaseTrack())
service_ref = args.CONCEPTS.service.Parse()
return client.Resolve(service_ref, args.max_endpoints, args.endpoint_filter)
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class ResolveBeta(Resolve):
"""Resolves a service."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services set-iam-policy` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
from googlecloudsdk.command_lib.service_directory import resource_args
_RESOURCE_TYPE = 'service'
@base.ReleaseTracks(base.ReleaseTrack.GA)
class SetIamPolicy(base.Command):
"""Sets IAM policy for a service."""
detailed_help = {
'EXAMPLES':
"""\
To set an IAM policy to a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1 policy.json
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(
parser,
"""to add IAM policy binding to.""")
iam_util.AddArgForPolicyFile(parser)
def Run(self, args):
client = services.ServicesClient(self.GetReleaseTrack())
service_ref = args.CONCEPTS.service.Parse()
policy = iam_util.ParsePolicyFile(args.policy_file, client.msgs.Policy)
result = client.SetIamPolicy(service_ref, policy)
iam_util.LogSetIamPolicy(service_ref.Name(), _RESOURCE_TYPE)
return result
def GetReleaseTrack(self):
return base.ReleaseTrack.GA
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class SetIamPolicyBeta(SetIamPolicy):
"""Sets IAM policy for a service."""
def GetReleaseTrack(self):
return base.ReleaseTrack.BETA

View File

@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 Google Inc. 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 service-directory services update` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import services
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.service_directory import flags
from googlecloudsdk.command_lib.service_directory import resource_args
from googlecloudsdk.command_lib.service_directory import util
from googlecloudsdk.core import log
_RESOURCE_TYPE = 'service'
_SERVICE_LIMIT = 2000
@base.ReleaseTracks(base.ReleaseTrack.GA)
class Update(base.UpdateCommand):
"""Updates a service."""
detailed_help = {
'EXAMPLES':
"""\
To update a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1 --annotations=a=b,c=d
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(parser, 'to update.')
flags.AddAnnotationsFlag(parser, _RESOURCE_TYPE, _SERVICE_LIMIT)
def Run(self, args):
client = services.ServicesClient()
service_ref = args.CONCEPTS.service.Parse()
annotations = util.ParseAnnotationsArg(args.annotations, _RESOURCE_TYPE)
result = client.Update(service_ref, annotations)
log.UpdatedResource(service_ref.servicesId, _RESOURCE_TYPE)
return result
@base.ReleaseTracks(base.ReleaseTrack.ALPHA, base.ReleaseTrack.BETA)
class UpdateBeta(base.UpdateCommand):
"""Updates a service."""
detailed_help = {
'EXAMPLES':
"""\
To update a Service Directory service, run:
$ {command} my-service --namespace=my-namespace --location=us-east1 --metadata=a=b,c=d
""",
}
@staticmethod
def Args(parser):
resource_args.AddServiceResourceArg(parser, 'to update.')
flags.AddMetadataFlag(parser, _RESOURCE_TYPE, _SERVICE_LIMIT)
def Run(self, args):
client = services.ServicesClientBeta()
service_ref = args.CONCEPTS.service.Parse()
metadata = util.ParseMetadataArg(args.metadata, _RESOURCE_TYPE)
result = client.Update(service_ref, metadata)
log.UpdatedResource(service_ref.servicesId, _RESOURCE_TYPE)
return result