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 @@
1
+
@@ -0,0 +1,16 @@
1
+ import sys
2
+ import typer
3
+ from dinemic_cli.client import ApiError
4
+ from dinemic_cli.main import app
5
+
6
+
7
+ def run():
8
+ try:
9
+ app()
10
+ except ApiError as e:
11
+ typer.secho(str(e), fg="red", err=True)
12
+ sys.exit(1)
13
+
14
+
15
+ if __name__ == "__main__":
16
+ run()
dinemic_cli/client.py ADDED
@@ -0,0 +1,75 @@
1
+ import httpx
2
+ import keyring
3
+
4
+ SERVICE = "dinemic"
5
+
6
+
7
+ def get_token() -> str | None:
8
+ return keyring.get_password(SERVICE, "token")
9
+
10
+
11
+ def set_token(token: str) -> None:
12
+ keyring.set_password(SERVICE, "token", token)
13
+
14
+
15
+ class ApiError(Exception):
16
+ pass
17
+
18
+
19
+ class Client:
20
+ def __init__(self, base_url: str, token: str | None):
21
+ headers = {"Authorization": f"Token {token}"} if token else {}
22
+ self._http = httpx.Client(
23
+ base_url=f"{base_url.rstrip('/')}/api/v1",
24
+ headers=headers,
25
+ timeout=30.0,
26
+ )
27
+ self._http_unauth = httpx.Client(
28
+ base_url=f"{base_url.rstrip('/')}/api/v1",
29
+ timeout=30.0,
30
+ )
31
+
32
+ def request(self, method: str, path: str, unauthorized=False, **kwargs) -> dict | list:
33
+ try:
34
+ if unauthorized:
35
+ r = self._http_unauth.request(method, path, **kwargs)
36
+ else:
37
+ r = self._http.request(method, path, **kwargs)
38
+ except httpx.RequestError as e:
39
+ raise ApiError(f"Can't connect with backend: {e}") from e
40
+
41
+ if r.is_success:
42
+ return r.json() if r.content else {}
43
+ raise self._to_error(r)
44
+
45
+ @staticmethod
46
+ def _to_error(r: httpx.Response) -> ApiError:
47
+ if r.status_code == 401:
48
+ return ApiError("Not logged in. run: dinemic auth login")
49
+ if r.status_code == 403:
50
+ return ApiError("Access denied")
51
+ if r.status_code == 404:
52
+ return ApiError("Resource not found")
53
+ if r.status_code == 400:
54
+ try:
55
+ data = r.json()
56
+ except ValueError:
57
+ return ApiError("Malformed data")
58
+ lines = [
59
+ f"{field}: {'; '.join(msgs) if isinstance(msgs, list) else msgs}"
60
+ for field, msgs in data.items()
61
+ ]
62
+ return ApiError("\n".join(lines))
63
+ return ApiError(f"Backend returned {r.status_code}")
64
+
65
+ def get(self, path, **params):
66
+ return self.request("GET", path, params=params or None)
67
+
68
+ def post(self, path, data: dict):
69
+ return self.request("POST", path, json=data)
70
+
71
+ def post_login(self, path, data: dict):
72
+ return self.request("POST", path, unauthorized=True, json=data)
73
+
74
+ def delete(self, path):
75
+ return self.request("DELETE", path)
File without changes
@@ -0,0 +1,31 @@
1
+ import typer
2
+
3
+ from dinemic_cli.client import set_token, get_token
4
+ from dinemic_cli.output import render
5
+
6
+ app = typer.Typer(no_args_is_help=True)
7
+
8
+
9
+ @app.command("login")
10
+ def login_credentials(
11
+ username: str = typer.Option(..., prompt=True),
12
+ password: str = typer.Option(..., prompt=True, hide_input=True),
13
+ ctx: typer.Context = None,
14
+ ):
15
+ data = ctx.obj["client"].post_login("/auth/token/", {"username": username, "password": password})
16
+ set_token(data["token"])
17
+ typer.secho("Logged in. Token stored in keyring.", fg="green")
18
+
19
+
20
+ @app.command("set-token")
21
+ def login(
22
+ token: str = typer.Option(prompt="Set Dinemic API token", hide_input=True, help="Set and save Dinemic API"),
23
+ ):
24
+ set_token(token)
25
+ typer.secho("Logged in. Token saved in your keyring", fg="green")
26
+
27
+
28
+ @app.command("get-token")
29
+ def login_get_token(ctx: typer.Context):
30
+ data = [{"token": get_token()}]
31
+ render(data, ctx.obj["output"], columns=["token"])
@@ -0,0 +1,11 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+
8
+ @app.command("list")
9
+ def list_caas(ctx: typer.Context):
10
+ data = ctx.obj["client"].get("/caa/")
11
+ render(data, ctx.obj["output"], columns=["id", "name"])
@@ -0,0 +1,29 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+
8
+ @app.command("list")
9
+ def list_certs(ctx: typer.Context):
10
+ data = ctx.obj["client"].get("/certificate/")
11
+ render(data, ctx.obj["output"], columns=["id", "project", "common_name", "status", "domains", "not_before", "not_after", "expires_in_days", "issued_at", "needs_renewal", "delivered_to", "attempts", "error"])
12
+
13
+ @app.command("reissue", help="Start issuance from scratch (new ACME order) for a certificate that is stuck or failed.")
14
+ def reissue_certificate(ctx: typer.Context,
15
+ certificate: str = typer.Option(..., "--certificate", "-c", help="Certificate ID"),
16
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),):
17
+ if not yes:
18
+ typer.confirm(f"Start a new ACME order for certificate {certificate}", abort=True)
19
+ data = ctx.obj["client"].post(f"/certificate/{certificate}/reissue/", {})
20
+ typer.secho(f"Certificate {data['id']} is {data['status']}. When it reaches challenge_set and the "
21
+ f"_acme-challenge TXT is visible on every DNS server, run: dinemic cert recheck -c {data['id']}",
22
+ fg="green")
23
+
24
+
25
+ @app.command("recheck", help="Make the agent check the DNS challenge again (certificate stuck in challenge_set).")
26
+ def recheck_certificate(ctx: typer.Context,
27
+ certificate: str = typer.Option(..., "--certificate", "-c", help="Certificate ID")):
28
+ data = ctx.obj["client"].post(f"/certificate/{certificate}/recheck/", {})
29
+ typer.secho(f"Recheck requested for certificate {data['id']} ({data['status']}).", fg="green")
@@ -0,0 +1,37 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
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", envvar="DINEMIC_PROJECT"),
20
+ name: str = typer.Option(..., "--name", "-n", help="Name"),
21
+ 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"),
22
+ max_parallel: int = typer.Option(..., "--max-parallel", "-m", help="Maximum number of certificates processed by one peer at once"),
23
+ ):
24
+ data = ctx.obj["client"].post("/certificate-peer/", {"project": project, "name": name, "directory_url": directory_url, "max_parallel": max_parallel})
25
+ typer.secho(f"Created certificate peer {data['id']}", fg="green")
26
+
27
+
28
+ @app.command("delete")
29
+ def delete_cert_peer(
30
+ ctx: typer.Context,
31
+ cert_peer_id: str = typer.Option(..., "--cert-peer", "-c", help="Certificate Peer ID"),
32
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
33
+ ):
34
+ if not yes:
35
+ typer.confirm(f"Remove Certificate Peer {cert_peer_id}? It will stop renewing your certificates if there is no redundant peer", abort=True)
36
+ ctx.obj["client"].delete(f"/certificate-peer/{cert_peer_id}/")
37
+ typer.secho("Removed.", fg="green")
@@ -0,0 +1,57 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True, help="Entries for DNS zone")
6
+
7
+
8
+ @app.command("list")
9
+ def list_entries(
10
+ ctx: typer.Context,
11
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE")
12
+ ):
13
+ data = ctx.obj["client"].get(f"/zone/{zone_id}/entry/")
14
+ render(data, ctx.obj["output"], columns=["id", "record", "type", "ttl"])
15
+
16
+
17
+ @app.command("list-values")
18
+ def list_values(
19
+ ctx: typer.Context,
20
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE")
21
+ ):
22
+ data = ctx.obj["client"].get(f"/zone/{zone_id}/entry/")
23
+ for entry in data:
24
+ if not "values" in entry:
25
+ entry["values"] = []
26
+ entry_data = ctx.obj["client"].get(f"/zone/{zone_id}/entry/{entry['id']}/value/")
27
+ for value in entry_data:
28
+ entry["values"].append(value["value"])
29
+ entry["values"] = "\n".join(entry["values"])
30
+ render(data, ctx.obj["output"], columns=["id", "record", "type", "ttl", "values"])
31
+
32
+
33
+ @app.command("create")
34
+ def create_entry(
35
+ ctx: typer.Context,
36
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
37
+ record: str = typer.Option(..., "--record", "-r", help="Record name, i.e. www (empty for zone apex)"),
38
+ type_: str = typer.Option(..., "--type", "-t", help="Record type, i.e. A, AAAA or MX"),
39
+ ttl: int = typer.Option(300, "--ttl", help="TTL value in seconds"),
40
+ ):
41
+ data = ctx.obj["client"].post(
42
+ f"/zone/{zone_id}/entry/", {"record": record, "type": type_, "ttl": ttl}
43
+ )
44
+ typer.secho(f"Added record {data['record']} ({data['id']})", fg="green")
45
+
46
+
47
+ @app.command("delete")
48
+ def delete_entry(
49
+ ctx: typer.Context,
50
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
51
+ record_id: str = typer.Option(..., "--record", "-r", help="Record id"),
52
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
53
+ ):
54
+ if not yes:
55
+ typer.confirm(f"Remove record {record_id} from zone {zone_id}?", abort=True)
56
+ ctx.obj["client"].delete(f"/zone/{zone_id}/entry/{record_id}/")
57
+ typer.secho("Removed.", fg="green")
@@ -0,0 +1,43 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True, help="Values for entry in DNS zone")
6
+
7
+
8
+ @app.command("list")
9
+ def list_values(
10
+ ctx: typer.Context,
11
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
12
+ record_id: str = typer.Option(..., "--record", "-r", help="Record ID")
13
+ ):
14
+ data = ctx.obj["client"].get(f"/zone/{zone_id}/entry/{record_id}/value/")
15
+ render(data, ctx.obj["output"], columns=["id", "value", "weight"])
16
+
17
+
18
+ @app.command("create")
19
+ def create_value(
20
+ ctx: typer.Context,
21
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
22
+ record_id: str = typer.Option(..., "--record", "-r", help="Record ID"),
23
+ value: str = typer.Option(..., "--value", "-v", help="Value for record"),
24
+ weight: int = typer.Option(1, "--weight", "-w", help="Weight"),
25
+ ):
26
+ data = ctx.obj["client"].post(
27
+ f"/zone/{zone_id}/entry/{record_id}/value/", {"value": value, "weight": weight}
28
+ )
29
+ typer.secho(f"Added value {data['value']} ({data['id']})", fg="green")
30
+
31
+
32
+ @app.command("delete")
33
+ def delete_value(
34
+ ctx: typer.Context,
35
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
36
+ record_id: str = typer.Option(..., "--record", "-r", help="Record ID"),
37
+ value_id: str = typer.Option(..., "--value", "-v", help="Value ID"),
38
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
39
+ ):
40
+ if not yes:
41
+ typer.confirm(f"Remove value {value_id} from record {record_id} in zone {zone_id}?", abort=True)
42
+ ctx.obj["client"].delete(f"/zone/{zone_id}/entry/{record_id}/value/{value_id}/")
43
+ typer.secho("Removed.", fg="green")
@@ -0,0 +1,98 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+
8
+ @app.command("list")
9
+ def list_zones(
10
+ ctx: typer.Context,
11
+ project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")
12
+ ):
13
+ data = ctx.obj["client"].get("/zone/", project=project)
14
+ render(data, ctx.obj["output"], columns=["id", "domain", "project"])
15
+
16
+
17
+ @app.command("create")
18
+ def create_zone(
19
+ ctx: typer.Context,
20
+ domain: str = typer.Option(..., "--domain", "-d", help="Domain name"),
21
+ project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
22
+ caa: str = typer.Option(..., "--caa", "-c", help="CAA ID"),
23
+ name: str = typer.Option(..., "--name", "-n", help="Zone name"),
24
+ email: str = typer.Option(..., "--email", "-e", help="Contact email"),
25
+ ):
26
+ data = ctx.obj["client"].post("/zone/", {"domain": domain, "project": project, "valid_caa": [caa], "name": name, "contact_email": email})
27
+ typer.secho(f"Created zone {data['domain']} ({data['id']})", fg="green")
28
+
29
+
30
+ @app.command("delete")
31
+ def delete_zone(
32
+ ctx: typer.Context,
33
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
34
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
35
+ ):
36
+ if not yes:
37
+ typer.confirm(f"Remove DNS zone {zone_id} and all its records?", abort=True)
38
+ ctx.obj["client"].delete(f"/zone/{zone_id}/")
39
+ typer.secho("Removed.", fg="green")
40
+
41
+
42
+ @app.command("check")
43
+ def check_zone(
44
+ ctx: typer.Context,
45
+ zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE")
46
+ ):
47
+ # Get data
48
+ zone = ctx.obj["client"].get(f"/zone/{zone_id}/")
49
+ domain = zone["domain"]
50
+ typer.secho(f"Checking zone {zone['domain']}")
51
+
52
+ entries = ctx.obj["client"].get(f"/zone/{zone_id}/entry/")
53
+ for entry in entries:
54
+ if not "values" in entry:
55
+ entry["values"] = []
56
+ entry_data = ctx.obj["client"].get(f"/zone/{zone_id}/entry/{entry['id']}/value/")
57
+ for value in entry_data:
58
+ entry["values"].append(value["value"])
59
+
60
+ # Validate collected data
61
+
62
+ record_a_www = False
63
+ record_a = False
64
+ for entry in entries:
65
+ if entry["type"] == "A" and entry["record"] == "www":
66
+ record_a_www = True
67
+
68
+ if entry["type"] == "A" and (entry["record"] == "" or entry["record"] is None):
69
+ record_a = True
70
+
71
+ if entry["type"] == "NS":
72
+ for value in entry["values"]:
73
+ # Check for trailing dot in NS
74
+ if not value.endswith("."):
75
+ typer.secho(f"NS record {entry['record']} does not end with . (dot)", fg="red")
76
+ else:
77
+ typer.secho(f"NS record {entry['record']} ok", fg="green")
78
+
79
+ ns_a_present = False
80
+ for e in entries:
81
+ if f"{e['record']}.{domain}." == value and e["type"] == "A":
82
+ if e["values"]:
83
+ ns_a_present = True
84
+ else:
85
+ typer.secho(f"Missing values for record A {e['record']}")
86
+
87
+ if not ns_a_present:
88
+ typer.secho(f"Missing record A corresponding to NS {value}")
89
+ else:
90
+ typer.secho(f"A for NS record {value} ok", fg="green")
91
+
92
+ if not record_a:
93
+ typer.secho("Missing A record \"@\" for domain - DNS will not resolve domain's IP address", fg="blue")
94
+
95
+ if not record_a_www:
96
+ typer.secho("Missing A record \"www\" for domain - DNS will not resolve domain's IP address", fg="blue")
97
+
98
+ #typer.secho(f"Zone entries validated. Check your resolver responses with: dig @[ip of nodes] {domain}")
@@ -0,0 +1,39 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+
8
+ @app.command("list")
9
+ def list_endpoints(
10
+ ctx: typer.Context,
11
+ project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")
12
+ ):
13
+ data = ctx.obj["client"].get("/endpoint/", project=project)
14
+ render(data, ctx.obj["output"], columns=["id", "project", "name", "scheme", "host", "port"])
15
+
16
+
17
+ @app.command("create")
18
+ def create_endpoint(
19
+ ctx: typer.Context,
20
+ project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
21
+ name: str = typer.Option(..., "--name", "-n", help="Name"),
22
+ scheme: str = typer.Option(..., "--scheme", "-s", help="Scheme (HTTP or HTTPS)"),
23
+ host: str = typer.Option(..., "--host", "-H", help="Host name"),
24
+ port: int = typer.Option(..., "--port", "-P", help="Port number"),
25
+ ):
26
+ data = ctx.obj["client"].post("/endpoint/", {"project": project, "name": name, "scheme": scheme, "host": host, "port": port, "tags": []})
27
+ typer.secho(f"Created endpoint {data['name']} ({data['id']})", fg="green")
28
+
29
+
30
+ @app.command("delete")
31
+ def delete_endpoint(
32
+ ctx: typer.Context,
33
+ endpoint_id: str = typer.Option(..., "--endpoint", "-e", help="Endpoint ID"),
34
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
35
+ ):
36
+ if not yes:
37
+ typer.confirm(f"Remove Endpoint {endpoint_id} and all its records?", abort=True)
38
+ ctx.obj["client"].delete(f"/endpoint/{endpoint_id}/")
39
+ typer.secho("Removed.", fg="green")
@@ -0,0 +1,40 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+
8
+ @app.command("list")
9
+ def list_healthchecks(
10
+ ctx: typer.Context,
11
+ project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")
12
+ ):
13
+ data = ctx.obj["client"].get("/healthcheck/", project=project)
14
+ render(data, ctx.obj["output"], columns=["id", "name", "project", "path", "period", "max_fail", "initial_delay"])
15
+
16
+
17
+ @app.command("create")
18
+ def create_healthcheck(
19
+ ctx: typer.Context,
20
+ project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
21
+ name: str = typer.Option(..., "--name", "-n", help="Name"),
22
+ path: str = typer.Option(..., "--path", "-P", help="Path"),
23
+ period: int = typer.Option(..., "--period", "-d", help="Period (seconds)"),
24
+ max_fail: int = typer.Option(..., "--max-fail", "-m", help="Maximum fails before disabling"),
25
+ initial_delay: int = typer.Option(..., "--initial-delay", "-i", help="Initial delay (seconds)"),
26
+ ):
27
+ data = ctx.obj["client"].post("/healthcheck/", {"project": project, "name": name, "path": path, "period": period, "max_fail": max_fail, "initial_delay": initial_delay})
28
+ typer.secho(f"Created healthcheck {data['id']}", fg="green")
29
+
30
+
31
+ @app.command("delete")
32
+ def delete_healthcheck(
33
+ ctx: typer.Context,
34
+ healthcheck_id: str = typer.Option(..., "--healthcheck", "-H", help="Healthcheck ID"),
35
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
36
+ ):
37
+ if not yes:
38
+ typer.confirm(f"Remove healthcheck {healthcheck_id}?", abort=True)
39
+ ctx.obj["client"].delete(f"/healthcheck/{healthcheck_id}/")
40
+ typer.secho("Removed.", fg="green")
@@ -0,0 +1,39 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+
8
+ @app.command("list")
9
+ def list_loadbalancers(
10
+ ctx: typer.Context,
11
+ project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")
12
+ ):
13
+ data = ctx.obj["client"].get("/loadbalancer/", project=project)
14
+ render(data, ctx.obj["output"], columns=["id", "name", "project", "http_port", "https_port", "redirect_to_https"])
15
+
16
+
17
+ @app.command("create")
18
+ def create_loadbalancer(
19
+ ctx: typer.Context,
20
+ project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
21
+ name: str = typer.Option(..., "--name", "-n", help="Name"),
22
+ http_port: int = typer.Option(80, "--http", "-x", help="Http port"),
23
+ https_port: int = typer.Option(443, "--https", "-s", help="Https port"),
24
+ redirect_to_https: bool = typer.Option(True, "--redirect", "-r", help="Redirect http to https"),
25
+ ):
26
+ data = ctx.obj["client"].post("/loadbalancer/", {"project": project, "name": name, "http_port": http_port, "https_port": https_port, "redirect_to_https": redirect_to_https})
27
+ typer.secho(f"Created loadbalancer {data['name']} ({data['id']})", fg="green")
28
+
29
+
30
+ @app.command("delete")
31
+ def delete_loadbalancer(
32
+ ctx: typer.Context,
33
+ loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Load balancer ID", envvar="DINEMIC_LB"),
34
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
35
+ ):
36
+ if not yes:
37
+ typer.confirm(f"Remove loadbalancer {loadbalancer_id} and all its hosts, routes and backends?", abort=True)
38
+ ctx.obj["client"].delete(f"/loadbalancer/{loadbalancer_id}/")
39
+ typer.secho("Removed.", fg="green")
@@ -0,0 +1,44 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+
8
+ @app.command("list")
9
+ def list_backends(
10
+ ctx: typer.Context,
11
+ loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
12
+ host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
13
+ route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE")
14
+ ):
15
+ data = ctx.obj["client"].get(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/{route_id}/backend/")
16
+ render(data, ctx.obj["output"], columns=["id", "endpoint", "weight", "route"])
17
+
18
+
19
+ @app.command("create")
20
+ def create_backend(
21
+ ctx: typer.Context,
22
+ loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
23
+ host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
24
+ route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE"),
25
+ endpoint_id: str = typer.Option(..., "--endpoint", "-e", help="Endpoint ID"),
26
+ weight: int = typer.Option(..., "--weight", "-w", help="Weight")
27
+ ):
28
+ data = ctx.obj["client"].post(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/{route_id}/backend/", {"endpoint": endpoint_id, "weight": weight})
29
+ typer.secho(f"Created backend {data['id']} (for route {route_id} in host {host_id} in loadbalancer {loadbalancer_id})", fg="green")
30
+
31
+
32
+ @app.command("delete")
33
+ def delete_backend(
34
+ ctx: typer.Context,
35
+ loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
36
+ host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
37
+ route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE"),
38
+ backend_id: str = typer.Option(..., "--backend", "-b", help="Backend ID"),
39
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
40
+ ):
41
+ if not yes:
42
+ typer.confirm(f"Remove backend {backend_id}?", abort=True)
43
+ ctx.obj["client"].delete(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/{route_id}/backend/{backend_id}/")
44
+ typer.secho("Removed.", fg="green")
@@ -0,0 +1,37 @@
1
+ import typer
2
+
3
+ from dinemic_cli.output import render
4
+
5
+ app = typer.Typer(no_args_is_help=True)
6
+
7
+
8
+ @app.command("list")
9
+ def list_hosts(
10
+ ctx: typer.Context,
11
+ loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB")
12
+ ):
13
+ data = ctx.obj["client"].get(f"/loadbalancer/{loadbalancer_id}/host/")
14
+ render(data, ctx.obj["output"], columns=["id", "domain"])
15
+
16
+
17
+ @app.command("create")
18
+ def create_host(
19
+ ctx: typer.Context,
20
+ loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
21
+ domain_id: str = typer.Option(..., "--domain", "-d", help="Route from DNS zone (domain)"),
22
+ ):
23
+ data = ctx.obj["client"].post(f"/loadbalancer/{loadbalancer_id}/host/", {"domain": domain_id})
24
+ typer.secho(f"Created host {data['id']} (for loadbalancer {loadbalancer_id})", fg="green")
25
+
26
+
27
+ @app.command("delete")
28
+ def delete_host(
29
+ ctx: typer.Context,
30
+ loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Load balancer ID", envvar="DINEMIC_LB"),
31
+ host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
32
+ yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
33
+ ):
34
+ if not yes:
35
+ typer.confirm(f"Remove host {host_id} and all its routes?", abort=True)
36
+ ctx.obj["client"].delete(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/")
37
+ typer.secho("Removed.", fg="green")