dinemic-cli 0.0.19__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.
Files changed (63) hide show
  1. dinemic_cli/__init__.py +1 -0
  2. dinemic_cli/__main__.py +16 -0
  3. dinemic_cli/client.py +75 -0
  4. dinemic_cli/commands/__init__.py +0 -0
  5. dinemic_cli/commands/auth.py +31 -0
  6. dinemic_cli/commands/caa.py +11 -0
  7. dinemic_cli/commands/cert.py +29 -0
  8. dinemic_cli/commands/cert_peer.py +37 -0
  9. dinemic_cli/commands/dns_entry.py +57 -0
  10. dinemic_cli/commands/dns_value.py +43 -0
  11. dinemic_cli/commands/dns_zone.py +98 -0
  12. dinemic_cli/commands/endpoint.py +39 -0
  13. dinemic_cli/commands/healthcheck.py +40 -0
  14. dinemic_cli/commands/loadbalancer.py +39 -0
  15. dinemic_cli/commands/loadbalancer_backend.py +44 -0
  16. dinemic_cli/commands/loadbalancer_host.py +37 -0
  17. dinemic_cli/commands/loadbalancer_route.py +42 -0
  18. dinemic_cli/commands/network.py +34 -0
  19. dinemic_cli/commands/node.py +29 -0
  20. dinemic_cli/commands/peer.py +33 -0
  21. dinemic_cli/commands/peer_config.py +33 -0
  22. dinemic_cli/commands/project.py +58 -0
  23. dinemic_cli/commands/quota.py +22 -0
  24. dinemic_cli/main.py +68 -0
  25. dinemic_cli/output.py +25 -0
  26. dinemic_cli-0.0.19.dist-info/METADATA +13 -0
  27. dinemic_cli-0.0.19.dist-info/RECORD +63 -0
  28. dinemic_cli-0.0.19.dist-info/WHEEL +5 -0
  29. dinemic_cli-0.0.19.dist-info/entry_points.txt +2 -0
  30. dinemic_cli-0.0.19.dist-info/licenses/LICENSE +696 -0
  31. dinemic_cli-0.0.19.dist-info/top_level.txt +2 -0
  32. tests/01-cli-fixes.patch +418 -0
  33. tests/02-tests-after-fixes.patch +208 -0
  34. tests/api_samples.py +214 -0
  35. tests/cert_peer.py +37 -0
  36. tests/cli_runner.py +113 -0
  37. tests/command_matrix.py +612 -0
  38. tests/conftest.py +235 -0
  39. tests/dns_entry.py +41 -0
  40. tests/dns_value.py +43 -0
  41. tests/dns_zone.py +38 -0
  42. tests/endpoint.py +39 -0
  43. tests/healthcheck.py +40 -0
  44. tests/loadbalancer.py +36 -0
  45. tests/loadbalancer_backend.py +44 -0
  46. tests/loadbalancer_host.py +37 -0
  47. tests/loadbalancer_route.py +42 -0
  48. tests/network.py +34 -0
  49. tests/network_node.py +74 -0
  50. tests/node.py +23 -0
  51. tests/peer.py +33 -0
  52. tests/project.py +58 -0
  53. tests/support.py +246 -0
  54. tests/test_auth.py +114 -0
  55. tests/test_columns.py +58 -0
  56. tests/test_commands.py +98 -0
  57. tests/test_confirmations.py +71 -0
  58. tests/test_envvars.py +119 -0
  59. tests/test_error_handling.py +83 -0
  60. tests/test_lifecycle.py +188 -0
  61. tests/test_network_node.py +116 -0
  62. tests/test_option_contract.py +335 -0
  63. tests/test_smoke.py +83 -0
