ethyca-fides 2.63.1b1__py2.py3-none-any.whl → 2.63.1b3__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.
Files changed (107) hide show
  1. {ethyca_fides-2.63.1b1.dist-info → ethyca_fides-2.63.1b3.dist-info}/METADATA +1 -1
  2. {ethyca_fides-2.63.1b1.dist-info → ethyca_fides-2.63.1b3.dist-info}/RECORD +107 -98
  3. fides/_version.py +3 -3
  4. fides/api/alembic/migrations/versions/5efcdf18438e_add_manual_task_tables.py +160 -0
  5. fides/api/db/base.py +2 -0
  6. fides/api/models/manual_tasks/__init__.py +8 -0
  7. fides/api/models/manual_tasks/manual_task.py +110 -0
  8. fides/api/models/manual_tasks/manual_task_log.py +100 -0
  9. fides/api/schemas/manual_tasks/__init__.py +0 -0
  10. fides/api/schemas/manual_tasks/manual_task_schemas.py +79 -0
  11. fides/api/schemas/manual_tasks/manual_task_status.py +151 -0
  12. fides/api/util/cache.py +77 -1
  13. fides/config/redis_settings.py +99 -8
  14. fides/service/manual_tasks/__init__.py +0 -0
  15. fides/service/manual_tasks/manual_task_service.py +150 -0
  16. fides/ui-build/static/admin/404.html +1 -1
  17. fides/ui-build/static/admin/add-systems/manual.html +1 -1
  18. fides/ui-build/static/admin/add-systems/multiple.html +1 -1
  19. fides/ui-build/static/admin/add-systems.html +1 -1
  20. fides/ui-build/static/admin/consent/configure/add-vendors.html +1 -1
  21. fides/ui-build/static/admin/consent/configure.html +1 -1
  22. fides/ui-build/static/admin/consent/privacy-experience/[id].html +1 -1
  23. fides/ui-build/static/admin/consent/privacy-experience/new.html +1 -1
  24. fides/ui-build/static/admin/consent/privacy-experience.html +1 -1
  25. fides/ui-build/static/admin/consent/privacy-notices/[id].html +1 -1
  26. fides/ui-build/static/admin/consent/privacy-notices/new.html +1 -1
  27. fides/ui-build/static/admin/consent/privacy-notices.html +1 -1
  28. fides/ui-build/static/admin/consent/properties.html +1 -1
  29. fides/ui-build/static/admin/consent/reporting.html +1 -1
  30. fides/ui-build/static/admin/consent.html +1 -1
  31. fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn]/[resourceUrn].html +1 -1
  32. fides/ui-build/static/admin/data-catalog/[systemId]/projects/[projectUrn].html +1 -1
  33. fides/ui-build/static/admin/data-catalog/[systemId]/projects.html +1 -1
  34. fides/ui-build/static/admin/data-catalog/[systemId]/resources/[resourceUrn].html +1 -1
  35. fides/ui-build/static/admin/data-catalog/[systemId]/resources.html +1 -1
  36. fides/ui-build/static/admin/data-catalog.html +1 -1
  37. fides/ui-build/static/admin/data-discovery/action-center/[monitorId]/[systemId].html +1 -1
  38. fides/ui-build/static/admin/data-discovery/action-center/[monitorId].html +1 -1
  39. fides/ui-build/static/admin/data-discovery/action-center.html +1 -1
  40. fides/ui-build/static/admin/data-discovery/activity.html +1 -1
  41. fides/ui-build/static/admin/data-discovery/detection/[resourceUrn].html +1 -1
  42. fides/ui-build/static/admin/data-discovery/detection.html +1 -1
  43. fides/ui-build/static/admin/data-discovery/discovery/[resourceUrn].html +1 -1
  44. fides/ui-build/static/admin/data-discovery/discovery.html +1 -1
  45. fides/ui-build/static/admin/datamap.html +1 -1
  46. fides/ui-build/static/admin/dataset/[datasetId]/[collectionName]/[...subfieldNames].html +1 -1
  47. fides/ui-build/static/admin/dataset/[datasetId]/[collectionName].html +1 -1
  48. fides/ui-build/static/admin/dataset/[datasetId].html +1 -1
  49. fides/ui-build/static/admin/dataset/new.html +1 -1
  50. fides/ui-build/static/admin/dataset.html +1 -1
  51. fides/ui-build/static/admin/datastore-connection/[id].html +1 -1
  52. fides/ui-build/static/admin/datastore-connection/new.html +1 -1
  53. fides/ui-build/static/admin/datastore-connection.html +1 -1
  54. fides/ui-build/static/admin/index.html +1 -1
  55. fides/ui-build/static/admin/integrations/[id].html +1 -1
  56. fides/ui-build/static/admin/integrations.html +1 -1
  57. fides/ui-build/static/admin/lib/fides-ext-gpp.js +1 -1
  58. fides/ui-build/static/admin/lib/fides-headless.js +1 -1
  59. fides/ui-build/static/admin/lib/fides-preview.js +1 -1
  60. fides/ui-build/static/admin/lib/fides-tcf.js +2 -2
  61. fides/ui-build/static/admin/lib/fides.js +2 -2
  62. fides/ui-build/static/admin/login/[provider].html +1 -1
  63. fides/ui-build/static/admin/login.html +1 -1
  64. fides/ui-build/static/admin/messaging/[id].html +1 -1
  65. fides/ui-build/static/admin/messaging/add-template.html +1 -1
  66. fides/ui-build/static/admin/messaging.html +1 -1
  67. fides/ui-build/static/admin/poc/ant-components.html +1 -1
  68. fides/ui-build/static/admin/poc/form-experiments/AntForm.html +1 -1
  69. fides/ui-build/static/admin/poc/form-experiments/FormikAntFormItem.html +1 -1
  70. fides/ui-build/static/admin/poc/form-experiments/FormikControlled.html +1 -1
  71. fides/ui-build/static/admin/poc/form-experiments/FormikField.html +1 -1
  72. fides/ui-build/static/admin/poc/form-experiments/FormikSpreadField.html +1 -1
  73. fides/ui-build/static/admin/poc/forms.html +1 -1
  74. fides/ui-build/static/admin/poc/table-migration.html +1 -1
  75. fides/ui-build/static/admin/privacy-requests/[id].html +1 -1
  76. fides/ui-build/static/admin/privacy-requests/configure/messaging.html +1 -1
  77. fides/ui-build/static/admin/privacy-requests/configure/storage.html +1 -1
  78. fides/ui-build/static/admin/privacy-requests/configure.html +1 -1
  79. fides/ui-build/static/admin/privacy-requests.html +1 -1
  80. fides/ui-build/static/admin/properties/[id].html +1 -1
  81. fides/ui-build/static/admin/properties/add-property.html +1 -1
  82. fides/ui-build/static/admin/properties.html +1 -1
  83. fides/ui-build/static/admin/reporting/datamap.html +1 -1
  84. fides/ui-build/static/admin/settings/about/alpha.html +1 -1
  85. fides/ui-build/static/admin/settings/about.html +1 -1
  86. fides/ui-build/static/admin/settings/consent/[configuration_id]/[purpose_id].html +1 -1
  87. fides/ui-build/static/admin/settings/consent.html +1 -1
  88. fides/ui-build/static/admin/settings/custom-fields.html +1 -1
  89. fides/ui-build/static/admin/settings/domain-records.html +1 -1
  90. fides/ui-build/static/admin/settings/domains.html +1 -1
  91. fides/ui-build/static/admin/settings/email-templates.html +1 -1
  92. fides/ui-build/static/admin/settings/locations.html +1 -1
  93. fides/ui-build/static/admin/settings/organization.html +1 -1
  94. fides/ui-build/static/admin/settings/regulations.html +1 -1
  95. fides/ui-build/static/admin/systems/configure/[id]/test-datasets.html +1 -1
  96. fides/ui-build/static/admin/systems/configure/[id].html +1 -1
  97. fides/ui-build/static/admin/systems.html +1 -1
  98. fides/ui-build/static/admin/taxonomy.html +1 -1
  99. fides/ui-build/static/admin/user-management/new.html +1 -1
  100. fides/ui-build/static/admin/user-management/profile/[id].html +1 -1
  101. fides/ui-build/static/admin/user-management.html +1 -1
  102. {ethyca_fides-2.63.1b1.dist-info → ethyca_fides-2.63.1b3.dist-info}/WHEEL +0 -0
  103. {ethyca_fides-2.63.1b1.dist-info → ethyca_fides-2.63.1b3.dist-info}/entry_points.txt +0 -0
  104. {ethyca_fides-2.63.1b1.dist-info → ethyca_fides-2.63.1b3.dist-info}/licenses/LICENSE +0 -0
  105. {ethyca_fides-2.63.1b1.dist-info → ethyca_fides-2.63.1b3.dist-info}/top_level.txt +0 -0
  106. /fides/ui-build/static/admin/_next/static/{74KgkHM2cEVIXGgJPlTZ3 → ycPcko8qnif6BlkQ6MN4D}/_buildManifest.js +0 -0
  107. /fides/ui-build/static/admin/_next/static/{74KgkHM2cEVIXGgJPlTZ3 → ycPcko8qnif6BlkQ6MN4D}/_ssgManifest.js +0 -0
