Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit edb1e0f

Browse files
feat: add state field in resources (#8)
* chore: upgrade gapic-generator-python to 0.40.5 PiperOrigin-RevId: 354996675 Source-Author: Google APIs <noreply@google.com> Source-Date: Mon Feb 1 12:11:49 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 20712b8fe95001b312f62c6c5f33e3e3ec92cfaf Source-Link: googleapis/googleapis@20712b8 * feat: Add state field in resources PiperOrigin-RevId: 355488930 Source-Author: Google APIs <noreply@google.com> Source-Date: Wed Feb 3 14:55:32 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 5e27c5cafe0952f50ff81552526b3e3d333ef2c3 Source-Link: googleapis/googleapis@5e27c5c * chore: update gapic-generator-python PiperOrigin-RevId: 355923884 Source-Author: Google APIs <noreply@google.com> Source-Date: Fri Feb 5 14:04:52 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 5e3dacee19405529b841b53797df799c2383536c Source-Link: googleapis/googleapis@5e3dace * chore(python): include py.typed files in release A py.typed file must be included in the released package for it to be considered typed by type checkers. https://www.python.org/dev/peps/pep-0561/#packaging-type-information. See googleapis/python-secret-manager#79 Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Source-Date: Fri Feb 5 17:32:06 2021 -0700 Source-Repo: googleapis/synthtool Source-Sha: 33366574ffb9e11737b3547eb6f020ecae0536e8 Source-Link: googleapis/synthtool@3336657 * docs: update python contributing guide Adds details about blacken, updates version for system tests, and shows how to pass through pytest arguments. Source-Author: Chris Cotter <cjcotter@google.com> Source-Date: Mon Feb 8 17:13:36 2021 -0500 Source-Repo: googleapis/synthtool Source-Sha: 4679e7e415221f03ff2a71e3ffad75b9ec41d87e Source-Link: googleapis/synthtool@4679e7e * build(python): enable flakybot on library unit and system tests Source-Author: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Source-Date: Wed Feb 17 14:10:46 2021 -0700 Source-Repo: googleapis/synthtool Source-Sha: d17674372e27fb8f23013935e794aa37502071aa Source-Link: googleapis/synthtool@d176743 Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
1 parent b122347 commit edb1e0f

File tree

16 files changed

+290
-156
lines changed

16 files changed

+290
-156
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ docs.metadata
5050

5151
# Virtual environment
5252
env/
53+
54+
# Test logs
5355
coverage.xml
54-
sponge_log.xml
56+
*sponge_log.xml
5557

5658
# System test environment variables.
5759
system_tests/local_test_setup

.kokoro/build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ python3 -m pip uninstall --yes --quiet nox-automation
4040
python3 -m pip install --upgrade --quiet nox
4141
python3 -m nox --version
4242

43+
# If this is a continuous build, send the test log to the FlakyBot.
44+
# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot.
45+
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then
46+
cleanup() {
47+
chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot
48+
$KOKORO_GFILE_DIR/linux_amd64/flakybot
49+
}
50+
trap cleanup EXIT HUP
51+
fi
52+
4353
# If NOX_SESSION is set, it only runs the specified session,
4454
# otherwise run all the sessions.
4555
if [[ -n "${NOX_SESSION:-}" ]]; then

CONTRIBUTING.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ We use `nox <https://nox.readthedocs.io/en/latest/>`__ to instrument our tests.
7070
- To test your changes, run unit tests with ``nox``::
7171

7272
$ nox -s unit-2.7
73-
$ nox -s unit-3.7
73+
$ nox -s unit-3.8
7474
$ ...
7575

76+
- Args to pytest can be passed through the nox command separated by a `--`. For
77+
example, to run a single test::
78+
79+
$ nox -s unit-3.8 -- -k <name of test>
80+
7681
.. note::
7782

7883
The unit tests and system tests are described in the
@@ -93,8 +98,12 @@ On Debian/Ubuntu::
9398
************
9499
Coding Style
95100
************
101+
- We use the automatic code formatter ``black``. You can run it using
102+
the nox session ``blacken``. This will eliminate many lint errors. Run via::
103+
104+
$ nox -s blacken
96105

97-
- PEP8 compliance, with exceptions defined in the linter configuration.
106+
- PEP8 compliance is required, with exceptions defined in the linter configuration.
98107
If you have ``nox`` installed, you can test that you have not introduced
99108
any non-compliant code via::
100109

@@ -133,13 +142,18 @@ Running System Tests
133142

134143
- To run system tests, you can execute::
135144

136-
$ nox -s system-3.7
145+
# Run all system tests
146+
$ nox -s system-3.8
137147
$ nox -s system-2.7
138148

149+
# Run a single system test
150+
$ nox -s system-3.8 -- -k <name of test>
151+
152+
139153
.. note::
140154

141155
System tests are only configured to run under Python 2.7 and
142-
Python 3.7. For expediency, we do not run them in older versions
156+
Python 3.8. For expediency, we do not run them in older versions
143157
of Python 3.
144158

145159
This alone will not run the tests. You'll need to change some local

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
# Generated by synthtool. DO NOT EDIT!
1818
include README.rst LICENSE
19-
recursive-include google *.json *.proto
19+
recursive-include google *.json *.proto py.typed
2020
recursive-include tests *
2121
global-exclude *.py[co]
2222
global-exclude __pycache__
2323

2424
# Exclude scripts for samples readmegen
25-
prune scripts/readme-gen
25+
prune scripts/readme-gen

google/cloud/networkconnectivity/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from google.cloud.networkconnectivity_v1alpha1.types.hub import ListSpokesResponse
3636
from google.cloud.networkconnectivity_v1alpha1.types.hub import RouterApplianceInstance
3737
from google.cloud.networkconnectivity_v1alpha1.types.hub import Spoke
38+
from google.cloud.networkconnectivity_v1alpha1.types.hub import State
3839
from google.cloud.networkconnectivity_v1alpha1.types.hub import UpdateHubRequest
3940
from google.cloud.networkconnectivity_v1alpha1.types.hub import UpdateSpokeRequest
4041

@@ -55,6 +56,7 @@
5556
"OperationMetadata",
5657
"RouterApplianceInstance",
5758
"Spoke",
59+
"State",
5860
"UpdateHubRequest",
5961
"UpdateSpokeRequest",
6062
)

