Coverage report: /home/ellis/comp/core/lib/box/ignition.lisp

KindCoveredAll%
expression0110 0.0
branch06 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; ignition.lisp --- CoreOS Ignition
2
 
3
 ;; Ignition JSON config parsing
4
 
5
 ;;; Commentary:
6
 
7
 ;; Objects <-> SXP <-> JSON
8
 
9
 ;; I really have no interest in reading or writing YAML, so instead we'll read
10
 ;; and write lisp. This package provides the role of Butane.
11
 
12
 ;; ref: https://coreos.github.io/butane
13
 
14
 ;; currently based on the 3.6.0 (WIP) 
15
 
16
 ;; spec: https://coreos.github.io/ignition/configuration-v3_6_experimental
17
 
18
 ;;; Example:
19
 #| json
20
 {
21
   "ignition": { "version": "3.6.0-experimental" },
22
   "systemd": {
23
     "units": [{
24
       "name": "example.service",
25
       "enabled": true,
26
       "contents": "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target"
27
     }]
28
   }
29
 }
30
 |#
31
 ;;; Code:
32
 (in-package :box/ignition)
33
 
34
 (define-constant +ignition-version+ "3.6.0-experimental" :test 'equal)
35
 (defvar *ignition-config*)
36
 
37
 (defconfig ignition-config (box-config) 
38
   ((version :initform +ignition-version+ :initarg :version)
39
    (config :initarg :config)
40
    (timeouts :initarg :timeouts)
41
    (security :initarg :security)
42
    (proxy :initarg :proxy)
43
    (storage :initarg :storage)
44
    (systemd :initarg :systemd)
45
    (passwd :initarg :passwd)
46
    (kernel-arguments :initarg :kernel-arguments)))
47
 
48
 (defmethod make-config ((self (eql :ignition)) &rest args)
49
   (apply 'make-instance 'ignition-config args))
50
 
51
 (defmethod deserialize (self (fmt (eql :ignition)) &key)
52
   (let* ((json (deserialize self :json))
53
          (ignition (json-getf json "ignition"))
54
          (passwd (json-getf json "passwd"))
55
          (storage (json-getf json "storage"))
56
          (systemd (json-getf json "systemd")))
57
     (make-config :ignition 
58
                  :version (json-getf ignition "version")
59
                  :config (json-getf ignition "config")
60
                  :security (json-getf ignition "security")
61
                  :proxy (json-getf ignition "proxy")
62
                  :timeouts (json-getf ignition "timeouts")
63
                  :passwd passwd
64
                  :storage storage
65
                  :systemd systemd)))
66
 
67
 (defmethod serialize ((self ignition-config) (fmt (eql :ignition)) &key stream)
68
   (serialize 
69
    (make-instance 'json-object
70
      :ast
71
      `(("version" ,(slot-value self 'version))
72
        ,@(when (slot-boundp* self 'passwd)
73
            `(("passwd" ,(slot-value self 'passwd))))
74
        ,@(when (slot-boundp* self 'storage)
75
            `(("storage" ,(slot-value self 'storage))))
76
        ,@(when (slot-boundp* self 'systemd)
77
            `(("systemd" ,(slot-value self 'systemd))))))
78
    :json
79
    :stream stream))
80
 
81
 (defconfig ignition-config-options () 
82
   ((merge)
83
    (replace)))
84
 
85
 (defconfig ignition-storage-config ()
86
   ((files)
87
    (directories)
88
    (links)
89
    (luks)
90
    (filesystems)
91
    (disks)))
92
 
93
 (defconfig ignition-timeouts-config ()
94
   ((http-response-headers)
95
    (http-total)))
96
 
97
 (defconfig ignition-security-config ()
98
   ((tls)))
99
 
100
 (defconfig ignition-proxy-config ()
101
   ((http-proxy)
102
    (https-proxy)
103
    (no-proxy)))
104
 
105
 (defstruct ignition-disk device wipe-table partitions)
106
 
107
 (defstruct ignition-partition label number size start)
108
 
109
 (defstruct ignition-raid devices level name)
110
 
111
 (defstruct ignition-filesystem device path format wipe-filesystem label)
112
 
113
 (defstruct ignition-file path mode contents)
114
 
115
 (defstruct ignition-file-contents source verification)
116
 
117
 (defconfig ignition-systemd-config () 
118
   ((units)))
119
 
120
 (defstruct ignition-systemd-unit
121
   name
122
   (enabled nil :type boolean)
123
   (mask nil :type boolean)
124
   dropins
125
   contents)
126
 
127
 (defstruct ignition-systemd-dropin name contents)
128
 
129
 (defconfig ignition-passwd-config () 
130
   ((users)
131
    (groups)))
132
 
133
 (defstruct ignition-user 
134
   name password-hash ssh-authorized-keys uid 
135
   gecos home-dir no-create-home primary-group
136
   groups no-user-group no-log-init shell
137
   should-exist system)
138
 
139
 (defstruct ignition-group
140
   name gid password-hash should-exist system)
141
 
142
 (defconfig ignition-kernel-arguments ()
143
   ((should-exist) (should-not-exist)))
144
 
145
 (defmethods build-ast
146
   (((self ignition-config) &key) (unwrap-object self)))