0
# Source Connector
1
2
Core Airbyte source connector functionality providing the main interface for data extraction from Microsoft OneDrive. Implements the standard Airbyte protocol for specification, validation, discovery, and reading operations.
3
4
## Capabilities
5
6
### Main Connector Class
7
8
The primary connector class that orchestrates OneDrive data extraction using Airbyte's file-based framework.
9
10
```python { .api }
11
class SourceMicrosoftOneDrive(FileBasedSource):
12
def __init__(
13
self,
14
catalog: Optional[ConfiguredAirbyteCatalog],
15
config: Optional[Mapping[str, Any]],
16
state: Optional[TState]
17
):
18
"""
19
Initialize the Microsoft OneDrive source connector.
20
21
Parameters:
22
- catalog: Optional[ConfiguredAirbyteCatalog] - Airbyte catalog configuration
23
- config: Optional[Mapping[str, Any]] - Connector configuration including authentication
24
- state: Optional[TState] - Connector state for incremental syncs
25
"""
26
27
def spec(self, *args: Any, **kwargs: Any) -> ConnectorSpecification:
28
"""
29
Returns the specification describing what fields can be configured by a user.
30
Includes OAuth 2.0 configuration for Microsoft Graph API authentication.
31
32
Returns:
33
ConnectorSpecification: Complete specification including authentication flows
34
"""
35
```
36
37
### CLI Entry Point
38
39
Main function for command-line execution supporting all standard Airbyte operations.
40
41
```python { .api }
42
def run():
43
"""
44
Main CLI entry point that processes command-line arguments and launches the connector.
45
Supports spec, check, discover, and read operations with proper argument parsing.
46
47
Handles:
48
- Command-line argument extraction (config, catalog, state paths)
49
- Source connector initialization
50
- Airbyte entrypoint launch with parsed arguments
51
"""
52
```
53
54
## Usage Examples
55
56
### Programmatic Usage
57
58
```python
59
from source_microsoft_onedrive import SourceMicrosoftOneDrive
60
from airbyte_cdk import launch
61
62
# OAuth configuration
63
config = {
64
"credentials": {
65
"auth_type": "Client",
66
"tenant_id": "your-tenant-id",
67
"client_id": "your-client-id",
68
"client_secret": "your-client-secret",
69
"refresh_token": "your-refresh-token"
70
},
71
"drive_name": "OneDrive",
72
"search_scope": "ACCESSIBLE_DRIVES",
73
"folder_path": "Documents",
74
"streams": [{
75
"name": "documents",
76
"globs": ["*.pdf", "*.docx"],
77
"validation_policy": "Emit Record",
78
"format": {"filetype": "unstructured"}
79
}]
80
}
81
82
# Initialize connector
83
source = SourceMicrosoftOneDrive(None, config, None)
84
85
# Launch with read operation
86
launch(source, ["read", "--config", "config.json", "--catalog", "catalog.json"])
87
```
88
89
### Service Authentication
90
91
```python
92
# Service principal configuration
93
service_config = {
94
"credentials": {
95
"auth_type": "Service",
96
"tenant_id": "your-tenant-id",
97
"user_principal_name": "user@yourdomain.com",
98
"client_id": "your-app-id",
99
"client_secret": "your-app-secret"
100
},
101
"drive_name": "OneDrive",
102
"search_scope": "ALL",
103
"folder_path": "."
104
}
105
106
source = SourceMicrosoftOneDrive(None, service_config, None)
107
```
108
109
### Command Line Operations
110
111
```bash
112
# Generate connector specification
113
source-microsoft-onedrive spec
114
115
# Validate configuration
116
source-microsoft-onedrive check --config secrets/config.json
117
118
# Discover available streams
119
source-microsoft-onedrive discover --config secrets/config.json
120
121
# Read data from configured streams
122
source-microsoft-onedrive read --config secrets/config.json --catalog catalog.json
123
```
124
125
## Error Handling
126
127
The connector implements comprehensive error handling:
128
129
- **Configuration Validation**: Validates authentication credentials and connection parameters
130
- **OAuth Flow Errors**: Handles token refresh failures and authentication issues
131
- **API Rate Limits**: Respects Microsoft Graph API rate limits with appropriate backoff
132
- **File Access Errors**: Gracefully handles permission issues and missing files
133
- **Network Failures**: Implements retry logic for transient network issues
134
135
## Connector Specification
136
137
The spec() method returns a complete ConnectorSpecification including:
138
139
- **Connection Specification**: Schema for configuration parameters
140
- **Advanced Auth**: OAuth 2.0 flow configuration for Microsoft Graph API
141
- **Documentation URL**: Links to integration documentation
142
- **Supported Operations**: Standard Airbyte source operations (spec, check, discover, read)