summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/fixtures/json/0006-user.json18
-rw-r--r--tools/hscript-fromjson/jsonconv.cc25
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/fixtures/json/0006-user.json b/tests/fixtures/json/0006-user.json
new file mode 100644
index 0000000..0f04d3d
--- /dev/null
+++ b/tests/fixtures/json/0006-user.json
@@ -0,0 +1,18 @@
+{
+ "hostname": "horizon-json-testmachine.adelielinux.org",
+ "packages": ["adelie-base-posix", "easy-kernel", "easy-kernel-modules", "netifrc", "openrc", "s6-linux-init"],
+ "rootpw": "$6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/",
+ "root": "/dev/sda1",
+ "netaddresses": [{"id":"eth0", "interface":"eth0", "addr-type": "dhcp"}],
+ "nameservers": ["9.9.9.9"],
+ "timezone": "America/Chicago",
+ "repositories": ["https://distfiles.adelielinux.org/adelie/1.0/system", "https://distfiles.adelielinux.org/adelie/1.0/user"],
+ "signingkeys": ["/etc/apk/keys/powerpc-1@packages.adelielinux.org.pub", "/etc/apk/keys/powerpc-2@packages.adelielinux.org.pub"],
+ "users": [
+ {"username": "awilfox",
+ "passphrase": "$6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/",
+ "groups": "wheel,video,audio,disk"},
+ {"username": "elizafox",
+ "passphrase": "$6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/"}
+ ]
+}
diff --git a/tools/hscript-fromjson/jsonconv.cc b/tools/hscript-fromjson/jsonconv.cc
index 7791136..3a5c564 100644
--- a/tools/hscript-fromjson/jsonconv.cc
+++ b/tools/hscript-fromjson/jsonconv.cc
@@ -113,6 +113,31 @@ bool parse_one_desc(json desc, std::ostream &out) {
#undef SIMPLE_PLURAL_KEY
+ if(desc.find("users") != desc.end()) {
+ for(const auto &user : desc["users"]) {
+ if(user.find("username") == user.end()) {
+ output_error("input json",
+ "user account specified without username");
+ continue;
+ }
+
+ const auto &name = user["username"].get<std::string>();
+
+ out << "username " << name << std::endl;
+
+#define USER_KEY(key_name, hscript_name) \
+ if(user.find(key_name) != user.end()) {\
+ out << hscript_name << " " << name << " " \
+ << user[key_name].get<std::string>() << std::endl;\
+ }
+
+ USER_KEY("alias", "useralias");
+ USER_KEY("passphrase", "userpw");
+ USER_KEY("groups", "usergroups");
+ /* Future expansion: user icons */
+ }
+ }
+
return true;
}