embed-client 2.0.0.0__py3-none-any.whl → 3.1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- embed_client/async_client.py +376 -16
- embed_client/auth.py +491 -0
- embed_client/auth_examples.py +248 -0
- embed_client/client_factory.py +396 -0
- embed_client/client_factory_examples.py +353 -0
- embed_client/config.py +592 -0
- embed_client/config_examples.py +197 -0
- embed_client/example_async_usage.py +578 -90
- embed_client/example_async_usage_ru.py +536 -102
- embed_client/ssl_examples.py +329 -0
- embed_client/ssl_manager.py +475 -0
- embed_client-3.1.0.1.dist-info/METADATA +256 -0
- embed_client-3.1.0.1.dist-info/RECORD +17 -0
- embed_client-3.1.0.1.dist-info/licenses/LICENSE +21 -0
- embed_client-2.0.0.0.dist-info/METADATA +0 -9
- embed_client-2.0.0.0.dist-info/RECORD +0 -8
- {embed_client-2.0.0.0.dist-info → embed_client-3.1.0.1.dist-info}/WHEEL +0 -0
- {embed_client-2.0.0.0.dist-info → embed_client-3.1.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,197 @@
|
|
1
|
+
"""
|
2
|
+
Configuration examples for all security modes.
|
3
|
+
|
4
|
+
This module provides ready-to-use configuration examples for all supported
|
5
|
+
security modes and authentication methods.
|
6
|
+
|
7
|
+
Author: Vasiliy Zdanovskiy
|
8
|
+
email: vasilyvz@gmail.com
|
9
|
+
"""
|
10
|
+
|
11
|
+
from typing import Dict, Any
|
12
|
+
from embed_client.config import ClientConfig
|
13
|
+
|
14
|
+
|
15
|
+
def get_http_simple_config(host: str = "localhost", port: int = 8001) -> Dict[str, Any]:
|
16
|
+
"""
|
17
|
+
Get configuration for HTTP connection without authentication.
|
18
|
+
|
19
|
+
Args:
|
20
|
+
host: Server host
|
21
|
+
port: Server port
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
Configuration dictionary
|
25
|
+
"""
|
26
|
+
config = ClientConfig.create_http_config(host, port)
|
27
|
+
return config.get_all()
|
28
|
+
|
29
|
+
|
30
|
+
def get_http_token_config(host: str = "localhost", port: int = 8001,
|
31
|
+
api_key: str = "test-token-123") -> Dict[str, Any]:
|
32
|
+
"""
|
33
|
+
Get configuration for HTTP connection with API key authentication.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
host: Server host
|
37
|
+
port: Server port
|
38
|
+
api_key: API key for authentication
|
39
|
+
|
40
|
+
Returns:
|
41
|
+
Configuration dictionary
|
42
|
+
"""
|
43
|
+
config = ClientConfig.create_http_token_config(host, port, api_key)
|
44
|
+
return config.get_all()
|
45
|
+
|
46
|
+
|
47
|
+
def get_https_simple_config(host: str = "localhost", port: int = 8443,
|
48
|
+
cert_file: str = None, key_file: str = None,
|
49
|
+
ca_cert_file: str = None) -> Dict[str, Any]:
|
50
|
+
"""
|
51
|
+
Get configuration for HTTPS connection without authentication.
|
52
|
+
|
53
|
+
Args:
|
54
|
+
host: Server host
|
55
|
+
port: Server port
|
56
|
+
cert_file: Client certificate file (optional)
|
57
|
+
key_file: Client key file (optional)
|
58
|
+
ca_cert_file: CA certificate file (optional)
|
59
|
+
|
60
|
+
Returns:
|
61
|
+
Configuration dictionary
|
62
|
+
"""
|
63
|
+
config = ClientConfig.create_https_config(host, port, cert_file, key_file, ca_cert_file)
|
64
|
+
return config.get_all()
|
65
|
+
|
66
|
+
|
67
|
+
def get_https_token_config(host: str = "localhost", port: int = 8443,
|
68
|
+
api_key: str = "test-token-123",
|
69
|
+
cert_file: str = None, key_file: str = None,
|
70
|
+
ca_cert_file: str = None) -> Dict[str, Any]:
|
71
|
+
"""
|
72
|
+
Get configuration for HTTPS connection with API key authentication.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
host: Server host
|
76
|
+
port: Server port
|
77
|
+
api_key: API key for authentication
|
78
|
+
cert_file: Client certificate file (optional)
|
79
|
+
key_file: Client key file (optional)
|
80
|
+
ca_cert_file: CA certificate file (optional)
|
81
|
+
|
82
|
+
Returns:
|
83
|
+
Configuration dictionary
|
84
|
+
"""
|
85
|
+
config = ClientConfig.create_https_token_config(host, port, api_key,
|
86
|
+
cert_file, key_file, ca_cert_file)
|
87
|
+
return config.get_all()
|
88
|
+
|
89
|
+
|
90
|
+
def get_mtls_config(host: str = "localhost", port: int = 8443,
|
91
|
+
cert_file: str = "certs/client.crt",
|
92
|
+
key_file: str = "keys/client.key",
|
93
|
+
ca_cert_file: str = "certs/ca.crt") -> Dict[str, Any]:
|
94
|
+
"""
|
95
|
+
Get configuration for mTLS connection with client certificates.
|
96
|
+
|
97
|
+
Args:
|
98
|
+
host: Server host
|
99
|
+
port: Server port
|
100
|
+
cert_file: Client certificate file
|
101
|
+
key_file: Client key file
|
102
|
+
ca_cert_file: CA certificate file
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
Configuration dictionary
|
106
|
+
"""
|
107
|
+
config = ClientConfig.create_mtls_config(host, port, cert_file, key_file, ca_cert_file)
|
108
|
+
return config.get_all()
|
109
|
+
|
110
|
+
|
111
|
+
def get_jwt_config(host: str = "localhost", port: int = 8001,
|
112
|
+
username: str = "user", password: str = "password",
|
113
|
+
secret: str = "jwt-secret", expiry_hours: int = 24) -> Dict[str, Any]:
|
114
|
+
"""
|
115
|
+
Get configuration for HTTP connection with JWT authentication.
|
116
|
+
|
117
|
+
Args:
|
118
|
+
host: Server host
|
119
|
+
port: Server port
|
120
|
+
username: Username for JWT
|
121
|
+
password: Password for JWT
|
122
|
+
secret: JWT secret key
|
123
|
+
expiry_hours: JWT token expiry in hours
|
124
|
+
|
125
|
+
Returns:
|
126
|
+
Configuration dictionary
|
127
|
+
"""
|
128
|
+
config = ClientConfig()
|
129
|
+
config.configure_server(host, port)
|
130
|
+
config.configure_auth_mode("jwt", username=username, password=password,
|
131
|
+
secret=secret, expiry_hours=expiry_hours)
|
132
|
+
return config.get_all()
|
133
|
+
|
134
|
+
|
135
|
+
def get_basic_auth_config(host: str = "localhost", port: int = 8001,
|
136
|
+
username: str = "user", password: str = "password") -> Dict[str, Any]:
|
137
|
+
"""
|
138
|
+
Get configuration for HTTP connection with basic authentication.
|
139
|
+
|
140
|
+
Args:
|
141
|
+
host: Server host
|
142
|
+
port: Server port
|
143
|
+
username: Username for basic auth
|
144
|
+
password: Password for basic auth
|
145
|
+
|
146
|
+
Returns:
|
147
|
+
Configuration dictionary
|
148
|
+
"""
|
149
|
+
config = ClientConfig()
|
150
|
+
config.configure_server(host, port)
|
151
|
+
config.configure_auth_mode("basic", username=username, password=password)
|
152
|
+
return config.get_all()
|
153
|
+
|
154
|
+
|
155
|
+
def get_all_config_examples() -> Dict[str, Dict[str, Any]]:
|
156
|
+
"""
|
157
|
+
Get all configuration examples.
|
158
|
+
|
159
|
+
Returns:
|
160
|
+
Dictionary with all configuration examples
|
161
|
+
"""
|
162
|
+
return {
|
163
|
+
"http_simple": get_http_simple_config(),
|
164
|
+
"http_token": get_http_token_config(),
|
165
|
+
"https_simple": get_https_simple_config(),
|
166
|
+
"https_token": get_https_token_config(),
|
167
|
+
"mtls": get_mtls_config(),
|
168
|
+
"jwt": get_jwt_config(),
|
169
|
+
"basic_auth": get_basic_auth_config()
|
170
|
+
}
|
171
|
+
|
172
|
+
|
173
|
+
def save_config_examples(output_dir: str = "configs") -> None:
|
174
|
+
"""
|
175
|
+
Save all configuration examples to files.
|
176
|
+
|
177
|
+
Args:
|
178
|
+
output_dir: Output directory for configuration files
|
179
|
+
"""
|
180
|
+
import os
|
181
|
+
import json
|
182
|
+
|
183
|
+
os.makedirs(output_dir, exist_ok=True)
|
184
|
+
|
185
|
+
examples = get_all_config_examples()
|
186
|
+
|
187
|
+
for name, config in examples.items():
|
188
|
+
filename = os.path.join(output_dir, f"{name}.json")
|
189
|
+
with open(filename, 'w', encoding='utf-8') as f:
|
190
|
+
json.dump(config, f, indent=2, ensure_ascii=False)
|
191
|
+
print(f"Saved configuration: {filename}")
|
192
|
+
|
193
|
+
|
194
|
+
if __name__ == "__main__":
|
195
|
+
# Save all configuration examples
|
196
|
+
save_config_examples()
|
197
|
+
print("All configuration examples saved to 'configs/' directory")
|