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

Commit

Permalink
feat(v3beta1): added support for DLP templates (#143)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gcf-owl-bot[bot] authored Aug 12, 2021
1 parent 69622b8 commit 7efb89c
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ class SecuritySettingsServiceAsyncClient:
DEFAULT_ENDPOINT = SecuritySettingsServiceClient.DEFAULT_ENDPOINT
DEFAULT_MTLS_ENDPOINT = SecuritySettingsServiceClient.DEFAULT_MTLS_ENDPOINT

deidentify_template_path = staticmethod(
SecuritySettingsServiceClient.deidentify_template_path
)
parse_deidentify_template_path = staticmethod(
SecuritySettingsServiceClient.parse_deidentify_template_path
)
inspect_template_path = staticmethod(
SecuritySettingsServiceClient.inspect_template_path
)
parse_inspect_template_path = staticmethod(
SecuritySettingsServiceClient.parse_inspect_template_path
)
security_settings_path = staticmethod(
SecuritySettingsServiceClient.security_settings_path
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,46 @@ def transport(self) -> SecuritySettingsServiceTransport:
"""
return self._transport

@staticmethod
def deidentify_template_path(
organization: str, location: str, deidentify_template: str,
) -> str:
"""Returns a fully-qualified deidentify_template string."""
return "organizations/{organization}/locations/{location}/deidentifyTemplates/{deidentify_template}".format(
organization=organization,
location=location,
deidentify_template=deidentify_template,
)

@staticmethod
def parse_deidentify_template_path(path: str) -> Dict[str, str]:
"""Parses a deidentify_template path into its component segments."""
m = re.match(
r"^organizations/(?P<organization>.+?)/locations/(?P<location>.+?)/deidentifyTemplates/(?P<deidentify_template>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def inspect_template_path(
organization: str, location: str, inspect_template: str,
) -> str:
"""Returns a fully-qualified inspect_template string."""
return "organizations/{organization}/locations/{location}/inspectTemplates/{inspect_template}".format(
organization=organization,
location=location,
inspect_template=inspect_template,
)

@staticmethod
def parse_inspect_template_path(path: str) -> Dict[str, str]:
"""Parses a inspect_template path into its component segments."""
m = re.match(
r"^organizations/(?P<organization>.+?)/locations/(?P<location>.+?)/inspectTemplates/(?P<inspect_template>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def security_settings_path(
project: str, location: str, security_settings: str,
Expand Down
26 changes: 22 additions & 4 deletions google/cloud/dialogflowcx_v3beta1/types/security_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,27 @@ class SecuritySettings(proto.Message):
If empty, we use the default DLP inspect config.
The template name will have one of the following formats:
``projects/<Project ID>/inspectTemplates/<Template ID>`` OR
``projects/<Project ID>/locations/<Location ID>/inspectTemplates/<Template ID>``
OR
``organizations/<Organization ID>/inspectTemplates/<Template ID>``
``organizations/<Organization ID>/locations/<Location ID>/inspectTemplates/<Template ID>``
Note: ``inspect_template`` must be located in the same
region as the ``SecuritySettings``.
deidentify_template (str):
`DLP <https://cloud.google.com/dlp/docs>`__ deidentify
template name. Use this template to define de-identification
configuration for the content.
If empty, Dialogflow replaces sensitive info with
``[redacted]`` text.
The template name will have one of the following formats:
``projects/<Project ID>/locations/<Location ID>/deidentifyTemplates/<Template ID>``
OR
``organizations/<Organization ID>/locations/<Location ID>/deidentifyTemplates/<Template ID>``
Note: ``deidentify_template`` must be located in the same
region as the ``SecuritySettings``.
retention_window_days (int):
Retains data in interaction logging for the
specified number of days. This does not apply to
Expand All @@ -186,8 +203,8 @@ class SecuritySettings(proto.Message):
List of types of data to remove when
retention settings triggers purge.
insights_export_settings (google.cloud.dialogflowcx_v3beta1.types.SecuritySettings.InsightsExportSettings):
Optional. Controls conversation exporting settings to
Insights after conversation is completed.
Controls conversation exporting settings to Insights after
conversation is completed.
If
[retention_strategy][google.cloud.dialogflow.cx.v3beta1.SecuritySettings.retention_strategy]
Expand Down Expand Up @@ -230,6 +247,7 @@ class InsightsExportSettings(proto.Message):
redaction_strategy = proto.Field(proto.ENUM, number=3, enum=RedactionStrategy,)
redaction_scope = proto.Field(proto.ENUM, number=4, enum=RedactionScope,)
inspect_template = proto.Field(proto.STRING, number=9,)
deidentify_template = proto.Field(proto.STRING, number=17,)
retention_window_days = proto.Field(proto.INT32, number=6, oneof="data_retention",)
purge_data_types = proto.RepeatedField(proto.ENUM, number=8, enum=PurgeDataType,)
insights_export_settings = proto.Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ def test_create_security_settings(
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
inspect_template="inspect_template_value",
deidentify_template="deidentify_template_value",
purge_data_types=[
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
],
Expand All @@ -575,6 +576,7 @@ def test_create_security_settings(
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
)
assert response.inspect_template == "inspect_template_value"
assert response.deidentify_template == "deidentify_template_value"
assert response.purge_data_types == [
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
]
Expand Down Expand Up @@ -626,6 +628,7 @@ async def test_create_security_settings_async(
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
inspect_template="inspect_template_value",
deidentify_template="deidentify_template_value",
purge_data_types=[
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
],
Expand All @@ -651,6 +654,7 @@ async def test_create_security_settings_async(
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
)
assert response.inspect_template == "inspect_template_value"
assert response.deidentify_template == "deidentify_template_value"
assert response.purge_data_types == [
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
]
Expand Down Expand Up @@ -842,6 +846,7 @@ def test_get_security_settings(
redaction_strategy=security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
redaction_scope=security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
inspect_template="inspect_template_value",
deidentify_template="deidentify_template_value",
purge_data_types=[
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
],
Expand All @@ -867,6 +872,7 @@ def test_get_security_settings(
== security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
)
assert response.inspect_template == "inspect_template_value"
assert response.deidentify_template == "deidentify_template_value"
assert response.purge_data_types == [
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
]
Expand Down Expand Up @@ -918,6 +924,7 @@ async def test_get_security_settings_async(
redaction_strategy=security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
redaction_scope=security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
inspect_template="inspect_template_value",
deidentify_template="deidentify_template_value",
purge_data_types=[
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
],
Expand All @@ -943,6 +950,7 @@ async def test_get_security_settings_async(
== security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
)
assert response.inspect_template == "inspect_template_value"
assert response.deidentify_template == "deidentify_template_value"
assert response.purge_data_types == [
security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
]
Expand Down Expand Up @@ -1111,6 +1119,7 @@ def test_update_security_settings(
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
inspect_template="inspect_template_value",
deidentify_template="deidentify_template_value",
purge_data_types=[
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
],
Expand All @@ -1136,6 +1145,7 @@ def test_update_security_settings(
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
)
assert response.inspect_template == "inspect_template_value"
assert response.deidentify_template == "deidentify_template_value"
assert response.purge_data_types == [
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
]
Expand Down Expand Up @@ -1187,6 +1197,7 @@ async def test_update_security_settings_async(
redaction_strategy=gcdc_security_settings.SecuritySettings.RedactionStrategy.REDACT_WITH_SERVICE,
redaction_scope=gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE,
inspect_template="inspect_template_value",
deidentify_template="deidentify_template_value",
purge_data_types=[
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
],
Expand All @@ -1212,6 +1223,7 @@ async def test_update_security_settings_async(
== gcdc_security_settings.SecuritySettings.RedactionScope.REDACT_DISK_STORAGE
)
assert response.inspect_template == "inspect_template_value"
assert response.deidentify_template == "deidentify_template_value"
assert response.purge_data_types == [
gcdc_security_settings.SecuritySettings.PurgeDataType.DIALOGFLOW_HISTORY
]
Expand Down Expand Up @@ -2487,6 +2499,60 @@ def test_security_settings_service_transport_channel_mtls_with_adc(transport_cla
assert transport.grpc_channel == mock_grpc_channel


def test_deidentify_template_path():
organization = "squid"
location = "clam"
deidentify_template = "whelk"
expected = "organizations/{organization}/locations/{location}/deidentifyTemplates/{deidentify_template}".format(
organization=organization,
location=location,
deidentify_template=deidentify_template,
)
actual = SecuritySettingsServiceClient.deidentify_template_path(
organization, location, deidentify_template
)
assert expected == actual


def test_parse_deidentify_template_path():
expected = {
"organization": "octopus",
"location": "oyster",
"deidentify_template": "nudibranch",
}
path = SecuritySettingsServiceClient.deidentify_template_path(**expected)

# Check that the path construction is reversible.
actual = SecuritySettingsServiceClient.parse_deidentify_template_path(path)
assert expected == actual


def test_inspect_template_path():
organization = "cuttlefish"
location = "mussel"
inspect_template = "winkle"
expected = "organizations/{organization}/locations/{location}/inspectTemplates/{inspect_template}".format(
organization=organization, location=location, inspect_template=inspect_template,
)
actual = SecuritySettingsServiceClient.inspect_template_path(
organization, location, inspect_template
)
assert expected == actual


def test_parse_inspect_template_path():
expected = {
"organization": "nautilus",
"location": "scallop",
"inspect_template": "abalone",
}
path = SecuritySettingsServiceClient.inspect_template_path(**expected)

# Check that the path construction is reversible.
actual = SecuritySettingsServiceClient.parse_inspect_template_path(path)
assert expected == actual


def test_security_settings_path():
project = "squid"
location = "clam"
Expand Down

0 comments on commit 7efb89c

Please sign in to comment.