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,39 @@
# -*- 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 base api lib for Service Directory CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
_API_NAME = 'servicedirectory'
_VERSION_MAP = {
base.ReleaseTrack.ALPHA: 'v1beta1',
base.ReleaseTrack.BETA: 'v1beta1',
base.ReleaseTrack.GA: 'v1'
}
class ServiceDirectoryApiLibBase(object):
"""The base class for all Service Directory clients."""
def __init__(self, release_track=base.ReleaseTrack.GA):
self.client = apis.GetClientInstance(_API_NAME,
_VERSION_MAP.get(release_track))
self.msgs = apis.GetMessagesModule(_API_NAME,
_VERSION_MAP.get(release_track))

View File

@@ -0,0 +1,129 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Utilities Service Directory endpoints API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.service_directory import base as sd_base
from googlecloudsdk.calliope import base
class EndpointsClient(sd_base.ServiceDirectoryApiLibBase):
"""Client for endpoints in the Service Directory API."""
def __init__(self, release_track=base.ReleaseTrack.GA):
super(EndpointsClient, self).__init__(release_track)
self.service = self.client.projects_locations_namespaces_services_endpoints
def Create(self,
endpoint_ref,
address=None,
port=None,
annotations=None,
network=None):
"""Endpoints create request."""
endpoint = self.msgs.Endpoint(
address=address, port=port, annotations=annotations, network=network)
create_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesEndpointsCreateRequest(
parent=endpoint_ref.Parent().RelativeName(),
endpoint=endpoint,
endpointId=endpoint_ref.endpointsId)
return self.service.Create(create_req)
def Delete(self, endpoint_ref):
"""Endpoints delete request."""
delete_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesEndpointsDeleteRequest(
name=endpoint_ref.RelativeName())
return self.service.Delete(delete_req)
def Describe(self, endpoint_ref):
"""Endpoints describe request."""
describe_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesEndpointsGetRequest(
name=endpoint_ref.RelativeName())
return self.service.Get(describe_req)
def List(self, service_ref, filter_=None, order_by=None, page_size=None):
"""Endpoints list request."""
list_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesEndpointsListRequest(
parent=service_ref.RelativeName(),
filter=filter_,
orderBy=order_by,
pageSize=page_size)
return list_pager.YieldFromList(
self.service,
list_req,
batch_size=page_size,
field='endpoints',
batch_size_attribute='pageSize')
def Update(self, endpoint_ref, address=None, port=None, annotations=None):
"""Endpoints update request."""
mask_parts = []
if address is not None:
mask_parts.append('address')
if port is not None:
mask_parts.append('port')
if annotations is not None:
mask_parts.append('annotations')
endpoint = self.msgs.Endpoint(
address=address, port=port, annotations=annotations)
update_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesEndpointsPatchRequest(
name=endpoint_ref.RelativeName(),
endpoint=endpoint,
updateMask=','.join(mask_parts))
return self.service.Patch(update_req)
class EndpointsClientBeta(EndpointsClient):
"""Client for endpoints in the v1beta1 Service Directory API."""
def __init__(self):
super(EndpointsClientBeta, self).__init__(base.ReleaseTrack.BETA)
def Create(self,
endpoint_ref,
address=None,
port=None,
metadata=None,
network=None):
"""Endpoints create request."""
endpoint = self.msgs.Endpoint(
address=address, port=port, metadata=metadata, network=network)
create_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesEndpointsCreateRequest(
parent=endpoint_ref.Parent().RelativeName(),
endpoint=endpoint,
endpointId=endpoint_ref.endpointsId)
return self.service.Create(create_req)
def Update(self, endpoint_ref, address=None, port=None, metadata=None):
"""Endpoints update request."""
mask_parts = []
if address is not None:
mask_parts.append('address')
if port is not None:
mask_parts.append('port')
if metadata is not None:
mask_parts.append('metadata')
endpoint = self.msgs.Endpoint(address=address, port=port, metadata=metadata)
update_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesEndpointsPatchRequest(
name=endpoint_ref.RelativeName(),
endpoint=endpoint,
updateMask=','.join(mask_parts))
return self.service.Patch(update_req)

