~xdavidwu/himitsu-docker

1064894d5b5f7c919f3c08250aec2f131d097a0d — xdavidwu 1 year, 9 months ago 370f87d
implement store
2 files changed, 24 insertions(+), 0 deletions(-)

M cmd/docker-credential-himitsu/main.ha
A cmd/docker-credential-himitsu/store.ha
M cmd/docker-credential-himitsu/main.ha => cmd/docker-credential-himitsu/main.ha +2 -0
@@ 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 =>

A cmd/docker-credential-himitsu/store.ha => cmd/docker-credential-himitsu/store.ha +22 -0
@@ 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)!;
};