From ba40364d3e79c94aceb6681c8c2b121546314102 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 15 Aug 2022 23:44:35 +0800 Subject: [PATCH] get: return json even if nothing is found fixes compatibility with podman --- cmd/docker-credential-himitsu/get.ha | 36 +++++++++++++++------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/cmd/docker-credential-himitsu/get.ha b/cmd/docker-credential-himitsu/get.ha index 624959d..e20f952 100644 --- a/cmd/docker-credential-himitsu/get.ha +++ b/cmd/docker-credential-himitsu/get.ha @@ -1,5 +1,6 @@ use bufio; use encoding::json; +use fmt; use himitsu::client; use himitsu::query; use os; @@ -20,26 +21,27 @@ fn get() void = { const iter = client::query(hi, client::operation::QUERY, &query, client::flags::DECRYPT)!; const json = json::newobject(); defer json::finish(json); - const res = match (client::next(&iter)!) { + json::set(&json, "SeverURL", url); + json::set(&json, "Username", ""); + json::set(&json, "Secret", ""); + match (client::next(&iter)!) { case void => - return; + yield; 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 secreti = 0z, usernamei = 0z; - for (let i = 0z; i < len(query.items); i += 1) { - if (strings::compare(query.items[i].key, "secret") == 0) { - secreti = i; - } else if (strings::compare(query.items[i].key, "username") == 0) { - usernamei = i; + const parts = shlex::split(s)!; + defer strings::freeall(parts); + const query = query::parse_items(parts)!; + defer query::finish(&query); + let secreti = 0z, usernamei = 0z; + for (let i = 0z; i < len(query.items); i += 1) { + if (strings::compare(query.items[i].key, "secret") == 0) { + secreti = i; + } else if (strings::compare(query.items[i].key, "username") == 0) { + usernamei = i; + }; }; + json::set(&json, "Username", query.items[usernamei].value); + json::set(&json, "Secret", query.items[secreti].value); }; - json::set(&json, "SeverURL", url); - json::set(&json, "Username", query.items[usernamei].value); - json::set(&json, "Secret", query.items[secreti].value); json::dump(os::stdout, json)!; }; -- 2.45.2