0
# Configuration
1
2
WebDAV and proxy server configuration with comprehensive validation, SSL certificate support, and connection management. The configuration system provides flexible options for connecting to various WebDAV servers and cloud storage providers.
3
4
## Capabilities
5
6
### WebDAV Configuration
7
8
Settings for connecting to WebDAV servers with authentication and advanced options.
9
10
```python { .api }
11
class WebDAVSettings:
12
"""WebDAV connection configuration settings."""
13
14
keys = {'hostname', 'login', 'password', 'token', 'root', 'cert_path', 'key_path', 'recv_speed', 'send_speed', 'verbose'}
15
ns = "webdav:"
16
prefix = "webdav_"
17
18
def __init__(self, options: dict) -> None:
19
"""
20
Initialize WebDAV settings from options dictionary.
21
22
Parameters:
23
- options: dict containing configuration options:
24
- hostname: str, WebDAV server URL (required)
25
- login: str, username for authentication
26
- password: str, password for authentication
27
- token: str, OAuth token for authentication (alternative to login/password)
28
- root: str, root directory path on server (default: "/")
29
- cert_path: str, path to SSL client certificate file
30
- key_path: str, path to SSL private key file
31
- recv_speed: int, download speed limit in bytes/second
32
- send_speed: int, upload speed limit in bytes/second
33
- verbose: bool, enable verbose logging
34
"""
35
36
def is_valid(self) -> None:
37
"""
38
Validate WebDAV configuration settings.
39
40
Raises:
41
- OptionNotValid: if required options are missing or invalid
42
"""
43
44
def valid(self) -> bool:
45
"""
46
Check if WebDAV configuration is valid.
47
48
Returns:
49
- bool: True if configuration is valid, False otherwise
50
"""
51
```
52
53
### Proxy Configuration
54
55
Settings for connecting through proxy servers with authentication support.
56
57
```python { .api }
58
class ProxySettings:
59
"""Proxy server configuration settings."""
60
61
keys = {'hostname', 'login', 'password'}
62
ns = "proxy:"
63
prefix = "proxy_"
64
65
def __init__(self, options: dict) -> None:
66
"""
67
Initialize proxy settings from options dictionary.
68
69
Parameters:
70
- options: dict containing proxy configuration:
71
- hostname: str, proxy server URL
72
- login: str, proxy username
73
- password: str, proxy password
74
"""
75
76
def is_valid(self) -> None:
77
"""
78
Validate proxy configuration settings.
79
80
Raises:
81
- OptionNotValid: if proxy options are invalid
82
"""
83
84
def valid(self) -> bool:
85
"""
86
Check if proxy configuration is valid.
87
88
Returns:
89
- bool: True if configuration is valid, False otherwise
90
"""
91
```
92
93
### Connection Settings Base Class
94
95
Base class providing common configuration validation functionality.
96
97
```python { .api }
98
class ConnectionSettings:
99
"""Base class for connection configuration settings."""
100
101
def is_valid(self) -> None:
102
"""
103
Validate configuration settings.
104
Must be implemented by subclasses.
105
"""
106
107
def valid(self) -> bool:
108
"""
109
Check if configuration is valid.
110
111
Returns:
112
- bool: True if configuration is valid, False otherwise
113
"""
114
```
115
116
## Configuration Examples
117
118
### Basic WebDAV Authentication
119
120
```python
121
import webdav.client as wc
122
123
# Basic username/password authentication
124
basic_config = {
125
'webdav_hostname': "https://webdav.example.com",
126
'webdav_login': "username",
127
'webdav_password': "password"
128
}
129
130
client = wc.Client(basic_config)
131
```
132
133
### OAuth Token Authentication
134
135
```python
136
# OAuth token authentication (for services like Yandex.Disk)
137
oauth_config = {
138
'webdav_hostname': "https://webdav.yandex.ru",
139
'webdav_token': "your_oauth_token_here"
140
}
141
142
client = wc.Client(oauth_config)
143
```
144
145
### SSL Certificate Configuration
146
147
```python
148
# Client certificate authentication
149
ssl_config = {
150
'webdav_hostname': "https://secure.webdav.com",
151
'webdav_login': "username",
152
'webdav_password': "password",
153
'cert_path': "/etc/ssl/certs/client.crt",
154
'key_path': "/etc/ssl/private/client.key"
155
}
156
157
client = wc.Client(ssl_config)
158
```
159
160
### Proxy Server Configuration
161
162
```python
163
# WebDAV through proxy server
164
proxy_config = {
165
'webdav_hostname': "https://webdav.company.com",
166
'webdav_login': "employee_id",
167
'webdav_password': "employee_password",
168
'proxy_hostname': "http://proxy.company.com:8080",
169
'proxy_login': "proxy_user",
170
'proxy_password': "proxy_pass"
171
}
172
173
client = wc.Client(proxy_config)
174
```
175
176
### Advanced Configuration with Speed Limits
177
178
```python
179
# Advanced configuration with speed limits and verbose logging
180
advanced_config = {
181
'webdav_hostname': "https://webdav.example.com",
182
'webdav_login': "username",
183
'webdav_password': "password",
184
'webdav_root': "/user_files", # Start in subdirectory
185
'recv_speed': 1024 * 1024, # 1 MB/s download limit
186
'send_speed': 512 * 1024, # 512 KB/s upload limit
187
'verbose': True # Enable verbose logging
188
}
189
190
client = wc.Client(advanced_config)
191
```
192
193
### Cloud Service Configurations
194
195
```python
196
# Yandex.Disk configuration
197
yandex_config = {
198
'webdav_hostname': "https://webdav.yandex.ru",
199
'webdav_token': "your_yandex_oauth_token"
200
}
201
202
# Box.com configuration
203
box_config = {
204
'webdav_hostname': "https://dav.box.com/dav",
205
'webdav_login': "your_box_email@example.com",
206
'webdav_password': "your_box_password"
207
}
208
209
# 4shared configuration
210
fourshared_config = {
211
'webdav_hostname': "https://webdav.4shared.com",
212
'webdav_login': "your_4shared_login",
213
'webdav_password': "your_4shared_password"
214
}
215
```
216
217
### Configuration Validation
218
219
```python
220
from webdav.connection import WebDAVSettings, ProxySettings
221
from webdav.exceptions import OptionNotValid
222
223
def validate_config(options):
224
"""Validate configuration before creating client"""
225
try:
226
# Validate WebDAV settings
227
webdav_settings = WebDAVSettings(options)
228
webdav_settings.is_valid()
229
print("WebDAV configuration is valid")
230
231
# Validate proxy settings if present
232
proxy_keys = [key for key in options.keys() if key.startswith('proxy_')]
233
if proxy_keys:
234
proxy_settings = ProxySettings(options)
235
proxy_settings.is_valid()
236
print("Proxy configuration is valid")
237
238
return True
239
240
except OptionNotValid as e:
241
print(f"Configuration error: {e}")
242
return False
243
244
# Test configuration validation
245
config = {
246
'webdav_hostname': "https://webdav.example.com",
247
'webdav_login': "user",
248
'webdav_password': "pass"
249
}
250
251
if validate_config(config):
252
client = wc.Client(config)
253
print("Client created successfully")
254
```
255
256
### Environment-Based Configuration
257
258
```python
259
import os
260
261
def create_client_from_env():
262
"""Create client using environment variables"""
263
config = {
264
'webdav_hostname': os.getenv('WEBDAV_HOSTNAME'),
265
'webdav_login': os.getenv('WEBDAV_LOGIN'),
266
'webdav_password': os.getenv('WEBDAV_PASSWORD'),
267
'webdav_token': os.getenv('WEBDAV_TOKEN'), # Optional
268
}
269
270
# Add proxy settings if available
271
if os.getenv('PROXY_HOSTNAME'):
272
config.update({
273
'proxy_hostname': os.getenv('PROXY_HOSTNAME'),
274
'proxy_login': os.getenv('PROXY_LOGIN'),
275
'proxy_password': os.getenv('PROXY_PASSWORD'),
276
})
277
278
# Add SSL settings if available
279
if os.getenv('WEBDAV_CERT_PATH'):
280
config.update({
281
'cert_path': os.getenv('WEBDAV_CERT_PATH'),
282
'key_path': os.getenv('WEBDAV_KEY_PATH'),
283
})
284
285
# Remove None values
286
config = {k: v for k, v in config.items() if v is not None}
287
288
return wc.Client(config)
289
290
# Usage: Set environment variables first
291
# export WEBDAV_HOSTNAME="https://webdav.example.com"
292
# export WEBDAV_LOGIN="username"
293
# export WEBDAV_PASSWORD="password"
294
295
client = create_client_from_env()
296
```
297
298
### Configuration Templates
299
300
```python
301
class WebDAVConfigurator:
302
"""Helper class for common WebDAV configurations"""
303
304
@staticmethod
305
def yandex_disk(token):
306
"""Yandex.Disk configuration template"""
307
return {
308
'webdav_hostname': "https://webdav.yandex.ru",
309
'webdav_token': token
310
}
311
312
@staticmethod
313
def box_com(email, password):
314
"""Box.com configuration template"""
315
return {
316
'webdav_hostname': "https://dav.box.com/dav",
317
'webdav_login': email,
318
'webdav_password': password
319
}
320
321
@staticmethod
322
def custom_server(hostname, username, password, **kwargs):
323
"""Custom WebDAV server configuration template"""
324
config = {
325
'webdav_hostname': hostname,
326
'webdav_login': username,
327
'webdav_password': password
328
}
329
config.update(kwargs) # Add any additional options
330
return config
331
332
@staticmethod
333
def with_proxy(base_config, proxy_host, proxy_user=None, proxy_pass=None):
334
"""Add proxy settings to existing configuration"""
335
proxy_config = base_config.copy()
336
proxy_config['proxy_hostname'] = proxy_host
337
if proxy_user:
338
proxy_config['proxy_login'] = proxy_user
339
if proxy_pass:
340
proxy_config['proxy_password'] = proxy_pass
341
return proxy_config
342
343
# Use configuration templates
344
configurator = WebDAVConfigurator()
345
346
# Create Yandex.Disk client
347
yandex_client = wc.Client(configurator.yandex_disk("your_token"))
348
349
# Create Box.com client with proxy
350
box_config = configurator.box_com("user@example.com", "password")
351
box_with_proxy = configurator.with_proxy(box_config, "http://proxy:8080", "proxy_user", "proxy_pass")
352
box_client = wc.Client(box_with_proxy)
353
354
# Create custom server client with speed limits
355
custom_config = configurator.custom_server(
356
"https://mywebdav.com",
357
"username",
358
"password",
359
recv_speed=2*1024*1024, # 2 MB/s
360
send_speed=1*1024*1024, # 1 MB/s
361
verbose=True
362
)
363
custom_client = wc.Client(custom_config)
364
```
365
366
## Configuration Options Reference
367
368
### Required Options
369
370
- `webdav_hostname`: WebDAV server URL (must start with http:// or https://)
371
372
### Authentication Options (choose one)
373
374
- `webdav_login` + `webdav_password`: Basic HTTP authentication
375
- `webdav_token`: OAuth token authentication
376
377
### Optional WebDAV Options
378
379
- `webdav_root`: Root directory path (default: "/")
380
- `cert_path`: SSL client certificate file path
381
- `key_path`: SSL private key file path (required if cert_path is set)
382
- `recv_speed`: Download speed limit in bytes/second (default: unlimited)
383
- `send_speed`: Upload speed limit in bytes/second (default: unlimited)
384
- `verbose`: Enable verbose logging (default: False)
385
386
### Optional Proxy Options
387
388
- `proxy_hostname`: Proxy server URL
389
- `proxy_login`: Proxy authentication username
390
- `proxy_password`: Proxy authentication password (required if proxy_login is set)