Skip to content

Commit 1c24c83

Browse files
Merge branch 'main' into v3.0.0
2 parents 151a378 + 81ca8c6 commit 1c24c83

26 files changed

+1001
-463
lines changed

.github/.OwlBot.lock.yaml

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
114
docker:
215
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
3-
digest: sha256:0e18b9475fbeb12d9ad4302283171edebb6baf2dfca1bd215ee3b34ed79d95d7
16+
digest: sha256:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6

.github/CODEOWNERS

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
# @googleapis/yoshi-python @googleapis/api-logging are the default owners for changes in this repo
99
* @googleapis/yoshi-python @googleapis/api-logging
1010

11-
# @googleapis/python-samples-owners @googleapis/api-logging are the default owners for samples changes
12-
/samples/ @googleapis/python-samples-owners @googleapis/api-logging
11+
# @googleapis/python-samples-reviewers @googleapis/api-logging are the default owners for samples changes
12+
/samples/ @googleapis/python-samples-reviewers @googleapis/api-logging

.github/auto-label.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
product: true
2+
requestsize:
3+
enabled: true
4+
staleness:
5+
pullrequest: true
6+
old: 30
7+
extraold: 60

.github/release-please.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
releaseType: python
2+
handleGHRelease: true

.github/release-trigger.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enabled: true

.github/sync-repo-settings.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ branchProtectionRules:
1010
- 'Kokoro'
1111
- 'cla/google'
1212
- 'Samples - Lint'
13-
- 'Samples - Python 3.6'
1413
- 'Samples - Python 3.7'
1514
- 'Samples - Python 3.8'

.kokoro/release.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools
2626
export PYTHONUNBUFFERED=1
2727

