From a885a2153f71b57b1678ecf522894815367e335f Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Mon, 5 Jun 2023 21:19:01 +0800 Subject: [PATCH] Revert "get: return json even if nothing is found" This reverts commit ba40364d3e79c94aceb6681c8c2b121546314102. let's try to fix it properly --- cmd/docker-credential-himitsu/get.ha | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/cmd/docker-credential-himitsu/get.ha b/cmd/docker-credential-himitsu/get.ha index 4a51f87..59fb4e1 100644 --- a/cmd/docker-credential-himitsu/get.ha +++ b/cmd/docker-credential-himitsu/get.ha @@ -20,27 +20,26 @@ fn get(hi: net::socket) void = { const iter = client::query(hi, client::operation::QUERY, &query, client::flags::DECRYPT)!; const json = json::newobject(); defer json::finish(json); - json::set(&json, "SeverURL", url); - json::set(&json, "Username", ""); - json::set(&json, "Secret", ""); - match (client::next(&iter)!) { + const res = match (client::next(&iter)!) { case void => - yield; + return; case let s: const str => - 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; - }; + 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; }; - 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