google/cloud/networkconnectivity_v1alpha1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .types.hub import ListSpokesResponse
3131
from .types.hub import RouterApplianceInstance
3232
from .types.hub import Spoke
33+
from .types.hub import State
3334
from .types.hub import UpdateHubRequest
3435
from .types.hub import UpdateSpokeRequest
3536

@@ -49,6 +50,7 @@
4950
"OperationMetadata",
5051
"RouterApplianceInstance",
5152
"Spoke",
53+
"State",
5254
"UpdateHubRequest",
5355
"UpdateSpokeRequest",
5456
"HubServiceClient",

google/cloud/networkconnectivity_v1alpha1/services/hub_service/async_client.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444

4545

4646
class HubServiceAsyncClient:
47-
"""Connectivity Hub is a hub-and-spoke abstraction for network
48-
connectivity management in Google Cloud. The Hub aims to reduce
47+
"""Network Connectivity Center is a hub-and-spoke abstraction
48+
for network connectivity management in Google Cloud. It reduces
4949
operational complexity through a simple, centralized
5050
connectivity management model.
5151
"""
@@ -272,13 +272,13 @@ async def get_hub(
272272
273273
Returns:
274274
google.cloud.networkconnectivity_v1alpha1.types.Hub:
275-
The Connectivity Hub is a hub-and-
276-
poke abstraction for network
275+
Network Connectivity Center is a hub-
276+
nd-spoke abstraction for network
277277
connectivity management in Google Cloud.
278-
It aims to reduce operational complexity
278+
It reduces operational complexity
279279
through a simple, centralized
280-
connectivity management model. Here is
281-
the resource message of a Hub.
280+
connectivity management model. Following
281+
is the resource message of a hub.
282282
283283
"""
284284
# Create or coerce a protobuf request object.
@@ -369,11 +369,11 @@ async def create_hub(
369369
google.api_core.operation_async.AsyncOperation:
370370
An object representing a long-running operation.
371371
372-
The result type for the operation will be :class:`google.cloud.networkconnectivity_v1alpha1.types.Hub` The Connectivity Hub is a hub-and-spoke abstraction for network connectivity
373-
management in Google Cloud. It aims to reduce
374-
operational complexity through a simple, centralized
375-
connectivity management model. Here is the resource
376-
message of a Hub.
372+
The result type for the operation will be :class:`google.cloud.networkconnectivity_v1alpha1.types.Hub` Network Connectivity Center is a hub-and-spoke abstraction for
373+
network connectivity management in Google Cloud. It
374+
reduces operational complexity through a simple,
375+
centralized connectivity management model. Following
376+
is the resource message of a hub.
377377
378378
"""
379379
# Create or coerce a protobuf request object.
@@ -472,11 +472,11 @@ async def update_hub(
472472
google.api_core.operation_async.AsyncOperation:
473473
An object representing a long-running operation.
474474
475-
The result type for the operation will be :class:`google.cloud.networkconnectivity_v1alpha1.types.Hub` The Connectivity Hub is a hub-and-spoke abstraction for network connectivity
476-
management in Google Cloud. It aims to reduce
477-
operational complexity through a simple, centralized
478-
connectivity management model. Here is the resource
479-
message of a Hub.
475+
The result type for the operation will be :class:`google.cloud.networkconnectivity_v1alpha1.types.Hub` Network Connectivity Center is a hub-and-spoke abstraction for
476+
network connectivity management in Google Cloud. It
477+
reduces operational complexity through a simple,
478+
centralized connectivity management model. Following
479+
is the resource message of a hub.
480480
481481
"""
482482
# Create or coerce a protobuf request object.

google/cloud/networkconnectivity_v1alpha1/services/hub_service/client.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def get_transport_class(cls, label: str = None,) -> Type[HubServiceTransport]:
7979

8080

8181
class HubServiceClient(metaclass=HubServiceClientMeta):
82-
"""Connectivity Hub is a hub-and-spoke abstraction for network
83-
connectivity management in Google Cloud. The Hub aims to reduce
82+
"""Network Connectivity Center is a hub-and-spoke abstraction
83+
for network connectivity management in Google Cloud. It reduces
8484
operational complexity through a simple, centralized
8585
connectivity management model.
8686
"""
@@ -359,21 +359,17 @@ def __init__(
359359
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
360360
)
361361

362-
ssl_credentials = None
362+
client_cert_source_func = None
363363
is_mtls = False
364364
if use_client_cert:
365365
if client_options.client_cert_source:
366-
import grpc # type: ignore
367-
368-
cert, key = client_options.client_cert_source()
369-
ssl_credentials = grpc.ssl_channel_credentials(
370-
certificate_chain=cert, private_key=key
371-
)
372366
is_mtls = True
367+
client_cert_source_func = client_options.client_cert_source
373368
else:
374-
creds = SslCredentials()
375-
is_mtls = creds.is_mtls
376-
ssl_credentials = creds.ssl_credentials if is_mtls else None
369+
is_mtls = mtls.has_default_client_cert_source()
370+
client_cert_source_func = (
371+
mtls.default_client_cert_source() if is_mtls else None
372+
)
377373

378374
# Figure out which api endpoint to use.
379375
if client_options.api_endpoint is not None:
@@ -416,7 +412,7 @@ def __init__(
416412
credentials_file=client_options.credentials_file,
417413
host=api_endpoint,
418414
scopes=client_options.scopes,
419-
ssl_channel_credentials=ssl_credentials,
415+
client_cert_source_for_mtls=client_cert_source_func,
420416
quota_project_id=client_options.quota_project_id,
421417
client_info=client_info,
422418
)
@@ -536,13 +532,13 @@ def get_hub(
536532
537533
Returns:
538534
google.cloud.networkconnectivity_v1alpha1.types.Hub:
539-
The Connectivity Hub is a hub-and-
540-
poke abstraction for network
535+
Network Connectivity Center is a hub-
536+
nd-spoke abstraction for network
541537
connectivity management in Google Cloud.
542-
It aims to reduce operational complexity
538+
It reduces operational complexity
543539
through a simple, centralized
544-
connectivity management model. Here is
545-
the resource message of a Hub.
540+
connectivity management model. Following
541+
is the resource message of a hub.
546542
547543
"""
548544
# Create or coerce a protobuf request object.
@@ -634,11 +630,11 @@ def create_hub(
634630
google.api_core.operation.Operation:
635631
An object representing a long-running operation.
636632
637-
The result type for the operation will be :class:`google.cloud.networkconnectivity_v1alpha1.types.Hub` The Connectivity Hub is a hub-and-spoke abstraction for network connectivity
638-
management in Google Cloud. It aims to reduce
639-
operational complexity through a simple, centralized
640-
connectivity management model. Here is the resource
641-
message of a Hub.
633+
The result type for the operation will be :class:`google.cloud.networkconnectivity_v1alpha1.types.Hub` Network Connectivity Center is a hub-and-spoke abstraction for
634+
network connectivity management in Google Cloud. It
635+
reduces operational complexity through a simple,
636+
centralized connectivity management model. Following
637+
is the resource message of a hub.
642638
643639
"""
644640
# Create or coerce a protobuf request object.
@@ -738,11 +734,11 @@ def update_hub(
738734
google.api_core.operation.Operation:
739735
An object representing a long-running operation.
740736
741-
The result type for the operation will be :class:`google.cloud.networkconnectivity_v1alpha1.types.Hub` The Connectivity Hub is a hub-and-spoke abstraction for network connectivity
742-
management in Google Cloud. It aims to reduce
743-
operational complexity through a simple, centralized
744-
connectivity management model. Here is the resource
745-
message of a Hub.
737+
The result type for the operation will be :class:`google.cloud.networkconnectivity_v1alpha1.types.Hub` Network Connectivity Center is a hub-and-spoke abstraction for
738+
network connectivity management in Google Cloud. It
739+
reduces operational complexity through a simple,
740+
centralized connectivity management model. Following
741+
is the resource message of a hub.
746742
747743
"""
748744
# Create or coerce a protobuf request object.

google/cloud/networkconnectivity_v1alpha1/services/hub_service/pagers.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
# limitations under the License.
1616
#
1717

18-
from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple
18+
from typing import (
19+
Any,
20+
AsyncIterable,
21+
Awaitable,
22+
Callable,
23+
Iterable,
24+
Sequence,
25+
Tuple,
26+
Optional,
27+
)
1928

2029
from google.cloud.networkconnectivity_v1alpha1.types import hub
2130

google/cloud/networkconnectivity_v1alpha1/services/hub_service/transports/grpc.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
class HubServiceGrpcTransport(HubServiceTransport):
3838
"""gRPC backend transport for HubService.
3939
40-
Connectivity Hub is a hub-and-spoke abstraction for network
41-
connectivity management in Google Cloud. The Hub aims to reduce
40+
Network Connectivity Center is a hub-and-spoke abstraction
41+
for network connectivity management in Google Cloud. It reduces
4242
operational complexity through a simple, centralized
4343
connectivity management model.
4444
@@ -63,6 +63,7 @@ def __init__(
6363
api_mtls_endpoint: str = None,
6464
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
6565
ssl_channel_credentials: grpc.ChannelCredentials = None,
66+
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6667
quota_project_id: Optional[str] = None,
6768
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
6869
) -> None:
@@ -93,6 +94,10 @@ def __init__(
9394
``api_mtls_endpoint`` is None.
9495
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
9596
for grpc channel. It is ignored if ``channel`` is provided.
97+
client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
98+
A callback to provide client certificate bytes and private key bytes,
99+
both in PEM format. It is used to configure mutual TLS channel. It is
100+
ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
96101
quota_project_id (Optional[str]): An optional project to use for billing
97102
and quota.
98103
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
@@ -109,6 +114,11 @@ def __init__(
109114
"""
110115
self._ssl_channel_credentials = ssl_channel_credentials
111116

117+
if api_mtls_endpoint:
118+
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
119+
if client_cert_source:
120+
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
121+
112122
if channel:
113123
# Sanity check: Ensure that channel and credentials are not both
114124
# provided.
@@ -118,11 +128,6 @@ def __init__(
118128
self._grpc_channel = channel
119129
self._ssl_channel_credentials = None
120130
elif api_mtls_endpoint:
121-
warnings.warn(
122-
"api_mtls_endpoint and client_cert_source are deprecated",
123-
DeprecationWarning,
124-
)
125-
126131
host = (
127132
api_mtls_endpoint
128133
if ":" in api_mtls_endpoint
@@ -166,12 +171,18 @@ def __init__(
166171
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
167172
)
168173

174+
if client_cert_source_for_mtls and not ssl_channel_credentials:
175+
cert, key = client_cert_source_for_mtls()
176+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
177+
certificate_chain=cert, private_key=key
178+
)
179+
169180
# create a new channel. The provided one is ignored.
170181
self._grpc_channel = type(self).create_channel(
171182
host,
172183
credentials=credentials,
173184
credentials_file=credentials_file,
174-
ssl_credentials=ssl_channel_credentials,
185+
ssl_credentials=self._ssl_channel_credentials,
175186
scopes=scopes or self.AUTH_SCOPES,
176187
quota_project_id=quota_project_id,
177188
options=[

0 commit comments

Comments
 (0)