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

Commit f83c035

Browse files
feat: add topic field to Secret (#80)
* changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * feat: added expire_time and ttl fields to Secret PiperOrigin-RevId: 352563582 Source-Author: Google APIs <[email protected]> Source-Date: Tue Jan 19 07:29:20 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 9ecdacc9a00e1dd443b11bf10215d6e7648db8a7 Source-Link: googleapis/googleapis@9ecdacc * chore: upgrade gapic-generator-python to 0.40.5 PiperOrigin-RevId: 354996675 Source-Author: Google APIs <[email protected]> Source-Date: Mon Feb 1 12:11:49 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 20712b8fe95001b312f62c6c5f33e3e3ec92cfaf Source-Link: googleapis/googleapis@20712b8 * chore: update gapic-generator-python PiperOrigin-RevId: 355923884 Source-Author: Google APIs <[email protected]> Source-Date: Fri Feb 5 14:04:52 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 5e3dacee19405529b841b53797df799c2383536c Source-Link: googleapis/googleapis@5e3dace * chore: remove non-existent package option in java_gapic_library rules for cloud APIs Committer: @miraleung PiperOrigin-RevId: 356328938 Source-Author: Google APIs <[email protected]> Source-Date: Mon Feb 8 12:39:42 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 78e0057d81c6969507bf1195b5aad8ac3e7feafd Source-Link: googleapis/googleapis@78e0057 * feat: added topic field to Secret PiperOrigin-RevId: 359285402 Source-Author: Google APIs <[email protected]> Source-Date: Wed Feb 24 07:59:50 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 8b3d36daaf5561496b7d4075fba4f2c52d18ca1c Source-Link: googleapis/googleapis@8b3d36d * chore: update gapic-generator-python to 0.40.11 PiperOrigin-RevId: 359562873 Source-Author: Google APIs <[email protected]> Source-Date: Thu Feb 25 10:52:32 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 07932bb995e7dc91b43620ea8402c6668c7d102c Source-Link: googleapis/googleapis@07932bb * chore: upgrade gapic-generator-python to 0.42.2 PiperOrigin-RevId: 361662015 Source-Author: Google APIs <[email protected]> Source-Date: Mon Mar 8 14:47:18 2021 -0800 Source-Repo: googleapis/googleapis Source-Sha: 28a591963253d52ce3a25a918cafbdd9928de8cf Source-Link: googleapis/googleapis@28a5919
1 parent 0e29327 commit f83c035

File tree

20 files changed

+1099
-285
lines changed

20 files changed

+1099
-285
lines changed

google/cloud/secretmanager/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from google.cloud.secretmanager_v1.types.resources import Secret
3131
from google.cloud.secretmanager_v1.types.resources import SecretPayload
3232
from google.cloud.secretmanager_v1.types.resources import SecretVersion
33+
from google.cloud.secretmanager_v1.types.resources import Topic
3334
from google.cloud.secretmanager_v1.types.service import AccessSecretVersionRequest
3435
from google.cloud.secretmanager_v1.types.service import AccessSecretVersionResponse
3536
from google.cloud.secretmanager_v1.types.service import AddSecretVersionRequest
@@ -70,5 +71,6 @@
7071
"SecretManagerServiceClient",
7172
"SecretPayload",
7273
"SecretVersion",
74+
"Topic",
7375
"UpdateSecretRequest",
7476
)

google/cloud/secretmanager_v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .types.resources import Secret
2424
from .types.resources import SecretPayload
2525
from .types.resources import SecretVersion
26+
from .types.resources import Topic
2627
from .types.service import AccessSecretVersionRequest
2728
from .types.service import AccessSecretVersionResponse
2829
from .types.service import AddSecretVersionRequest
@@ -62,6 +63,7 @@
6263
"Secret",
6364
"SecretPayload",
6465
"SecretVersion",
66+
"Topic",
6567
"UpdateSecretRequest",
6668
"SecretManagerServiceClient",
6769
)

google/cloud/secretmanager_v1/services/secret_manager_service/async_client.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class SecretManagerServiceAsyncClient:
6363
parse_secret_version_path = staticmethod(
6464
SecretManagerServiceClient.parse_secret_version_path
6565
)
66+
topic_path = staticmethod(SecretManagerServiceClient.topic_path)
67+
parse_topic_path = staticmethod(SecretManagerServiceClient.parse_topic_path)
6668

6769
common_billing_account_path = staticmethod(
6870
SecretManagerServiceClient.common_billing_account_path
@@ -93,8 +95,36 @@ class SecretManagerServiceAsyncClient:
9395
SecretManagerServiceClient.parse_common_location_path
9496
)
9597

