0
# Configuration Management
1
2
Runtime configuration migration and data center detection for both API key and OAuth authentication methods. Handles automatic data center location detection and configuration updates for Mailchimp API integration.
3
4
## Capabilities
5
6
### Data Center Location Detection
7
8
Determines the appropriate Mailchimp data center from authentication credentials for API routing.
9
10
```python { .api }
11
@classmethod
12
def get_data_center_location(cls, config: Mapping[str, Any]) -> Mapping[str, Any]:
13
"""
14
Detect and set data center location in configuration.
15
16
Parameters:
17
- config: Configuration mapping containing credentials
18
19
Returns:
20
Updated configuration with data_center field added
21
22
For API key auth: Extracts data center from apikey suffix (e.g., 'key-us10' -> 'us10')
23
For OAuth auth: Makes API call to determine data center location
24
"""
25
```
26
27
### OAuth Data Center Resolution
28
29
Retrieves data center information for OAuth access tokens through Mailchimp's metadata endpoint.
30
31
```python { .api }
32
@staticmethod
33
def get_oauth_data_center(access_token: str) -> str:
34
"""
35
Get data center location for OAuth access token.
36
37
Parameters:
38
- access_token: OAuth access token for Mailchimp API
39
40
Returns:
41
Data center identifier (e.g., 'us10', 'us20')
42
43
Raises:
44
AirbyteTracedException: If access token is invalid or API call fails
45
46
Makes request to https://login.mailchimp.com/oauth2/metadata
47
to retrieve data center information embedded in token metadata.
48
"""
49
```
50
51
### Configuration Migration Orchestration
52
53
Coordinates the complete configuration migration process with proper error handling and control message emission.
54
55
```python { .api }
56
@classmethod
57
def migrate(cls, args: List[str], source: Source) -> None:
58
"""
59
Orchestrate configuration migration process.
60
61
Parameters:
62
- args: Command-line arguments list
63
- source: Airbyte source instance
64
65
Process:
66
1. Extract config path from arguments
67
2. Read existing configuration
68
3. Detect and set data center location
69
4. Save updated configuration
70
5. Emit control message for Airbyte platform
71
72
Only performs migration if --config argument is provided.
73
"""
74
```
75
76
### Configuration Persistence
77
78
Saves migrated configuration back to the source with proper formatting and validation.
79
80
```python { .api }
81
@classmethod
82
def modify_and_save(cls, config_path: str, source: Source, config: Mapping[str, Any]) -> Mapping[str, Any]:
83
"""
84
Modify configuration and save to source.
85
86
Parameters:
87
- config_path: Path to configuration file
88
- source: Airbyte source instance for config operations
89
- config: Current configuration mapping
90
91
Returns:
92
Updated configuration with data center location
93
94
Updates config with data center information and persists changes.
95
"""
96
```
97
98
### Control Message Emission
99
100
Emits Airbyte control messages for configuration changes to notify the platform.
101
102
```python { .api }
103
@classmethod
104
def emit_control_message(cls, migrated_config: Mapping[str, Any]) -> None:
105
"""
106
Emit control message for configuration migration.
107
108
Parameters:
109
- migrated_config: Updated configuration mapping
110
111
Prints connector config control message in JSON format
112
for Airbyte platform consumption. Required for proper
113
configuration update notification.
114
"""
115
```
116
117
## Configuration Examples
118
119
### API Key Configuration
120
121
```python
122
# Input configuration
123
config = {
124
"credentials": {
125
"auth_type": "apikey",
126
"apikey": "your-api-key-us10"
127
},
128
"start_date": "2023-01-01T00:00:00.000Z"
129
}
130
131
# After migration
132
migrated_config = MigrateDataCenter.get_data_center_location(config)
133
# Result includes: "data_center": "us10"
134
```
135
136
### OAuth Configuration
137
138
```python
139
# Input configuration
140
config = {
141
"credentials": {
142
"auth_type": "oauth2.0",
143
"client_id": "your-client-id",
144
"client_secret": "your-client-secret",
145
"access_token": "your-access-token"
146
},
147
"start_date": "2023-01-01T00:00:00.000Z"
148
}
149
150
# Data center detected via API call
151
data_center = MigrateDataCenter.get_oauth_data_center(config["credentials"]["access_token"])
152
```
153
154
## Usage Examples
155
156
### Manual Configuration Migration
157
158
```python
159
from source_mailchimp.config_migrations import MigrateDataCenter
160
from source_mailchimp import SourceMailchimp
161
162
# Load configuration
163
config = {"credentials": {"auth_type": "apikey", "apikey": "key-us10"}}
164
165
# Detect data center
166
migrated_config = MigrateDataCenter.get_data_center_location(config)
167
print(migrated_config["data_center"]) # Output: "us10"
168
```
169
170
### Integration with Connector Launch
171
172
```python
173
import sys
174
from source_mailchimp import SourceMailchimp
175
from source_mailchimp.config_migrations import MigrateDataCenter
176
177
source = SourceMailchimp()
178
# Automatically handles migration before connector launch
179
MigrateDataCenter.migrate(sys.argv[1:], source)
180
```