@@ -0,0 +1,100 @@
1
+ from typing import TYPE_CHECKING, Any, Optional
2
+
3
+ from sqlalchemy import Column, ForeignKey, String
4
+ from sqlalchemy.dialects.postgresql import JSONB
5
+ from sqlalchemy.ext.declarative import declared_attr
6
+ from sqlalchemy.orm import Session, relationship
7
+
8
+ from fides.api.db.base_class import Base
9
+ from fides.api.schemas.manual_tasks.manual_task_schemas import ManualTaskLogStatus
10
+
11
+ if TYPE_CHECKING:
12
+ from fides.api.models.manual_tasks.manual_task import ManualTask
13
+
14
+
15
+ class ManualTaskLog(Base):
16
+ """Model for storing manual task execution logs."""
17
+
18
+ @declared_attr
19
+ def __tablename__(cls) -> str:
20
+ """Overriding base class method to set the table name."""
21
+ return "manual_task_log"
22
+
23
+ task_id = Column(
24
+ String, ForeignKey("manual_task.id", ondelete="CASCADE"), nullable=False
25
+ )
26
+ # TODO: Add foreign key constraints when config and instance are implemented
27
+ config_id = Column(String, nullable=True)
28
+ instance_id = Column(String, nullable=True)
29
+ status = Column(String, nullable=False)
30
+ message = Column(String, nullable=True)
31
+ details = Column(JSONB, nullable=True)
32
+
33
+ # Relationships - using string references to avoid circular imports
34
+ task = relationship("ManualTask", back_populates="logs", foreign_keys=[task_id])
35
+ # TODO: Add config and instance relationships when they are implemented
36
+ # config = relationship("ManualTaskConfig", back_populates="logs")
37
+ # instance = relationship("ManualTaskInstance", back_populates="logs")
38
+
39
+ @classmethod
40
+ def create_log(
41
+ cls,
42
+ db: Session,
43
+ status: ManualTaskLogStatus,
44
+ task_id: str,
45
+ config_id: Optional[str] = None,
46
+ instance_id: Optional[str] = None,
47
+ message: Optional[str] = None,
48
+ details: Optional[dict[str, Any]] = None,
49
+ ) -> "ManualTaskLog":
50
+ """Create a new task log entry.
51
+
52
+ Args:
53
+ db: Database session
54
+ task_id: ID of the task
55
+ status: Status of the log entry
56
+ message: Optional message describing the event
57
+ details: Optional additional details about the event
58
+ """
59
+ data = {
60
+ "task_id": task_id,
61
+ "config_id": config_id,
62
+ "instance_id": instance_id,
63
+ "status": status,
64
+ "message": message,
65
+ "details": details,
66
+ }
67
+ return cls.create(db=db, data=data)
68
+
69
+ @classmethod
70
+ def create_error_log(
71
+ cls,
72
+ db: Session,
73
+ task_id: str,
74
+ message: str,
75
+ config_id: Optional[str] = None,
76
+ instance_id: Optional[str] = None,
77
+ details: Optional[dict[str, Any]] = None,
78
+ ) -> "ManualTaskLog":
79
+ """Create a new error log entry.
80
+
81
+ Args:
82
+ db: Database session
83
+ task_id: ID of the task
84
+ message: Error message describing what went wrong
85
+ config_id: Optional ID of the configuration
86
+ instance_id: Optional ID of the instance
87
+ details: Optional additional details about the error
88
+
89
+ Returns:
90
+ The created error log entry
91
+ """
92
+ return cls.create_log(
93
+ db=db,
94
+ status=ManualTaskLogStatus.error,
95
+ task_id=task_id,
96
+ config_id=config_id,
97
+ instance_id=instance_id,
98
+ message=message,
99
+ details=details,
100
+ )
File without changes
@@ -0,0 +1,79 @@
1
+ from datetime import datetime
2
+ from enum import Enum
3
+ from typing import Annotated, Any, Optional
4
+
5
+ from pydantic import ConfigDict, Field
6
+
7
+ from fides.api.schemas.base_class import FidesSchema
8
+
9
+
10
+ class ManualTaskType(str, Enum):
11
+ """Enum for manual task types."""
12
+
13
+ privacy_request = "privacy_request"
14
+ # Add more task types as needed
15
+
16
+
17
+ class ManualTaskParentEntityType(str, Enum):
18
+ """Enum for manual task parent entity types."""
19
+
20
+ connection_config = (
21
+ "connection_config" # used for access and erasure privacy requests
22
+ )
23
+ # Add more parent entity types as needed
24
+
25
+
26
+ class ManualTaskReferenceType(str, Enum):
27
+ """Enum for manual task reference types."""
28
+
29
+ privacy_request = "privacy_request"
30
+ connection_config = "connection_config"
31
+ manual_task_config = "manual_task_config"
32
+ assigned_user = "assigned_user" # Reference to the user assigned to the task
33
+ # Add more reference types as needed
34
+
35
+
36
+ class ManualTaskLogStatus(str, Enum):
37
+ """Enum for manual task log status."""
38
+
39
+ created = "created"
40
+ updated = "updated"
41
+ in_processing = "in_processing"
42
+ complete = "complete"
43
+ error = "error"
44
+ retrying = "retrying"
45
+ paused = "paused"
46
+ awaiting_input = "awaiting_input"
47
+
48
+
49
+ class ManualTaskLogCreate(FidesSchema):
50
+ """Schema for creating a manual task log entry."""
51
+
52
+ model_config = ConfigDict(extra="forbid")
53
+
54
+ task_id: Annotated[str, Field(..., description="ID of the task")]
55
+ status: Annotated[ManualTaskLogStatus, Field(..., description="Log status")]
56
+ message: Annotated[Optional[str], Field(None, description="Log message")]
57
+ details: Annotated[
58
+ Optional[dict[str, Any]], Field(None, description="Additional details")
59
+ ]
60
+ config_id: Annotated[Optional[str], Field(None, description="Configuration ID")]
61
+ instance_id: Annotated[Optional[str], Field(None, description="Instance ID")]
62
+
63
+
64
+ class ManualTaskLogResponse(FidesSchema):
65
+ """Schema for manual task log response."""
66
+
67
+ model_config = ConfigDict(extra="forbid")
68
+
69
+ id: Annotated[str, Field(..., description="Log ID")]
70
+ task_id: Annotated[str, Field(..., description="Task ID")]
71
+ status: Annotated[ManualTaskLogStatus, Field(..., description="Log status")]
72
+ message: Annotated[Optional[str], Field(None, description="Log message")]
73
+ details: Annotated[
74
+ Optional[dict[str, Any]], Field(None, description="Additional details")
75
+ ]
76
+ config_id: Annotated[Optional[str], Field(None, description="Configuration ID")]
77
+ instance_id: Annotated[Optional[str], Field(None, description="Instance ID")]
78
+ created_at: Annotated[datetime, Field(..., description="Creation timestamp")]
79
+ updated_at: Annotated[datetime, Field(..., description="Last update timestamp")]
@@ -0,0 +1,151 @@
1
+ from datetime import datetime, timezone
2
+ from enum import Enum as EnumType
3
+ from typing import Optional
4
+
5
+ from sqlalchemy.orm import Session
6
+
7
+
8
+ class StatusTransitionNotAllowed(Exception):
9
+ """Exception raised when a status transition is not allowed."""
10
+
11
+ def __init__(self, message: str):
12
+ self.message = message
13
+ super().__init__(self.message)
14
+
15
+
16
+ class StatusType(str, EnumType):
17
+ """Enum for manual task status."""
18
+
19
+ pending = "pending"
20
+ in_progress = "in_progress"
21
+ completed = "completed"
22
+ failed = "failed"
23
+
24
+ @classmethod
25
+ def get_valid_transitions(cls, current_status: "StatusType") -> list["StatusType"]:
26
+ """Get valid transitions from the current status.
27
+
28
+ Args:
29
+ current_status: The current status
30
+
31
+ Returns:
32
+ list[StatusType]: List of valid transitions
33
+ """
34
+ if current_status == cls.pending:
35
+ return [cls.in_progress, cls.failed]
36
+ if current_status == cls.in_progress:
37
+ return [cls.completed, cls.failed]
38
+ if current_status == cls.completed:
39
+ return []
40
+ if current_status == cls.failed:
41
+ return [cls.pending, cls.in_progress]
42
+ return []
43
+
44
+
45
+ class StatusTransitionMixin:
46
+ """Mixin for handling status transitions.
47
+
48
+ This mixin provides methods for managing status transitions and completion tracking.
49
+ It can be used by any model that needs status management.
50
+ """
51
+
52
+ # These should be overridden by the implementing class
53
+ status: StatusType
54
+ completed_at: Optional[datetime]
55
+ completed_by_id: Optional[str]
56
+
57
+ def _get_valid_transitions(self) -> list[StatusType]:
58
+ """Get valid transitions from the current status.
59
+
60
+ Returns:
61
+ list[StatusType]: List of valid transitions
62
+ """
63
+ return StatusType.get_valid_transitions(self.status)
64
+
65
+ def _validate_status_transition(self, new_status: StatusType) -> None:
66
+ """Validate that a status transition is allowed.
67
+
68
+ Args:
69
+ new_status: The new status to transition to
70
+
71
+ Raises:
72
+ StatusTransitionNotAllowed: If the transition is not allowed
73
+ """
74
+ # Don't allow transitions to the same status
75
+ if new_status == self.status:
76
+ raise StatusTransitionNotAllowed(
77
+ f"Invalid status transition: already in status {new_status}"
78
+ )
79
+
80
+ # Get valid transitions for current status
81
+ valid_transitions = self._get_valid_transitions()
82
+ if new_status not in valid_transitions:
83
+ raise StatusTransitionNotAllowed(
84
+ f"Invalid status transition from {self.status} to {new_status}. "
85
+ f"Valid transitions are: {valid_transitions}"
86
+ )
87
+
88
+ def update_status(
89
+ self, db: Session, new_status: StatusType, user_id: Optional[str] = None
90
+ ) -> None:
91
+ """Update the status with validation and completion handling.
92
+
93
+ Args:
94
+ db: Database session
95
+ new_status: New status to set
96
+ user_id: Optional user ID who is making the change
97
+ """
98
+ self._validate_status_transition(new_status)
99
+
100
+ if new_status == StatusType.completed:
101
+ self.completed_at = datetime.now(timezone.utc)
102
+ self.completed_by_id = user_id
103
+ elif new_status == StatusType.pending:
104
+ # Reset completion fields if going back to pending
105
+ self.completed_at = None
106
+ self.completed_by_id = None
107
+
108
+ self.status = new_status
109
+ db.add(self)
110
+ db.commit()
111
+
112
+ def mark_completed(self, db: Session, user_id: str) -> None:
113
+ """Mark as completed.
114
+
115
+ Args:
116
+ db: Database session
117
+ user_id: user ID who completed the task
118
+ """
119
+ self.update_status(db, StatusType.completed, user_id)
120
+
121
+ def mark_failed(self, db: Session) -> None:
122
+ """Mark as failed."""
123
+ self.update_status(db, StatusType.failed)
124
+
125
+ def start_progress(self, db: Session) -> None:
126
+ """Mark as in progress."""
127
+ self.update_status(db, StatusType.in_progress)
128
+
129
+ def reset_to_pending(self, db: Session) -> None:
130
+ """Reset to pending status."""
131
+ self.update_status(db, StatusType.pending)
132
+
133
+ @property
134
+ def is_completed(self) -> bool:
135
+ """Check if completed."""
136
+ return self.status == StatusType.completed
137
+
138
+ @property
139
+ def is_failed(self) -> bool:
140
+ """Check if failed."""
141
+ return self.status == StatusType.failed
142
+
143
+ @property
144
+ def is_in_progress(self) -> bool:
145
+ """Check if in progress."""
146
+ return self.status == StatusType.in_progress
147
+
148
+ @property
149
+ def is_pending(self) -> bool:
150
+ """Check if pending."""
151
+ return self.status == StatusType.pending
fides/api/util/cache.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import json
2
+ import os
2
3
  from typing import Any, Dict, List, Optional, Union
