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,37 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 Cloud Monitoring uptime."""
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 Uptime(base.Group):
"""Manage Cloud Monitoring uptime checks and synthetic monitors."""
detailed_help = {
'DESCRIPTION': """\
Manage Monitoring uptime checks and synthetic monitors.
More information can be found here:
https://cloud.google.com/monitoring/api/v3/
"""}

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 monitoring uptime create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.monitoring import uptime
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.monitoring import flags
from googlecloudsdk.command_lib.monitoring import util
from googlecloudsdk.command_lib.projects import util as projects_util
from googlecloudsdk.core import log
from googlecloudsdk.core import properties
class Create(base.CreateCommand):
"""Create a new uptime check or synthetic monitor."""
detailed_help = {
"DESCRIPTION": """\
Create a new uptime check or synthetic monitor.
Flags only apply to uptime checks unless noted that they apply to
synthetic monitors.
For information about the JSON/YAML format of an uptime check:
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs
""",
"EXAMPLES": """\
To create an uptime check against a URL, run:
$ {command} DISPLAY_NAME --resource-type=uptime-url
--resource-labels=host=google.com,project_id=PROJECT_ID
To create a synthetic monitor, run:
$ {command} SYNTHETIC_MONITOR_NAME
--synthetic-target=projects/PROJECT_ID/locations/REGION/functions/FUNCTION_NAME
""",
}
@staticmethod
def Args(parser):
flags.AddDisplayNameFlag(
parser, "uptime check or synthetic monitor", positional=True
)
flags.AddUptimeSettingsFlags(parser)
def Run(self, args):
client = uptime.UptimeClient()
uptime_check = util.CreateUptimeFromArgs(args, client.messages)
project_ref = projects_util.ParseProject(
properties.VALUES.core.project.Get()
)
result = client.Create(project_ref, uptime_check)
log.CreatedResource(result.name, "uptime")
return result

View File

@@ -0,0 +1,18 @@
- help_text:
brief: Delete an uptime check or synthetic monitor.
description: Delete an uptime check or synthetic monitor
examples: |
To delete an uptime check or synthetic monitor:
$ {command} CHECK_ID
More information can be found at
https://cloud.google.com/monitoring/uptime-checks/manage#delete.
request:
collection: monitoring.projects.uptimeCheckConfigs
arguments:
resource:
help_text: The uptime check or synthetic monitor to delete.
spec: !REF googlecloudsdk.command_lib.monitoring.resources:uptime_check

View File

@@ -0,0 +1,18 @@
- help_text:
brief: Describe an uptime check or synthetic monitor.
description: Describe an uptime check or synthetic monitor
examples: |
To describe an uptime check or synthetic monitor:
$ {command} CHECK_ID
More information can be found at
https://cloud.google.com/monitoring/uptime-checks/manage#get.
request:
collection: monitoring.projects.uptimeCheckConfigs
arguments:
resource:
help_text: The uptime check or synthetic monitor to describe.
spec: !REF googlecloudsdk.command_lib.monitoring.resources:uptime_check

View File

@@ -0,0 +1,22 @@
- help_text:
brief: List uptime checks and synthetic monitors.
description: List uptime checks and synthetic monitors.
examples: |
To see all uptime checks and synthetic monitors:
$ {command}
More information can be found at
https://cloud.google.com/monitoring/uptime-checks/using-uptime-checks
command_type: LIST
request:
collection: monitoring.projects.uptimeCheckConfigs
response:
id_field: name
arguments:
resource:
help_text: |
The Cloud Monitoring Workspace from which to list uptime checks and synthetic monitors.
spec: !REF googlecloudsdk.command_lib.monitoring.resources:project

View File

@@ -0,0 +1,26 @@
- help_text:
brief: List uptime check server ips.
description: List uptime check egress ips.
examples: |
To see all uptime check servers ips:
$ {command}
More information can be found at
https://cloud.google.com/monitoring/uptime-checks/using-uptime-checks
command_type: LIST
request:
method: list
collection: monitoring.uptimeCheckIps
response:
id_field: ipAddress
arguments:
params:
[]
output:
format: yaml

View File

@@ -0,0 +1,162 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 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 monitoring uptime create` command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.monitoring import uptime
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.monitoring import flags
from googlecloudsdk.command_lib.monitoring import resource_args
from googlecloudsdk.command_lib.monitoring import util
from googlecloudsdk.command_lib.util.args import repeated
from googlecloudsdk.core import log
class Update(base.UpdateCommand):
"""Update an existing uptime check or synthetic monitor."""
detailed_help = {
'DESCRIPTION': """\
Updates an existing uptime check or synthetic monitor.
Flags only apply to uptime checks unless noted that they apply to
synthetic monitors.
For information about the JSON/YAML format of an uptime check:
https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs
""",
'EXAMPLES': """\
To update an uptime check or synthetic monitor, run:
$ {command} CHECK_ID --period=5 --timeout=30
""",}
@staticmethod
def Args(parser):
resources = [resource_args.CreateUptimeResourceArg('to be updated.')]
resource_args.AddResourceArgs(parser, resources)
flags.AddUptimeSettingsFlags(parser, update=True)
def Run(self, args):
client = uptime.UptimeClient()
uptime_check_ref = args.CONCEPTS.check_id.Parse()
uptime_check = client.Get(uptime_check_ref)
new_user_labels = util.ProcessUpdateLabels(
args,
'user_labels',
client.messages.UptimeCheckConfig.UserLabelsValue,
uptime_check.userLabels,
)
new_headers = None
regions = ParseSelectedRegions(uptime_check.selectedRegions)
new_regions = repeated.ParsePrimitiveArgs(args, 'regions', lambda: regions)
status_codes = []
new_status_codes = []
status_classes = []
new_status_classes = []
if uptime_check.httpCheck is not None:
new_headers = util.ProcessUpdateLabels(
args,
'headers',
client.messages.HttpCheck.HeadersValue,
uptime_check.httpCheck.headers,
)
for status in uptime_check.httpCheck.acceptedResponseStatusCodes:
if status.statusClass is not None:
status_classes.append(status.statusClass)
else:
status_codes.append(status.statusValue)
new_status_codes = repeated.ParsePrimitiveArgs(
args, 'status_codes', lambda: status_codes
)
status_classes = ParseStatusClasses(status_classes)
new_status_classes = repeated.ParsePrimitiveArgs(
args, 'status_classes', lambda: status_classes
)
util.ModifyUptimeCheck(
uptime_check,
client.messages,
args,
regions=new_regions,
user_labels=new_user_labels,
headers=new_headers,
status_classes=new_status_classes,
status_codes=new_status_codes,
update=True
)
# Full replace, no fields_mask
result = client.Update(uptime_check_ref, uptime_check, fields=None)
log.UpdatedResource(result.name, 'uptime')
return result
def ParseSelectedRegions(selected_regions):
"""Convert previously selected regions from enum to flag for update logic."""
client = uptime.UptimeClient()
messages = client.messages
region_mapping = {
messages.UptimeCheckConfig.SelectedRegionsValueListEntryValuesEnum.USA_OREGON: (
'usa-oregon'
),
messages.UptimeCheckConfig.SelectedRegionsValueListEntryValuesEnum.USA_IOWA: (
'usa-iowa'
),
messages.UptimeCheckConfig.SelectedRegionsValueListEntryValuesEnum.USA_VIRGINIA: (
'usa-virginia'
),
messages.UptimeCheckConfig.SelectedRegionsValueListEntryValuesEnum.EUROPE: (
'europe'
),
messages.UptimeCheckConfig.SelectedRegionsValueListEntryValuesEnum.SOUTH_AMERICA: (
'south-america'
),
messages.UptimeCheckConfig.SelectedRegionsValueListEntryValuesEnum.ASIA_PACIFIC: (
'asia-pacific'
),
}
return [region_mapping.get(region) for region in selected_regions]
def ParseStatusClasses(status_classes):
"""Convert previously status classes from enum to flag for update logic."""
client = uptime.UptimeClient()
messages = client.messages
status_mapping = {
messages.ResponseStatusCode.StatusClassValueValuesEnum.STATUS_CLASS_1XX: (
'1xx'
),
messages.ResponseStatusCode.StatusClassValueValuesEnum.STATUS_CLASS_2XX: (
'2xx'
),
messages.ResponseStatusCode.StatusClassValueValuesEnum.STATUS_CLASS_3XX: (
'3xx'
),
messages.ResponseStatusCode.StatusClassValueValuesEnum.STATUS_CLASS_4XX: (
'4xx'
),
messages.ResponseStatusCode.StatusClassValueValuesEnum.STATUS_CLASS_5XX: (
'5xx'
),
messages.ResponseStatusCode.StatusClassValueValuesEnum.STATUS_CLASS_ANY: (
'any'
),
}
return [status_mapping.get(status_class) for status_class in status_classes]