From 3ac63b4c611671afc8ca411b6567d08cbddce290 Mon Sep 17 00:00:00 2001 From: Krakinou Date: Sun, 6 Dec 2020 15:46:57 +0100 Subject: [PATCH] API_PATH management --- conf/nginx.conf | 2 +- scripts/change_url | 14 ++++++++++---- scripts/install | 9 ++++++--- scripts/restore | 2 +- scripts/upgrade | 33 ++++++++------------------------- 5 files changed, 26 insertions(+), 34 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index f61437a..67ff968 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -26,7 +26,7 @@ location __PATH__/ { #sub_path_only rewrite ^api___PATH__$ api___PATH__/ permanent; -location api___PATH__/ { +location __API_PATH__/ { #Alternative path for api, only authorized json command will be accepted #allow only local network on IPv4 diff --git a/scripts/change_url b/scripts/change_url index dc94edb..2da543e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -19,8 +19,6 @@ old_path=$YNH_APP_OLD_PATH new_domain=$YNH_APP_NEW_DOMAIN new_path=$YNH_APP_NEW_PATH -old_api=/api_$old_path -new_api=/api_$new_path app=$YNH_APP_INSTANCE_NAME @@ -32,6 +30,14 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) +old_api=$(ynh_app_setting_get --app=$app --key=api_path) + +if [ "$new_path" == "/" ]; then + new_api=/api_/$app +else + new_api=/api_$new_path +fi + #================================================= @@ -92,7 +98,8 @@ then domain="$old_domain" path_url="$new_path" # Create a dedicated nginx config - ynh_add_nginx_config + # Create a dedicated nginx config + ynh_add_nginx_config "api_path" fi # Change the domain for nginx @@ -121,7 +128,6 @@ ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 # If the app is private, API should stays publicly accessible. ynh_app_setting_delete --app=$app --key="api_path" ynh_app_setting_set --app=$app --key="api_path" --value=$new_api - ynh_permission_url --permission="domoticz_API" --url="$new_domain$new_api" --allowed="visitors" diff --git a/scripts/install b/scripts/install index f5dde79..2217b28 100755 --- a/scripts/install +++ b/scripts/install @@ -30,8 +30,11 @@ is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME #Set dedicated variables -api_path=/api_$path_url - +if [ "$path_url" == "/" ]; then + api_path=/api_/$app +else + api_path=/api_$path_url +fi #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -107,7 +110,7 @@ fi ynh_script_progression --message="Configuring nginx web server..." --weight=2 # Create a dedicated nginx config -ynh_add_nginx_config +ynh_add_nginx_config "api_path" #================================================= # CREATE DEDICATED USER diff --git a/scripts/restore b/scripts/restore index 4305630..165a767 100755 --- a/scripts/restore +++ b/scripts/restore @@ -116,7 +116,7 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" +yunohost service add $app --description "Domotique open sources" --log "/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 39b4427..0281134 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -78,16 +78,19 @@ fi #Create a dedicated path for the api access if [ -z "$api_path" ]; then - api_path=/api_$path_url - ynh_app_setting_set --app=$app --key=final_path --value=$final_path -# ynh_webpath_register --app=$app --domain=$domain --path_url=$api_path + if [ "$path_url" == "/" ]; then + api_path=/api_/$app + else + api_path=/api_$path_url + fi + ynh_app_setting_set --app=$app --key=api_path --value=$api_path fi # Create the permission "domoticz_API" only if it doesn't exist. if ! ynh_permission_exists --permission="domoticz_API" then - # API Authorization wit dedicated URL + # API Authorization with dedicated URL ynh_permission_create --permission="domoticz_API" ---url="$domain$api_path" --allowed="visitors" fi @@ -119,19 +122,6 @@ fi # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# CHECK THE PATH -#================================================= - - -# Normalize the URL path syntax -# N.B. : this is for app installations before YunoHost 2.7 -# where this value might be something like /foo/ or foo/ -# instead of /foo .... -# If nobody installed your app before 2.7, then you may -# safely remove this line -path_url=$(ynh_normalize_url_path --path_url=$path_url) - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -168,7 +158,7 @@ fi ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 # Create a dedicated nginx config -ynh_add_nginx_config +ynh_add_nginx_config "api_path" #================================================= # UPGRADE DEPENDENCIES @@ -200,13 +190,6 @@ chmod 440 /etc/sudoers.d/$app mkdir -p /var/log/$app chown -R domoticz: /var/log/$app -#================================================= -# SETUP HOOKS FILE -#================================================= - -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_addaccess" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../hooks/post_app_removeaccess" - #================================================= # SETUP SYSTEMD