96-
from_service_account_info = SecretManagerServiceClient.from_service_account_info
97-
from_service_account_file = SecretManagerServiceClient.from_service_account_file
98+
@classmethod
99+
def from_service_account_info(cls, info: dict, *args, **kwargs):
100+
"""Creates an instance of this client using the provided credentials info.
101+
102+
Args:
103+
info (dict): The service account private key info.
104+
args: Additional arguments to pass to the constructor.
105+
kwargs: Additional arguments to pass to the constructor.
106+
107+
Returns:
108+
SecretManagerServiceAsyncClient: The constructed client.
109+
"""
110+
return SecretManagerServiceClient.from_service_account_info.__func__(SecretManagerServiceAsyncClient, info, *args, **kwargs) # type: ignore
111+
112+
@classmethod
113+
def from_service_account_file(cls, filename: str, *args, **kwargs):
114+
"""Creates an instance of this client using the provided credentials
115+
file.
116+
117+
Args:
118+
filename (str): The path to the service account private key json
119+
file.
120+
args: Additional arguments to pass to the constructor.
121+
kwargs: Additional arguments to pass to the constructor.
122+
123+
Returns:
124+
SecretManagerServiceAsyncClient: The constructed client.
125+
"""
126+
return SecretManagerServiceClient.from_service_account_file.__func__(SecretManagerServiceAsyncClient, filename, *args, **kwargs) # type: ignore
127+
98128
from_service_account_json = from_service_account_file
99129

100130
@property

google/cloud/secretmanager_v1/services/secret_manager_service/client.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ def parse_secret_version_path(path: str) -> Dict[str, str]:
199199
)
200200
return m.groupdict() if m else {}
201201

202+
@staticmethod
203+
def topic_path(project: str, topic: str,) -> str:
204+
"""Return a fully-qualified topic string."""
205+
return "projects/{project}/topics/{topic}".format(project=project, topic=topic,)
206+
207+
@staticmethod
208+
def parse_topic_path(path: str) -> Dict[str, str]:
209+
"""Parse a topic path into its component segments."""
210+
m = re.match(r"^projects/(?P<project>.+?)/topics/(?P<topic>.+?)$", path)
211+
return m.groupdict() if m else {}
212+
202213
@staticmethod
203214
def common_billing_account_path(billing_account: str,) -> str:
204215
"""Return a fully-qualified billing_account string."""
@@ -313,21 +324,17 @@ def __init__(
313324
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
314325
)
315326

316-
ssl_credentials = None
327+
client_cert_source_func = None
317328
is_mtls = False
318329
if use_client_cert:
319330
if client_options.client_cert_source:
320-
import grpc # type: ignore
321-
322-
cert, key = client_options.client_cert_source()
323-
ssl_credentials = grpc.ssl_channel_credentials(
324-
certificate_chain=cert, private_key=key
325-
)
326331
is_mtls = True
332+
client_cert_source_func = client_options.client_cert_source
327333
else:
328-
creds = SslCredentials()
329-
is_mtls = creds.is_mtls
330-
ssl_credentials = creds.ssl_credentials if is_mtls else None
334+
is_mtls = mtls.has_default_client_cert_source()
335+
client_cert_source_func = (
336+
mtls.default_client_cert_source() if is_mtls else None
337+
)
331338

