| 49 | |
| 50 | |
| 51 | class BaseDataSource(ABC): |
| 52 | |
| 53 | @staticmethod |
| 54 | @abstractmethod |
| 55 | def get_config_fields() -> List[ConfigField]: |
| 56 | """ |
| 57 | Returns a list of fields that are required to configure the data source for UI. |
| 58 | for example: |
| 59 | [ |
| 60 | ConfigField(label="Url", name="url", type="text", placeholder="https://example.com"), |
| 61 | ConfigField(label="Token", name="token", type="password", placeholder="paste-your-token-here") |
| 62 | ] |
| 63 | """ |
| 64 | raise NotImplementedError |
| 65 | |
| 66 | @staticmethod |
| 67 | @abstractmethod |
| 68 | async def validate_config(config: Dict) -> None: |
| 69 | """ |
| 70 | Validates the config and raises an exception if it's invalid. |
| 71 | """ |
| 72 | raise NotImplementedError |
| 73 | |
| 74 | @classmethod |
| 75 | def get_display_name(cls) -> str: |
| 76 | """ |
| 77 | Returns the display name of the data source, change GoogleDriveDataSource to Google Drive. |
| 78 | """ |
| 79 | pascal_case_source = cls.__name__.replace("DataSource", "") |
| 80 | words = re.findall('[A-Z][^A-Z]*', pascal_case_source) |
| 81 | return " ".join(words) |
| 82 | |
| 83 | @staticmethod |
| 84 | def has_prerequisites() -> bool: |
| 85 | """ |
| 86 | Data sources that require some prerequisites to be installed before they can be used should override this method |
| 87 | """ |
| 88 | return False |
| 89 | |
| 90 | @staticmethod |
| 91 | def list_locations(config: Dict) -> List[Location]: |
| 92 | """ |
| 93 | Returns a list of locations that are available in the data source. |
| 94 | Only for data sources that want the user to select only some location to index |
| 95 | """ |
| 96 | return [] |
| 97 | |
| 98 | @abstractmethod |
| 99 | def _feed_new_documents(self) -> None: |
| 100 | """ |
| 101 | Feeds the indexing queue with new documents. |
| 102 | """ |
| 103 | raise NotImplementedError |
| 104 | |
| 105 | def __init__(self, config: Dict, data_source_id: int, last_index_time: datetime = None) -> None: |
| 106 | self._raw_config = config |
| 107 | self._config: BaseDataSourceConfig = BaseDataSourceConfig(**self._raw_config) |
| 108 | self._data_source_id = data_source_id |
nothing calls this directly
no outgoing calls
no test coverage detected