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

Commit c74e3ac

Browse files
feat(v3): added support for DLP templates (#144)
PiperOrigin-RevId: 389939863 Source-Link: googleapis/googleapis@626df52 Source-Link: https://github.com/googleapis/googleapis-gen/commit/6d110f5fb7540ab832798e838d226539122fccf2 feat(v3): expose `Locations` service to get/list avaliable locations of Dialogflow products
1 parent 7efb89c commit c74e3ac

File tree

4 files changed

+140
-4
lines changed

4 files changed

+140
-4
lines changed

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

Lines changed: 12 additions & 0 deletions
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_v3/services/security_settings_service/client.py

Lines changed: 40 additions & 0 deletions
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_v3/types/security_settings.py

Lines changed: 22 additions & 4 deletions
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_v3.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.v3.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_v3/test_security_settings_service.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ def test_create_security_settings(
548548
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
549549
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
550550
inspect_template="inspect_template_value",
551+
deidentify_template="deidentify_template_value",
551552
purge_data_types=[
552553
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
553554
],
@@ -573,6 +574,7 @@ def test_create_security_settings(
573574
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
574575
)
575576
assert response.inspect_template == "inspect_template_value"
577+
assert response.deidentify_template == "deidentify_template_value"
576578
assert response.purge_data_types == [
577579
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
578580
]
@@ -624,6 +626,7 @@ async def test_create_security_settings_async(
624626
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
625627
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
626628
inspect_template="inspect_template_value",
629+
deidentify_template="deidentify_template_value",
627630
purge_data_types=[
628631
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
629632
],
@@ -649,6 +652,7 @@ async def test_create_security_settings_async(
649652
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
650653
)
651654
assert response.inspect_template == "inspect_template_value"
655+
assert response.deidentify_template == "deidentify_template_value"
652656
assert response.purge_data_types == [
653657
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
654658
]
@@ -840,6 +844,7 @@ def test_get_security_settings(
840844
redaction_strategy=security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
841845
redaction_scope=security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
842846
inspect_template="inspect_template_value",
847+
deidentify_template="deidentify_template_value",
843848
purge_data_types=[
844849
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
845850
],
@@ -865,6 +870,7 @@ def test_get_security_settings(
865870
== security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
866871
)
867872
assert response.inspect_template == "inspect_template_value"
873+
assert response.deidentify_template == "deidentify_template_value"
868874
assert response.purge_data_types == [
869875
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
870876
]
@@ -916,6 +922,7 @@ async def test_get_security_settings_async(
916922
redaction_strategy=security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
917923
redaction_scope=security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
918924
inspect_template="inspect_template_value",
925+
deidentify_template="deidentify_template_value",
919926
purge_data_types=[
920927
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
921928
],
@@ -941,6 +948,7 @@ async def test_get_security_settings_async(
941948
== security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
942949
)
943950
assert response.inspect_template == "inspect_template_value"
951+
assert response.deidentify_template == "deidentify_template_value"
944952
assert response.purge_data_types == [
945953
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
946954
]
@@ -1109,6 +1117,7 @@ def test_update_security_settings(
11091117
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
11101118
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
11111119
inspect_template="inspect_template_value",
1120+
deidentify_template="deidentify_template_value",
11121121
purge_data_types=[
11131122
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
11141123
],
@@ -1134,6 +1143,7 @@ def test_update_security_settings(
11341143
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
11351144
)
11361145
assert response.inspect_template == "inspect_template_value"
1146+
assert response.deidentify_template == "deidentify_template_value"
11371147
assert response.purge_data_types == [
11381148
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
11391149
]
@@ -1185,6 +1195,7 @@ async def test_update_security_settings_async(
11851195
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
11861196
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
11871197
inspect_template="inspect_template_value",
1198+
deidentify_template="deidentify_template_value",
11881199
purge_data_types=[
11891200
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
11901201
],
@@ -1210,6 +1221,7 @@ async def test_update_security_settings_async(
12101221
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
12111222
)
12121223
assert response.inspect_template == "inspect_template_value"
1224+
assert response.deidentify_template == "deidentify_template_value"
12131225
assert response.purge_data_types == [
12141226
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
12151227
]
@@ -2485,6 +2497,60 @@ def test_security_settings_service_transport_channel_mtls_with_adc(transport_cla
24852497
assert transport.grpc_channel == mock_grpc_channel
24862498

24872499

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

0 commit comments

Comments
 (0)