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

Commit 7efb89c

Browse files
feat(v3beta1): added support for DLP templates (#143)
PiperOrigin-RevId: 389907245 Source-Link: googleapis/googleapis@114b141 Source-Link: https://github.com/googleapis/googleapis-gen/commit/20ed8580efd4268184fddedc5eee147b82472e68 feat(v3beta1): expose `Locations` service to get/list avaliable locations of Dialogflow products docs(v3beta1): reorder some fields
1 parent 69622b8 commit 7efb89c

File tree

4 files changed

+140
-4
lines changed

4 files changed

+140
-4
lines changed

google/cloud/dialogflowcx_v3beta1/services/security_settings_service/async_client.py

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ class SecuritySettingsServiceAsyncClient:
4545
DEFAULT_ENDPOINT = SecuritySettingsServiceClient.DEFAULT_ENDPOINT
4646
DEFAULT_MTLS_ENDPOINT = SecuritySettingsServiceClient.DEFAULT_MTLS_ENDPOINT
4747

48+
deidentify_template_path = staticmethod(
49+
SecuritySettingsServiceClient.deidentify_template_path
50+
)
51+
parse_deidentify_template_path = staticmethod(
52+
SecuritySettingsServiceClient.parse_deidentify_template_path
53+
)
54+
inspect_template_path = staticmethod(
55+
SecuritySettingsServiceClient.inspect_template_path
56+
)
57+
parse_inspect_template_path = staticmethod(
58+
SecuritySettingsServiceClient.parse_inspect_template_path
59+
)
4860
security_settings_path = staticmethod(
4961
SecuritySettingsServiceClient.security_settings_path
5062
)

google/cloud/dialogflowcx_v3beta1/services/security_settings_service/client.py

+40
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,46 @@ def transport(self) -> SecuritySettingsServiceTransport:
161161
"""
162162
return self._transport
163163

164+
@staticmethod
165+
def deidentify_template_path(
166+
organization: str, location: str, deidentify_template: str,
167+
) -> str:
168+
"""Returns a fully-qualified deidentify_template string."""
169+
return "organizations/{organization}/locations/{location}/deidentifyTemplates/{deidentify_template}".format(
170+
organization=organization,
171+
location=location,
172+
deidentify_template=deidentify_template,
173+
)
174+
175+
@staticmethod
176+
def parse_deidentify_template_path(path: str) -> Dict[str, str]:
177+
"""Parses a deidentify_template path into its component segments."""
178+
m = re.match(
179+
r"^organizations/(?P<organization>.+?)/locations/(?P<location>.+?)/deidentifyTemplates/(?P<deidentify_template>.+?)$",
180+
path,
181+
)
182+
return m.groupdict() if m else {}
183+
184+
@staticmethod
185+
def inspect_template_path(
186+
organization: str, location: str, inspect_template: str,
187+
) -> str:
188+
"""Returns a fully-qualified inspect_template string."""
189+
return "organizations/{organization}/locations/{location}/inspectTemplates/{inspect_template}".format(
190+
organization=organization,
191+
location=location,
192+
inspect_template=inspect_template,
193+
)
194+
195+
@staticmethod
196+
def parse_inspect_template_path(path: str) -> Dict[str, str]:
197+
"""Parses a inspect_template path into its component segments."""
198+
m = re.match(
199+
r"^organizations/(?P<organization>.+?)/locations/(?P<location>.+?)/inspectTemplates/(?P<inspect_template>.+?)$",
200+
path,
201+
)
202+
return m.groupdict() if m else {}
203+
164204
@staticmethod
165205
def security_settings_path(
166206
project: str, location: str, security_settings: str,

google/cloud/dialogflowcx_v3beta1/types/security_settings.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,27 @@ class SecuritySettings(proto.Message):
165165
If empty, we use the default DLP inspect config.
166166
167167
The template name will have one of the following formats:
168-
``projects/<Project ID>/inspectTemplates/<Template ID>`` OR
169168
``projects/<Project ID>/locations/<Location ID>/inspectTemplates/<Template ID>``
170169
OR
171-
``organizations/<Organization ID>/inspectTemplates/<Template ID>``
170+
``organizations/<Organization ID>/locations/<Location ID>/inspectTemplates/<Template ID>``
171+
172+
Note: ``inspect_template`` must be located in the same
173+
region as the ``SecuritySettings``.
174+
deidentify_template (str):
175+
`DLP <https://cloud.google.com/dlp/docs>`__ deidentify
176+
template name. Use this template to define de-identification
177+
configuration for the content.
178+
179+
If empty, Dialogflow replaces sensitive info with
180+
``[redacted]`` text.
181+
182+
The template name will have one of the following formats:
183+
``projects/<Project ID>/locations/<Location ID>/deidentifyTemplates/<Template ID>``
184+
OR
185+
``organizations/<Organization ID>/locations/<Location ID>/deidentifyTemplates/<Template ID>``
186+
187+
Note: ``deidentify_template`` must be located in the same
188+
region as the ``SecuritySettings``.
172189
retention_window_days (int):
173190
Retains data in interaction logging for the
174191
specified number of days. This does not apply to
@@ -186,8 +203,8 @@ class SecuritySettings(proto.Message):
186203
List of types of data to remove when
187204
retention settings triggers purge.
188205
insights_export_settings (google.cloud.dialogflowcx_v3beta1.types.SecuritySettings.InsightsExportSettings):
189-
Optional. Controls conversation exporting settings to
190-
Insights after conversation is completed.
206+
Controls conversation exporting settings to Insights after
207+
conversation is completed.
191208
192209
If
193210
[retention_strategy][google.cloud.dialogflow.cx.v3beta1.SecuritySettings.retention_strategy]
@@ -230,6 +247,7 @@ class InsightsExportSettings(proto.Message):
230247
redaction_strategy = proto.Field(proto.ENUM, number=3, enum=RedactionStrategy,)
231248
redaction_scope = proto.Field(proto.ENUM, number=4, enum=RedactionScope,)
232249
inspect_template = proto.Field(proto.STRING, number=9,)
250+
deidentify_template = proto.Field(proto.STRING, number=17,)
233251
retention_window_days = proto.Field(proto.INT32, number=6, oneof="data_retention",)
234252
purge_data_types = proto.RepeatedField(proto.ENUM, number=8, enum=PurgeDataType,)
235253
insights_export_settings = proto.Field(

tests/unit/gapic/dialogflowcx_v3beta1/test_security_settings_service.py

+66
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ def test_create_security_settings(
550550
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
551551
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
552552
inspect_template="inspect_template_value",
553+
deidentify_template="deidentify_template_value",
553554
purge_data_types=[
554555
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
555556
],
@@ -575,6 +576,7 @@ def test_create_security_settings(
575576
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
576577
)
577578
assert response.inspect_template == "inspect_template_value"
579+
assert response.deidentify_template == "deidentify_template_value"
578580
assert response.purge_data_types == [
579581
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
580582
]
@@ -626,6 +628,7 @@ async def test_create_security_settings_async(
626628
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
627629
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
628630
inspect_template="inspect_template_value",
631+
deidentify_template="deidentify_template_value",
629632
purge_data_types=[
630633
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
631634
],
@@ -651,6 +654,7 @@ async def test_create_security_settings_async(
651654
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
652655
)
653656
assert response.inspect_template == "inspect_template_value"
657+
assert response.deidentify_template == "deidentify_template_value"
654658
assert response.purge_data_types == [
655659
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
656660
]
@@ -842,6 +846,7 @@ def test_get_security_settings(
842846
redaction_strategy=security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
843847
redaction_scope=security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
844848
inspect_template="inspect_template_value",
849+
deidentify_template="deidentify_template_value",
845850
purge_data_types=[
846851
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
847852
],
@@ -867,6 +872,7 @@ def test_get_security_settings(
867872
== security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
868873
)
869874
assert response.inspect_template == "inspect_template_value"
875+
assert response.deidentify_template == "deidentify_template_value"
870876
assert response.purge_data_types == [
871877
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
872878
]
@@ -918,6 +924,7 @@ async def test_get_security_settings_async(
918924
redaction_strategy=security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
919925
redaction_scope=security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
920926
inspect_template="inspect_template_value",
927+
deidentify_template="deidentify_template_value",
921928
purge_data_types=[
922929
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
923930
],
@@ -943,6 +950,7 @@ async def test_get_security_settings_async(
943950
== security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
944951
)
945952
assert response.inspect_template == "inspect_template_value"
953+
assert response.deidentify_template == "deidentify_template_value"
946954
assert response.purge_data_types == [
947955
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
948956
]
@@ -1111,6 +1119,7 @@ def test_update_security_settings(
11111119
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
11121120
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
11131121
inspect_template="inspect_template_value",
1122+
deidentify_template="deidentify_template_value",
11141123
purge_data_types=[
11151124
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
11161125
],
@@ -1136,6 +1145,7 @@ def test_update_security_settings(
11361145
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
11371146
)
11381147
assert response.inspect_template == "inspect_template_value"
1148+
assert response.deidentify_template == "deidentify_template_value"
11391149
assert response.purge_data_types == [
11401150
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
11411151
]
@@ -1187,6 +1197,7 @@ async def test_update_security_settings_async(
11871197
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
11881198
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
11891199
inspect_template="inspect_template_value",
1200+
deidentify_template="deidentify_template_value",
11901201
purge_data_types=[
11911202
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
11921203
],
@@ -1212,6 +1223,7 @@ async def test_update_security_settings_async(
12121223
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
12131224
)
12141225
assert response.inspect_template == "inspect_template_value"
1226+
assert response.deidentify_template == "deidentify_template_value"
12151227
assert response.purge_data_types == [
12161228
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
12171229
]
@@ -2487,6 +2499,60 @@ def test_security_settings_service_transport_channel_mtls_with_adc(transport_cla
24872499
assert transport.grpc_channel == mock_grpc_channel
24882500

24892501

2502+
def test_deidentify_template_path():
2503+
organization = "squid"
2504+
location = "clam"
2505+
deidentify_template = "whelk"
2506+
expected = "organizations/{organization}/locations/{location}/deidentifyTemplates/{deidentify_template}".format(
2507+
organization=organization,
2508+
location=location,
2509+
deidentify_template=deidentify_template,
2510+
)
2511+
actual = SecuritySettingsServiceClient.deidentify_template_path(
2512+
organization, location, deidentify_template
2513+
)
2514+
assert expected == actual
2515+
2516+
2517+
def test_parse_deidentify_template_path():
2518+
expected = {
2519+
"organization": "octopus",
2520+
"location": "oyster",
2521+
"deidentify_template": "nudibranch",
2522+
}
2523+
path = SecuritySettingsServiceClient.deidentify_template_path(**expected)
2524+
2525+
# Check that the path construction is reversible.
2526+
actual = SecuritySettingsServiceClient.parse_deidentify_template_path(path)
2527+
assert expected == actual
2528+
2529+
2530+
def test_inspect_template_path():
2531+
organization = "cuttlefish"
2532+
location = "mussel"
2533+
inspect_template = "winkle"
2534+
expected = "organizations/{organization}/locations/{location}/inspectTemplates/{inspect_template}".format(
2535+
organization=organization, location=location, inspect_template=inspect_template,
2536+
)
2537+
actual = SecuritySettingsServiceClient.inspect_template_path(
2538+
organization, location, inspect_template
2539+
)
2540+
assert expected == actual
2541+
2542+
2543+
def test_parse_inspect_template_path():
2544+
expected = {
2545+
"organization": "nautilus",
2546+
"location": "scallop",
2547+
"inspect_template": "abalone",
2548+
}
2549+
path = SecuritySettingsServiceClient.inspect_template_path(**expected)
2550+
2551+
# Check that the path construction is reversible.
2552+
actual = SecuritySettingsServiceClient.parse_inspect_template_path(path)
2553+
assert expected == actual
2554+
2555+
24902556
def test_security_settings_path():
24912557
project = "squid"
24922558
location = "clam"

0 commit comments

Comments
 (0)