View File

@@ -0,0 +1,41 @@
# -*- 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.
"""Utilities Service Directory locations API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.service_directory import base as sd_base
from googlecloudsdk.calliope import base
class LocationsClient(sd_base.ServiceDirectoryApiLibBase):
"""Client for locations in the Service Directory API."""
def __init__(self, release_track=base.ReleaseTrack.GA):
super(LocationsClient, self).__init__(release_track)
self.service = self.client.projects_locations
def List(self, project_ref):
"""Locations list request."""
list_req = self.msgs.ServicedirectoryProjectsLocationsListRequest(
name=project_ref.RelativeName())
return self.service.List(list_req)
def Describe(self, location_ref):
"""Locations describe request."""
describe_req = self.msgs.ServicedirectoryProjectsLocationsGetRequest(
name=location_ref.RelativeName())
return self.service.Get(describe_req)

View File

@@ -0,0 +1,105 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Utilities Service Directory namespaces API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.service_directory import base as sd_base
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
class NamespacesClient(sd_base.ServiceDirectoryApiLibBase):
"""Client for namespaces in the Service Directory API."""
def __init__(self, release_track=base.ReleaseTrack.GA):
super(NamespacesClient, self).__init__(release_track)
self.service = self.client.projects_locations_namespaces
def Create(self, namespace_ref, labels=None):
"""Namespaces create request."""
namespace = self.msgs.Namespace(labels=labels)
create_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesCreateRequest(
parent=namespace_ref.Parent().RelativeName(),
namespace=namespace,
namespaceId=namespace_ref.namespacesId)
return self.service.Create(create_req)
def Delete(self, namespace_ref):
"""Namespaces delete request."""
delete_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesDeleteRequest(
name=namespace_ref.RelativeName())
return self.service.Delete(delete_req)
def Describe(self, namespace_ref):
"""Namespaces describe request."""
describe_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesGetRequest(
name=namespace_ref.RelativeName())
return self.service.Get(describe_req)
def List(self, location_ref, filter_=None, order_by=None, page_size=None):
"""Namespaces list request."""
list_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesListRequest(
parent=location_ref.RelativeName(),
filter=filter_,
orderBy=order_by,
pageSize=page_size)
return list_pager.YieldFromList(
self.service,
list_req,
batch_size=page_size,
field='namespaces',
batch_size_attribute='pageSize')
def Update(self, namespace_ref, labels=None):
"""Namespaces update request."""
mask_parts = []
if labels:
mask_parts.append('labels')
namespace = self.msgs.Namespace(labels=labels)
update_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesPatchRequest(
name=namespace_ref.RelativeName(),
namespace=namespace,
updateMask=','.join(mask_parts))
return self.service.Patch(update_req)
def AddIamPolicyBinding(self, namespace_ref, member, role):
"""Namespaces add iam policy binding request."""
policy = self.GetIamPolicy(namespace_ref)
iam_util.AddBindingToIamPolicy(self.msgs.Binding, policy, member, role)
return self.SetIamPolicy(namespace_ref, policy)
def GetIamPolicy(self, namespace_ref):
"""Namespaces get iam policy request."""
get_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesGetIamPolicyRequest(
resource=namespace_ref.RelativeName())
return self.service.GetIamPolicy(get_req)
def RemoveIamPolicyBinding(self, namespace_ref, member, role):
"""Namespaces remove iam policy binding request."""
policy = self.GetIamPolicy(namespace_ref)
iam_util.RemoveBindingFromIamPolicy(policy, member, role)
return self.SetIamPolicy(namespace_ref, policy)
def SetIamPolicy(self, namespace_ref, policy):
"""Namespaces set iam policy request."""
set_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesSetIamPolicyRequest(
resource=namespace_ref.RelativeName(),
setIamPolicyRequest=self.msgs.SetIamPolicyRequest(policy=policy))
return self.service.SetIamPolicy(set_req)

View File

@@ -0,0 +1,142 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 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.
"""Utilities Service Directory services API."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
from googlecloudsdk.api_lib.service_directory import base as sd_base
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.iam import iam_util
class ServicesClient(sd_base.ServiceDirectoryApiLibBase):
"""Client for service in the Service Directory API."""
def __init__(self, release_track=base.ReleaseTrack.GA):
super(ServicesClient, self).__init__(release_track)
self.service = self.client.projects_locations_namespaces_services
def Create(self, service_ref, annotations=None):
"""Services create request."""
service = self.msgs.Service(annotations=annotations)
create_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesCreateRequest(
parent=service_ref.Parent().RelativeName(),
service=service,
serviceId=service_ref.servicesId)
return self.service.Create(create_req)
def Delete(self, service_ref):
"""Services delete request."""
delete_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesDeleteRequest(
name=service_ref.RelativeName())
return self.service.Delete(delete_req)
def Describe(self, service_ref):
"""Services describe request."""
describe_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesGetRequest(
name=service_ref.RelativeName())
return self.service.Get(describe_req)
def List(self, namespace_ref, filter_=None, order_by=None, page_size=None):
"""Services list request."""
list_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesListRequest(
parent=namespace_ref.RelativeName(),
filter=filter_,
orderBy=order_by,
pageSize=page_size)
return list_pager.YieldFromList(
self.service,
list_req,
batch_size=page_size,
field='services',
batch_size_attribute='pageSize')
def Update(self, service_ref, annotations=None):
"""Services update request."""
mask_parts = []
if annotations:
mask_parts.append('annotations')
service = self.msgs.Service(annotations=annotations)
update_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesPatchRequest(
name=service_ref.RelativeName(),
service=service,
updateMask=','.join(mask_parts))
return self.service.Patch(update_req)
def Resolve(self, service_ref, max_endpoints=None, endpoint_filter=None):
"""Services resolve request."""
resolve_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesResolveRequest(
name=service_ref.RelativeName(),
resolveServiceRequest=self.msgs.ResolveServiceRequest(
maxEndpoints=max_endpoints, endpointFilter=endpoint_filter))
return self.service.Resolve(resolve_req)
def AddIamPolicyBinding(self, service_ref, member, role):
"""Services add iam policy binding request."""
policy = self.GetIamPolicy(service_ref)
iam_util.AddBindingToIamPolicy(self.msgs.Binding, policy, member, role)
return self.SetIamPolicy(service_ref, policy)
def GetIamPolicy(self, service_ref):
"""Services get iam policy request."""
get_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesGetIamPolicyRequest(
resource=service_ref.RelativeName())
return self.service.GetIamPolicy(get_req)
def RemoveIamPolicyBinding(self, service_ref, member, role):
"""Services remove iam policy binding request."""
policy = self.GetIamPolicy(service_ref)
iam_util.RemoveBindingFromIamPolicy(policy, member, role)
return self.SetIamPolicy(service_ref, policy)
def SetIamPolicy(self, service_ref, policy):
"""Services set iam policy request."""
set_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesSetIamPolicyRequest(
resource=service_ref.RelativeName(),
setIamPolicyRequest=self.msgs.SetIamPolicyRequest(policy=policy))
return self.service.SetIamPolicy(set_req)
class ServicesClientBeta(ServicesClient):
"""Client for service in the Service Directory API."""
def __init__(self):
super(ServicesClientBeta, self).__init__(base.ReleaseTrack.BETA)
def Create(self, service_ref, metadata=None):
"""Services create request."""
service = self.msgs.Service(metadata=metadata)
create_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesCreateRequest(
parent=service_ref.Parent().RelativeName(),
service=service,
serviceId=service_ref.servicesId)
return self.service.Create(create_req)
def Update(self, service_ref, metadata=None):
"""Services update request."""
mask_parts = []
if metadata:
mask_parts.append('metadata')
service = self.msgs.Service(metadata=metadata)
update_req = self.msgs.ServicedirectoryProjectsLocationsNamespacesServicesPatchRequest(
name=service_ref.RelativeName(),
service=service,
updateMask=','.join(mask_parts))
return self.service.Patch(update_req)