Validate some kstore args
This commit is contained in:
parent
f6d744fda5
commit
da241a1027
@ -36,7 +36,7 @@ function kstore {
|
||||
__func_head "add [key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
__func_help "update [key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
__func_help "get [key] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
__func_help "del [key]"
|
||||
__func_help "del [key] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
__func_help "list"
|
||||
__func_help "search [key] [prop]"
|
||||
__func_help "secret ..."
|
||||
@ -230,6 +230,10 @@ function kstore-secret-clear {
|
||||
}
|
||||
|
||||
function kstore-update {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "[key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
return 1
|
||||
fi
|
||||
kstore-init || return 1
|
||||
local _key _val _prop
|
||||
_key=`kstore-quote "$1"`
|
||||
@ -241,34 +245,46 @@ function kstore-update {
|
||||
}
|
||||
|
||||
function kstore-add {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "[key] [value|file|-] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
return 1
|
||||
fi
|
||||
kstore-init || return 1
|
||||
local _key _val _prop
|
||||
_key=`kstore-quote "$1"`
|
||||
_val=`kstore-enc "$2"`
|
||||
_val=`kstore-quote "$_val"`
|
||||
_prop=`kstore-quote "${3:-$_KSTORE_DEF_PROP}"`
|
||||
sqlite3 "$_AUTH_DB" \
|
||||
$_SQLITE "$_AUTH_DB" \
|
||||
"INSERT INTO store ( key, prop, data )
|
||||
VALUES( '$_key', '$_prop', '$_val' );"
|
||||
}
|
||||
|
||||
function kstore-get {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "[key] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
return 1
|
||||
fi
|
||||
kstore-init || return 1
|
||||
local _key _prop _cond
|
||||
_key=`kstore-quote "$1"`
|
||||
_prop=`kstore-quote "${2:-$_KSTORE_DEF_PROP}"`
|
||||
_cond="key = '$_key' AND prop = '$_prop'"
|
||||
|
||||
sqlite3 "$_AUTH_DB" "SELECT 1111 FROM store WHERE $_cond;" | grep -q 1111
|
||||
$_SQLITE "$_AUTH_DB" "SELECT 1111 FROM store WHERE $_cond;" | grep -q 1111
|
||||
if [ $? -eq 0 ]; then
|
||||
$_SQLITE -list "$_AUTH_DB" "SELECT ( data ) FROM store WHERE $_cond;" | kstore-dec
|
||||
else
|
||||
echo "\"$1\" not found" >&2
|
||||
echo "\"$1\" not found (prop: $_prop)" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function kstore-del {
|
||||
if [ -z "$1" ]; then
|
||||
__func_head "[key] [prop, default: $_KSTORE_DEF_PROP]"
|
||||
return 1
|
||||
fi
|
||||
kstore-init || return 1
|
||||
|
||||
local _CONFIRM _key _prop _cond
|
||||
@ -276,13 +292,13 @@ function kstore-del {
|
||||
_prop=`kstore-quote "${2:-$_KSTORE_DEF_PROP}"`
|
||||
_cond="key = '$_key' AND prop = '$_prop'"
|
||||
|
||||
sqlite3 "$_AUTH_DB" "SELECT 1111 FROM store WHERE $_cond;" | grep -q 1111
|
||||
$_SQLITE "$_AUTH_DB" "SELECT 1111 FROM store WHERE $_cond;" | grep -q 1111
|
||||
if [ $? -eq 0 ]; then
|
||||
sqlite3 "$_AUTH_DB" "SELECT * FROM store WHERE $_cond;"
|
||||
$_SQLITE "$_AUTH_DB" "SELECT * FROM store WHERE $_cond;"
|
||||
echo
|
||||
read -p "Delete this entry (yes/no)? " _CONFIRM
|
||||
if [ "$_CONFIRM" == "yes" ]; then
|
||||
sqlite3 "$_AUTH_DB" "DELETE FROM store WHERE $_cond;"
|
||||
$_SQLITE "$_AUTH_DB" "DELETE FROM store WHERE $_cond;"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "deleted"
|
||||
fi
|
||||
@ -290,7 +306,7 @@ function kstore-del {
|
||||
echo "action canceled"
|
||||
fi
|
||||
else
|
||||
echo "\"$1\" not found" >&2
|
||||
echo "\"$1\" not found (prop: $_prop)" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user