Allow to set --profile option at any position :

- functions to create keys now launched out of parseArguments()

bugfix :
- fix empty CURRENT_PATH when launching --init/--initApp

enhancements :
- better output for --list-profile output + add 'default' profile

refactoring :
- move initApplication() into createConsumerKey() instead of calling it each time
pull/4/head
Didier BONNEFOI 2017-06-21 00:21:47 +02:00
parent 485cbd833e
commit 143ad5114b
1 changed files with 28 additions and 8 deletions

View File

@ -31,7 +31,7 @@ TARGET="EU"
TIME="" TIME=""
SIGDATA="" SIGDATA=""
POST_DATA="" POST_DATA=""
PROFILE=""
isTargetValid() isTargetValid()
{ {
@ -82,7 +82,6 @@ createApp()
read NEXT read NEXT
if [ -n "$NEXT" ] && [ $( echo $NEXT | tr [:upper:] [:lower:] ) = y ] if [ -n "$NEXT" ] && [ $( echo $NEXT | tr [:upper:] [:lower:] ) = y ]
then then
initApplication
createConsumerKey createConsumerKey
else else
echo -e "OK, no consumer key created for now.\nYou will be able to initalize the consumer key later calling :\n${HELP_CMD} --init" echo -e "OK, no consumer key created for now.\nYou will be able to initalize the consumer key later calling :\n${HELP_CMD} --init"
@ -91,10 +90,12 @@ createApp()
createConsumerKey() createConsumerKey()
{ {
METHOD="POST" METHOD="POST"
URL="/auth/credential" URL="/auth/credential"
# ensure an OVH App key is set # ensure an OVH App key is set
initApplication
hasOvhAppKey || exit 1 hasOvhAppKey || exit 1
# all grants if no post data defined # all grants if no post data defined
@ -156,6 +157,9 @@ help()
parseArguments() parseArguments()
{ {
# an action launched out of this function
INIT_KEY_ACTION=
while [ $# -gt 0 ] while [ $# -gt 0 ]
do do
case $1 in case $1 in
@ -164,13 +168,10 @@ parseArguments()
POST_DATA=$1 POST_DATA=$1
;; ;;
--init) --init)
initApplication INIT_KEY_ACTION="ConsumerKey"
createConsumerKey
exit 0
;; ;;
--initApp) --initApp)
createApp INIT_KEY_ACTION="AppKey"
exit 0
;; ;;
--method) --method)
shift shift
@ -265,8 +266,18 @@ initProfile()
listProfile() listProfile()
{ {
local dir=
echo "Available profiles : " echo "Available profiles : "
cd ${PROFILES_PATH} && ls -1 echo "- default"
if [ -d "${PROFILES_PATH}" ]
then
# only list directory
for dir in $(cd ${PROFILES_PATH}; echo */);
do
# display directory name without slash
echo "- ${dir%%/}"
done
fi
} }
# ensure OVH App Key an App Secret are defined # ensure OVH App Key an App Secret are defined
@ -285,8 +296,17 @@ main()
parseArguments "$@" parseArguments "$@"
# set profile location
initProfile ${PROFILE} initProfile ${PROFILE}
# user want to add An API Key
case ${INIT_KEY_ACTION} in
AppKey) createApp;;
ConsumerKey) createConsumerKey;;
esac
## exit after initializing any API Keys
[ -n "${INIT_KEY_ACTION}" ] && exit 0
initApplication initApplication
initConsumerKey initConsumerKey