From 6f2f2769a24db15b692f10edaf9b132be9e6cccd Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Wed, 20 Jan 2021 11:57:44 +0100 Subject: [PATCH] Add keyring credential helper for git --- bin/git-credential-keyring | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 bin/git-credential-keyring diff --git a/bin/git-credential-keyring b/bin/git-credential-keyring new file mode 100755 index 0000000..02a50d7 --- /dev/null +++ b/bin/git-credential-keyring @@ -0,0 +1,34 @@ +#!/usr/bin/env lua + +-- usage: secret-tool store --label='label' attribute value ... +-- secret-tool lookup attribute value ... +-- secret-tool clear attribute value ... +-- secret-tool search [--all] [--unlock] attribute value ... + +local action = ... + +local options = {} +for line in io.stdin:lines() do + local key, value = line:match("^(.*)=(.*)$") + options[key]=value +end + +if action == "get" then + local command = string.format('secret-tool lookup application git username %s host %s', options.username, options.host, options.username, options.host) + local file = io.popen(command, "r") + local password = file:read("all") + if password~="" then + print("password="..password) + else + os.exit(1, true) + end + file:close() +elseif action == "store" then + local command = string.format('secret-tool store --label="git %s@%s" application git username %s host %s', options.username, options.host, options.username, options.host) + local file = io.popen(command, "w") + file:write(options.password) + file:close() +elseif action == "erase" then + local command = string.format('secret-tool clear application git username %s host %s', options.username, options.host, options.username, options.host) + os.execute(command) +end