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,30 @@
# Copyright 2017 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.
import sys
x=sys.modules['containerregistry.transport']
from containerregistry.transport import nested_
setattr(x, 'nested', nested_)
from containerregistry.transport import retry_
setattr(x, 'retry', retry_)
from containerregistry.transport import transport_pool_
setattr(x, 'transport_pool', transport_pool_)

View File

@@ -0,0 +1,44 @@
# Copyright 2018 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.
"""An httplib2.Http extending and composing an inner httplib2.Http transport.
"""
import httplib2
class NestedTransport(httplib2.Http):
"""Extends and composes an inner httplib2.Http transport."""
def __init__(self, source_transport):
self.source_transport = source_transport
def __getstate__(self):
raise NotImplementedError()
def __setstate__(self, state):
# Don't want to bother reflectivley instantiating the source_transport.
# Don't serialize your transports.
raise NotImplementedError()
def add_credentials(self, *args, **kwargs):
self.source_transport.add_credentials(*args, **kwargs)
def add_certificate(self, *args, **kwargs):
self.source_transport.add_certificate(*args, **kwargs)
def clear_credentials(self):
self.source_transport.clear_credentials()
def request(self, *args, **kwargs):
return self.source_transport.request(*args, **kwargs)

View File

@@ -0,0 +1,114 @@
# Copyright 2017 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.
"""This package facilitates retries for HTTP/REST requests to the registry."""
import logging
import time
from containerregistry.transport import nested
import httplib2
import six.moves.http_client
DEFAULT_SOURCE_TRANSPORT_CALLABLE = httplib2.Http
DEFAULT_MAX_RETRIES = 2
DEFAULT_BACKOFF_FACTOR = 0.5
if six.PY3:
import builtins # pylint: disable=g-import-not-at-top,import-error
BrokenPipeError = builtins.BrokenPipeError
RETRYABLE_EXCEPTION_TYPES = [
BrokenPipeError,
six.moves.http_client.IncompleteRead,
six.moves.http_client.ResponseNotReady
]
else:
RETRYABLE_EXCEPTION_TYPES = [
six.moves.http_client.IncompleteRead,
six.moves.http_client.ResponseNotReady
]
def ShouldRetry(err):
for exception_type in RETRYABLE_EXCEPTION_TYPES:
if isinstance(err, exception_type):
return True
return False
class Factory(object):
"""A factory for creating RetryTransports."""
def __init__(self):
self.kwargs = {}
self.source_transport_callable = DEFAULT_SOURCE_TRANSPORT_CALLABLE
def WithSourceTransportCallable(self, source_transport_callable):
self.source_transport_callable = source_transport_callable
return self
def WithMaxRetries(self, max_retries):
self.kwargs['max_retries'] = max_retries
return self
def WithBackoffFactor(self, backoff_factor):
self.kwargs['backoff_factor'] = backoff_factor
return self
def WithShouldRetryFunction(self, should_retry_fn):
self.kwargs['should_retry_fn'] = should_retry_fn
return self
def Build(self):
"""Returns a RetryTransport constructed with the given values."""
return RetryTransport(self.source_transport_callable(), **self.kwargs)
class RetryTransport(nested.NestedTransport):
"""A wrapper for the given transport which automatically retries errors."""
def __init__(self,
source_transport,
max_retries = DEFAULT_MAX_RETRIES,
backoff_factor = DEFAULT_BACKOFF_FACTOR,
should_retry_fn = ShouldRetry):
super(RetryTransport, self).__init__(source_transport)
self._max_retries = max_retries
self._backoff_factor = backoff_factor
self._should_retry = should_retry_fn
def request(self, *args, **kwargs):
"""Does the request, exponentially backing off and retrying as appropriate.
Backoff is backoff_factor * (2 ^ (retry #)) seconds.
Args:
*args: The sequence of positional arguments to forward to the source
transport.
**kwargs: The keyword arguments to forward to the source transport.
Returns:
The response of the HTTP request, and its contents.
"""
retries = 0
while True:
try:
return self.source_transport.request(*args, **kwargs)
except Exception as err: # pylint: disable=broad-except
if retries >= self._max_retries or not self._should_retry(err):
raise
logging.error('Retrying after exception %s.', err)
retries += 1
time.sleep(self._backoff_factor * (2**retries))
continue

View File

@@ -0,0 +1,64 @@
# Copyright 2017 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.
"""A threadsafe pool of httplib2.Http handlers."""
from __future__ import absolute_import
from __future__ import print_function
import threading
import httplib2
from six.moves import range # pylint: disable=redefined-builtin
class Http(httplib2.Http):
"""A threadsafe pool of httplib2.Http transports."""
def __init__(self, transport_factory, size=2):
self._condition = threading.Condition(threading.Lock())
self._transports = [transport_factory() for _ in range(size)]
def _get_transport(self):
with self._condition:
while True:
if self._transports:
return self._transports.pop()
# Nothing is available, wait until it is.
# This releases the lock until a notification occurs.
self._condition.wait()
def _return_transport(self, transport):
with self._condition:
self._transports.append(transport)
# We returned an item, notify a waiting thread.
self._condition.notify(n=1)
def request(self, *args, **kwargs):
"""This awaits a transport and delegates the request call.
Args:
*args: arguments to request.
**kwargs: named arguments to request.
Returns:
tuple of response and content.
"""
transport = self._get_transport()
try:
return transport.request(*args, **kwargs)
finally:
self._return_transport(transport)