mirror of
https://github.com/YunoHost-Apps/domoticz_ynh.git
synced 2024-09-03 18:26:17 +02:00
API_PATH management
This commit is contained in:
parent
573b3ed34a
commit
3ac63b4c61
5 changed files with 26 additions and 34 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue