ethyca-fides 2.71.0rc4__py2.py3-none-any.whl → 2.71.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ethyca-fides might be problematic. Click here for more details.
- {ethyca_fides-2.71.0rc4.dist-info → ethyca_fides-2.71.1.dist-info}/METADATA +1 -1
- {ethyca_fides-2.71.0rc4.dist-info → ethyca_fides-2.71.1.dist-info}/RECORD +168 -153
- fides/_version.py +3 -3
- fides/api/alembic/migrations/versions/3efe14d4469a_adds_new_experience_configs_for_vendor_.py +79 -0
- fides/api/alembic/migrations/versions/4bfbeff34611_add_polling_status.py +68 -0
- fides/api/alembic/migrations/versions/7db29f9cd77b_create_new_sub_request_table.py +95 -0
- fides/api/alembic/migrations/versions/918aefc950c9_create_digest_conditional_dependencies.py +125 -0
- fides/api/alembic/migrations/versions/9caf76161e55_make_user_assigned_data_uses_nullable_.py +64 -0
- fides/api/alembic/migrations/versions/b97e92b038d2_add_digest_execution_model.py +117 -0
- fides/api/alembic/migrations/versions/f108fa05c579_adds_optional_duration_field_to_assets.py +28 -0
- fides/api/common_exceptions.py +4 -0
- fides/api/db/base.py +1 -1
- fides/api/main.py +2 -2
- fides/api/models/asset.py +14 -1
- fides/api/models/attachment.py +1 -0
- fides/api/models/conditional_dependency/conditional_dependency_base.py +253 -24
- fides/api/models/detection_discovery/core.py +57 -3
- fides/api/models/digest/__init__.py +7 -1
- fides/api/models/digest/conditional_dependencies.py +267 -1
- fides/api/models/digest/digest_config.py +44 -10
- fides/api/models/digest/digest_execution.py +132 -0
- fides/api/models/event_audit.py +8 -0
- fides/api/models/fides_user.py +9 -0
- fides/api/models/manual_task/conditional_dependency.py +16 -18
- fides/api/models/privacy_experience.py +10 -0
- fides/api/models/privacy_notice.py +139 -20
- fides/api/models/privacy_request/request_task.py +98 -1
- fides/api/models/worker_task.py +8 -0
- fides/api/schemas/saas/async_polling_configuration.py +81 -0
- fides/api/schemas/saas/saas_config.py +10 -3
- fides/api/schemas/saas/strategy_configuration.py +0 -12
- fides/api/service/async_dsr/handlers/__init__.py +0 -0
- fides/api/service/async_dsr/handlers/polling_attachment_handler.py +155 -0
- fides/api/service/async_dsr/handlers/polling_request_handler.py +88 -0
- fides/api/service/async_dsr/handlers/polling_response_handler.py +261 -0
- fides/api/service/async_dsr/handlers/polling_sub_request_handler.py +123 -0
- fides/api/service/async_dsr/strategies/__init__.py +0 -0
- fides/api/service/async_dsr/strategies/async_dsr_strategy.py +52 -0
- fides/api/service/async_dsr/strategies/async_dsr_strategy_callback.py +199 -0
- fides/api/service/async_dsr/strategies/async_dsr_strategy_factory.py +72 -0
- fides/api/service/async_dsr/strategies/async_dsr_strategy_polling.py +678 -0
- fides/api/service/async_dsr/utils.py +130 -0
- fides/api/service/connectors/fides/fides_client.py +63 -1
- fides/api/service/connectors/query_configs/saas_query_config.py +4 -5
- fides/api/service/connectors/saas_connector.py +77 -69
- fides/api/service/privacy_request/attachment_handling.py +9 -2
- fides/api/service/privacy_request/request_runner_service.py +9 -83
- fides/api/service/privacy_request/request_service.py +47 -74
- fides/api/service/saas_request/saas_request_override_factory.py +66 -1
- fides/api/task/execute_request_tasks.py +5 -2
- fides/api/task/filter_results.py +35 -2
- fides/api/task/graph_task.py +34 -2
- fides/api/task/manual/manual_task_conditional_evaluation.py +1 -1
- fides/config/execution_settings.py +7 -3
- fides/ui-build/static/admin/404.html +1 -1
- fides/ui-build/static/admin/_next/static/-sJd4KUm81_d189v12Jmo/_buildManifest.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/155-c1ae010c664e2245.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/1817-1ad037b7d6d2f6d2.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/5279-12c9cbdc67ad7b14.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/6277-182efc294d413f64.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/7079-bbc7b856802a4834.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/pages/add-systems/{manual-75e99306393938e8.js → manual-4ec03eed67572861.js} +1 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/consent/privacy-experience/{[id]-fd41ffaff543e05a.js → [id]-e1e2fd704ac2d71d.js} +1 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/consent/privacy-experience/{new-e74cb5ea87f15b40.js → new-a5e738a234dadc7e.js} +1 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/consent/privacy-notices/{[id]-9c23fbe813c997d0.js → [id]-5fc78b78a51c239c.js} +1 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/consent/privacy-notices/{new-0e5e38bbcfe59fd2.js → new-b79bcb93b5f4c734.js} +1 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/data-discovery/action-center/[monitorId]/[systemId]-29c1fb777bd464e0.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/pages/integrations/[id]-153eb88ab4e7dc6d.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/pages/integrations-f682b1def859931e.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/pages/privacy-requests/[id]-febf156d2977f3ac.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/pages/settings/consent-4d658222ec800511.js +1 -0
- fides/ui-build/static/admin/_next/static/chunks/pages/systems/configure/{[id]-547c6ef0ad52b85d.js → [id]-4d470bbf199a2f9c.js} +1 -1
- fides/ui-build/static/admin/_next/static/css/f38242c11f7fea64.css +1 -0
- fides/ui-build/static/admin/add-systems/manual.html +1 -1
- fides/ui-build/static/admin/add-systems/multiple.html +1 -1
- fides/ui-build/static/admin/add-systems.html +1 -1
- fides/ui-build/static/admin/consent/configure/add-vendors.html +1 -1
- fides/ui-build/static/admin/consent/configure.html +1 -1
- fides/ui-build/static/admin/consent/privacy-experience/[id].html +1 -1
- fides/ui-build/static/admin/consent/privacy-experience/new.html +1 -1
- fides/ui-build/static/admin/consent/privacy-experience.html +1 -1
- fides/ui-build/static/admin/consent/privacy-notices/[id].html +1 -1
- fides/ui-build/static/admin/consent/privacy-notices/new.html +1 -1
- fides/ui-build/static/admin/consent/privacy-notices.html +1 -1
- fides/ui-build/static/admin/consent/properties.html +1 -1
- fides/ui-build/static/admin/consent/reporting.html +1 -1
- fides/ui-build/static/admin/consent.html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn]/[resourceUrn].html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn].html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/projects.html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/resources/[resourceUrn].html +1 -1
- fides/ui-build/static/admin/data-catalog/[systemId]/resources.html +1 -1
- fides/ui-build/static/admin/data-catalog.html +1 -1
- fides/ui-build/static/admin/data-discovery/action-center/[monitorId]/[systemId].html +1 -1
- fides/ui-build/static/admin/data-discovery/action-center/[monitorId].html +1 -1
- fides/ui-build/static/admin/data-discovery/action-center.html +1 -1
- fides/ui-build/static/admin/data-discovery/activity.html +1 -1
- fides/ui-build/static/admin/data-discovery/detection/[resourceUrn].html +1 -1
- fides/ui-build/static/admin/data-discovery/detection.html +1 -1
- fides/ui-build/static/admin/data-discovery/discovery/[resourceUrn].html +1 -1
- fides/ui-build/static/admin/data-discovery/discovery.html +1 -1
- fides/ui-build/static/admin/datamap.html +1 -1
- fides/ui-build/static/admin/dataset/[datasetId]/[collectionName]/[...subfieldNames].html +1 -1
- fides/ui-build/static/admin/dataset/[datasetId]/[collectionName].html +1 -1
- fides/ui-build/static/admin/dataset/[datasetId].html +1 -1
- fides/ui-build/static/admin/dataset/new.html +1 -1
- fides/ui-build/static/admin/dataset.html +1 -1
- fides/ui-build/static/admin/datastore-connection/[id].html +1 -1
- fides/ui-build/static/admin/datastore-connection/new.html +1 -1
- fides/ui-build/static/admin/datastore-connection.html +1 -1
- fides/ui-build/static/admin/index.html +1 -1
- fides/ui-build/static/admin/integrations/[id].html +1 -1
- fides/ui-build/static/admin/integrations.html +1 -1
- fides/ui-build/static/admin/lib/fides-headless.js +1 -1
- fides/ui-build/static/admin/lib/fides-preview.js +1 -1
- fides/ui-build/static/admin/lib/fides-tcf.js +3 -3
- fides/ui-build/static/admin/lib/fides.js +3 -3
- fides/ui-build/static/admin/login/[provider].html +1 -1
- fides/ui-build/static/admin/login.html +1 -1
- fides/ui-build/static/admin/messaging/[id].html +1 -1
- fides/ui-build/static/admin/messaging/add-template.html +1 -1
- fides/ui-build/static/admin/messaging.html +1 -1
- fides/ui-build/static/admin/poc/ant-components.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/AntForm.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/FormikAntFormItem.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/FormikControlled.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/FormikField.html +1 -1
- fides/ui-build/static/admin/poc/form-experiments/FormikSpreadField.html +1 -1
- fides/ui-build/static/admin/poc/forms.html +1 -1
- fides/ui-build/static/admin/poc/table-migration.html +1 -1
- fides/ui-build/static/admin/privacy-requests/[id].html +1 -1
- fides/ui-build/static/admin/privacy-requests/configure/storage.html +1 -1
- fides/ui-build/static/admin/privacy-requests/configure.html +1 -1
- fides/ui-build/static/admin/privacy-requests.html +1 -1
- fides/ui-build/static/admin/properties/[id].html +1 -1
- fides/ui-build/static/admin/properties/add-property.html +1 -1
- fides/ui-build/static/admin/properties.html +1 -1
- fides/ui-build/static/admin/reporting/datamap.html +1 -1
- fides/ui-build/static/admin/settings/about/alpha.html +1 -1
- fides/ui-build/static/admin/settings/about.html +1 -1
- fides/ui-build/static/admin/settings/consent/[configuration_id]/[purpose_id].html +1 -1
- fides/ui-build/static/admin/settings/consent.html +1 -1
- fides/ui-build/static/admin/settings/custom-fields/[id].html +1 -1
- fides/ui-build/static/admin/settings/custom-fields/new.html +1 -1
- fides/ui-build/static/admin/settings/custom-fields.html +1 -1
- fides/ui-build/static/admin/settings/domain-records.html +1 -1
- fides/ui-build/static/admin/settings/domains.html +1 -1
- fides/ui-build/static/admin/settings/email-templates.html +1 -1
- fides/ui-build/static/admin/settings/locations.html +1 -1
- fides/ui-build/static/admin/settings/messaging-providers/[key].html +1 -1
- fides/ui-build/static/admin/settings/messaging-providers/new.html +1 -1
- fides/ui-build/static/admin/settings/messaging-providers.html +1 -1
- fides/ui-build/static/admin/settings/organization.html +1 -1
- fides/ui-build/static/admin/settings/privacy-requests.html +1 -1
- fides/ui-build/static/admin/settings/regulations.html +1 -1
- fides/ui-build/static/admin/systems/configure/[id]/test-datasets.html +1 -1
- fides/ui-build/static/admin/systems/configure/[id].html +1 -1
- fides/ui-build/static/admin/systems.html +1 -1
- fides/ui-build/static/admin/taxonomy.html +1 -1
- fides/ui-build/static/admin/user-management/new.html +1 -1
- fides/ui-build/static/admin/user-management/profile/[id].html +1 -1
- fides/ui-build/static/admin/user-management.html +1 -1
- fides/api/service/async_dsr/async_dsr_service.py +0 -195
- fides/api/service/async_dsr/async_dsr_strategy.py +0 -5
- fides/api/service/async_dsr/async_dsr_strategy_callback.py +0 -16
- fides/api/service/async_dsr/async_dsr_strategy_factory.py +0 -63
- fides/api/service/async_dsr/async_dsr_strategy_polling.py +0 -94
- fides/ui-build/static/admin/_next/static/chunks/155-047c3806cc41295e.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/1817-ca6473f31a67a804.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/3700-08e0703b1ef770da.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/6084-d0943ee628bf4388.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/6416-0ccadfefcdad00cc.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/data-discovery/action-center/[monitorId]/[systemId]-2e1e2b7808d3b21f.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/integrations/[id]-01e025f878ba806c.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/integrations-14120a529d7dac27.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/privacy-requests/[id]-7dac2302f573f5ee.js +0 -1
- fides/ui-build/static/admin/_next/static/chunks/pages/settings/consent-e5d781b28f8e29c8.js +0 -1
- fides/ui-build/static/admin/_next/static/css/073713cd1eddda79.css +0 -1
- fides/ui-build/static/admin/_next/static/kdnucJIsIefS6ViqY-8w3/_buildManifest.js +0 -1
- {ethyca_fides-2.71.0rc4.dist-info → ethyca_fides-2.71.1.dist-info}/WHEEL +0 -0
- {ethyca_fides-2.71.0rc4.dist-info → ethyca_fides-2.71.1.dist-info}/entry_points.txt +0 -0
- {ethyca_fides-2.71.0rc4.dist-info → ethyca_fides-2.71.1.dist-info}/licenses/LICENSE +0 -0
- {ethyca_fides-2.71.0rc4.dist-info → ethyca_fides-2.71.1.dist-info}/top_level.txt +0 -0
- /fides/ui-build/static/admin/_next/static/{kdnucJIsIefS6ViqY-8w3 → -sJd4KUm81_d189v12Jmo}/_ssgManifest.js +0 -0
- /fides/ui-build/static/admin/_next/static/chunks/pages/{_app-a77584f9ad3334af.js → _app-a7c02dd2ff07f9e1.js} +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pure HTTP utility for executing polling requests.
|
|
3
|
+
|
|
4
|
+
This module contains low-level HTTP request execution for async DSR polling,
|
|
5
|
+
with no business logic or orchestration dependencies.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Any, Dict, Optional
|
|
9
|
+
|
|
10
|
+
from requests import Response
|
|
11
|
+
|
|
12
|
+
from fides.api.common_exceptions import PrivacyRequestError
|
|
13
|
+
from fides.api.schemas.saas.async_polling_configuration import (
|
|
14
|
+
PollingResultRequest,
|
|
15
|
+
PollingStatusRequest,
|
|
16
|
+
)
|
|
17
|
+
from fides.api.service.connectors.saas.authenticated_client import AuthenticatedClient
|
|
18
|
+
from fides.api.util.saas_util import map_param_values
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class PollingRequestHandler:
|
|
22
|
+
"""
|
|
23
|
+
Pure HTTP utility for executing polling requests.
|
|
24
|
+
|
|
25
|
+
Handles status checks and result retrieval with no business logic dependencies.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
status_request: PollingStatusRequest,
|
|
31
|
+
result_request: Optional[PollingResultRequest] = None,
|
|
32
|
+
):
|
|
33
|
+
self.status_request = status_request
|
|
34
|
+
self.result_request = result_request
|
|
35
|
+
|
|
36
|
+
def get_status_response(
|
|
37
|
+
self,
|
|
38
|
+
client: AuthenticatedClient,
|
|
39
|
+
param_values: Dict[str, Any],
|
|
40
|
+
) -> Response:
|
|
41
|
+
"""Execute HTTP status request and return raw response."""
|
|
42
|
+
if not self.status_request:
|
|
43
|
+
raise PrivacyRequestError(
|
|
44
|
+
"status_request is not configured in the async polling configuration"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
prepared_status_request = map_param_values(
|
|
48
|
+
action="status",
|
|
49
|
+
context="polling request",
|
|
50
|
+
current_request=self.status_request,
|
|
51
|
+
param_values=param_values,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
response: Response = client.send(prepared_status_request)
|
|
55
|
+
|
|
56
|
+
if not response.ok:
|
|
57
|
+
raise PrivacyRequestError(
|
|
58
|
+
f"Status request failed with status code {response.status_code}: {response.text}"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
return response
|
|
62
|
+
|
|
63
|
+
def get_result_response(
|
|
64
|
+
self,
|
|
65
|
+
client: AuthenticatedClient,
|
|
66
|
+
param_values: Dict[str, Any],
|
|
67
|
+
) -> Response:
|
|
68
|
+
"""Execute HTTP result request and return raw response."""
|
|
69
|
+
if not self.result_request:
|
|
70
|
+
raise PrivacyRequestError(
|
|
71
|
+
"result_request is not configured in the async polling configuration"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
prepared_result_request = map_param_values(
|
|
75
|
+
action="result",
|
|
76
|
+
context="polling request",
|
|
77
|
+
current_request=self.result_request,
|
|
78
|
+
param_values=param_values,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
response: Response = client.send(prepared_result_request)
|
|
82
|
+
|
|
83
|
+
if not response.ok:
|
|
84
|
+
raise PrivacyRequestError(
|
|
85
|
+
f"Result request failed with status code {response.status_code}: {response.text}"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
return response
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pure response processing utility for async DSR polling.
|
|
3
|
+
|
|
4
|
+
This module handles data type inference, attachment classification,
|
|
5
|
+
and response parsing with no business logic dependencies.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import mimetypes
|
|
9
|
+
import os
|
|
10
|
+
from email.message import Message
|
|
11
|
+
from typing import Any, List, Optional
|
|
12
|
+
from urllib.parse import urlparse
|
|
13
|
+
|
|
14
|
+
import pydash
|
|
15
|
+
from loguru import logger
|
|
16
|
+
from requests import Response
|
|
17
|
+
|
|
18
|
+
from fides.api.common_exceptions import PrivacyRequestError
|
|
19
|
+
from fides.api.schemas.saas.async_polling_configuration import (
|
|
20
|
+
PollingResult,
|
|
21
|
+
PollingResultType,
|
|
22
|
+
SupportedDataType,
|
|
23
|
+
)
|
|
24
|
+
from fides.api.util.collection_util import Row
|
|
25
|
+
|
|
26
|
+
CONTENT_TYPE = "content-type"
|
|
27
|
+
CONTENT_DISPOSITION = "content-disposition"
|
|
28
|
+
|
|
29
|
+
# Content type mappings for data type detection
|
|
30
|
+
CONTENT_TYPE_MAP = {
|
|
31
|
+
"application/json": SupportedDataType.json,
|
|
32
|
+
"text/csv": SupportedDataType.csv,
|
|
33
|
+
"application/csv": SupportedDataType.csv,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# File extensions that indicate attachments
|
|
37
|
+
ATTACHMENT_EXTENSIONS = {
|
|
38
|
+
".zip",
|
|
39
|
+
".pdf",
|
|
40
|
+
".tar",
|
|
41
|
+
".gz",
|
|
42
|
+
".xlsx",
|
|
43
|
+
".xls",
|
|
44
|
+
".xml",
|
|
45
|
+
".csv",
|
|
46
|
+
".jpg",
|
|
47
|
+
".jpeg",
|
|
48
|
+
".png",
|
|
49
|
+
".gif",
|
|
50
|
+
".bmp",
|
|
51
|
+
".tiff",
|
|
52
|
+
".webp",
|
|
53
|
+
".svg",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# Content types that should always be attachments
|
|
57
|
+
ATTACHMENT_CONTENT_TYPES = {
|
|
58
|
+
"application/octet-stream",
|
|
59
|
+
"application/zip",
|
|
60
|
+
"application/pdf",
|
|
61
|
+
"application/xml",
|
|
62
|
+
"text/xml",
|
|
63
|
+
"image/",
|
|
64
|
+
"video/",
|
|
65
|
+
"text/csv",
|
|
66
|
+
"application/csv",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
# Initialize mimetypes module for content type inference
|
|
70
|
+
mimetypes.init()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class PollingResponseProcessor:
|
|
74
|
+
"""Pure utility for processing async polling responses with smart data type inference."""
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
def process_result_response(
|
|
78
|
+
cls, request_path: str, response: Response, result_path: Optional[str] = None
|
|
79
|
+
) -> PollingResult:
|
|
80
|
+
"""Process response with smart data type inference."""
|
|
81
|
+
inferred_type = cls._infer_data_type(request_path, response)
|
|
82
|
+
|
|
83
|
+
if cls._should_store_as_attachment(response, request_path, inferred_type):
|
|
84
|
+
return cls._build_attachment_result(response, request_path, inferred_type)
|
|
85
|
+
|
|
86
|
+
rows = cls._parse_to_rows(response, inferred_type, result_path)
|
|
87
|
+
return PollingResult(
|
|
88
|
+
data=rows,
|
|
89
|
+
result_type=PollingResultType.rows,
|
|
90
|
+
metadata={
|
|
91
|
+
"inferred_type": inferred_type.value,
|
|
92
|
+
"content_type": response.headers.get(CONTENT_TYPE, ""),
|
|
93
|
+
"row_count": len(rows),
|
|
94
|
+
"parsed_to_rows": True,
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
@staticmethod
|
|
99
|
+
def evaluate_status_response(
|
|
100
|
+
response: Response,
|
|
101
|
+
status_path: str,
|
|
102
|
+
status_completed_value: Optional[Any] = None,
|
|
103
|
+
) -> bool:
|
|
104
|
+
"""Process status response and extract completion status."""
|
|
105
|
+
# Check if response is JSON
|
|
106
|
+
content_type = response.headers.get(CONTENT_TYPE, "").lower()
|
|
107
|
+
if "application/json" not in content_type:
|
|
108
|
+
return False
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
status_value = pydash.get(response.json(), status_path)
|
|
112
|
+
except ValueError as e:
|
|
113
|
+
logger.error(f"Invalid JSON response in status check: {e}")
|
|
114
|
+
return False
|
|
115
|
+
|
|
116
|
+
# Handle list values - check first element
|
|
117
|
+
if isinstance(status_value, list) and status_value:
|
|
118
|
+
status_value = status_value[0]
|
|
119
|
+
|
|
120
|
+
# Direct comparison if completed value specified
|
|
121
|
+
if status_completed_value is not None:
|
|
122
|
+
return status_value == status_completed_value
|
|
123
|
+
|
|
124
|
+
# Otherwise, check truthiness
|
|
125
|
+
return bool(status_value)
|
|
126
|
+
|
|
127
|
+
@staticmethod
|
|
128
|
+
def _infer_data_type(request_path: str, response: Response) -> SupportedDataType:
|
|
129
|
+
"""Infer data type from response characteristics."""
|
|
130
|
+
content_type = response.headers.get(CONTENT_TYPE, "").lower()
|
|
131
|
+
|
|
132
|
+
# Check for attachment content types first
|
|
133
|
+
if any(ct in content_type for ct in ATTACHMENT_CONTENT_TYPES):
|
|
134
|
+
return SupportedDataType.attachment
|
|
135
|
+
|
|
136
|
+
# Check content-type header (most reliable)
|
|
137
|
+
for content_type_pattern, data_type in CONTENT_TYPE_MAP.items():
|
|
138
|
+
if content_type_pattern in content_type:
|
|
139
|
+
return data_type
|
|
140
|
+
|
|
141
|
+
# Check URL extension
|
|
142
|
+
path = urlparse(request_path.lower()).path
|
|
143
|
+
if path.endswith(".csv"):
|
|
144
|
+
return SupportedDataType.csv
|
|
145
|
+
|
|
146
|
+
# Try parsing as JSON
|
|
147
|
+
try:
|
|
148
|
+
response.json()
|
|
149
|
+
return SupportedDataType.json
|
|
150
|
+
except (ValueError, TypeError):
|
|
151
|
+
pass
|
|
152
|
+
|
|
153
|
+
return SupportedDataType.attachment # Preserve unknown types as raw data
|
|
154
|
+
|
|
155
|
+
@staticmethod
|
|
156
|
+
def _should_store_as_attachment(
|
|
157
|
+
response: Response, request_path: str, inferred_type: SupportedDataType
|
|
158
|
+
) -> bool:
|
|
159
|
+
"""Determine if response should be treated as an attachment."""
|
|
160
|
+
content_type = response.headers.get(CONTENT_TYPE, "").lower()
|
|
161
|
+
|
|
162
|
+
# Check attachment-specific indicators
|
|
163
|
+
if inferred_type == SupportedDataType.attachment:
|
|
164
|
+
return True
|
|
165
|
+
|
|
166
|
+
if "attachment" in response.headers.get(CONTENT_DISPOSITION, "").lower():
|
|
167
|
+
return True
|
|
168
|
+
|
|
169
|
+
if any(ct in content_type for ct in ATTACHMENT_CONTENT_TYPES):
|
|
170
|
+
return True
|
|
171
|
+
|
|
172
|
+
# Check file extension in URL
|
|
173
|
+
path = urlparse(request_path.lower()).path
|
|
174
|
+
if any(path.endswith(ext) for ext in ATTACHMENT_EXTENSIONS):
|
|
175
|
+
return True
|
|
176
|
+
|
|
177
|
+
return False
|
|
178
|
+
|
|
179
|
+
@staticmethod
|
|
180
|
+
def _extract_filename(response: Response, request_url: str) -> str:
|
|
181
|
+
"""Extract filename from response or URL."""
|
|
182
|
+
# Try Content-Disposition header using email.message for proper parsing
|
|
183
|
+
disposition = response.headers.get(CONTENT_DISPOSITION)
|
|
184
|
+
if disposition:
|
|
185
|
+
msg = Message()
|
|
186
|
+
msg[CONTENT_DISPOSITION] = disposition
|
|
187
|
+
filename = msg.get_filename()
|
|
188
|
+
if filename:
|
|
189
|
+
return filename
|
|
190
|
+
|
|
191
|
+
# Extract from URL path using os.path.basename
|
|
192
|
+
path = urlparse(request_url).path
|
|
193
|
+
if path:
|
|
194
|
+
filename = os.path.basename(path)
|
|
195
|
+
if filename:
|
|
196
|
+
return filename
|
|
197
|
+
|
|
198
|
+
return "polling_result"
|
|
199
|
+
|
|
200
|
+
@staticmethod
|
|
201
|
+
def _build_attachment_result(
|
|
202
|
+
response: Response, request_url: str, inferred_type: SupportedDataType
|
|
203
|
+
) -> PollingResult:
|
|
204
|
+
"""Build a PollingResult for attachment data."""
|
|
205
|
+
filename = PollingResponseProcessor._extract_filename(response, request_url)
|
|
206
|
+
|
|
207
|
+
# Get content type from header, or infer from filename extension
|
|
208
|
+
content_type = response.headers.get(CONTENT_TYPE)
|
|
209
|
+
|
|
210
|
+
# If no content type or it's generic, try to infer from filename extension using mimetypes
|
|
211
|
+
if not content_type or content_type in (
|
|
212
|
+
"application/octet-stream",
|
|
213
|
+
"text/plain",
|
|
214
|
+
):
|
|
215
|
+
guessed_type, _ = mimetypes.guess_type(filename)
|
|
216
|
+
if guessed_type:
|
|
217
|
+
content_type = guessed_type
|
|
218
|
+
else:
|
|
219
|
+
content_type = content_type or "application/octet-stream"
|
|
220
|
+
|
|
221
|
+
return PollingResult(
|
|
222
|
+
data=response.content,
|
|
223
|
+
result_type=PollingResultType.attachment,
|
|
224
|
+
metadata={
|
|
225
|
+
"inferred_type": inferred_type.value,
|
|
226
|
+
"content_type": content_type,
|
|
227
|
+
"filename": filename,
|
|
228
|
+
"size": len(response.content),
|
|
229
|
+
"preserved_as_attachment": True,
|
|
230
|
+
},
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
@staticmethod
|
|
234
|
+
def _parse_to_rows(
|
|
235
|
+
response: Response,
|
|
236
|
+
data_type: SupportedDataType,
|
|
237
|
+
result_path: Optional[str] = None,
|
|
238
|
+
) -> List[Row]:
|
|
239
|
+
"""Parse response to List[Row] based on data type."""
|
|
240
|
+
if data_type == SupportedDataType.json:
|
|
241
|
+
try:
|
|
242
|
+
data = response.json()
|
|
243
|
+
if result_path:
|
|
244
|
+
data = pydash.get(data, result_path)
|
|
245
|
+
if data is None:
|
|
246
|
+
raise PrivacyRequestError(
|
|
247
|
+
f"Could not extract data from response using path: {result_path}"
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
if isinstance(data, list):
|
|
251
|
+
return data
|
|
252
|
+
if isinstance(data, dict):
|
|
253
|
+
return [data]
|
|
254
|
+
raise PrivacyRequestError(
|
|
255
|
+
f"Expected list or dict from result request, got: {type(data)}"
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
except ValueError as e:
|
|
259
|
+
raise PrivacyRequestError(f"Invalid JSON response: {e}")
|
|
260
|
+
|
|
261
|
+
raise PrivacyRequestError(f"Cannot parse {data_type} to rows")
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Manager for polling sub-request operations and lifecycle management."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timedelta, timezone
|
|
4
|
+
from typing import Any, Dict
|
|
5
|
+
|
|
6
|
+
from loguru import logger
|
|
7
|
+
from sqlalchemy.orm import Session
|
|
8
|
+
|
|
9
|
+
from fides.api.common_exceptions import PrivacyRequestError
|
|
10
|
+
from fides.api.models.privacy_request.request_task import (
|
|
11
|
+
RequestTask,
|
|
12
|
+
RequestTaskSubRequest,
|
|
13
|
+
)
|
|
14
|
+
from fides.api.models.worker_task import ExecutionLogStatus
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PollingSubRequestHandler:
|
|
18
|
+
"""Utility class for managing polling sub-request lifecycle and status checking."""
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def create_sub_request(
|
|
22
|
+
session: Session,
|
|
23
|
+
request_task: RequestTask,
|
|
24
|
+
param_values_map: Dict[str, Any],
|
|
25
|
+
) -> RequestTaskSubRequest:
|
|
26
|
+
"""
|
|
27
|
+
Create a new sub-request for tracking async polling operations.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
session: Database session
|
|
31
|
+
request_task: The parent request task
|
|
32
|
+
param_values_map: Parameter values including correlation_id for polling
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
RequestTaskSubRequest: The created sub-request
|
|
36
|
+
"""
|
|
37
|
+
sub_request = RequestTaskSubRequest.create(
|
|
38
|
+
session,
|
|
39
|
+
data={
|
|
40
|
+
"request_task_id": request_task.id,
|
|
41
|
+
"param_values": param_values_map,
|
|
42
|
+
"status": ExecutionLogStatus.pending.value,
|
|
43
|
+
},
|
|
44
|
+
)
|
|
45
|
+
logger.info(
|
|
46
|
+
f"Created sub-request {sub_request.id} for task '{request_task.id}'"
|
|
47
|
+
)
|
|
48
|
+
return sub_request
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def check_completion(polling_task: RequestTask) -> bool:
|
|
52
|
+
"""
|
|
53
|
+
Check if all sub-requests for a polling task are complete.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
polling_task: The polling task to check
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
bool: True if all sub-requests are complete, False if still in progress
|
|
60
|
+
"""
|
|
61
|
+
# Get all sub-requests and categorize by status
|
|
62
|
+
all_sub_requests = polling_task.sub_requests
|
|
63
|
+
completed_sub_requests = [
|
|
64
|
+
sub_request
|
|
65
|
+
for sub_request in all_sub_requests
|
|
66
|
+
if sub_request.status == ExecutionLogStatus.complete.value
|
|
67
|
+
]
|
|
68
|
+
failed_sub_requests = [
|
|
69
|
+
sub_request
|
|
70
|
+
for sub_request in all_sub_requests
|
|
71
|
+
if sub_request.status == ExecutionLogStatus.error.value
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
if (
|
|
75
|
+
len(completed_sub_requests) == len(all_sub_requests)
|
|
76
|
+
and len(all_sub_requests) > 0
|
|
77
|
+
):
|
|
78
|
+
# All sub-requests completed successfully - aggregate results
|
|
79
|
+
logger.info(
|
|
80
|
+
f"All sub-requests completed successfully for task {polling_task.id}"
|
|
81
|
+
)
|
|
82
|
+
return True
|
|
83
|
+
|
|
84
|
+
# Still polling - some sub-requests are pending
|
|
85
|
+
logger.info(
|
|
86
|
+
f"Polling task {polling_task.id}: {len(completed_sub_requests)}/{len(all_sub_requests)} sub-requests complete, {len(failed_sub_requests)} failed"
|
|
87
|
+
)
|
|
88
|
+
return False
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def check_timeout(polling_task: RequestTask, timeout_days: int) -> None:
|
|
92
|
+
"""
|
|
93
|
+
Check if any sub-requests have exceeded the polling timeout.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
polling_task: The polling task to check
|
|
97
|
+
timeout_days: Timeout threshold in days
|
|
98
|
+
|
|
99
|
+
Raises:
|
|
100
|
+
PrivacyRequestError: If any sub-request has timed out
|
|
101
|
+
"""
|
|
102
|
+
timeout_seconds = timeout_days * 24 * 60 * 60 # Convert days to seconds
|
|
103
|
+
|
|
104
|
+
# Check timeout for incomplete sub-requests only
|
|
105
|
+
timed_out_sub_requests = []
|
|
106
|
+
|
|
107
|
+
for sub_request in polling_task.sub_requests:
|
|
108
|
+
if sub_request.status != ExecutionLogStatus.complete.value:
|
|
109
|
+
# Check if this sub-request has timed out
|
|
110
|
+
if sub_request.created_at:
|
|
111
|
+
timeout_threshold = sub_request.created_at + timedelta(
|
|
112
|
+
seconds=timeout_seconds
|
|
113
|
+
)
|
|
114
|
+
current_time = datetime.now(timezone.utc)
|
|
115
|
+
if current_time > timeout_threshold:
|
|
116
|
+
timed_out_sub_requests.append(sub_request)
|
|
117
|
+
|
|
118
|
+
if timed_out_sub_requests:
|
|
119
|
+
sub_request_ids = [sr.id for sr in timed_out_sub_requests]
|
|
120
|
+
raise PrivacyRequestError(
|
|
121
|
+
f"Polling timeout exceeded for sub-requests {sub_request_ids} "
|
|
122
|
+
f"in task {polling_task.id}. Timeout interval: {timeout_days} days"
|
|
123
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import Any, Dict, List
|
|
3
|
+
|
|
4
|
+
from sqlalchemy.orm import Session
|
|
5
|
+
|
|
6
|
+
from fides.api.models.privacy_request.request_task import AsyncTaskType, RequestTask
|
|
7
|
+
from fides.api.service.connectors.query_configs.saas_query_config import SaaSQueryConfig
|
|
8
|
+
from fides.api.service.connectors.saas.authenticated_client import AuthenticatedClient
|
|
9
|
+
from fides.api.service.strategy import Strategy
|
|
10
|
+
from fides.api.util.collection_util import Row
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AsyncDSRStrategy(Strategy):
|
|
14
|
+
"""Abstract base class for async DSR strategies"""
|
|
15
|
+
|
|
16
|
+
type: AsyncTaskType
|
|
17
|
+
session: Session
|
|
18
|
+
|
|
19
|
+
@abstractmethod
|
|
20
|
+
def async_retrieve_data(
|
|
21
|
+
self,
|
|
22
|
+
client: AuthenticatedClient,
|
|
23
|
+
request_task_id: str,
|
|
24
|
+
query_config: SaaSQueryConfig,
|
|
25
|
+
input_data: Dict[str, List[Any]],
|
|
26
|
+
) -> List[Row]:
|
|
27
|
+
"""
|
|
28
|
+
Execute async retrieve data.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def async_mask_data(
|
|
33
|
+
self,
|
|
34
|
+
client: AuthenticatedClient,
|
|
35
|
+
request_task_id: str,
|
|
36
|
+
query_config: SaaSQueryConfig,
|
|
37
|
+
rows: List[Row],
|
|
38
|
+
) -> int:
|
|
39
|
+
"""
|
|
40
|
+
Execute async mask data.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def _get_request_task(self, request_task_id: str) -> RequestTask:
|
|
44
|
+
"""Get request task by ID or raise ValueError if not found."""
|
|
45
|
+
request_task = (
|
|
46
|
+
self.session.query(RequestTask)
|
|
47
|
+
.filter(RequestTask.id == request_task_id)
|
|
48
|
+
.first()
|
|
49
|
+
)
|
|
50
|
+
if not request_task:
|
|
51
|
+
raise ValueError(f"RequestTask with ID {request_task_id} not found")
|
|
52
|
+
return request_task
|