Skip to content

Commit 526850c

Browse files
imobachgslslezak
andauthored
feat: add a new questions API (#2813)
This PR introduces a new questions API. It is build on a single resource `/questions` which lists all the registered questions. ```json [ { "id": 1, "text": "LUKS password", "class": "storage.luks", "field": { "type": "string" }, "actions": [ { "id": "accept", "label": "Accept" }, { "id": "skip", "label": "Skip" } ], "defaultAction": "skip" } ] ``` ## The new model According to this new API, each question is composed by: * `text`: the text for the question. * `class`: it works as a hint for the UI or to match pre-defined answers (e.g., "autoyast.unsupported"). * `field`: optionally, a question might define an additional field (e.g., a password, a selector, etc.). * `actions`: list of available actions (e.g., "next", "skip", etc.). * `defaultAction`: default action. ## Registering a question A new question is registered through a `POST` request to the `/questions` API. The payload describes the question. ```json { "text": "LUKS password", "class": "storage.luks", "field": { "type": "string" }, "actions": [ { "id": "accept", "label": "Accept" }, { "id": "skip", "label": "Skip" } ], "defaultAction": "skip" } ``` ## Answering a question A question is answered by sending a `PATCH` on the connection with the following payload. ```json { "id": 1, "action": "accept", "value": "my-password" } ``` ## Automatic answers As in the previous API, it is possible to set up the questions service to automatically response some questions. ```json { "update": { "questions": { "policy": "auto", "answers": [ { "class": "storage.luks", "action": "ok", "value": "secret" } ] } } } ``` ## Field types The field types allow to grow this API to cover more use cases in the future, like software conflicts. At this time, it supports: * `none`: when no additional data is needed (most of the cases). * `string`: currently unused. * `password`: for LUKS. * `selection`: unused but planed for software conflicts (although it might need some improvements). --------- Co-authored-by: Ladislav Slezák <[email protected]>
1 parent 29a8685 commit 526850c

File tree

135 files changed

+1936
-3327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+1936
-3327
lines changed

doc/dbus/bus/org.opensuse.Agama1.Questions.Generic.bus.xml

Lines changed: 0 additions & 48 deletions
This file was deleted.

doc/dbus/bus/org.opensuse.Agama1.Questions.WithPassword.bus.xml

Lines changed: 0 additions & 51 deletions
This file was deleted.

doc/dbus/bus/org.opensuse.Agama1.Questions.bus.xml

Lines changed: 0 additions & 99 deletions
This file was deleted.

doc/dbus/bus/seed.sh

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/bin/bash
22
abusctl() {
3-
busctl --address=unix:path=/run/agama/bus "$@"
3+
busctl --address=unix:path=/run/agama/bus "$@"
44
}
55

66
# a stdio filter for XML introspection,
77
# to fix some less clever choices made by zbus:
88
# - remove detailed introspection of _child_ nodes
99
# - make interfaces order deterministic by sorting them
1010
cleanup() {
11-
# also remove the DTD declaration
12-
# otherwise xmlstarlet will complain about it not being available
13-
sed -e '/^<!DOCTYPE/d' -e '/http.*introspect.dtd/d' \
14-
| xmlstarlet tr cleanup-zbus.xslt \
15-
| xmllint --nonet --format -
11+
# also remove the DTD declaration
12+
# otherwise xmlstarlet will complain about it not being available
13+
sed -e '/^<!DOCTYPE/d' -e '/http.*introspect.dtd/d' |
14+
xmlstarlet tr cleanup-zbus.xslt |
15+
xmllint --nonet --format -
1616
}
1717

1818
# "dot dot name"
@@ -21,47 +21,19 @@ DD=org.opensuse.Agama
2121
SS=/${DD//./\/}
2222

2323
look() {
24-
abusctl tree --list $DD.${1%.*}
25-
abusctl introspect --xml-interface $DD.${1%.*} $SS/${1//./\/} \
26-
| cleanup \
27-
> $DD.$1.bus.xml
24+
abusctl tree --list $DD.${1%.*}
25+
abusctl introspect --xml-interface $DD.${1%.*} $SS/${1//./\/} |
26+
cleanup \
27+
>$DD.$1.bus.xml
2828
}
2929

3030
look Manager1
3131
look Software1
3232
look Software1.Proposal
3333
look Storage1
3434

35-
abusctl introspect --xml-interface \
36-
${DD}1 \
37-
${SS}1/Questions \
38-
| cleanup \
39-
> ${DD}1.Questions.bus.xml
40-
41-
abusctl call \
42-
${DD}1 \
43-
${SS}1/Questions \
44-
${DD}1.Questions \
45-
New "ssassa{ss}" "org.bands.Clash" "should I stay or should I go" 2 yes no yes 0
46-
abusctl introspect --xml-interface \
47-
${DD}1 \
48-
${SS}1/Questions/0 |
49-
cleanup \
50-
>${DD}1.Questions.Generic.bus.xml
51-
52-
abusctl call \
53-
${DD}1 \
54-
${SS}1/Questions \
55-
${DD}1.Questions \
56-
NewWithPassword "ssassa{ss}" "world.MiddleEarth.Moria.gate1" "Speak friend and enter" 2 enter giveup giveup 0
57-
abusctl introspect --xml-interface \
58-
${DD}1 \
59-
${SS}1/Questions/1 |
60-
cleanup \
61-
>${DD}1.Questions.WithPassword.bus.xml
62-
6335
abusctl introspect --xml-interface \
6436
${DD}.Manager1 \
65-
${SS}/Users1 \
66-
| cleanup \
67-
>${DD}.Users1.bus.xml
37+
${SS}/Users1 |
38+
cleanup \
39+
>${DD}.Users1.bus.xml

doc/dbus/org.opensuse.Agama1.Questions.Generic.doc.xml

Lines changed: 0 additions & 51 deletions
This file was deleted.

doc/dbus/org.opensuse.Agama1.Questions.WithPassword.doc.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)