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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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