Remove: deprecated idm_validate, idm_get and idm_is_enabled

This commit is contained in:
mrjk 2018-02-27 00:12:40 -05:00
parent 47da7fb7e0
commit 3f448882a9
7 changed files with 129 additions and 120 deletions

193
bin/idmgr
View File

@ -112,7 +112,7 @@ idm_core__enable ()
#set -x
# Local checks
#idm_validate id $id || idm_exit 1 ERR "You must provide an id"
#lib_id_is_valid_syntax $id || idm_exit 1 ERR "You must provide an id"
lib_id_has_config $id || idm_exit 1 ERR "Configuration '$id' does not exists"
# Check if workspace is enabled
@ -140,8 +140,7 @@ idm_core__enable ()
idm_core__disable ()
{
local id=${1}
#idm_is_enabled $id
idm_validate is_enabled $id
lib_id_is_enabled $id
# Reverse module unloading
IDM_MOD_ORDER="$( lib_reverse_doted_list $IDM_MOD_ORDER )"
@ -154,7 +153,7 @@ idm_core__disable ()
idm_core__kill ()
{
local id=${1}
idm_is_enabled $id
lib_id_is_enabled $id
# Reverse module killing
IDM_MOD_ORDER="$( lib_reverse_doted_list $IDM_MOD_ORDER )"
@ -215,7 +214,7 @@ idm_core__sourced_words()
local words=
# When we are asking to output source words
words="enable disable kill shell quit q $(idm_get all_id | xargs)"
words="enable disable kill shell quit q $(lib_id_get_all_id | xargs)"
echo ":${words// /:}:"
@ -396,97 +395,105 @@ idm_exit_trap () {
# DEPRECATRED, replaced by lib_id
# Should be replaced by idm_validate ?
# Is a wrapper for enduser !!!
idm_is_enabled ()
{
lib_log DEPRECATED "call: idm_is enabled $@, use lib_id_is_enabled ${1-} instead"
lib_trace
local id=${1}
idm_validate is_enabled $id
{
lib_log WARN "You need to activate an id first"
return 1
}
}
# idm_is_enabled ()
# {
# lib_log DEPRECATED "call: idm_is enabled $@, use lib_id_is_enabled ${1-} instead"
# lib_trace
# local id=${1}
# idm_validate is_enabled $id
# {
# lib_log WARN "You need to activate an id first"
# return 1
# }
# }
# DEPRECATRED, replaced by lib_id
idm_get ()
{
lib_log DEPRECATED "call: idm_get $@, use lib_id_has_config instead"
lib_trace
local item=$1
local value=${2-}
# # DEPRECATRED, replaced by lib_id
# idm_get ()
# {
# lib_log DEPRECATED "call: idm_get $@, use lib_id_has_config instead"
# lib_trace
# local item=$1
# local value=${2-}
#
# case $item in
# all_id)
# # idm_get all_id
# # => lib_id_get_all_id
# for id in $( find $IDM_DIR_ID -type f -name '*.env' 2>/dev/null ); do
# id=${id%%\.env}
# echo "${id##*/}"
# done
# ;;
#
# all_id_files)
# # => lib_id_get_all_file
# ls $IDM_DIR_ID/*.env || true
# ;;
#
# id_config)
# # => lib_id_get_config
# if [ -f "$IDM_DIR_ID/$value.env" ]; then
# echo "id=$value"
# cat $IDM_DIR_ID/$value.env
# else
# return 1
# fi
# ;;
#
# *)
# lib_log ERR "Cannot get item '$item'"
# ;;
# esac
# }
case $item in
all_id)
for id in $( find $IDM_DIR_ID -type f -name '*.env' 2>/dev/null ); do
id=${id%%\.env}
echo "${id##*/}"
done
;;
all_id_files)
ls $IDM_DIR_ID/*.env || true
;;
id_config)
if [ -f "$IDM_DIR_ID/$value.env" ]; then
echo "id=$value"
cat $IDM_DIR_ID/$value.env
else
return 1
fi
;;
*)
lib_log ERR "Cannot get item '$item'"
;;
esac
}
# DEPRECATRED, replaced by lib_id
idm_validate ()
{
lib_log DEPRECATED "call: idm_validate $@"
local type=$1
local value=${2-}
case $type in
id_filter|id)
[ "$value" != '_' ] && \
[[ "$value" =~ ^[a-zA-Z0-9_-]+$ ]] && return $?
;;
id_config)
if [[ -f "$IDM_DIR_ID/$value.env" ]]; then
return 0
fi
;;
is_enabled)
if [[ -z "${value-}" && "${value-}" != '_' ]]; then
if [ -z "${SHELL_ID-}" ] ; then
return 1
else
return 0
fi
else
if [ "${value-}" == "${SHELL_ID-}" ]; then
return 0
else
return 1
fi
fi
;;
is_disabled)
[ -z "${SHELL_ID-}" ] && return $?
;;
*)
lib_log ERR "Cannot validate type '$type'"
;;
esac
return 1
}
# # DEPRECATRED, replaced by lib_id
# idm_validate ()
# {
# #lib_log DEPRECATED "call: idm_validate $@, sed with: lib_id_has_config or equivalent"
# local type=$1
# local value=${2-}
#
# case $type in
# id_filter|id)
# lib_log DEPRECATED "call: idm_validate id_filter $@, sed with: lib_id_is_valid_syntax \$id"
# [ "$value" != '_' ] && \
# [[ "$value" =~ ^[a-zA-Z0-9_-]+$ ]] && return $?
# ;;
# id_config)
# lib_log DEPRECATED "call: idm_validate id_config $@, sed with: lib_id_has_config \$id"
# if [[ -f "$IDM_DIR_ID/$value.env" ]]; then
# return 0
# fi
# ;;
# is_enabled)
# lib_log DEPRECATED "call: idm_validate is_enabled $@, sed with: lib_id_is_enabled \$id"
# if [[ -z "${value-}" && "${value-}" != '_' ]]; then
# if [ -z "${SHELL_ID-}" ] ; then
# return 1
# else
# return 0
# fi
# else
# if [ "${value-}" == "${SHELL_ID-}" ]; then
# return 0
# else
# return 1
# fi
# fi
# ;;
# is_disabled)
# lib_log DEPRECATED "call: idm_validate is_disabled $@, sed with: ! lib_id_is_enabled \$id"
# [ -z "${SHELL_ID-}" ] && return $?
# ;;
#
# *)
# lib_log ERR "Cannot validate type '$type'"
# ;;
# esac
#
# return 1
# }
## User interface

View File

@ -19,7 +19,7 @@ idm_cloud__ls ()
{
local id=${1}
if idm_validate is_enabled $id; then
if lib_id_is_enabled $id; then
if [ -f "${OS_CLOUD-}" ]; then
echo " enabled ($OS_CLOUD)"
else

View File

@ -170,8 +170,9 @@ idm_git__enable ()
idm_git_header $id
cat <<EOF -
export GIT_DIR="$git_local_dir"
export GIT_WORK_TREE="$git_local_work_tree"
echo "INFO: Run this if your want to enable native git"
echo export GIT_DIR="$git_id_dir"
echo export GIT_WORK_TREE="$git_id_work_tree"
EOF
}

View File

@ -14,7 +14,7 @@ idm_gpg__help ()
idm_gpg__enable ()
{
local id=${1}
idm_validate id_config $id
lib_id_has_config $id
# Source environment
if [ -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env" ]; then
@ -42,14 +42,14 @@ idm_gpg__enable ()
idm_gpg__disable ()
{
local id=${1}
idm_validate id_config $id
lib_id_has_config $id
echo "unset GPG_AGENT_INFO GNUPGHOME GPG_TTY"
}
idm_gpg__kill ()
{
local id=${1}
idm_is_enabled $id
lib_id_is_enabled $id
gpgconf --kill gpg-agent
lib_log NOTICE "Kill gpg-agent ..."
@ -64,7 +64,7 @@ idm_gpg__kill ()
idm_gpg__ls ()
{
local id=${1}
idm_validate is_enabled $id || return 0
lib_id_is_enabled $id || return 0
gpg --list-keys | sed 's/^/ /' #| lib_log DUMP -
}
@ -72,7 +72,7 @@ idm_gpg__ls ()
idm_gpg__new ()
{
local id=${1}
idm_is_enabled $id
lib_id_is_enabled $id
key="$( idm_gpg_match_one_pubkey $id )"
idm_gpg_cli_helper $id sub
@ -85,7 +85,7 @@ idm_gpg__new ()
idm_gpg__init ()
{
local id=${1}
idm_is_enabled $id
lib_id_is_enabled $id
! idm_gpg_match_one_pubkey $id &>/dev/null || \
idm_exit 1 "You already have an id !"

View File

@ -70,8 +70,8 @@ idm_id__new ()
local id=${2:-$1}
# Local checks
idm_validate id $id || idm_exit 1 "Id '$id' is not valid"
idm_validate id_config $id && idm_exit 1 "Configuration '$id' already exists"
lib_id_is_valid_syntax $id || idm_exit 1 "Id '$id' is not valid"
lib_id_has_config $id && idm_exit 1 "Configuration '$id' already exists"
# Create new id
conf="$IDM_DIR_ID/$id.env"
@ -92,14 +92,14 @@ idm_id__show ()
local conf
# Local checks
idm_validate id_config $id || idm_exit 1 ERR "Configuration '$id' does not exists"
lib_id_has_config $id || idm_exit 1 ERR "Configuration '$id' does not exists"
# Edit id
conf="$IDM_DIR_ID/$id.env"
# Notice user
lib_log INFO "Id '$id' configuration:"
idm_get id_config $id | lib_log CODE -
lib_id_has_config $id | lib_log CODE -
# cat $conf | lib_log CODE
}
@ -136,7 +136,7 @@ idm_id__edit ()
local md5 conf
# Local checks
idm_validate id_config $id || idm_exit 1 ERR "Configuration '$id' does not exists"
lib_id_has_config $id || idm_exit 1 ERR "Configuration '$id' does not exists"
# Edit id
conf="$IDM_DIR_ID/$id.env"
@ -174,7 +174,7 @@ idm_id__dump ()
for id in $(idm_get all_id); do
#lib_log NOTICE "Identity $id"
{
idm_get id_config $id
lib_id_has_config $id
echo " "
} | lib_log CODE -
done
@ -198,8 +198,8 @@ idm_id__rm ()
local id=${1}
# Local checks
idm_validate id $id || idm_exit 1 ERR "Id '$id' is not valid"
#idm_validate id_config $id && idm_exit 1 "Configuration '$id' already exists"
lib_id_is_valid_syntax $id || idm_exit 1 ERR "Id '$id' is not valid"
#lib_id_has_config $id && idm_exit 1 "Configuration '$id' already exists"
# Delete config

View File

@ -23,7 +23,7 @@ idm_pass ()
# Interncal override case
# Fallback to command
idm_is_enabled $id
lib_id_is_enabled $id
PASSWORD_STORE_DIR=~/.config/pass/${id} pass $action ${@-}
}
@ -31,7 +31,7 @@ idm_pass ()
idm_pass__ls ()
{
local id=${1}
idm_validate is_enabled $id || return 0
lib_id_is_enabled $id || return 0
PASSWORD_STORE_DIR=~/.config/pass/${id} pass ls | sed 's/^/ /'
}
@ -52,7 +52,7 @@ idm_pass__help ()
idm_pass__enable ()
{
local id=${1}
! idm_validate id_config $id
! lib_id_has_config $id
echo "export PASSWORD_STORE_DIR=~/.config/pass/${id}"
}
@ -61,7 +61,7 @@ idm_pass__enable ()
idm_pass__disable ()
{
local id=${1}
idm_validate id_config $id
lib_id_has_config $id
echo "unset PASSWORD_STORE_DIR"
}

View File

@ -56,7 +56,7 @@ idm_ssh__ls ()
local opt=${2:--l}
local opt=-l
idm_validate is_enabled $id || return 0
lib_id_is_enabled $id || return 0
{ ssh-add $opt || true ; } | sed 's/^/ /'
}
@ -64,8 +64,8 @@ idm_ssh__ls ()
idm_ssh__disable ()
{
local id=$1
#idm_is_enabled $id
idm_validate id_config $id
#lib_id_is_enabled $id
lib_id_has_config $id
# Return portion of code to clean
echo "unset SSH_AUTH_SOCK SSH_AGENT_PID"
@ -75,7 +75,7 @@ idm_ssh__disable ()
idm_ssh__enable ()
{
local id=$1
idm_validate id_config $id
lib_id_has_config $id
# Source environment
if [ -f "${XDG_RUNTIME_DIR}/ssh-agent/${id}/env" ] ; then
@ -104,7 +104,7 @@ idm_ssh__kill () {
local id=$1
local run_dir="${XDG_RUNTIME_DIR}/ssh-agent/${id}"
idm_is_enabled $id
lib_id_is_enabled $id
#lib_log NOTICE "Cleaning ssh-agent ..."
@ -220,7 +220,8 @@ idm_ssh_add ()
local key=${2-}
local maxdepth=1
idm_is_enabled $id
#lib_id_is_enabled $id
lib_id_is_enabled $id
if [[ ! -z $key ]]; then