From 370f87db08975d9e1d17e10be83991fe6a1b9f7a Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 15 Aug 2022 21:25:35 +0800 Subject: [PATCH] initial commit --- .gitignore | 1 + .gitmodules | 3 ++ Makefile | 3 ++ cmd/docker-credential-himitsu/list.ha | 43 +++++++++++++++++++++++++++ cmd/docker-credential-himitsu/main.ha | 11 +++++++ vendor/himitsu | 1 + 6 files changed, 62 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 Makefile create mode 100644 cmd/docker-credential-himitsu/list.ha create mode 100644 cmd/docker-credential-himitsu/main.ha create mode 160000 vendor/himitsu diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee4b2b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/docker-credential-himitsu diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9267e50 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/himitsu"] + path = vendor/himitsu + url = https://git.sr.ht/~sircmpwn/himitsu diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eba152c --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +docker-credential-himitsu: + HAREPATH=vendor/himitsu:${HAREPATH} hare build cmd/docker-credential-himitsu +.PHONY: docker-credential-himitsu diff --git a/cmd/docker-credential-himitsu/list.ha b/cmd/docker-credential-himitsu/list.ha new file mode 100644 index 0000000..6dc1a8b --- /dev/null +++ b/cmd/docker-credential-himitsu/list.ha @@ -0,0 +1,43 @@ +use encoding::json; +use himitsu::client; +use himitsu::query; +use os; +use shlex; +use strings; + +fn list() void = { + const hi = client::connect()!; + const query = query::query { + items = [ + query::pair { key = "proto", value = "docker", private = false, optional = false}, + query::pair { key = "host", value = "", private = false, optional = false}, + query::pair { key = "username", value = "", private = false, optional = false}, + query::pair { key = "secret", value = "", private = true, optional = false}, + ], + }; + const iter = client::query(hi, client::operation::QUERY, &query, 0)!; + const json = json::newobject(); + defer json::finish(json); + for (true) { + const res = match (client::next(&iter)!) { + case void => + break; + case let s: const str => + yield s; + }; + const parts = shlex::split(res)!; + defer strings::freeall(parts); + const query = query::parse_items(parts)!; + defer query::finish(&query); + let hosti = 0z, usernamei = 0z; + for (let i = 0z; i < len(query.items); i += 1) { + if (strings::compare(query.items[i].key, "host") == 0) { + hosti = i; + } else if (strings::compare(query.items[i].key, "username") == 0) { + usernamei = i; + }; + }; + json::set(&json, query.items[hosti].value, query.items[usernamei].value); + }; + json::dump(os::stdout, json)!; +}; diff --git a/cmd/docker-credential-himitsu/main.ha b/cmd/docker-credential-himitsu/main.ha new file mode 100644 index 0000000..ebdc740 --- /dev/null +++ b/cmd/docker-credential-himitsu/main.ha @@ -0,0 +1,11 @@ +use os; + +export fn main() void = { + assert(len(os::args) == 2); + switch (os::args[1]) { + case "list" => + list(); + case => + assert(false); + }; +}; diff --git a/vendor/himitsu b/vendor/himitsu new file mode 160000 index 0000000..c7d4942 --- /dev/null +++ b/vendor/himitsu @@ -0,0 +1 @@ +Subproject commit c7d49426e712889c04f00e37467dd98ecbf6569a -- 2.45.2