@@ -0,0 +1,2 @@
1
+ dinemic_cli
2
+ tests
@@ -0,0 +1,418 @@
1
+ --- a/src/dinemic_cli/commands/cert_peer.py
2
+ +++ b/src/dinemic_cli/commands/cert_peer.py
3
+ @@ -4,22 +4,25 @@
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+ +PRODUCTION_DIRECTORY = "https://acme-v02.api.letsencrypt.org/directory"
8
+ +
9
+
10
+ @app.command("list")
11
+ def list_cert_peers(ctx: typer.Context):
12
+ data = ctx.obj["client"].get("/certificate-peer/")
13
+ render(data, ctx.obj["output"], columns=["id", "name", "project", "directory_url", "email", "max_parallel", "dns_servers", "lb_recipients"])
14
+
15
+ +
16
+ @app.command("create")
17
+ def create_cert_peer(
18
+ ctx: typer.Context,
19
+ - project: str = typer.Option(..., "--project", "-p", help="Project ID"),
20
+ + project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
21
+ name: str = typer.Option(..., "--name", "-n", help="Name"),
22
+ - directory_url: str = typer.Option("https://acme-v02.api.letsencrypt.org/directory", "--directory-url", "-d", help="Let's encrypt directory url. For tests use https://acme-staging-v02.api.letsencrypt.org/directory. For production use https://acme-v02.api.letsencrypt.org/directory (default)"),
23
+ - max_parallel: str = typer.Option(..., "--max-parallel", "-m", help="Maximum number of certificates processed by one peer at once"),
24
+ + directory_url: str = typer.Option(PRODUCTION_DIRECTORY, "--directory-url", "-d", help="Let's Encrypt directory url. For tests use https://acme-staging-v02.api.letsencrypt.org/directory"),
25
+ + max_parallel: int = typer.Option(..., "--max-parallel", "-m", help="Maximum number of certificates processed by one peer at once"),
26
+ ):
27
+ data = ctx.obj["client"].post("/certificate-peer/", {"project": project, "name": name, "directory_url": directory_url, "max_parallel": max_parallel})
28
+ - typer.secho(f"Created endpoint {data['id']} ({data['id']})", fg="green")
29
+ + typer.secho(f"Created certificate peer {data['id']}", fg="green")
30
+
31
+
32
+ @app.command("delete")
33
+ --- a/src/dinemic_cli/commands/dns_entry.py
34
+ +++ b/src/dinemic_cli/commands/dns_entry.py
35
+ @@ -18,9 +18,9 @@
36
+ def create_entry(
37
+ ctx: typer.Context,
38
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
39
+ - record: str = typer.Option(..., "--record", "-r", help="Record name, i.e. www"),
40
+ + record: str = typer.Option(..., "--record", "-r", help="Record name, i.e. www (empty for zone apex)"),
41
+ type_: str = typer.Option(..., "--type", "-t", help="Record type, i.e. A, AAAA or MX"),
42
+ - ttl: int = typer.Option(300, help="TTL value"),
43
+ + ttl: int = typer.Option(300, "--ttl", help="TTL value in seconds"),
44
+ ):
45
+ data = ctx.obj["client"].post(
46
+ f"/zone/{zone_id}/entry/", {"record": record, "type": type_, "ttl": ttl}
47
+ @@ -36,7 +36,6 @@
48
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
49
+ ):
50
+ if not yes:
51
+ - typer.confirm(f"Remove record {record_id} form zone {zone_id}?", abort=True)
52
+ + typer.confirm(f"Remove record {record_id} from zone {zone_id}?", abort=True)
53
+ ctx.obj["client"].delete(f"/zone/{zone_id}/entry/{record_id}/")
54
+ typer.secho("Removed.", fg="green")
55
+ -
56
+ --- a/src/dinemic_cli/commands/dns_value.py
57
+ +++ b/src/dinemic_cli/commands/dns_value.py
58
+ @@ -26,18 +26,18 @@
59
+ data = ctx.obj["client"].post(
60
+ f"/zone/{zone_id}/entry/{record_id}/value/", {"value": value, "weight": weight}
61
+ )
62
+ - typer.secho(f"Added record {data['value']} ({data['id']})", fg="green")
63
+ + typer.secho(f"Added value {data['value']} ({data['id']})", fg="green")
64
+
65
+
66
+ @app.command("delete")
67
+ def delete_value(
68
+ ctx: typer.Context,
69
+ - zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID"),
70
+ + zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
71
+ record_id: str = typer.Option(..., "--record", "-r", help="Record ID"),
72
+ value_id: str = typer.Option(..., "--value", "-v", help="Value ID"),
73
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
74
+ ):
75
+ if not yes:
76
+ - typer.confirm(f"Remove value {value_id} form record {record_id} in zone {zone_id}?", abort=True)
77
+ + typer.confirm(f"Remove value {value_id} from record {record_id} in zone {zone_id}?", abort=True)
78
+ ctx.obj["client"].delete(f"/zone/{zone_id}/entry/{record_id}/value/{value_id}/")
79
+ typer.secho("Removed.", fg="green")
80
+ --- a/src/dinemic_cli/commands/dns_zone.py
81
+ +++ b/src/dinemic_cli/commands/dns_zone.py
82
+ @@ -13,22 +13,23 @@
83
+ data = ctx.obj["client"].get("/zone/", project=project)
84
+ render(data, ctx.obj["output"], columns=["id", "domain", "project"])
85
+
86
+ +
87
+ @app.command("create")
88
+ def create_zone(
89
+ ctx: typer.Context,
90
+ domain: str = typer.Option(..., "--domain", "-d", help="Domain name"),
91
+ - project: str = typer.Option(..., "--project", "-p", help="Project ID"),
92
+ + project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
93
+ caa: str = typer.Option(..., "--caa", "-c", help="CAA ID"),
94
+ name: str = typer.Option(..., "--name", "-n", help="Zone name"),
95
+ ):
96
+ data = ctx.obj["client"].post("/zone/", {"domain": domain, "project": project, "valid_caa": [caa], "name": name})
97
+ - typer.secho(f"Created zone {data['domain']} for project ({data['id']})", fg="green")
98
+ + typer.secho(f"Created zone {data['domain']} ({data['id']})", fg="green")
99
+
100
+
101
+ @app.command("delete")
102
+ def delete_zone(
103
+ ctx: typer.Context,
104
+ - zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID"),
105
+ + zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
106
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
107
+ ):
108
+ if not yes:
109
+ --- a/src/dinemic_cli/commands/endpoint.py
110
+ +++ b/src/dinemic_cli/commands/endpoint.py
111
+ @@ -17,14 +17,14 @@
112
+ @app.command("create")
113
+ def create_endpoint(
114
+ ctx: typer.Context,
115
+ - project: str = typer.Option(..., "--project", "-p", help="Project ID"),
116
+ + project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
117
+ name: str = typer.Option(..., "--name", "-n", help="Name"),
118
+ scheme: str = typer.Option(..., "--scheme", "-s", help="Scheme (HTTP or HTTPS)"),
119
+ host: str = typer.Option(..., "--host", "-H", help="Host name"),
120
+ port: int = typer.Option(..., "--port", "-P", help="Port number"),
121
+ ):
122
+ data = ctx.obj["client"].post("/endpoint/", {"project": project, "name": name, "scheme": scheme, "host": host, "port": port, "tags": []})
123
+ - typer.secho(f"Created endpoint {data['id']} ({data['id']})", fg="green")
124
+ + typer.secho(f"Created endpoint {data['name']} ({data['id']})", fg="green")
125
+
126
+
127
+ @app.command("delete")
128
+ --- a/src/dinemic_cli/commands/healthcheck.py
129
+ +++ b/src/dinemic_cli/commands/healthcheck.py
130
+ @@ -17,19 +17,19 @@
131
+ @app.command("create")
132
+ def create_healthcheck(
133
+ ctx: typer.Context,
134
+ - project: str = typer.Option(..., "--project", "-p", help="Project ID"),
135
+ + project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
136
+ name: str = typer.Option(..., "--name", "-n", help="Name"),
137
+ path: str = typer.Option(..., "--path", "-P", help="Path"),
138
+ - period: str = typer.Option(..., "--period", "-d", help="Period (seconds)"),
139
+ - max_fail: str = typer.Option(..., "--max-fail", "-m", help="Maximum fails before disabling"),
140
+ - initial_delay: str = typer.Option(..., "--initial-delay", "-i", help="Initial delay (seconds)"),
141
+ + period: int = typer.Option(..., "--period", "-d", help="Period (seconds)"),
142
+ + max_fail: int = typer.Option(..., "--max-fail", "-m", help="Maximum fails before disabling"),
143
+ + initial_delay: int = typer.Option(..., "--initial-delay", "-i", help="Initial delay (seconds)"),
144
+ ):
145
+ data = ctx.obj["client"].post("/healthcheck/", {"project": project, "name": name, "path": path, "period": period, "max_fail": max_fail, "initial_delay": initial_delay})
146
+ typer.secho(f"Created healthcheck {data['id']}", fg="green")
147
+
148
+
149
+ @app.command("delete")
150
+ -def delete_loadbalancer(
151
+ +def delete_healthcheck(
152
+ ctx: typer.Context,
153
+ healthcheck_id: str = typer.Option(..., "--healthcheck", "-H", help="Healthcheck ID"),
154
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
155
+ --- a/src/dinemic_cli/commands/loadbalancer.py
156
+ +++ b/src/dinemic_cli/commands/loadbalancer.py
157
+ @@ -17,17 +17,17 @@
158
+ @app.command("create")
159
+ def create_loadbalancer(
160
+ ctx: typer.Context,
161
+ - project: str = typer.Option(..., "--project", "-p", help="Project ID"),
162
+ + project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
163
+ name: str = typer.Option(..., "--name", "-n", help="Name"),
164
+ ):
165
+ data = ctx.obj["client"].post("/loadbalancer/", {"project": project, "name": name})
166
+ - typer.secho(f"Created loadbalancer {data['id']} ({data['id']})", fg="green")
167
+ + typer.secho(f"Created loadbalancer {data['name']} ({data['id']})", fg="green")
168
+
169
+
170
+ @app.command("delete")
171
+ def delete_loadbalancer(
172
+ ctx: typer.Context,
173
+ - loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Load balancer ID"),
174
+ + loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Load balancer ID", envvar="DINEMIC_LB"),
175
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
176
+ ):
177
+ if not yes:
178
+ --- a/src/dinemic_cli/commands/loadbalancer_backend.py
179
+ +++ b/src/dinemic_cli/commands/loadbalancer_backend.py
180
+ @@ -32,9 +32,9 @@
181
+ @app.command("delete")
182
+ def delete_backend(
183
+ ctx: typer.Context,
184
+ - loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID"),
185
+ - host_id: str = typer.Option(..., "--host", "-H", help="Host ID"),
186
+ - route_id: str = typer.Option(..., "--host", "-H", help="Route ID"),
187
+ + loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
188
+ + host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
189
+ + route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE"),
190
+ backend_id: str = typer.Option(..., "--backend", "-b", help="Backend ID"),
191
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
192
+ ):
193
+ --- a/src/dinemic_cli/commands/loadbalancer_host.py
194
+ +++ b/src/dinemic_cli/commands/loadbalancer_host.py
195
+ @@ -27,8 +27,8 @@
196
+ @app.command("delete")
197
+ def delete_host(
198
+ ctx: typer.Context,
199
+ - loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Load balancer ID"),
200
+ - host_id: str = typer.Option(..., "--host", "-H", help="Host ID"),
201
+ + loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Load balancer ID", envvar="DINEMIC_LB"),
202
+ + host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
203
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
204
+ ):
205
+ if not yes:
206
+ --- a/src/dinemic_cli/commands/loadbalancer_route.py
207
+ +++ b/src/dinemic_cli/commands/loadbalancer_route.py
208
+ @@ -31,9 +31,9 @@
209
+ @app.command("delete")
210
+ def delete_route(
211
+ ctx: typer.Context,
212
+ - loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID"),
213
+ - host_id: str = typer.Option(..., "--host", "-H", help="Host ID"),
214
+ - route_id: str = typer.Option(..., "--route", "-r", help="Route ID"),
215
+ + loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
216
+ + host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
217
+ + route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE"),
218
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
219
+ ):
220
+ if not yes:
221
+ --- a/src/dinemic_cli/commands/network.py
222
+ +++ b/src/dinemic_cli/commands/network.py
223
+ @@ -7,7 +7,7 @@
224
+
225
+ @app.command("list")
226
+ def list_networks(ctx: typer.Context,
227
+ - project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")):
228
+ + project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")):
229
+ data = ctx.obj["client"].get("/network/", project=project)
230
+ render(data, ctx.obj["output"], columns=["id", "name", "project", "ip_address", "ip_netmask"])
231
+
232
+ @@ -15,7 +15,7 @@
233
+ @app.command("create")
234
+ def create_network(
235
+ ctx: typer.Context,
236
+ - project: str = typer.Option(..., "--project", "-p", help="Project ID"),
237
+ + project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
238
+ name: str = typer.Option(..., "--name", "-n", help="Network name"),
239
+ ip_address: str = typer.Option(..., "--ip", "-i", help="IPv4 address"),
240
+ ip_netmask: str = typer.Option(..., "--netmask", "-m", help="IPv4 netmask"),
241
+ @@ -26,9 +26,9 @@
242
+
243
+ @app.command("delete")
244
+ def delete_network(ctx: typer.Context,
245
+ - network_id: str = typer.Option(..., "--network", "-n", help="Network ID"),
246
+ + network_id: str = typer.Option(..., "--network", "-n", help="Network ID", envvar="DINEMIC_NETWORK"),
247
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),):
248
+ if not yes:
249
+ - typer.confirm(f"Remove network {network_id}", abort=True)
250
+ + typer.confirm(f"Remove network {network_id}?", abort=True)
251
+ ctx.obj["client"].delete(f"/network/{network_id}/")
252
+ typer.secho("Removed.", fg="green")
253
+ --- a/src/dinemic_cli/commands/network_node.py
254
+ +++ b/src/dinemic_cli/commands/network_node.py
255
+ @@ -0,0 +1,74 @@
256
+ +"""Komendy dla modelu NetworkNode.
257
+ +
258
+ +SZKIC — ścieżki API (`/network-node/`) i nazwy pól są odtworzone z opisu modelu,
259
+ +nie z serializera. Zweryfikuj je przed scaleniem:
260
+ +
261
+ + curl -H "Authorization: Token $DINEMIC_API_TOKEN" $DINEMIC_API_URL/schema/ \
262
+ + | grep -i network-node
263
+ +
264
+ +NetworkNode to wpięcie węzła do sieci: jeden interfejs WireGuard na parę
265
+ +(network, node), współdzielony przez wszystkie peery tej sieci na tym węźle.
266
+ +Wcześniej każdy peer stawiał własny interfejs — stąd problemy sieciowe.
267
+ +
268
+ +Rejestracja w ``main.py``::
269
+ +
270
+ + from dinemic_cli.commands import network_node
271
+ + app.add_typer(network_node.app, name="network-node")
272
+ +
273
+ +Po scaleniu: dopisz "network_node" do COMMAND_MODULES w ``tests/support.py``,
274
+ +dodaj wiersze do ``tests/command_matrix.py`` i zdejmij ``skip`` z testów
275
+ +w ``tests/test_network_node.py``.
276
+ +"""
277
+ +
278
+ +import typer
279
+ +
280
+ +from dinemic_cli.output import render
281
+ +
282
+ +app = typer.Typer(no_args_is_help=True, help="Node attachments to networks (WireGuard interfaces)")
283
+ +
284
+ +
285
+ +@app.command("list")
286
+ +def list_network_nodes(
287
+ + ctx: typer.Context,
288
+ + network: str = typer.Option(None, "--network", "-n", help="Network ID", envvar="DINEMIC_NETWORK"),
289
+ + node: str = typer.Option(None, "--node", "-N", help="Node ID"),
290
+ +):
291
+ + """Show which nodes are attached to which networks."""
292
+ + data = ctx.obj["client"].get("/network-node/", network=network, node=node)
293
+ + render(
294
+ + data,
295
+ + ctx.obj["output"],
296
+ + columns=["id", "network", "node", "ipv4_address", "wg_public_key", "wg_port", "state"],
297
+ + )
298
+ +
299
+ +
300
+ +@app.command("create")
301
+ +def create_network_node(
302
+ + ctx: typer.Context,
303
+ + network: str = typer.Option(..., "--network", "-n", help="Network ID", envvar="DINEMIC_NETWORK"),
304
+ + node: str = typer.Option(..., "--node", "-N", help="Node ID"),
305
+ +):
306
+ + """Attach a node to a network.
307
+ +
308
+ + Normally not needed: the attachment is created automatically with the first
309
+ + peer of that network on that node. Use it to pre-allocate an address and key.
310
+ + """
311
+ + data = ctx.obj["client"].post("/network-node/", {"network": network, "node": node})
312
+ + typer.secho(f"Attached node {node} to network {network} ({data['id']})", fg="green")
313
+ +
314
+ +
315
+ +@app.command("delete")
316
+ +def delete_network_node(
317
+ + ctx: typer.Context,
318
+ + network_node_id: str = typer.Option(..., "--network-node", "-a", help="Network node (attachment) ID"),
319
+ + yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
320
+ +):
321
+ + """Detach a node from a network and tear down its WireGuard interface."""
322
+ + if not yes:
323
+ + typer.confirm(
324
+ + f"Remove attachment {network_node_id}? Every peer of this network on that "
325
+ + f"node will lose connectivity",
326
+ + abort=True,
327
+ + )
328
+ + ctx.obj["client"].delete(f"/network-node/{network_node_id}/")
329
+ + typer.secho("Removed.", fg="green")
330
+ --- a/src/dinemic_cli/commands/node.py
331
+ +++ b/src/dinemic_cli/commands/node.py
332
+ @@ -4,12 +4,13 @@
333
+
334
+ app = typer.Typer(no_args_is_help=True)
335
+
336
+ +
337
+ @app.command("list")
338
+ def list_nodes(
339
+ ctx: typer.Context,
340
+ project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")):
341
+ data = ctx.obj["client"].get("/node/", project=project)
342
+ - render(data, ctx.obj["output"], columns=["id", "project", "public_key", "project", "description", "created", "sync_time", "state", "ipv4_address", "ipv6_address", "continent_code", "country_code", "city_name"])
343
+ + render(data, ctx.obj["output"], columns=["id", "project", "public_key", "description", "created", "sync_time", "state", "ipv4_address", "ipv6_address", "continent_code", "country_code", "city_name"])
344
+
345
+
346
+ @app.command("delete")
347
+ @@ -20,12 +21,3 @@
348
+ typer.confirm(f"Remove node {node_id} and all peers assigned to it?", abort=True)
349
+ ctx.obj["client"].delete(f"/node/{node_id}/")
350
+ typer.secho("Removed.", fg="green")
351
+ -
352
+ -#
353
+ -# @app.command("peers")
354
+ -# def list_peers(
355
+ -# ctx: typer.Context,
356
+ -# node_id: str = typer.Option(..., "--node")
357
+ -# ):
358
+ -# data = ctx.obj["client"].get(f"/node/{node_id}/")
359
+ -# render(data["peer_set"], ctx.obj["output"], columns=["id"])
360
+ --- a/src/dinemic_cli/commands/peer.py
361
+ +++ b/src/dinemic_cli/commands/peer.py
362
+ @@ -4,11 +4,12 @@
363
+
364
+ app = typer.Typer(no_args_is_help=True)
365
+
366
+ +
367
+ @app.command("list")
368
+ def list_peers(ctx: typer.Context,
369
+ project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")):
370
+ data = ctx.obj["client"].get("/peer/", project=project)
371
+ - render(data, ctx.obj["output"], columns=["id", "node", "network", "ip_address", "service_port", "role"])
372
+ + render(data, ctx.obj["output"], columns=["id", "node", "network", "network_node", "ipv4_address", "service_port", "role"])
373
+
374
+
375
+ @app.command("create")
376
+ --- a/src/dinemic_cli/commands/project.py
377
+ +++ b/src/dinemic_cli/commands/project.py
378
+ @@ -13,11 +13,12 @@
379
+ data = ctx.obj["client"].get("/project/")
380
+ render(data, ctx.obj["output"], columns=["id", "name", "public_key", "auto_accept_nodes"])
381
+
382
+ +
383
+ @app.command("create")
384
+ def create_project(ctx: typer.Context,
385
+ name: str = typer.Option(..., "--name", "-n", help="Project name")):
386
+ data = ctx.obj["client"].post("/project/", {"name": name})
387
+ - typer.secho(f"Created project {data['name']} for project ({data['id']})", fg="green")
388
+ + typer.secho(f"Created project {data['name']} ({data['id']})", fg="green")
389
+
390
+
391
+ @app.command("delete")
392
+ @@ -32,12 +33,21 @@
393
+
394
+ @app.command("configure")
395
+ def configure_node(ctx: typer.Context,
396
+ - project_id: str = typer.Option(..., "--project", "-p", help="Project ID"),
397
+ - log_level: str = typer.Option(False, "--yes", "-y", help="Logging level"),
398
+ - debug: bool = typer.Option(False, "--yes", "-y", help="Enable debug"),
399
+ + project_id: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
400
+ + log_level: str = typer.Option("info", "--log-level", "-L", help="Agent log level (error, warn, info, debug, trace)"),
401
+ + debug: bool = typer.Option(False, "--debug", "-D", help="Enable agent debug mode"),
402
+ ):
403
+ - params = []
404
+ - typer.secho(f"sudo RUST_DEBUG=True RUST_LOG=debug ./dinemic-agent -p '2z/gdqCRIvmHj7YAQkFVN+8IuW4NhoiBO39v+zSuS3I='", fg="green")
405
+ + """Print the command that registers an agent in this project."""
406
+ + data = ctx.obj["client"].get(f"/project/{project_id}/")
407
+ + env = [f"RUST_LOG={log_level}"]
408
+ + if debug:
409
+ + env.append("RUST_DEBUG=True")
410
+ + typer.secho(
411
+ + f"sudo {' '.join(env)} ./dinemic-agent -p '{data['public_key']}'",
412
+ + fg="green",
413
+ + )
414
+ +
415
+ +
416
+ ###########
417
+ # Members #
418
+ ###########
@@ -0,0 +1,208 @@
1
+ --- a/tests/api_samples.py
2
+ +++ b/tests/api_samples.py
3
+ @@ -194,6 +194,20 @@
4
+ )
5
+
6
+
7
+ +_DETAIL = re.compile(r"^(?P<collection>.*/)[^/]+/$")
8
+ +
9
+ +
10
+ +def sample_for(path: str):
11
+ + """Lista dla ścieżki kolekcji, pojedynczy obiekt dla ścieżki szczegółowej."""
12
+ + try:
13
+ + return sample_list(path)
14
+ + except KeyError:
15
+ + match = _DETAIL.match(path)
16
+ + if match:
17
+ + return sample_object(match.group("collection"))
18
+ + raise
19
+ +
20
+ +
21
+ def sample_object(path: str) -> dict[str, Any]:
22
+ return sample_list(path)[0]
23
+
24
+ --- a/tests/command_matrix.py
25
+ +++ b/tests/command_matrix.py
26
+ @@ -37,7 +37,6 @@
27
+ "id",
28
+ "project",
29
+ "public_key",
30
+ - "project", # duplikat obecny w node.py - patrz test_option_contract.py
31
+ "description",
32
+ "created",
33
+ "sync_time",
34
+ @@ -100,13 +99,8 @@
35
+ module="project",
36
+ args=("configure", "-p", s.PROJECT_ID),
37
+ method="GET",
38
+ - path="/project/",
39
+ + path=f"/project/{s.PROJECT_ID}/",
40
+ kind="other",
41
+ - xfail=(
42
+ - "project.configure jest niezaimplementowane: trzy opcje deklarują ten sam "
43
+ - "flag '--yes/-y', log_level ma typ str z domyślnym False, a komenda "
44
+ - "wypisuje zaszyty na sztywno klucz publiczny zamiast danych projektu"
45
+ - ),
46
+ ),
47
+ # ------------------------------------------------------------------ network
48
+ Case(
49
+ @@ -189,7 +183,15 @@
50
+ path="/peer/",
51
+ kind="list",
52
+ params={"project": None},
53
+ - columns=["id", "node", "network", "ip_address", "service_port", "role"],
54
+ + columns=[
55
+ + "id",
56
+ + "node",
57
+ + "network",
58
+ + "network_node",
59
+ + "ipv4_address",
60
+ + "service_port",
61
+ + "role",
62
+ + ],
63
+ ),
64
+ Case(
65
+ id="peer-create",
66
+ @@ -287,14 +289,13 @@
67
+ method="POST",
68
+ path="/healthcheck/",
69
+ kind="create",
70
+ - # UWAGA: period/max_fail/initial_delay są typu str, więc lecą jako stringi
71
+ payload={
72
+ "project": s.PROJECT_ID,
73
+ "name": "http-ok",
74
+ "path": "/healthz",
75
+ - "period": "10",
76
+ - "max_fail": "3",
77
+ - "initial_delay": "30",
78
+ + "period": 10,
79
+ + "max_fail": 3,
80
+ + "initial_delay": 30,
81
+ },
82
+ ),
83
+ Case(
84
+ @@ -448,11 +449,6 @@
85
+ f"/backend/{s.BACKEND_ID}/"
86
+ ),
87
+ kind="delete",
88
+ - xfail=(
89
+ - "loadbalancer_backend.delete_backend deklaruje route_id jako '--host'/'-H' "
90
+ - "(kopiuj-wklej z host_id). Click nadpisuje wcześniejszą definicję, więc "
91
+ - "host_id nigdy nie da się podać i komenda jest niewywoływalna"
92
+ - ),
93
+ ),
94
+ # ---------------------------------------------------------------------- dns
95
+ Case(
96
+ @@ -597,7 +593,7 @@
97
+ "project": s.PROJECT_ID,
98
+ "name": "acme-1",
99
+ "directory_url": "https://acme-v02.api.letsencrypt.org/directory",
100
+ - "max_parallel": "2",
101
+ + "max_parallel": 2,
102
+ },
103
+ ),
104
+ Case(
105
+ --- a/tests/support.py
106
+ +++ b/tests/support.py
107
+ @@ -143,9 +143,9 @@
108
+ self._maybe_raise("GET", path)
109
+ if ("GET", path) in self._responses:
110
+ return self._responses[("GET", path)]
111
+ - from api_samples import sample_list # import lokalny: patrz conftest rootdir
112
+ + from api_samples import sample_for # import lokalny: patrz conftest rootdir
113
+
114
+ - return sample_list(path)
115
+ + return sample_for(path)
116
+
117
+ def post(self, path: str, payload: dict[str, Any]) -> Any:
118
+ self._record("POST", path, payload, {})
119
+ --- a/tests/test_columns.py
120
+ +++ b/tests/test_columns.py
121
+ @@ -15,13 +15,7 @@
122
+ from command_matrix import LIST_CASES
123
+
124
+ #: Kolumny, o których wiemy, że nie zgadzają się z modelem backendu.
125
+ -COLUMN_BUGS = {
126
+ - "peer-list": (
127
+ - "peer.py renderuje 'ip_address', ale model Peer (i Peer.to_dict w backendzie) "
128
+ - "ma 'ipv4_address' — kolumna wychodzi pusta. Zweryfikuj na żywym API: "
129
+ - "pytest tests/integration -m integration -k columns"
130
+ - ),
131
+ -}
132
+ +COLUMN_BUGS: dict[str, str] = {}
133
+
134
+
135
+ def _param(case):
136
+ --- a/tests/test_envvars.py
137
+ +++ b/tests/test_envvars.py
138
+ @@ -110,15 +110,6 @@
139
+ assert client.last.payload["network"] == s.NETWORK_ID
140
+
141
+
142
+ -@pytest.mark.xfail(
143
+ - strict=True,
144
+ - reason=(
145
+ - "niespójność: 'list'/'create' czytają DINEMIC_ZONE, ale 'dns_value delete' "
146
+ - "deklaruje --zone bez envvar (dns_value.py), więc ten sam workflow raz działa, "
147
+ - "raz wymaga -z. To samo dotyczy delete w loadbalancer_host/route/backend "
148
+ - "(brak DINEMIC_LB/DINEMIC_HOST/DINEMIC_ROUTE)"
149
+ - ),
150
+ -)
151
+ def test_delete_commands_honour_the_same_envvars_as_list(invoke, client, monkeypatch):
152
+ monkeypatch.setenv("DINEMIC_ZONE", s.ZONE_ID)
153
+
154
+ --- a/tests/test_option_contract.py
155
+ +++ b/tests/test_option_contract.py
156
+ @@ -157,17 +157,7 @@
157
+ # Testy
158
+ # ---------------------------------------------------------------------------
159
+
160
+ -DUPLICATE_FLAG_BUGS = {
161
+ - "loadbalancer_backend": (
162
+ - "delete_backend: route_id zadeklarowany jako '--host'/'-H', tak samo jak host_id. "
163
+ - "Click nadpisuje pierwszą definicję, więc --host ustawia route_id, a host_id "
164
+ - "pozostaje niepodany => komendy nie da się wywołać"
165
+ - ),
166
+ - "project": (
167
+ - "configure_node: log_level i debug deklarują '--yes'/'-y' (kopiuj-wklej z delete), "
168
+ - "obie opcje kolidują ze sobą"
169
+ - ),
170
+ -}
171
+ +DUPLICATE_FLAG_BUGS: dict[str, str] = {}
172
+
173
+
174
+ @pytest.mark.parametrize(
175
+ @@ -186,12 +176,7 @@
176
+ seen[flag] = option.param
177
+
178
+
179
+ -TYPE_MISMATCH_BUGS = {
180
+ - "project": (
181
+ - "configure_node: 'log_level: str = typer.Option(False, ...)' — wartość domyślna "
182
+ - "typu bool na opcji str (pułapka opisana w 7.4 dokumentacji)"
183
+ - ),
184
+ -}
185
+ +TYPE_MISMATCH_BUGS: dict[str, str] = {}
186
+
187
+
188
+ @pytest.mark.parametrize(
189
+ @@ -214,9 +199,7 @@
190
+ )
191
+
192
+
193
+ -DUPLICATE_COLUMN_BUGS = {
194
+ - "node": "list_nodes renderuje kolumnę 'project' dwa razy",
195
+ -}
196
+ +DUPLICATE_COLUMN_BUGS: dict[str, str] = {}
197
+
198
+
199
+ @pytest.mark.parametrize(
200
+ @@ -294,6 +277,8 @@
201
+ #: Krótkie flagi używane dziś w więcej niż jednym znaczeniu. Nowe kolizje = fail.
202
+ KNOWN_SHORT_FLAG_COLLISIONS = {
203
+ "-H": {"healthcheck_id", "host", "host_id"},
204
+ + "-D": {"debug"},
205
+ + "-L": {"log_level"},
206
+ "-N": {"node"},
207
+ "-P": {"path", "port", "priority"},
208
+ "-b": {"backend_id"},