|
| 1 | +# How to Add a New Provider |
| 2 | + |
| 3 | +This guide explains how to integrate a new storage provider (e.g., DropBox, OneDrive) into DocBinder-OSS. The process involves creating configuration and client classes, registering the provider, and ensuring compatibility with the system’s models and interfaces. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. Create a Service Configuration Class |
| 8 | + |
| 9 | +Each provider must define a configuration class that inherits from [`ServiceConfig`](https://github.com/SnappyLab/DocBinder-OSS/blob/main/src/docbinder_oss/services/base_class.py): |
| 10 | + |
| 11 | +```python |
| 12 | +# filepath: src/docbinder_oss/services/my_provider/my_provider_service_config.py |
| 13 | +from docbinder_oss.services.base_class import ServiceConfig |
| 14 | + |
| 15 | +class MyProviderServiceConfig(ServiceConfig): |
| 16 | + type: str = "my_provider" |
| 17 | + name: str |
| 18 | + # Add any other provider-specific fields here |
| 19 | + api_key: str |
| 20 | +``` |
| 21 | + |
| 22 | +- `type` must be unique and match the provider’s identifier. |
| 23 | +- `name` is a user-defined label for this provider instance. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## 2. Implement the Storage Client |
| 28 | + |
| 29 | +Create a client class that inherits from [`BaseStorageClient`](https://github.com/SnappyLab/DocBinder-OSS/blob/main/src/docbinder_oss/services/base_class.py) and implements all abstract methods: |
| 30 | + |
| 31 | +```python |
| 32 | +# filepath: src/docbinder_oss/services/my_provider/my_provider_client.py |
| 33 | +from typing import Optional, List |
| 34 | +from docbinder_oss.services.base_class import BaseStorageClient |
| 35 | +from docbinder_oss.core.schema import File, Permission |
| 36 | +from .my_provider_service_config import MyProviderServiceConfig |
| 37 | + |
| 38 | +class MyProviderClient(BaseStorageClient): |
| 39 | + def __init__(self, config: MyProviderServiceConfig): |
| 40 | + self.config = config |
| 41 | + # Initialize SDK/client here |
| 42 | + |
| 43 | + def test_connection(self) -> bool: |
| 44 | + # Implement connection test |
| 45 | + pass |
| 46 | + |
| 47 | + def list_files(self, folder_id: Optional[str] = None) -> List[File]: |
| 48 | + # Implement file listing |
| 49 | + pass |
| 50 | + |
| 51 | + def get_file_metadata(self, item_id: str) -> File: |
| 52 | + # Implement metadata retrieval |
| 53 | + pass |
| 54 | + |
| 55 | + def get_permissions(self, item_id: str) -> List[Permission]: |
| 56 | + # Implement permissions retrieval |
| 57 | + pass |
| 58 | +``` |
| 59 | + |
| 60 | +- Use the shared models [`File`](https://github.com/SnappyLab/DocBinder-OSS/blob/main/src/docbinder_oss/core/schemas.py), [`Permission`](https://github.com/SnappyLab/DocBinder-OSS/blob/main/src/docbinder_oss/core/schemas.py), etc., for return types. |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 3. Register the Provider |
| 65 | + |
| 66 | +Add an `__init__.py` in your provider’s folder with a `register()` function: |
| 67 | + |
| 68 | +```python |
| 69 | +# filepath: src/docbinder_oss/services/my_provider/__init__.py |
| 70 | +from .my_provider_client import MyProviderClient |
| 71 | +from .my_provider_service_config import MyProviderServiceConfig |
| 72 | + |
| 73 | +def register(): |
| 74 | + return { |
| 75 | + "display_name": "my_provider", |
| 76 | + "config_class": MyProviderServiceConfig, |
| 77 | + "client_class": MyProviderClient, |
| 78 | + } |
| 79 | +``` |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## 4. Ensure Discovery |
| 84 | + |
| 85 | +The system will automatically discover your provider if it’s in the `src/docbinder_oss/services/` directory and contains a `register()` function in `__init__.py`. |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## 5. Update the Config File |
| 90 | + |
| 91 | +Add your provider’s configuration to `~/.config/docbinder/config.yaml`: |
| 92 | + |
| 93 | +```yaml |
| 94 | +providers: |
| 95 | + - type: my_provider |
| 96 | + name: my_instance |
| 97 | + # Add other required fields |
| 98 | + api_key: <your-api-key> |
| 99 | +``` |
| 100 | +
|
| 101 | +--- |
| 102 | +
|
| 103 | +## 6. Test Your Provider |
| 104 | +
|
| 105 | +- Run the application and ensure your provider appears and works as expected. |
| 106 | +- The config loader will validate your config using your `ServiceConfig` subclass. |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## Reference |
| 111 | + |
| 112 | +- [src/docbinder_oss/services/base_class.py](https://github.com/SnappyLab/DocBinder-OSS/blob/main/src/docbinder_oss/services/base_class.py) |
| 113 | +- [src/docbinder_oss/core/schemas.py](https://github.com/SnappyLab/DocBinder-OSS/blob/main/src/docbinder_oss/core/schemas.py) |
| 114 | +- [src/docbinder_oss/services/google_drive/](https://github.com/SnappyLab/DocBinder-OSS/tree/main/src/docbinder_oss/services/google_drive/) (example implementation) |
| 115 | +- [src/docbinder_oss/services/__init__.py](https://github.com/SnappyLab/DocBinder-OSS/blob/main/src/docbinder_oss/services/__init__.py) |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +**Tip:** Use the Google Drive as a template for your implementation. Make sure to follow the abstract method signatures and use the shared models for compatibility. |
0 commit comments