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,107 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""API Library for gcloud cloudscheduler."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.scheduler import cmek_config
from googlecloudsdk.api_lib.scheduler import jobs
from googlecloudsdk.api_lib.scheduler import locations
from googlecloudsdk.api_lib.scheduler import operations
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
API_NAME = 'cloudscheduler'
ALPHA_API_VERSION = 'v1alpha1'
BETA_API_VERSION = 'v1beta1'
GA_API_VERSION = 'v1'
class UnsupportedReleaseTrackError(Exception):
"""Raised when requesting an api for an unsupported release track."""
def ApiVersionFromReleaseTrack(release_track):
if release_track == base.ReleaseTrack.ALPHA:
return ALPHA_API_VERSION
if release_track == base.ReleaseTrack.BETA:
return BETA_API_VERSION
if release_track == base.ReleaseTrack.GA:
return GA_API_VERSION
else:
raise UnsupportedReleaseTrackError(release_track)
def GetApiAdapter(release_track, legacy_cron=False):
if release_track == base.ReleaseTrack.ALPHA:
return AlphaApiAdapter(legacy_cron=legacy_cron)
elif release_track == base.ReleaseTrack.BETA:
return BetaApiAdapter(legacy_cron=legacy_cron)
elif release_track == base.ReleaseTrack.GA:
return GaApiAdapter(legacy_cron=legacy_cron)
else:
raise UnsupportedReleaseTrackError(release_track)
class BaseApiAdapter(object):
def __init__(self, api_version):
self.client = apis.GetClientInstance(API_NAME, api_version)
self.messages = self.client.MESSAGES_MODULE
self.locations = locations.Locations(
self.client.MESSAGES_MODULE, self.client.projects_locations
)
self.cmek_config = cmek_config.CmekConfig(
self.client.MESSAGES_MODULE, self.client.projects_locations
)
class AlphaApiAdapter(BaseApiAdapter):
def __init__(self, legacy_cron=False):
super(AlphaApiAdapter, self).__init__(ALPHA_API_VERSION)
self.jobs = jobs.BaseJobs(
self.client.MESSAGES_MODULE,
self.client.projects_locations_jobs,
legacy_cron=legacy_cron,
)
class BetaApiAdapter(BaseApiAdapter):
def __init__(self, legacy_cron=False):
super(BetaApiAdapter, self).__init__(BETA_API_VERSION)
self.jobs = jobs.BaseJobs(
self.client.MESSAGES_MODULE,
self.client.projects_locations_jobs,
legacy_cron=legacy_cron,
)
class GaApiAdapter(BaseApiAdapter):
def __init__(self, legacy_cron=False):
super(GaApiAdapter, self).__init__(GA_API_VERSION)
self.jobs = jobs.BaseJobs(
self.client.MESSAGES_MODULE,
self.client.projects_locations_jobs,
legacy_cron=legacy_cron,
)
self.operations = operations.Operations(
self.client.MESSAGES_MODULE, self.client.projects_locations_operations
)

View File

@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""API Library for gcloud scheduler CMEK config."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.core import exceptions
class RequiredFieldsMissingError(exceptions.Error):
"""Error for when calling a method when a required field is unspecified."""
class CmekConfig(object):
"""API client for Cloud Scheduler CMEK Config."""
def __init__(self, messages, cmek_config_service):
self.messages = messages
self.cmek_config_service = cmek_config_service
def GetCmekConfig(self, project_id, location_id):
"""Prepares and sends a GetCmekConfig request for the given CmekConfig."""
cmek_config_name = (
'projects/{project_id}/locations/{location_id}/cmekConfig'.format(
project_id=project_id, location_id=location_id
)
)
request = self.messages.CloudschedulerProjectsLocationsGetCmekConfigRequest(
name=cmek_config_name,
)
return self.cmek_config_service.GetCmekConfig(request)
def UpdateCmekConfig(self, project_id, location_id, cmek_config):
"""Prepares and sends an UpdateCmekConfig request for the given CmekConfig."""
cmek_config_name = (
'projects/{project_id}/locations/{location_id}/cmekConfig'.format(
project_id=project_id, location_id=location_id
)
)
request = (
self.messages.CloudschedulerProjectsLocationsUpdateCmekConfigRequest(
name=cmek_config_name, cmekConfig=cmek_config
)
)
return self.cmek_config_service.UpdateCmekConfig(request)

View File

@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""API Library for gcloud scheduler jobs."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
class BaseJobs(object):
"""Base API client for Cloud Scheduler jobs."""
def __init__(self, messages, jobs_service, legacy_cron):
self.messages = messages
self.jobs_service = jobs_service
self.legacy_cron = legacy_cron
def List(self, parent_ref, limit=None, page_size=100):
request = (
self.messages.CloudschedulerProjectsLocationsJobsListRequest(
parent=parent_ref,
legacyAppEngineCron=self.legacy_cron))
return list_pager.YieldFromList(
self.jobs_service, request, batch_size=page_size, limit=limit,
field='jobs', batch_size_attribute='pageSize')
def Delete(self, job_ref):
request = (
self.messages.CloudschedulerProjectsLocationsJobsDeleteRequest(
name=job_ref, legacyAppEngineCron=self.legacy_cron))
return self.jobs_service.Delete(request)
def Create(self, parent_ref, job):
request = (
self.messages.CloudschedulerProjectsLocationsJobsCreateRequest(
job=job, parent=parent_ref))
return self.jobs_service.Create(request)
def Run(self, job_ref, legacy_cron=False):
request = (
self.messages.CloudschedulerProjectsLocationsJobsRunRequest(
name=job_ref,
runJobRequest=self.messages.RunJobRequest(
legacyAppEngineCron=legacy_cron))
)
return self.jobs_service.Run(request)

View File

@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*- #
# Copyright 2020 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.
"""API Library for `gcloud scheduler`."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from apitools.base.py import list_pager
class Locations(object):
"""Client for locations service in the Cloud Scheduler API."""
def __init__(self, messages, locations_service):
self.messages = messages
self.locations_service = locations_service
def Get(self, location_ref):
request = self.messages.CloudschedulerProjectsLocationsGetRequest(
name=location_ref.RelativeName())
return self.locations_service.Get(request)
def List(self, project_ref, limit=None, page_size=100):
request = self.messages.CloudschedulerProjectsLocationsListRequest(
name=project_ref.RelativeName())
return list_pager.YieldFromList(
self.locations_service, request, batch_size=page_size, limit=limit,
field='locations', batch_size_attribute='pageSize')

View File

@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*- #
# Copyright 2025 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""API Library for gcloud scheduler operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
class Operations(object):
"""Client for interacting with Cloud Scheduler Operations."""
def __init__(self, messages, operations_service):
self.messages = messages
self.operations_service = operations_service
def Get(self, operation_ref):
request = self.messages.CloudschedulerProjectsLocationsOperationsGetRequest(
name=operation_ref.RelativeName()
)
return self.operations_service.Get(request)