From 1064894d5b5f7c919f3c08250aec2f131d097a0d Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 15 Aug 2022 23:00:35 +0800 Subject: [PATCH] implement store --- cmd/docker-credential-himitsu/main.ha | 2 ++ cmd/docker-credential-himitsu/store.ha | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 cmd/docker-credential-himitsu/store.ha diff --git a/cmd/docker-credential-himitsu/main.ha b/cmd/docker-credential-himitsu/main.ha index ebdc740..96a15c8 100644 --- a/cmd/docker-credential-himitsu/main.ha +++ b/cmd/docker-credential-himitsu/main.ha @@ -3,6 +3,8 @@ use os; export fn main() void = { assert(len(os::args) == 2); switch (os::args[1]) { + case "store" => + store(); case "list" => list(); case => diff --git a/cmd/docker-credential-himitsu/store.ha b/cmd/docker-credential-himitsu/store.ha new file mode 100644 index 0000000..2994f52 --- /dev/null +++ b/cmd/docker-credential-himitsu/store.ha @@ -0,0 +1,22 @@ +use encoding::json; +use himitsu::client; +use himitsu::query; +use os; + +fn store() void = { + const hi = client::connect()!; + const json = json::load(os::stdin)! as json::object; + defer json::finish(json); + const url = *(json::get(&json, "ServerURL") as *json::value) as str; + const username = *(json::get(&json, "Username") as *json::value) as str; + const secret = *(json::get(&json, "Secret") as *json::value) as str; + const query = query::query { + items = [ + query::pair { key = "proto", value = "docker", private = false, optional = false}, + query::pair { key = "host", value = url, private = false, optional = false}, + query::pair { key = "username", value = username, private = false, optional = false}, + query::pair { key = "secret", value = secret, private = true, optional = false}, + ], + }; + client::query(hi, client::operation::ADD, &query, 0)!; +}; -- 2.45.2