From 60dac31d9e4b509262cac45db1d9ecfe87d2bd88 Mon Sep 17 00:00:00 2001 From: Kayou Date: Thu, 11 Apr 2019 01:12:07 +0200 Subject: [PATCH] Add action and config --- actions.json | 46 ++++++++++++++++++ config_panel.json | 57 ++++++++++++++++++++++ scripts/actions/public_private | 74 +++++++++++++++++++++++++++++ scripts/actions/web_account | 57 ++++++++++++++++++++++ scripts/config | 86 ++++++++++++++++++++++++++++++++++ 5 files changed, 320 insertions(+) create mode 100644 actions.json create mode 100644 config_panel.json create mode 100644 scripts/actions/public_private create mode 100644 scripts/actions/web_account create mode 100644 scripts/config diff --git a/actions.json b/actions.json new file mode 100644 index 0000000..e3b6513 --- /dev/null +++ b/actions.json @@ -0,0 +1,46 @@ +[ + { + "id": "public_private", + "name": "Move to public or private", + "command": "/bin/bash scripts/actions/public_private", + "user": "root", + "accepted_return_codes": [ + 0 + ], + "description": { + "en": "Change the public access of the app." + }, + "arguments": [ + { + "name": "is_public", + "type": "boolean", + "ask": { + "en": "Is it a public app ?" + }, + "default": true + } + ] + }, + { + "id": "web_account", + "name": "External users", + "command": "/bin/bash scripts/actions/web_account", + "user": "root", + "accepted_return_codes": [ + 0 + ], + "description": { + "en": "Allow user to be created without yunohost account." + }, + "arguments": [ + { + "name": "use_web_account", + "type": "boolean", + "ask": { + "en": "Authorized external user creation ?" + }, + "default": true + } + ] + } +] \ No newline at end of file diff --git a/config_panel.json b/config_panel.json new file mode 100644 index 0000000..bb7f754 --- /dev/null +++ b/config_panel.json @@ -0,0 +1,57 @@ +{ + "name": "GitLab configuration panel", + "version": "0.1", + "panel": [ + { + "name": "GitLab configuration", + "id": "main", + "sections": [ + { + "name": "Public access", + "id": "is_public", + "options": [ + { + "name": "Is it a public app ?", + "id": "is_public", + "type": "boolean", + "default": true + } + ] + }, + { + "name": "Overwriting config files", + "id": "overwrite_files", + "options": [ + { + "name": "Overwrite the nginx config file ?", + "help": "If the file is overwritten, a backup will be created.", + "id": "overwrite_nginx", + "type": "boolean", + "default": true + }, + { + "name": "Overwrite the gitlab.rb config file ?", + "help": "If the file is overwritten, a backup will be created.", + "id": "overwrite_gitlab_config", + "type": "boolean", + "default": true + } + ] + }, + { + "name": "External users", + "id": "users", + "options": [ + { + "name": "Authorized external user creation ?", + "help": "Allow user to be created without yunohost account.", + "id": "use_web_account", + "type": "boolean", + "default": true + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/scripts/actions/public_private b/scripts/actions/public_private new file mode 100644 index 0000000..8c683f6 --- /dev/null +++ b/scripts/actions/public_private @@ -0,0 +1,74 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +# Get is_public +is_public=${YNH_ACTION_IS_PUBLIC} + +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +is_public_old=$(ynh_app_setting_get $app is_public) + +if [ $is_public -eq $is_public_old ] +then + ynh_die "is_public is already set as $is_public." 0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# MOVE TO PUBLIC OR PRIVATE +#================================================= +if [ $is_public -eq 0 ]; then + public_private="private" +else + public_private="public" +fi +ynh_print_info --message="Moving the application to $public_private..." + +# Make app public if necessary +if [ $is_public -eq 0 ]; then + ynh_app_setting_delete $app unprotected_uris +else + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" +fi + +ynh_print_info --message="Reconfiguring SSOwat..." +# Regen ssowat configuration +yunohost app ssowatconf + +# Update the config of the app +ynh_app_setting_set $app is_public $is_public + +#================================================= +# RELOAD NGINX +#================================================= +ynh_print_info --message="Reloading nginx web server..." + +ynh_systemd_action --action=reload --service_name=nginx + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Execution completed" \ No newline at end of file diff --git a/scripts/actions/web_account b/scripts/actions/web_account new file mode 100644 index 0000000..b7edfbe --- /dev/null +++ b/scripts/actions/web_account @@ -0,0 +1,57 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +# Get use_web_account +use_web_account=${YNH_ACTION_USE_WEB_ACCOUNT} + +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +#================================================= +# CHECK IF AN ACTION HAS TO BE DONE +#================================================= + +use_web_account_old=$(ynh_app_setting_get $app use_web_account) + +if [ $use_web_account -eq $use_web_account_old ] +then + ynh_die "use_web_account is already set as $use_web_account." 0 +fi + +#================================================= +# SPECIFIC ACTION +#================================================= +# SET USER CREATION POLICY +#================================================= +if [ $use_web_account -eq 0 ]; then + web_account="Enable" +else + web_account="Disable" +fi +ynh_print_info --message="$web_account web user creation..." + +echo "ApplicationSetting.last.update_attributes(password_authentication_enabled_for_web: $use_web_account, signup_enabled: $use_web_account)" | gitlab-rails console + +# Update the config of the app +ynh_app_setting_set $app use_web_account $use_web_account + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Execution completed" \ No newline at end of file diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..575232e --- /dev/null +++ b/scripts/config @@ -0,0 +1,86 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=${YNH_APP_INSTANCE_NAME:-$YNH_APP_ID} + + +#================================================= +# LOAD VALUES +#================================================= + +# Load the real value from the app config or elsewhere. +# Then get the value from the form. +# If the form has a value for a variable, take the value from the form, +# Otherwise, keep the value from the app config. + +# is_public +old_is_public="$(ynh_app_setting_get $app is_public)" +is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}" + +# Overwrite nginx configuration +old_overwrite_nginx="$(ynh_app_setting_get $app overwrite_nginx)" +overwrite_nginx="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX:-$old_overwrite_nginx}" + +# Overwrite gitlab.rb configuration +old_overwrite_gitlab_config="$(ynh_app_setting_get $app overwrite_gitlab_config)" +overwrite_gitlab_config="${YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_GITLAB_CONFIG:-$old_overwrite_gitlab_config}" + +# use_web_account +old_use_web_account="$(ynh_app_setting_get $app use_web_account)" +use_web_account="${YNH_CONFIG_MAIN_GLOBAL_CONFIG_EMAIL_TYPE:-$old_admin_mail_html}" + +#================================================= +# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND +#================================================= + +show_config() { + # here you are supposed to read some config file/database/other then print the values + # echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value" + + echo "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public" + + echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_NGINX=$overwrite_nginx" + echo "YNH_CONFIG_MAIN_OVERWRITE_FILES_OVERWRITE_GITLAB_CONFIG=$overwrite_gitlab_config" + + echo "YNH_CONFIG_MAIN_USERS_USE_WEB_ACCOUNT=$use_web_account" +} + +#================================================= +# MODIFY THE CONFIGURATION +#================================================= + +apply_config() { + # Change public accessibility + yunohost app action run $app public_private --args $is_public + + # Change use_web_account + yunohost app action run $app web_account --args $use_web_account + + # Set overwrite_nginx + ynh_app_setting_set $app overwrite_nginx "$overwrite_nginx" + # Set overwrite_gitlab_config + ynh_app_setting_set $app overwrite_gitlab_config "$overwrite_gitlab_config" +} + +#================================================= +# GENERIC FINALIZATION +#================================================= +# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT +#================================================= + +case $1 in + show) show_config ;; + apply) apply_config ;; +esac