Skip to content

Commit c9b51e8

Browse files
feat: add from_service_account_info factory and fix sphinx identifiers (#46)
feat: add 'from_service_account_info' factory to clients fix: fix sphinx identifiers PiperOrigin-RevId: 350246057 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue Jan 5 16:44:11 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 520682435235d9c503983a360a2090025aa47cd1 Source-Link: googleapis/googleapis@5206824
1 parent fd3df42 commit c9b51e8

8 files changed

Lines changed: 75 additions & 44 deletions

File tree

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Copyright 2020 Google LLC
4-
#
5-
# Licensed under the Apache License, Version 2.0 (the "License");
6-
# you may not use this file except in compliance with the License.
7-
# You may obtain a copy of the License at
8-
#
9-
# https://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing, software
12-
# distributed under the License is distributed on an "AS IS" BASIS,
13-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
# See the License for the specific language governing permissions and
15-
# limitations under the License.
16-
17-
# Generated by synthtool. DO NOT EDIT!
181
[run]
192
branch = True
203

214
[report]
225
fail_under = 100
236
show_missing = True
7+
omit =
8+
google/cloud/phishingprotection/__init__.py
249
exclude_lines =
2510
# Re-enable the standard pragma
2611
pragma: NO COVER
2712
# Ignore debug-only repr
2813
def __repr__
29-
# Ignore abstract methods
30-
raise NotImplementedError
31-
omit =
32-
*/gapic/*.py
33-
*/proto/*.py
34-
*/core/*.py
35-
*/site-packages/*.py
14+
# Ignore pkg_resources exceptions.
15+
# This is added at the module level as a safeguard for if someone
16+
# generates the code and tries to run it without pip installing. This
17+
# makes it virtually impossible to test properly.
18+
except pkg_resources.DistributionNotFound
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PhishingProtectionServiceV1Beta1
2+
--------------------------------------------------
3+
4+
.. automodule:: google.cloud.phishingprotection_v1beta1.services.phishing_protection_service_v1_beta1
5+
:members:
6+
:inherited-members:
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Services for Google Cloud Phishingprotection v1beta1 API
22
========================================================
3+
.. toctree::
4+
:maxdepth: 2
35

4-
.. automodule:: google.cloud.phishingprotection_v1beta1.services.phishing_protection_service_v1_beta1
5-
:members:
6-
:inherited-members:
6+
phishing_protection_service_v1_beta1

packages/google-cloud-phishing-protection/docs/phishingprotection_v1beta1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Types for Google Cloud Phishingprotection v1beta1 API
33

44
.. automodule:: google.cloud.phishingprotection_v1beta1.types
55
:members:
6+
:undoc-members:
67
:show-inheritance:

packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/async_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class PhishingProtectionServiceV1Beta1AsyncClient:
8383
PhishingProtectionServiceV1Beta1Client.parse_common_location_path
8484
)
8585

86+
from_service_account_info = (
87+
PhishingProtectionServiceV1Beta1Client.from_service_account_info
88+
)
8689
from_service_account_file = (
8790
PhishingProtectionServiceV1Beta1Client.from_service_account_file
8891
)
@@ -173,19 +176,21 @@ async def report_phishing(
173176
in the future.
174177
175178
Args:
176-
request (:class:`~.phishingprotection.ReportPhishingRequest`):
179+
request (:class:`google.cloud.phishingprotection_v1beta1.types.ReportPhishingRequest`):
177180
The request object. The ReportPhishing request message.
178181
parent (:class:`str`):
179182
Required. The name of the project for which the report
180183
will be created, in the format
181184
"projects/{project_number}".
185+
182186
This corresponds to the ``parent`` field
183187
on the ``request`` instance; if ``request`` is provided, this
184188
should not be set.
185189
uri (:class:`str`):
186190
Required. The URI that is being
187191
reported for phishing content to be
188192
analyzed.
193+
189194
This corresponds to the ``uri`` field
190195
on the ``request`` instance; if ``request`` is provided, this
191196
should not be set.
@@ -197,7 +202,7 @@ async def report_phishing(
197202
sent along with the request as metadata.
198203
199204
Returns:
200-
~.phishingprotection.ReportPhishingResponse:
205+
google.cloud.phishingprotection_v1beta1.types.ReportPhishingResponse:
201206
The ReportPhishing (empty) response
202207
message.
203208

packages/google-cloud-phishing-protection/google/cloud/phishingprotection_v1beta1/services/phishing_protection_service_v1_beta1/client.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ def _get_default_mtls_endpoint(api_endpoint):
120120
DEFAULT_ENDPOINT
121121
)
122122

123+
@classmethod
124+
def from_service_account_info(cls, info: dict, *args, **kwargs):
125+
"""Creates an instance of this client using the provided credentials info.
126+
127+
Args:
128+
info (dict): The service account private key info.
129+
args: Additional arguments to pass to the constructor.
130+
kwargs: Additional arguments to pass to the constructor.
131+
132+
Returns:
133+
PhishingProtectionServiceV1Beta1Client: The constructed client.
134+
"""
135+
credentials = service_account.Credentials.from_service_account_info(info)
136+
kwargs["credentials"] = credentials
137+
return cls(*args, **kwargs)
138+
123139
@classmethod
124140
def from_service_account_file(cls, filename: str, *args, **kwargs):
125141
"""Creates an instance of this client using the provided credentials
@@ -132,7 +148,7 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
132148
kwargs: Additional arguments to pass to the constructor.
133149
134150
Returns:
135-
{@api.name}: The constructed client.
151+
PhishingProtectionServiceV1Beta1Client: The constructed client.
136152
"""
137153
credentials = service_account.Credentials.from_service_account_file(filename)
138154
kwargs["credentials"] = credentials
@@ -224,10 +240,10 @@ def __init__(
224240
credentials identify the application to the service; if none
225241
are specified, the client will attempt to ascertain the
226242
credentials from the environment.
227-
transport (Union[str, ~.PhishingProtectionServiceV1Beta1Transport]): The
243+
transport (Union[str, PhishingProtectionServiceV1Beta1Transport]): The
228244
transport to use. If set to None, a transport is chosen
229245
automatically.
230-
client_options (client_options_lib.ClientOptions): Custom options for the
246+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
231247
client. It won't take effect if a ``transport`` instance is provided.
232248
(1) The ``api_endpoint`` property can be used to override the
233249
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
@@ -346,19 +362,21 @@ def report_phishing(
346362
in the future.
347363
348364
Args:
349-
request (:class:`~.phishingprotection.ReportPhishingRequest`):
365+
request (google.cloud.phishingprotection_v1beta1.types.ReportPhishingRequest):
350366
The request object. The ReportPhishing request message.
351-
parent (:class:`str`):
367+
parent (str):
352368
Required. The name of the project for which the report
353369
will be created, in the format
354370
"projects/{project_number}".
371+
355372
This corresponds to the ``parent`` field
356373
on the ``request`` instance; if ``request`` is provided, this
357374
should not be set.
358-
uri (:class:`str`):
375+
uri (str):
359376
Required. The URI that is being
360377
reported for phishing content to be
361378
analyzed.
379+
362380
This corresponds to the ``uri`` field
363381
on the ``request`` instance; if ``request`` is provided, this
364382
should not be set.
@@ -370,7 +388,7 @@ def report_phishing(
370388
sent along with the request as metadata.
371389
372390
Returns:
373-
~.phishingprotection.ReportPhishingResponse:
391+
google.cloud.phishingprotection_v1beta1.types.ReportPhishingResponse:
374392
The ReportPhishing (empty) response
375393
message.
376394

packages/google-cloud-phishing-protection/synth.metadata

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"git": {
55
"name": ".",
66
"remote": "https://github.com/googleapis/python-phishingprotection.git",
7-
"sha": "e587e30187c88b252664a0f39d1860cc9eed98ea"
7+
"sha": "43b38b5e2001d22318ac2e5152d1ceeb38e28b3b"
88
}
99
},
1010
{
1111
"git": {
1212
"name": "googleapis",
1313
"remote": "https://github.com/googleapis/googleapis.git",
14-
"sha": "dd372aa22ded7a8ba6f0e03a80e06358a3fa0907",
15-
"internalRef": "347055288"
14+
"sha": "520682435235d9c503983a360a2090025aa47cd1",
15+
"internalRef": "350246057"
1616
}
1717
},
1818
{
@@ -35,6 +35,7 @@
3535
}
3636
],
3737
"generatedFiles": [
38+
".coveragerc",
3839
".flake8",
3940
".github/CONTRIBUTING.md",
4041
".github/ISSUE_TEMPLATE/bug_report.md",
@@ -88,6 +89,7 @@
8889
"docs/_templates/layout.html",
8990
"docs/conf.py",
9091
"docs/multiprocessing.rst",
92+
"docs/phishingprotection_v1beta1/phishing_protection_service_v1_beta1.rst",
9193
"docs/phishingprotection_v1beta1/services.rst",
9294
"docs/phishingprotection_v1beta1/types.rst",
9395
"google/cloud/phishingprotection/__init__.py",

packages/google-cloud-phishing-protection/tests/unit/gapic/phishingprotection_v1beta1/test_phishing_protection_service_v1_beta1.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ def test__get_default_mtls_endpoint():
9898
)
9999

100100

101+
def test_phishing_protection_service_v1_beta1_client_from_service_account_info():
102+
creds = credentials.AnonymousCredentials()
103+
with mock.patch.object(
104+
service_account.Credentials, "from_service_account_info"
105+
) as factory:
106+
factory.return_value = creds
107+
info = {"valid": True}
108+
client = PhishingProtectionServiceV1Beta1Client.from_service_account_info(info)
109+
assert client.transport._credentials == creds
110+
111+
assert client.transport._host == "phishingprotection.googleapis.com:443"
112+
113+
101114
@pytest.mark.parametrize(
102115
"client_class",
103116
[
@@ -124,7 +137,10 @@ def test_phishing_protection_service_v1_beta1_client_from_service_account_file(
124137

125138
def test_phishing_protection_service_v1_beta1_client_get_transport_class():
126139
transport = PhishingProtectionServiceV1Beta1Client.get_transport_class()
127-
assert transport == transports.PhishingProtectionServiceV1Beta1GrpcTransport
140+
available_transports = [
141+
transports.PhishingProtectionServiceV1Beta1GrpcTransport,
142+
]
143+
assert transport in available_transports
128144

129145
transport = PhishingProtectionServiceV1Beta1Client.get_transport_class("grpc")
130146
assert transport == transports.PhishingProtectionServiceV1Beta1GrpcTransport
@@ -875,7 +891,7 @@ def test_phishing_protection_service_v1_beta1_host_with_port():
875891

876892

877893
def test_phishing_protection_service_v1_beta1_grpc_transport_channel():
878-
channel = grpc.insecure_channel("http://localhost/")
894+
channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials())
879895

880896
# Check that channel is used if provided.
881897
transport = transports.PhishingProtectionServiceV1Beta1GrpcTransport(
@@ -887,7 +903,7 @@ def test_phishing_protection_service_v1_beta1_grpc_transport_channel():
887903

888904

889905
def test_phishing_protection_service_v1_beta1_grpc_asyncio_transport_channel():
890-
channel = aio.insecure_channel("http://localhost/")
906+
channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials())
891907

892908
# Check that channel is used if provided.
893909
transport = transports.PhishingProtectionServiceV1Beta1GrpcAsyncIOTransport(
@@ -912,7 +928,7 @@ def test_phishing_protection_service_v1_beta1_transport_channel_mtls_with_client
912928
"grpc.ssl_channel_credentials", autospec=True
913929
) as grpc_ssl_channel_cred:
914930
with mock.patch.object(
915-
transport_class, "create_channel", autospec=True
931+
transport_class, "create_channel"
916932
) as grpc_create_channel:
917933
mock_ssl_cred = mock.Mock()
918934
grpc_ssl_channel_cred.return_value = mock_ssl_cred
@@ -967,7 +983,7 @@ def test_phishing_protection_service_v1_beta1_transport_channel_mtls_with_adc(
967983
ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred),
968984
):
969985
with mock.patch.object(
970-
transport_class, "create_channel", autospec=True
986+
transport_class, "create_channel"
971987
) as grpc_create_channel:
972988
mock_grpc_channel = mock.Mock()
973989
grpc_create_channel.return_value = mock_grpc_channel

0 commit comments

Comments
 (0)