Skip to content

Commit

Permalink
HJ-181 - Updaeting connection configs so Datahub is only visible on f…
Browse files Browse the repository at this point in the history
…idesplus
  • Loading branch information
andres-torres-marroquin committed Jan 13, 2025
1 parent 6316961 commit 037f9be
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 23 deletions.
47 changes: 45 additions & 2 deletions src/fides/api/models/connectionconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import enum
from datetime import datetime
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type
from typing import TYPE_CHECKING, Any, List, Optional, Type

from loguru import logger
from sqlalchemy import Boolean, Column, DateTime, Enum, ForeignKey, String, event
Expand Down Expand Up @@ -72,7 +72,7 @@ def human_readable(self) -> str:
"""Human-readable mapping for ConnectionTypes
Add to this mapping if you add a new ConnectionType
"""
readable_mapping: Dict[str, str] = {
readable_mapping: dict[str, str] = {
ConnectionType.attentive_email.value: "Attentive Email",
ConnectionType.bigquery.value: "BigQuery",
ConnectionType.datahub.value: "DataHub",
Expand Down Expand Up @@ -108,6 +108,49 @@ def human_readable(self) -> str:
"Add new ConnectionType to human_readable mapping"
)

@property
def is_fidesplus(self) -> bool:
fidesplus_only_mapping: list[str] = [
ConnectionType.datahub.value
]
return self.value in fidesplus_only_mapping

@property
def system_type(self) -> SystemType:
from fides.api.schemas.connection_configuration.enums.system_type import SystemType

system_type_mapping: dict[str, SystemType] = {
ConnectionType.attentive_email.value: SystemType.email,
ConnectionType.bigquery.value: SystemType.database,
ConnectionType.datahub.value: SystemType.data_catalog,
ConnectionType.dynamic_erasure_email.value: SystemType.email,
ConnectionType.dynamodb.value: SystemType.database,
ConnectionType.fides.value: SystemType.database, # What's the actualy SystemType here?
ConnectionType.generic_consent_email.value: SystemType.email,
ConnectionType.generic_erasure_email.value: SystemType.email,
ConnectionType.google_cloud_sql_mysql.value: SystemType.database,
ConnectionType.google_cloud_sql_postgres.value: SystemType.database,
ConnectionType.https.value: SystemType.database, # What's the actualy SystemType here?
ConnectionType.manual_webhook.value: SystemType.manual,
ConnectionType.manual.value: SystemType.manual,
ConnectionType.mariadb.value: SystemType.database,
ConnectionType.mongodb.value: SystemType.database,
ConnectionType.mssql.value: SystemType.database,
ConnectionType.mysql.value: SystemType.database,
ConnectionType.postgres.value: SystemType.database,
ConnectionType.rds_mysql.value: SystemType.database,
ConnectionType.rds_postgres.value: SystemType.database,
ConnectionType.redshift.value: SystemType.database,
ConnectionType.s3.value: SystemType.database,
ConnectionType.saas.value: SystemType.saas,
ConnectionType.scylla.value: SystemType.database,
ConnectionType.snowflake.value: SystemType.database,
ConnectionType.sovrn.value: SystemType.email,
ConnectionType.timescale.value: SystemType.database,
}

return system_type_mapping[self.value]


class AccessLevel(enum.Enum):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
)


class PeriodicIntegrationFrequency(Enum):
"""Enum for periodic integration frequency"""

daily = "daily"
weekly = "weekly"
monthly = "monthly"


class DatahubSchema(ConnectionConfigSecretsSchema):
datahub_server_url: AnyHttpUrlStringRemovesSlash = Field(
title="DataHub Server URL",
Expand All @@ -28,11 +20,6 @@ class DatahubSchema(ConnectionConfigSecretsSchema):
description="The token used to authenticate with your DataHub server.",
json_schema_extra={"sensitive": True},
)
frequency: PeriodicIntegrationFrequency = Field(
title="Frequency",
description="The frequency at which the integration should run. Defaults to daily.",
default=PeriodicIntegrationFrequency.daily,
)

_required_components: ClassVar[List[str]] = ["datahub_server_url", "datahub_token"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


class SystemType(Enum):
saas = "saas"
data_catalog = "data_catalog"
database = "database"
manual = "manual"
email = "email"
manual = "manual"
saas = "saas"
20 changes: 14 additions & 6 deletions src/fides/api/util/connection_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import importlib
from typing import Any, Dict, Set

from fides.api.common_exceptions import NoSuchConnectionTypeSecretSchemaError
Expand Down Expand Up @@ -194,6 +195,12 @@ def get_connection_types(
system_type: SystemType | None = None,
action_types: Set[ActionType] = SUPPORTED_ACTION_TYPES,
) -> list[ConnectionSystemTypeMap]:

def check_fidesplus(conn_type: ConnectionType) -> bool:
"""Check if the given connection type is a Fidesplus connector."""
fidesplus_found = importlib.util.find_spec("fidesplus")
return conn_type.is_fidesplus and fidesplus_found

def is_match(elem: str) -> bool:
"""If a search query param was included, is it a substring of an available connector type?"""
return search.lower() in elem.lower() if search else True
Expand All @@ -220,9 +227,9 @@ def saas_request_type_filter(connection_type: str) -> bool:
if (system_type == SystemType.database or system_type is None) and (
ActionType.access in action_types or ActionType.erasure in action_types
):
database_types: list[str] = sorted(
database_types: list[ConnectionType] = sorted(
[
conn_type.value
conn_type
for conn_type in ConnectionType
if conn_type
not in [
Expand All @@ -237,15 +244,15 @@ def saas_request_type_filter(connection_type: str) -> bool:
ConnectionType.saas,
ConnectionType.sovrn,
]
and is_match(conn_type.value)
and is_match(conn_type.value) and check_fidesplus(conn_type)
]
)
, key=lambda x: x.value)
connection_system_types.extend(
[
ConnectionSystemTypeMap(
identifier=item,
type=SystemType.database,
human_readable=ConnectionType(item).human_readable,
type=item.system_type,
human_readable=item.human_readable,
supported_actions=[ActionType.access, ActionType.erasure],
)
for item in database_types
Expand Down Expand Up @@ -336,4 +343,5 @@ def saas_request_type_filter(connection_type: str) -> bool:
for email_type in email_types
]
)

return connection_system_types

0 comments on commit 037f9be

Please sign in to comment.