3
4
  from urllib.parse import unquote_to_bytes
4
5
 
@@ -27,6 +28,7 @@ from fides.config import CONFIG
27
28
  RedisValue = Union[bytes, float, int, str]
28
29
 
29
30
  _connection = None
31
+ _read_only_connection = None
30
32
 
31
33
 
32
34
  class FidesopsRedis(Redis):
@@ -157,6 +159,36 @@ class FidesopsRedis(Redis):
157
159
  return list_length
158
160
 
159
161
 
162
+ # FIXME: Ideally we don't want our code to be aware of the way tests are run,
163
+ # e.g that we run them in parallel with pytest-xdist. We need to find a way
164
+ # to change the pytest_configure_node hook to set the correct environment variable
165
+ # like we do for the readonly database. It wasn't working so we're using this workaround for now.
166
+ def _determine_redis_db_index(
167
+ read_only: Optional[bool] = False,
168
+ ) -> int: # pragma: no cover
169
+ """Return the Redis DB index that should be used for the current process.
170
+
171
+ Behavior:
172
+ 1. Test mode:
173
+ - If running under xdist, map `gwN` → DB `N + 1` (reserve DB 0).
174
+ - If *not* running under xdist, always use DB 1.
175
+
176
+ 2. Non-test mode: return the value already present in `CONFIG.redis.db_index`
177
+ """
178
+
179
+ # 1. Test mode logic
180
+ if CONFIG.test_mode:
181
+ worker_id = os.getenv("PYTEST_XDIST_WORKER")
182
+ if worker_id and worker_id.startswith("gw"):
183
+ suffix = worker_id[2:]
184
+ if suffix.isdigit():
185
+ return int(suffix) + 1 # gw0 -> 1, gw1 -> 2, etc.
186
+ return CONFIG.redis.test_db_index
187
+
188
+ # 2. Non-test mode
189
+ return CONFIG.redis.read_only_db_index if read_only else CONFIG.redis.db_index
190
+
191
+
160
192
  def get_cache(should_log: Optional[bool] = False) -> FidesopsRedis:
