1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/code-server_ynh.git synced 2024-09-03 18:16:28 +02:00

auth and password

This commit is contained in:
Tagada 2022-01-16 13:01:08 +00:00
parent a11dbf3504
commit cf401f7447
4 changed files with 71 additions and 1 deletions

View file

@ -1,5 +1,5 @@
bind-addr: 127.0.0.1:__PORT__
auth: "none"
auth: none
cert: false
disable-telemetry: true
disable-update-check: true

View file

@ -10,6 +10,21 @@ version = "1.0"
name = "Main configuration"
services = ["__APP__"]
[main.auth]
name = "Authentication"
[main.auth.type]
ask = "Auth type"
type = "select"
choices = ["none", "password"]
default = "none"
bind: ":/opt/yunohost/__APP__/config.yaml"
[main.auth.password]
ask = "Password"
type = "password"
visible = "main.auth.type == 'password'"
[main.extensions]
name = "Extensions"
optional = false

48
scripts/config Normal file
View file

@ -0,0 +1,48 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__password() {
echo YNH_NULL
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
#=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__password() {
hashed_password="$(printf "$password" | sha256sum | cut -d' ' -f1)"
sed -i "/hashed-password:.*/d" "$final_path/config.py"
echo "hashed-password: $hashed_password" >> "$final_path/config.py"
ynh_app_setting_set $app hashed_password $hashed_password
}
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1

View file

@ -21,6 +21,8 @@ admin=$(ynh_app_setting_get --app=$app --key=admin)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
auth_type=$(ynh_app_setting_get --app=$app --key=auth_type)
hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password)
#=================================================
# CHECK VERSION
@ -116,6 +118,11 @@ ynh_script_progression --message="Updating a configuration file..." --time --wei
ynh_add_config --template="config.yaml" --destination="$final_path/config.yaml"
if [ $auth == "password" ]
then
echo "hashed-password: $hashed_password" >> "$final_path/config.py"
fi
chmod 440 "$final_path/config.yaml"
chown root:$admin "$final_path/config.yaml"