332339
# Figure out which api endpoint to use.
333340
if client_options.api_endpoint is not None:
@@ -370,7 +377,7 @@ def __init__(
370377
credentials_file=client_options.credentials_file,
371378
host=api_endpoint,
372379
scopes=client_options.scopes,
373-
ssl_channel_credentials=ssl_credentials,
380+
client_cert_source_for_mtls=client_cert_source_func,
374381
quota_project_id=client_options.quota_project_id,
375382
client_info=client_info,
376383
)
@@ -1488,10 +1495,13 @@ def set_iam_policy(
14881495
"""
14891496
# Create or coerce a protobuf request object.
14901497

1491-
# The request isn't a proto-plus wrapped type,
1492-
# so it must be constructed via keyword expansion.
14931498
if isinstance(request, dict):
1499+
# The request isn't a proto-plus wrapped type,
1500+
# so it must be constructed via keyword expansion.
14941501
request = iam_policy.SetIamPolicyRequest(**request)
1502+
elif not request:
1503+
# Null request, just make one.
1504+
request = iam_policy.SetIamPolicyRequest()
14951505

14961506
# Wrap the RPC method; this adds retry and timeout information,
14971507
# and friendly error handling.
@@ -1593,10 +1603,13 @@ def get_iam_policy(
15931603
"""
15941604
# Create or coerce a protobuf request object.
15951605

1596-
# The request isn't a proto-plus wrapped type,
1597-
# so it must be constructed via keyword expansion.
15981606
if isinstance(request, dict):
1607+
# The request isn't a proto-plus wrapped type,
1608+
# so it must be constructed via keyword expansion.
15991609
request = iam_policy.GetIamPolicyRequest(**request)
1610+
elif not request:
1611+
# Null request, just make one.
1612+
request = iam_policy.GetIamPolicyRequest()
16001613

16011614
# Wrap the RPC method; this adds retry and timeout information,
16021615
# and friendly error handling.
@@ -1648,10 +1661,13 @@ def test_iam_permissions(
16481661
"""
16491662
# Create or coerce a protobuf request object.
16501663

1651-
# The request isn't a proto-plus wrapped type,
1652-
# so it must be constructed via keyword expansion.
16531664
if isinstance(request, dict):
1665+
# The request isn't a proto-plus wrapped type,
1666+
# so it must be constructed via keyword expansion.
16541667
request = iam_policy.TestIamPermissionsRequest(**request)
1668+
elif not request:
1669+
# Null request, just make one.
1670+
request = iam_policy.TestIamPermissionsRequest()
16551671

16561672
# Wrap the RPC method; this adds retry and timeout information,
16571673
# and friendly error handling.

google/cloud/secretmanager_v1/services/secret_manager_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.secretmanager_v1.types import resources
2130
from google.cloud.secretmanager_v1.types import service

google/cloud/secretmanager_v1/services/secret_manager_service/transports/grpc.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
api_mtls_endpoint: str = None,
6868
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
6969
ssl_channel_credentials: grpc.ChannelCredentials = None,
70+
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
7071
quota_project_id: Optional[str] = None,
7172
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
7273
) -> None:
@@ -97,6 +98,10 @@ def __init__(
9798
``api_mtls_endpoint`` is None.
9899
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
99100
for grpc channel. It is ignored if ``channel`` is provided.
101+
client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
102+
A callback to provide client certificate bytes and private key bytes,
103+
both in PEM format. It is used to configure mutual TLS channel. It is
104+
ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
100105
quota_project_id (Optional[str]): An optional project to use for billing
101106
and quota.
102107
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
@@ -113,6 +118,11 @@ def __init__(
113118
"""
114119
self._ssl_channel_credentials = ssl_channel_credentials
115120

121+
if api_mtls_endpoint:
122+
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
123+
if client_cert_source:
124+
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
125+
116126
if channel:
117127
# Sanity check: Ensure that channel and credentials are not both
118128
# provided.
@@ -122,11 +132,6 @@ def __init__(
122132
self._grpc_channel = channel
123133
self._ssl_channel_credentials = None
124134
elif api_mtls_endpoint:
125-
warnings.warn(
126-
"api_mtls_endpoint and client_cert_source are deprecated",
127-
DeprecationWarning,
128-
)
129-
130135
host = (
131136
api_mtls_endpoint
132137
if ":" in api_mtls_endpoint
@@ -170,12 +175,18 @@ def __init__(
170175
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
171176
)
172177

178+
if client_cert_source_for_mtls and not ssl_channel_credentials:
179+
cert, key = client_cert_source_for_mtls()
180+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
181+
certificate_chain=cert, private_key=key
182+
)
183+
173184
# create a new channel. The provided one is ignored.
174185
self._grpc_channel = type(self).create_channel(
175186
host,
176187
credentials=credentials,
177188
credentials_file=credentials_file,
178-
ssl_credentials=ssl_channel_credentials,
189+
ssl_credentials=self._ssl_channel_credentials,
179190
scopes=scopes or self.AUTH_SCOPES,
180191
quota_project_id=quota_project_id,
181192
options=[

google/cloud/secretmanager_v1/services/secret_manager_service/transports/grpc_asyncio.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(
111111
api_mtls_endpoint: str = None,
112112
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
113113
ssl_channel_credentials: grpc.ChannelCredentials = None,
114+
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
114115
quota_project_id=None,
115116
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
116117
) -> None:
@@ -142,6 +143,10 @@ def __init__(
142143
``api_mtls_endpoint`` is None.
143144
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
144145
for grpc channel. It is ignored if ``channel`` is provided.
146+
client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
147+
A callback to provide client certificate bytes and private key bytes,
148+
both in PEM format. It is used to configure mutual TLS channel. It is
149+
ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
145150
quota_project_id (Optional[str]): An optional project to use for billing
146151
and quota.
147152
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
@@ -158,6 +163,11 @@ def __init__(
158163
"""
159164
self._ssl_channel_credentials = ssl_channel_credentials
160165

166+
if api_mtls_endpoint:
167+
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
168+
if client_cert_source:
169+
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
170+
161171
if channel:
162172
# Sanity check: Ensure that channel and credentials are not both
163173
# provided.
@@ -167,11 +177,6 @@ def __init__(
167177
self._grpc_channel = channel
168178
self._ssl_channel_credentials = None
169179
elif api_mtls_endpoint:
170-
warnings.warn(
171-
"api_mtls_endpoint and client_cert_source are deprecated",
172-
DeprecationWarning,
173-
)
174-
175180
host = (
176181
api_mtls_endpoint
177182
if ":" in api_mtls_endpoint
@@ -215,12 +220,18 @@ def __init__(
215220
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
216221
)
217222

223+
if client_cert_source_for_mtls and not ssl_channel_credentials:
224+
cert, key = client_cert_source_for_mtls()
225+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
226+
certificate_chain=cert, private_key=key
227+
)
228+
218229
# create a new channel. The provided one is ignored.
219230
self._grpc_channel = type(self).create_channel(
220231
host,
221232
credentials=credentials,
222233
credentials_file=credentials_file,
223-
ssl_credentials=ssl_channel_credentials,
234+
ssl_credentials=self._ssl_channel_credentials,
224235
scopes=scopes or self.AUTH_SCOPES,
225236
quota_project_id=quota_project_id,
226237
options=[

0 commit comments

Comments
 (0)