1{ lib, ... }:
2
3{
4 name = "zipline";
5 meta.maintainers = with lib.maintainers; [ defelo ];
6
7 nodes.machine = {
8 services.zipline = {
9 enable = true;
10 settings = {
11 CORE_HOSTNAME = "127.0.0.1";
12 CORE_PORT = 8000;
13 };
14 environmentFiles = [
15 (builtins.toFile "zipline.env" ''
16 CORE_SECRET=DMlouex3W0QLRbVwkUafNnNws5jpgRDX
17 '')
18 ];
19 };
20
21 networking.hosts."127.0.0.1" = [ "zipline.local" ];
22 };
23
24 interactive.nodes.machine = {
25 services.zipline.settings.CORE_HOSTNAME = lib.mkForce "0.0.0.0";
26 networking.firewall.allowedTCPPorts = [ 8000 ];
27 virtualisation.forwardPorts = [
28 {
29 from = "host";
30 host.port = 8000;
31 guest.port = 8000;
32 }
33 ];
34 };
35
36 testScript = ''
37 import json
38 import re
39
40 machine.wait_for_unit("zipline.service")
41 machine.wait_for_open_port(8000)
42
43 resp = machine.succeed("curl zipline.local:8000/api/setup -v -X POST -H 'Content-Type: application/json' -d '{\"username\": \"administrator\", \"password\": \"password\"}' 2>&1")
44 data = json.loads(resp.splitlines()[-1])
45 assert data["firstSetup"] is True
46 assert data["user"]["username"] == "administrator"
47 assert data["user"]["role"] == "SUPERADMIN"
48
49 resp = machine.succeed("curl zipline.local:8000/api/auth/login -v -X POST -H 'Content-Type: application/json' -d '{\"username\": \"administrator\", \"password\": \"password\"}' 2>&1")
50
51 assert (cookie := re.search(r"(?m)^< set-cookie: ([^;]*)", resp))
52 resp = machine.succeed(f"curl zipline.local:8000/api/user -H 'Cookie: {cookie[1]}'")
53 assert json.loads(resp)["user"]["id"] == data["user"]["id"]
54 '';
55}