Skip to content

Latest commit

 

History

History

password-cache

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

password-cache

Cache credentials using the Linux keyring/MacOS security in Go

Library

Go Reference

Import:

import (
	passwordcache "github.com/DavidGamba/dgtools/password-cache"
)

Simplest use:

	data, err := passwordcache.GetAndCacheSecret("ActiveDirectoryPassword", "", uint(timeout))
	if err != nil {
		return err
	}
	fmt.Printf("%s", data)

CLI

Password cache also comes as a handy CLI that works for both Linux and MacOS. When called from bash, it will handle the user prompt.

#!/bin/bash

# Allow interactive operation
./password-cache mykey -t 60
if [[ $? == 0 ]]; then
	# Read from store
	password=$(./password-cache mykey -t 60 --print)
	# Use
	echo "|$password|"
fi

Then we call it the first time:

$ bash bash-script.sh
Enter 'mykey' password:
|password|

The second time around it just retrieves the key as expected:

$ bash bash-script.sh
|password|

CLI Install

  • Install using homebrew:

    brew tap DavidGamba/dgtools https://github.com/DavidGamba/dgtools
    brew install DavidGamba/dgtools/password-cache
    Note

    Completion is auto setup for bash.

    For zsh completions, an additional step is required, add the following to your .zshrc:

    export ZSHELL="true"
    source "$(brew --prefix)/share/zsh/site-functions/dgtools.password-cache.zsh"

    Upgrade with:

    brew update
    brew upgrade password-cache
  • Install using go:

    Install the binary into your ~/go/bin:

    go install github.com/DavidGamba/dgtools/password-cache@latest

    Then setup the completion.

    For bash:

    complete -o default -C password-cache password-cache

    For zsh:

    export ZSHELL="true"
    autoload -U +X compinit && compinit
    autoload -U +X bashcompinit && bashcompinit
    complete -o default -C password-cache password-cache