konecty-sdk-python 0.3.0__tar.gz → 0.5.0__tar.gz
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.
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/PKG-INFO +1 -1
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/cli/apply.py +64 -17
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/cli/backup.py +50 -17
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/cli/pull.py +62 -17
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/pyproject.toml +1 -1
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/.gitignore +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/.python-version +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/README.md +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/__init__.py +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/cli/__init__.py +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/lib/client.py +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/lib/file_manager.py +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/lib/filters.py +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/lib/model.py +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/lib/settings.py +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/lib/types.py +0 -0
- {konecty_sdk_python-0.3.0 → konecty_sdk_python-0.5.0}/uv.lock +0 -0
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
# ///
|
|
10
10
|
"""Script para aplicar alterações locais ao MongoDB."""
|
|
11
11
|
|
|
12
|
+
import asyncio
|
|
12
13
|
import json
|
|
13
14
|
from pathlib import Path
|
|
14
15
|
from typing import Any, Dict, List, Literal, Optional, Set, Tuple, TypedDict, cast
|
|
@@ -329,7 +330,8 @@ async def apply_namespace(
|
|
|
329
330
|
help="Tenta reescrever em caso de falha",
|
|
330
331
|
)
|
|
331
332
|
@click.option("--w", default="majority", help="Nível de escrita do MongoDB")
|
|
332
|
-
|
|
333
|
+
@click.option("--mongo-url", help="URL do MongoDB")
|
|
334
|
+
def apply_command(
|
|
333
335
|
metadata_dir: str,
|
|
334
336
|
host: str,
|
|
335
337
|
port: int,
|
|
@@ -343,30 +345,71 @@ async def apply_command(
|
|
|
343
345
|
direct_connection: bool,
|
|
344
346
|
retry_writes: bool,
|
|
345
347
|
w: str,
|
|
348
|
+
mongo_url: Optional[str],
|
|
346
349
|
) -> None:
|
|
347
350
|
"""Aplica alterações locais ao MongoDB."""
|
|
351
|
+
asyncio.run(
|
|
352
|
+
_apply_command(
|
|
353
|
+
metadata_dir=metadata_dir,
|
|
354
|
+
host=host,
|
|
355
|
+
port=port,
|
|
356
|
+
database=database,
|
|
357
|
+
username=username,
|
|
358
|
+
password=password,
|
|
359
|
+
replicaset=replicaset,
|
|
360
|
+
document=document,
|
|
361
|
+
prune=prune,
|
|
362
|
+
dry_run=dry_run,
|
|
363
|
+
direct_connection=direct_connection,
|
|
364
|
+
retry_writes=retry_writes,
|
|
365
|
+
w=w,
|
|
366
|
+
mongo_url=mongo_url,
|
|
367
|
+
)
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
async def _apply_command(
|
|
372
|
+
metadata_dir: str,
|
|
373
|
+
host: str,
|
|
374
|
+
port: int,
|
|
375
|
+
database: str,
|
|
376
|
+
username: Optional[str],
|
|
377
|
+
password: Optional[str],
|
|
378
|
+
replicaset: Optional[str],
|
|
379
|
+
document: Optional[str],
|
|
380
|
+
prune: bool,
|
|
381
|
+
dry_run: bool,
|
|
382
|
+
direct_connection: bool,
|
|
383
|
+
retry_writes: bool,
|
|
384
|
+
w: str,
|
|
385
|
+
mongo_url: Optional[str],
|
|
386
|
+
) -> None:
|
|
387
|
+
"""Internal async implementation of apply command."""
|
|
348
388
|
metadata_path = Path(metadata_dir).resolve()
|
|
349
389
|
if not metadata_path.exists():
|
|
350
390
|
console.print(f"[red]Diretório {metadata_dir} não encontrado[/red]")
|
|
351
391
|
return
|
|
352
392
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
393
|
+
uri = mongo_url
|
|
394
|
+
|
|
395
|
+
if not uri:
|
|
396
|
+
uri_params = []
|
|
397
|
+
if replicaset:
|
|
398
|
+
uri_params.extend(
|
|
399
|
+
[
|
|
400
|
+
f"replicaSet={replicaset}",
|
|
401
|
+
f"directConnection={'true' if direct_connection else 'false'}",
|
|
402
|
+
f"retryWrites={'true' if retry_writes else 'false'}",
|
|
403
|
+
f"w={w}",
|
|
404
|
+
]
|
|
405
|
+
)
|
|
363
406
|
|
|
364
|
-
|
|
407
|
+
uri_suffix = f"?{'&'.join(uri_params)}" if uri_params else ""
|
|
365
408
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
409
|
+
if username and password:
|
|
410
|
+
uri = f"mongodb://{username}:{password}@{host}:{port}/admin{uri_suffix}"
|
|
411
|
+
else:
|
|
412
|
+
uri = f"mongodb://{host}:{port}{uri_suffix}"
|
|
370
413
|
|
|
371
414
|
client = MongoClient(
|
|
372
415
|
uri,
|
|
@@ -497,9 +540,13 @@ def main():
|
|
|
497
540
|
if sys.platform == "win32":
|
|
498
541
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
499
542
|
|
|
500
|
-
|
|
543
|
+
apply_command()
|
|
501
544
|
|
|
502
545
|
|
|
503
546
|
if __name__ == "__main__":
|
|
504
547
|
main()
|
|
505
548
|
main()
|
|
549
|
+
main()
|
|
550
|
+
main()
|
|
551
|
+
main()
|
|
552
|
+
main()
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Script para fazer backup dos documentos do MongoDB."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
import json
|
|
4
5
|
import tarfile
|
|
5
6
|
import tempfile
|
|
@@ -24,7 +25,8 @@ console = Console()
|
|
|
24
25
|
@click.option("--password", help="Senha do MongoDB")
|
|
25
26
|
@click.option("--replicaset", help="Nome do ReplicaSet do MongoDB (ex: rs0)")
|
|
26
27
|
@click.option("--version", help="Rótulo de versão para o arquivo de backup")
|
|
27
|
-
|
|
28
|
+
@click.option("--mongo-url", help="URL do MongoDB")
|
|
29
|
+
def backup_command(
|
|
28
30
|
host: str,
|
|
29
31
|
port: int,
|
|
30
32
|
database: str,
|
|
@@ -33,8 +35,36 @@ async def backup_command(
|
|
|
33
35
|
password: Optional[str],
|
|
34
36
|
replicaset: Optional[str],
|
|
35
37
|
version: Optional[str],
|
|
38
|
+
mongo_url: Optional[str],
|
|
36
39
|
) -> None:
|
|
37
40
|
"""Gera backup dos documentos do MongoDB."""
|
|
41
|
+
asyncio.run(
|
|
42
|
+
_backup_command(
|
|
43
|
+
host=host,
|
|
44
|
+
port=port,
|
|
45
|
+
database=database,
|
|
46
|
+
output=output,
|
|
47
|
+
username=username,
|
|
48
|
+
password=password,
|
|
49
|
+
replicaset=replicaset,
|
|
50
|
+
version=version,
|
|
51
|
+
mongo_url=mongo_url,
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
async def _backup_command(
|
|
57
|
+
host: str,
|
|
58
|
+
port: int,
|
|
59
|
+
database: str,
|
|
60
|
+
output: str,
|
|
61
|
+
username: Optional[str],
|
|
62
|
+
password: Optional[str],
|
|
63
|
+
replicaset: Optional[str],
|
|
64
|
+
version: Optional[str],
|
|
65
|
+
mongo_url: Optional[str],
|
|
66
|
+
) -> None:
|
|
67
|
+
"""Internal async implementation of backup command."""
|
|
38
68
|
output_dir = Path(output).resolve()
|
|
39
69
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
40
70
|
|
|
@@ -43,23 +73,26 @@ async def backup_command(
|
|
|
43
73
|
version_label = f"_{version}" if version else ""
|
|
44
74
|
backup_file = output_dir / f"backup_{timestamp}{version_label}.tar.gz"
|
|
45
75
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
uri = mongo_url
|
|
77
|
+
|
|
78
|
+
if not uri:
|
|
79
|
+
uri_params = []
|
|
80
|
+
if replicaset:
|
|
81
|
+
uri_params.extend(
|
|
82
|
+
[
|
|
83
|
+
f"replicaSet={replicaset}",
|
|
84
|
+
"directConnection=false",
|
|
85
|
+
"retryWrites=true",
|
|
86
|
+
"w=majority",
|
|
87
|
+
]
|
|
88
|
+
)
|
|
56
89
|
|
|
57
|
-
|
|
90
|
+
uri_suffix = f"?{'&'.join(uri_params)}" if uri_params else ""
|
|
58
91
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
92
|
+
if username and password:
|
|
93
|
+
uri = f"mongodb://{username}:{password}@{host}:{port}/admin{uri_suffix}"
|
|
94
|
+
else:
|
|
95
|
+
uri = f"mongodb://{host}:{port}{uri_suffix}"
|
|
63
96
|
|
|
64
97
|
client = MongoClient(
|
|
65
98
|
uri,
|
|
@@ -121,7 +154,7 @@ def main():
|
|
|
121
154
|
if sys.platform == "win32":
|
|
122
155
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
123
156
|
|
|
124
|
-
|
|
157
|
+
backup_command()
|
|
125
158
|
|
|
126
159
|
|
|
127
160
|
if __name__ == "__main__":
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Script para extrair dados do MongoDB e gerar arquivos JSON."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
import json
|
|
4
5
|
from pathlib import Path
|
|
5
6
|
from typing import Any, Dict, List, Literal, Optional, TypedDict, Union, cast
|
|
@@ -84,13 +85,14 @@ async def write_file(file_path: str, content: str) -> None:
|
|
|
84
85
|
@click.option("--pivot", help="Nome do pivot específico para extrair")
|
|
85
86
|
@click.option("--access", help="Nome do access específica para extrair")
|
|
86
87
|
@click.option("--hook", help="Nome do hook específico para extrair")
|
|
88
|
+
@click.option("--mongo-url", help="URL do MongoDB")
|
|
87
89
|
@click.option(
|
|
88
90
|
"--all",
|
|
89
91
|
"extract_all",
|
|
90
92
|
is_flag=True,
|
|
91
93
|
help="Extrair todas as collections sem perguntar",
|
|
92
94
|
)
|
|
93
|
-
|
|
95
|
+
def pull_command(
|
|
94
96
|
host: str,
|
|
95
97
|
port: int,
|
|
96
98
|
database: str,
|
|
@@ -105,28 +107,71 @@ async def pull_command(
|
|
|
105
107
|
access: Optional[str],
|
|
106
108
|
hook: Optional[str],
|
|
107
109
|
extract_all: bool,
|
|
110
|
+
mongo_url: Optional[str],
|
|
108
111
|
) -> None:
|
|
109
112
|
"""Baixa metadados do MongoDB."""
|
|
113
|
+
asyncio.run(
|
|
114
|
+
_pull_command(
|
|
115
|
+
host=host,
|
|
116
|
+
port=port,
|
|
117
|
+
database=database,
|
|
118
|
+
output=output,
|
|
119
|
+
username=username,
|
|
120
|
+
password=password,
|
|
121
|
+
replicaset=replicaset,
|
|
122
|
+
document=document,
|
|
123
|
+
view=view,
|
|
124
|
+
list_param=list_param,
|
|
125
|
+
pivot=pivot,
|
|
126
|
+
access=access,
|
|
127
|
+
hook=hook,
|
|
128
|
+
extract_all=extract_all,
|
|
129
|
+
mongo_url=mongo_url,
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
async def _pull_command(
|
|
135
|
+
host: str,
|
|
136
|
+
port: int,
|
|
137
|
+
database: str,
|
|
138
|
+
output: str,
|
|
139
|
+
username: Optional[str],
|
|
140
|
+
password: Optional[str],
|
|
141
|
+
replicaset: Optional[str],
|
|
142
|
+
document: Optional[str],
|
|
143
|
+
view: Optional[str],
|
|
144
|
+
list_param: Optional[str],
|
|
145
|
+
pivot: Optional[str],
|
|
146
|
+
access: Optional[str],
|
|
147
|
+
hook: Optional[str],
|
|
148
|
+
mongo_url: Optional[str],
|
|
149
|
+
extract_all: bool,
|
|
150
|
+
) -> None:
|
|
151
|
+
"""Internal async implementation of pull command."""
|
|
110
152
|
output_dir = Path(output).resolve()
|
|
111
153
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
112
154
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
155
|
+
uri = mongo_url
|
|
156
|
+
|
|
157
|
+
if not uri:
|
|
158
|
+
uri_params = []
|
|
159
|
+
if replicaset:
|
|
160
|
+
uri_params.extend(
|
|
161
|
+
[
|
|
162
|
+
f"replicaSet={replicaset}",
|
|
163
|
+
"directConnection=false",
|
|
164
|
+
"retryWrites=true",
|
|
165
|
+
"w=majority",
|
|
166
|
+
]
|
|
167
|
+
)
|
|
123
168
|
|
|
124
|
-
|
|
169
|
+
uri_suffix = f"?{'&'.join(uri_params)}" if uri_params else ""
|
|
125
170
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
171
|
+
if username and password:
|
|
172
|
+
uri = f"mongodb://{username}:{password}@{host}:{port}/admin{uri_suffix}"
|
|
173
|
+
else:
|
|
174
|
+
uri = f"mongodb://{host}:{port}{uri_suffix}"
|
|
130
175
|
|
|
131
176
|
client = MongoClient(
|
|
132
177
|
uri,
|
|
@@ -258,7 +303,7 @@ def main():
|
|
|
258
303
|
if sys.platform == "win32":
|
|
259
304
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
260
305
|
|
|
261
|
-
|
|
306
|
+
pull_command()
|
|
262
307
|
|
|
263
308
|
|
|
264
309
|
if __name__ == "__main__":
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|