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

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(v3): added support for DLP templates (#144)
PiperOrigin-RevId: 389939863

Source-Link: googleapis/googleapis@626df52

Source-Link: googleapis/googleapis-gen@6d110f5

feat(v3): expose `Locations` service to get/list avaliable locations of Dialogflow products
  • Loading branch information
gcf-owl-bot[bot] committed Aug 12, 2021
1 parent 7efb89c commit c74e3ac
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 4 deletions.
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
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_v3/types/security_settings.py
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_v3.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.v3.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
66 changes: 66 additions & 0 deletions tests/unit/gapic/dialogflowcx_v3/test_security_settings_service.py
Expand Up @@ -548,6 +548,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 @@ -573,6 +574,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 @@ -624,6 +626,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 @@ -649,6 +652,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 @@ -840,6 +844,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 @@ -865,6 +870,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 @@ -916,6 +922,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 @@ -941,6 +948,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 @@ -1109,6 +1117,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 @@ -1134,6 +1143,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 @@ -1185,6 +1195,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 @@ -1210,6 +1221,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 @@ -2485,6 +2497,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 c74e3ac

Please sign in to comment.