161
193
  """Return a singleton connection to our Redis cache"""
162
194
 
@@ -173,7 +205,7 @@ def get_cache(should_log: Optional[bool] = False) -> FidesopsRedis:
173
205
  decode_responses=CONFIG.redis.decode_responses,
174
206
  host=CONFIG.redis.host,
175
207
  port=CONFIG.redis.port,
176
- db=CONFIG.redis.db_index,
208
+ db=_determine_redis_db_index(),
177
209
  username=CONFIG.redis.user,
178
210
  password=CONFIG.redis.password,
179
211
  ssl=CONFIG.redis.ssl,
@@ -202,6 +234,50 @@ def get_cache(should_log: Optional[bool] = False) -> FidesopsRedis:
202
234
  return _connection
203
235
 
204
236
 
237
+ def get_read_only_cache() -> FidesopsRedis:
238
+ """
239
+ Return a singleton connection to the read-only Redis cache.
240
+ If read-only is not enabled, return the regular cache.
241
+ """
242
+ # If read-only is not enabled, return the regular cache
243
+ if not CONFIG.redis.read_only_enabled:
244
+ logger.debug(
245
+ "Read-only Redis is not enabled. Returning writeable cache connection instead."
246
+ )
247
+ return get_cache()
248
+
249
+ global _read_only_connection # pylint: disable=W0603
250
+ if _read_only_connection is None:
251
+ logger.debug("Creating new read-only Redis connection...")
252
+ _read_only_connection = FidesopsRedis( # type: ignore[call-overload]
253
+ charset=CONFIG.redis.charset,
254
+ decode_responses=CONFIG.redis.decode_responses,
255
+ host=CONFIG.redis.read_only_host,
256
+ port=CONFIG.redis.read_only_port,
257
+ db=_determine_redis_db_index(read_only=True),
258
+ username=CONFIG.redis.read_only_user,
259
+ password=CONFIG.redis.read_only_password,
260
+ ssl=CONFIG.redis.read_only_ssl,
261
+ ssl_ca_certs=CONFIG.redis.read_only_ssl_ca_certs,
262
+ ssl_cert_reqs=CONFIG.redis.read_only_ssl_cert_reqs,
263
+ )
264
+ logger.debug("New read-only Redis connection created.")
265
+
266
+ try:
267
+ connected = _read_only_connection.ping()
268
+ logger.debug("Read-only Redis connection succeeded.")
269
+ except ConnectionErrorFromRedis:
270
+ connected = False
271
+
272
+ if not connected:
273
+ logger.error(
274
+ "Unable to establish read-only Redis connection. Returning writeable cache connection instead."
275
+ )
276
+ return get_cache()
277
+
278
+ return _read_only_connection
279
+
280
+
205
281
  def get_identity_cache_key(privacy_request_id: str, identity_attribute: str) -> str:
