1{ lib, ... }:
2
3{
4 name = "olivetin";
5 meta.maintainers = with lib.maintainers; [ defelo ];
6
7 nodes.machine = {
8 services.olivetin = {
9 enable = true;
10 settings = {
11 actions = [
12 {
13 id = "hello_world";
14 title = "Say Hello";
15 shell = "echo -n 'Hello World!' | tee /tmp/result";
16 }
17 ];
18 };
19 extraConfigFiles = [
20 (builtins.toFile "secrets.yaml" ''
21 actions:
22 - id: secret
23 title: Secret Action
24 shell: echo -n secret > /tmp/result2
25 '')
26 ];
27 };
28 };
29
30 interactive.nodes.machine = {
31 services.olivetin.settings.ListenAddressSingleHTTPFrontend = "0.0.0.0:8000";
32 networking.firewall.allowedTCPPorts = [ 8000 ];
33 virtualisation.forwardPorts = [
34 {
35 from = "host";
36 host.port = 8000;
37 guest.port = 8000;
38 }
39 ];
40 };
41
42 testScript = ''
43 import json
44
45 machine.wait_for_unit("olivetin.service")
46 machine.wait_for_open_port(8000)
47
48 response = json.loads(machine.succeed("curl http://localhost:8000/api/StartActionByGetAndWait/hello_world"))
49 assert response["logEntry"]["exitCode"] == 0
50 assert response["logEntry"]["output"] == "Hello World!"
51 assert machine.succeed("cat /tmp/result") == "Hello World!"
52
53 response = json.loads(machine.succeed("curl http://localhost:8000/api/StartActionByGetAndWait/secret"))
54 assert response["logEntry"]["exitCode"] == 0
55 assert machine.succeed("cat /tmp/result2") == "secret"
56 '';
57}