credentials: handle all cases with one function
This commit is contained in:
parent
c0f051acd7
commit
83d15c417d
@ -50,24 +50,35 @@ get_2fa()
|
|||||||
sekrit get "services/$1/2fa" | otpcli $otpcli_opts | clip && printf "\n"
|
sekrit get "services/$1/2fa" | otpcli $otpcli_opts | clip && printf "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_from_flags()
|
get_service()
|
||||||
{
|
{
|
||||||
service=$1
|
service=$1
|
||||||
user=$2
|
user=$2
|
||||||
pass=$3
|
pass=$3
|
||||||
sfa=$4
|
sfa=$4
|
||||||
|
|
||||||
if [ $user = yes ]; then
|
if [ $user = no ] && [ $pass = no ] && [ $sfa = no ]; then
|
||||||
|
sekrit has "services/$service/pass" ||
|
||||||
|
err "Unknown service \"$service\"."
|
||||||
|
pass=yes
|
||||||
|
sekrit has services/"$service"/user && user=yes
|
||||||
|
sekrit has services/"$service"/2fa && sfa=yes
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $user = check ]; then
|
||||||
sekrit has services/"$service"/user ||
|
sekrit has services/"$service"/user ||
|
||||||
err "Service \"$service\" has no user."
|
err "Service \"$service\" has no user."
|
||||||
|
user=yes
|
||||||
fi
|
fi
|
||||||
if [ $pass = yes ]; then
|
if [ $pass = check ]; then
|
||||||
sekrit has services/"$service"/pass ||
|
sekrit has services/"$service"/pass ||
|
||||||
err "Service \"$service\" has no pass."
|
err "Service \"$service\" has no pass."
|
||||||
|
pass=yes
|
||||||
fi
|
fi
|
||||||
if [ $sfa = yes ]; then
|
if [ $sfa = check ]; then
|
||||||
sekrit has services/"$service"/2fa ||
|
sekrit has services/"$service"/2fa ||
|
||||||
err "Service \"$service\" has no 2fa."
|
err "Service \"$service\" has no 2fa."
|
||||||
|
sfa=yes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ $user = yes ] && get_user "$service"
|
[ $user = yes ] && get_user "$service"
|
||||||
@ -75,27 +86,16 @@ get_from_flags()
|
|||||||
[ $sfa = yes ] && get_2fa "$service"
|
[ $sfa = yes ] && get_2fa "$service"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_all()
|
|
||||||
{
|
|
||||||
service=$1
|
|
||||||
sekrit has "services/$service/pass" ||
|
|
||||||
err "Unknown service \"$service\"."
|
|
||||||
|
|
||||||
sekrit has "services/$service/user" && get_user "$service"
|
|
||||||
get_pass "$service"
|
|
||||||
sekrit has "services/$service/2fa" && get_2fa "$service"
|
|
||||||
}
|
|
||||||
|
|
||||||
sfa=no
|
sfa=no
|
||||||
pass=no
|
pass=no
|
||||||
user=no
|
user=no
|
||||||
while getopts 2pu flag; do
|
while getopts 2pu flag; do
|
||||||
case $flag in
|
case $flag in
|
||||||
2) sfa=yes
|
2) sfa=check
|
||||||
;;
|
;;
|
||||||
p) pass=yes
|
p) pass=check
|
||||||
;;
|
;;
|
||||||
u) user=yes
|
u) user=check
|
||||||
;;
|
;;
|
||||||
*) usage
|
*) usage
|
||||||
;;
|
;;
|
||||||
@ -104,10 +104,6 @@ done
|
|||||||
shift $(($OPTIND - 1))
|
shift $(($OPTIND - 1))
|
||||||
|
|
||||||
[ $# -eq 1 ] && [ -n "$1" ] || usage
|
[ $# -eq 1 ] && [ -n "$1" ] || usage
|
||||||
service=$1
|
key=$1
|
||||||
|
|
||||||
if [ $sfa = yes ] || [ $pass = yes ] || [ $user = yes ]; then
|
get_service "$key" $user $pass $sfa
|
||||||
get_from_flags "$service" $user $pass $sfa
|
|
||||||
else
|
|
||||||
get_all "$service"
|
|
||||||
fi
|
|
||||||
|
Loading…
Reference in New Issue
Block a user