2828
# Move into the package, build the distribution and upload.
29-
TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token")
29+
TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-pypi-token-keystore-1")
3030
cd github/python-logging
3131
python3 setup.py sdist bdist_wheel
3232
twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/*

.kokoro/release/common.cfg

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@ env_vars: {
2323
value: "github/python-logging/.kokoro/release.sh"
2424
}
2525

26+
# Fetch PyPI password
27+
before_action {
28+
fetch_keystore {
29+
keystore_resource {
30+
keystore_config_id: 73713
31+
keyname: "google-cloud-pypi-token-keystore-1"
32+
}
33+
}
34+
}
35+
2636
# Tokens needed to report release status back to GitHub
2737
env_vars: {
2838
key: "SECRET_MANAGER_KEYS"
29-
value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token"
39+
value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem"
3040
}

.repo-metadata.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
"name": "logging",
33
"name_pretty": "Cloud Logging",
44
"product_documentation": "https://cloud.google.com/logging/docs",
5-
"client_documentation": "https://googleapis.dev/python/logging/latest",
5+
"client_documentation": "https://cloud.google.com/python/docs/reference/logging/latest",
66
"issue_tracker": "https://issuetracker.google.com/savedsearches/559764",
7-
"release_level": "ga",
7+
"release_level": "stable",
88
"language": "python",
99
"library_type": "GAPIC_COMBO",
1010
"repo": "googleapis/python-logging",
1111
"distribution_name": "google-cloud-logging",
1212
"api_id": "logging.googleapis.com",
1313
"codeowner_team": "@googleapis/api-logging",
14-
"default_version": "v2"
14+
"default_version": "v2",
15+
"api_shortname": "logging"
1516
}

google/cloud/logging_v2/services/config_service_v2/async_client.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from collections import OrderedDict
1717
import functools
1818
import re
19-
from typing import Dict, Sequence, Tuple, Type, Union
19+
from typing import Dict, Optional, Sequence, Tuple, Type, Union
2020
import pkg_resources
2121

2222
from google.api_core.client_options import ClientOptions
@@ -120,6 +120,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
120120

121121
from_service_account_json = from_service_account_file
122122

123+
@classmethod
124+
def get_mtls_endpoint_and_cert_source(
125+
cls, client_options: Optional[ClientOptions] = None
126+
):
127+
"""Return the API endpoint and client cert source for mutual TLS.
128+
129+
The client cert source is determined in the following order:
130+
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
131+
client cert source is None.
132+
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
133+
default client cert source exists, use the default one; otherwise the client cert
134+
source is None.
135+
136+
The API endpoint is determined in the following order:
137+
(1) if `client_options.api_endpoint` if provided, use the provided one.
138+
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
139+
default mTLS endpoint; if the environment variabel is "never", use the default API
140+
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
141+
use the default API endpoint.
142+
143+
More details can be found at https://google.aip.dev/auth/4114.
144+
145+
Args:
146+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
147+
client. Only the `api_endpoint` and `client_cert_source` properties may be used
148+
in this method.
149+
150+
Returns:
151+
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
152+
client cert source to use.
153+
154+
Raises:
155+
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
156+
"""
157+
return ConfigServiceV2Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
158+
123159
@property
124160
def transport(self) -> ConfigServiceV2Transport:
125161
"""Returns the transport used by the client instance.

google/cloud/logging_v2/services/config_service_v2/client.py

+84-43
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]:
287287
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
288288
return m.groupdict() if m else {}
289289

290+
@classmethod
291+
def get_mtls_endpoint_and_cert_source(
292+
cls, client_options: Optional[client_options_lib.ClientOptions] = None
293+
):
294+
"""Return the API endpoint and client cert source for mutual TLS.
295+
296+
The client cert source is determined in the following order:
297+
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
298+
client cert source is None.
299+
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
300+
default client cert source exists, use the default one; otherwise the client cert
301+
source is None.
302+
303+
The API endpoint is determined in the following order:
304+
(1) if `client_options.api_endpoint` if provided, use the provided one.
305+
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
306+
default mTLS endpoint; if the environment variabel is "never", use the default API
307+
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
308+
use the default API endpoint.
309+
310+
More details can be found at https://google.aip.dev/auth/4114.
311+
312+
Args:
313+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
314+
client. Only the `api_endpoint` and `client_cert_source` properties may be used
315+
in this method.
316+
317+
Returns:
318+
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
319+
client cert source to use.
320+
321+
Raises:
322+
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
323+
"""
324+
if client_options is None:
325+
client_options = client_options_lib.ClientOptions()
326+
use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
327+
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
328+
if use_client_cert not in ("true", "false"):
329+
raise ValueError(
330+
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
331+
)
332+
if use_mtls_endpoint not in ("auto", "never", "always"):
333+
raise MutualTLSChannelError(
334+
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
335+
)
336+
337+
# Figure out the client cert source to use.
338+
client_cert_source = None
339+
if use_client_cert == "true":
340+
if client_options.client_cert_source:
341+
client_cert_source = client_options.client_cert_source
342+
elif mtls.has_default_client_cert_source():
343+
client_cert_source = mtls.default_client_cert_source()
344+
345+
# Figure out which api endpoint to use.
346+
if client_options.api_endpoint is not None:
347+
api_endpoint = client_options.api_endpoint
348+
elif use_mtls_endpoint == "always" or (
349+
use_mtls_endpoint == "auto" and client_cert_source
350+
):
351+
api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
352+
else:
353+
api_endpoint = cls.DEFAULT_ENDPOINT
354+
355+
return api_endpoint, client_cert_source
356+
290357
def __init__(
291358
self,
292359
*,
@@ -337,57 +404,22 @@ def __init__(
337404
if client_options is None:
338405
client_options = client_options_lib.ClientOptions()
339406

340-
# Create SSL credentials for mutual TLS if needed.
341-
if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in (
342-
"true",
343-
"false",
344-
):
345-
raise ValueError(
346-
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
347-
)
348-
use_client_cert = (
349-
os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true"
407+
api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source(
408+
client_options
350409
)
351410

352-
client_cert_source_func = None
353-
is_mtls = False
354-
if use_client_cert:
355-
if client_options.client_cert_source:
356-
is_mtls = True
357-
client_cert_source_func = client_options.client_cert_source
358-
else:
359-
is_mtls = mtls.has_default_client_cert_source()
360-
if is_mtls:
361-
client_cert_source_func = mtls.default_client_cert_source()
362-
else:
363-
client_cert_source_func = None
364-
365-
# Figure out which api endpoint to use.
366-
if client_options.api_endpoint is not None:
367-
api_endpoint = client_options.api_endpoint
368-
else:
369-
use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
370-
if use_mtls_env == "never":
371-
api_endpoint = self.DEFAULT_ENDPOINT
372-
elif use_mtls_env == "always":
373-
api_endpoint = self.DEFAULT_MTLS_ENDPOINT
374-
elif use_mtls_env == "auto":
375-
if is_mtls:
376-
api_endpoint = self.DEFAULT_MTLS_ENDPOINT
377-
else:
378-
api_endpoint = self.DEFAULT_ENDPOINT
379-
else:
380-
raise MutualTLSChannelError(
381-
"Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted "
382-
"values: never, auto, always"
383-
)
411+
api_key_value = getattr(client_options, "api_key", None)
412+
if api_key_value and credentials:
413+
raise ValueError(
414+
"client_options.api_key and credentials are mutually exclusive"
415+
)
384416

385417
# Save or instantiate the transport.
386418
# Ordinarily, we provide the transport, but allowing a custom transport
387419
# instance provides an extensibility point for unusual situations.
388420
if isinstance(transport, ConfigServiceV2Transport):
389421
# transport is a ConfigServiceV2Transport instance.
390-
if credentials or client_options.credentials_file:
422+
if credentials or client_options.credentials_file or api_key_value:
391423
raise ValueError(
392424
"When providing a transport instance, "
393425
"provide its credentials directly."
@@ -399,6 +431,15 @@ def __init__(
399431
)
400432
self._transport = transport
401433
else:
434+
import google.auth._default # type: ignore
435+
436+
if api_key_value and hasattr(
437+
google.auth._default, "get_api_key_credentials"
438+
):
439+
credentials = google.auth._default.get_api_key_credentials(
440+
api_key_value
441+
)
442+
402443
Transport = type(self).get_transport_class(transport)
403444
self._transport = Transport(
404445
credentials=credentials,

google/cloud/logging_v2/services/config_service_v2/transports/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def __init__(
105105
credentials, _ = google.auth.load_credentials_from_file(
106106
credentials_file, **scopes_kwargs, quota_project_id=quota_project_id
107107
)
108-
109108
elif credentials is None:
110109
credentials, _ = google.auth.default(
111110
**scopes_kwargs, quota_project_id=quota_project_id

google/cloud/logging_v2/services/logging_service_v2/async_client.py

+37
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import re
1919
from typing import (
2020
Dict,
21+
Optional,
2122
AsyncIterable,
2223
Awaitable,
2324
AsyncIterator,
@@ -117,6 +118,42 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
117118

118119
from_service_account_json = from_service_account_file
119120

121+
@classmethod
122+
def get_mtls_endpoint_and_cert_source(
123+
cls, client_options: Optional[ClientOptions] = None
124+
):
125+
"""Return the API endpoint and client cert source for mutual TLS.
126+
127+
The client cert source is determined in the following order:
128+
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
129+
client cert source is None.
130+
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
131+
default client cert source exists, use the default one; otherwise the client cert
132+
source is None.
133+
134+
The API endpoint is determined in the following order:
135+
(1) if `client_options.api_endpoint` if provided, use the provided one.
136+
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
137+
default mTLS endpoint; if the environment variabel is "never", use the default API
138+
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
139+
use the default API endpoint.
140+
141+
More details can be found at https://google.aip.dev/auth/4114.
142+
143+
Args:
144+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
145+
client. Only the `api_endpoint` and `client_cert_source` properties may be used
146+
in this method.
147+
148+
Returns:
149+
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
150+
client cert source to use.
151+
152+
Raises:
153+
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
154+
"""
155+
return LoggingServiceV2Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
156+
120157
@property
121158
def transport(self) -> LoggingServiceV2Transport:
122159
"""Returns the transport used by the client instance.

0 commit comments

Comments
 (0)