206
282
  """Return the key at which to save this PrivacyRequest's identity for the passed in attribute"""
207
283
  # TODO: Remove this prefix
@@ -20,6 +20,10 @@ class RedisSettings(FidesSettings):
20
20
  default=0,
21
21
  description="The application will use this index in the Redis cache to cache data.",
22
22
  )
23
+ test_db_index: int = Field(
24
+ default=1,
25
+ description="The application will use this index in the Redis cache to cache data for testing.",
26
+ )
23
27
  decode_responses: bool = Field(
24
28
  default=True,
25
29
  description="Whether or not to automatically decode the values fetched from Redis. Decodes using the `charset` configuration value.",
@@ -64,14 +68,57 @@ class RedisSettings(FidesSettings):
64
68
  default="", description="The user with which to login to the Redis cache."
65
69
  )
66
70
 
71
+ # Read-only Redis settings
72
+ read_only_enabled: bool = Field(
73
+ default=False,
74
+ description="Whether a read-only Redis cache is enabled.",
75
+ )
76
+ read_only_host: str = Field(
77
+ default="",
78
+ description="The network address for the read-only Redis cache.",
79
+ )
80
+ read_only_port: int = Field(
81
+ default=6379,
82
+ description="The port at which the read-only Redis cache will be accessible.",
83
+ )
84
+ read_only_user: str = Field(
85
+ default="",
86
+ description="The user with which to login to the read-only Redis cache.",
87
+ )
88
+ read_only_password: str = Field(
89
+ default="",
90
+ description="The password with which to login to the read-only Redis cache.",
91
+ )
92
+ read_only_db_index: int = Field(
93
+ default=0,
94
+ description="The application will use this index in the read-only Redis cache to cache data.",
95
+ )
96
+ read_only_ssl: bool = Field(
97
+ default=False,
98
+ description="Whether the application's connections to the read-only cache should be encrypted using TLS.",
99
+ )
100
+ read_only_ssl_cert_reqs: Optional[str] = Field(
101
+ default="required",
102
+ description="If using TLS encryption, set this to 'required' if you wish to enforce the read-only Redis cache to provide a certificate. Note that not all cache providers support this without setting ssl_ca_certs (e.g. AWS Elasticache).",
103
+ )
104
+ read_only_ssl_ca_certs: str = Field(
105
+ default="",
106
+ description="If using TLS encryption rooted with a custom Certificate Authority, set this to the path of the CA certificate.",
107
+ )
108
+
67
109
  # This relies on other values to get built so must be last
