summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-05-15 02:12:12 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-05-15 02:12:12 -0500
commit5ae043001202cd064334c3c826ba3c4f656699ec (patch)
treef48c9e875518267243465b73ae67c8e4b5102f71
parentc99eb3f4236ee23fecf7bdff83296b47b6df43ec (diff)
downloadhorizon-5ae043001202cd064334c3c826ba3c4f656699ec.tar.gz
horizon-5ae043001202cd064334c3c826ba3c4f656699ec.tar.bz2
horizon-5ae043001202cd064334c3c826ba3c4f656699ec.tar.xz
horizon-5ae043001202cd064334c3c826ba3c4f656699ec.zip
JSON: Handle user account creation
-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;
}