68
110
  connection_url: Optional[str] = Field(
69
111
  default=None,
70
112
  description="A full connection URL to the Redis cache. If not specified, this URL is automatically assembled from the host, port, password and db_index specified above.",
71
113
  exclude=True,
72
114
  )
115
+ read_only_connection_url: Optional[str] = Field(
116
+ default=None,
117
+ description="A full connection URL to the read-only Redis cache. If not specified, this URL is automatically assembled from the read_only_host, read_only_port, read_only_password and read_only_db_index specified above.",
118
+ exclude=True,
119
+ )
73
120
 
74
- @field_validator("connection_url", mode="before")
121
+ @field_validator("connection_url", "read_only_connection_url", mode="before")
75
122
  @classmethod
76
123
  def assemble_connection_url(
77
124
  cls,
@@ -83,22 +130,50 @@ class RedisSettings(FidesSettings):
83
130
  # If the whole URL is provided via the config, preference that
84
131
  return v
85
132
 
133
+ is_read_only = info.field_name == "read_only_connection_url"
134
+
86
135
  connection_protocol = "redis"
87
136
  params_str = ""
88
- use_tls = info.data.get("ssl", False)
137
+ use_tls = (
138
+ info.data.get("read_only_ssl")
139
+ if is_read_only
140
+ else info.data.get("ssl", False)
141
+ )
89
142
 
90
143
  # These vars are intentionally fetched with `or ""` as the default to account
91
144
  # for the edge case where `None` is explicitly set in `values` by Pydantic because
92
145
  # it is not overridden by the config file or an env var
93
- user = info.data.get("user") or ""
94
- password = info.data.get("password") or ""
95
- db_index = info.data.get("db_index") or ""
146
+ user = (
147
+ info.data.get("read_only_user", "")
148
+ if is_read_only
149
+ else info.data.get("user", "")
150
+ )
151
+ password = (
152
+ info.data.get("read_only_password", "")
153
+ if is_read_only
154
+ else info.data.get("password", "")
155
+ )
156
+ db_index = (
157
+ info.data.get("read_only_db_index", "")
158
+ if is_read_only
159
+ else info.data.get("db_index", "")
160
+ )
96
161
  if use_tls:
97
162
  # If using TLS update the connection URL format
98
163
  connection_protocol = "rediss"
99
- cert_reqs = info.data.get("ssl_cert_reqs", "none")
164
+ cert_reqs = (
165
+ info.data.get("read_only_ssl_cert_reqs", "none")
166
+ if is_read_only
167
+ else info.data.get("ssl_cert_reqs", "none")
168
+ )
100
169
  params = {"ssl_cert_reqs": quote_plus(cert_reqs)}
101
- if ssl_ca_certs := info.data.get("ssl_ca_certs", ""):
170
+
171
+ ssl_ca_certs = (
172
+ info.data.get("read_only_ssl_ca_certs", "")
173
+ if is_read_only
174
+ else info.data.get("ssl_ca_certs", "")
175
+ )
176
+ if ssl_ca_certs:
102
177
  params["ssl_ca_certs"] = quote(ssl_ca_certs, safe="/")
103
178
  params_str = "?" + urlencode(params, quote_via=quote, safe="/")
104
179
 
@@ -108,7 +183,23 @@ class RedisSettings(FidesSettings):
108
183
  if password or user:
109
184
  auth_prefix = f"{quote_plus(user)}:{quote_plus(password)}@"
110
185
 
111
- connection_url = f"{connection_protocol}://{auth_prefix}{info.data.get('host', '')}:{info.data.get('port', '')}/{db_index}{params_str}"
186
+ host = (
187
+ info.data.get("read_only_host", "")
188
+ if is_read_only
189
+ else info.data.get("host", "")
190
+ )
191
+ port = (
192
+ info.data.get("read_only_port", "")
193
+ if is_read_only
194
+ else info.data.get("port", "")
195
+ )
196
+
197
+ # Only include database index in URL if it's not the default (0)
198
+ db_path = f"{db_index}" if db_index != 0 else ""
199
+
200
+ connection_url = (
201
+ f"{connection_protocol}://{auth_prefix}{host}:{port}/{db_path}{params_str}"
202
+ )
112
203
  return connection_url
113
204
 
114
205
  model_config = SettingsConfigDict(env_prefix=ENV_PREFIX)
File without changes