generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configure-module
action
#2
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
42b388c
Update to WebTop 5.8.3
Amygos 5386d2a
build-images.sh: fix ui build in node 18
Amygos 86bda91
Add `configure-module` action
Amygos 357e3a0
configure-module: start service before configure
Amygos 1299c39
configure-module: set public and davserver urls
Amygos 56ffcb1
configure-module: wait for postgres to be ready
Amygos 3be6ed9
configure-module: make field `hostname` required
Amygos bdbcd48
configure-module: add https certificate config
Amygos 3a46356
configure-module: use a pipe to send SQL commands
Amygos b4aa02b
configure-module: use agent lib to restart webapp
Amygos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (C) 2022 Nethesis S.r.l. | ||
# http://www.nethesis.it - [email protected] | ||
# | ||
# This script is part of NethServer. | ||
# | ||
# NethServer is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, | ||
# or any later version. | ||
# | ||
# NethServer is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with NethServer. If not, see COPYING. | ||
# | ||
# Redirect any output to the journal (stderr) | ||
|
||
set -e | ||
|
||
exec 1>&2 | ||
|
||
systemctl --user start postgres | ||
|
||
podman exec -i postgres sh -s <<'EOF' | ||
query="SELECT EXISTS ( SELECT * FROM pg_tables WHERE schemaname = 'core' AND tablename = 'settings');" | ||
psql -q -U postgres webtop5 -tA -c "$query" 2> /dev/null | grep -q t | ||
db_check=$? | ||
c=10 | ||
while [ "$db_check" -ne 0 -o $c -eq 0 ]; do | ||
sleep 1s | ||
psql -q -U postgres webtop5 -tA -c "$query" 2> /dev/null | grep -q t | ||
db_check=$? | ||
c=$(expr $c - 1 ) | ||
done | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2022 Nethesis S.r.l. | ||
# http://www.nethesis.it - [email protected] | ||
# | ||
# This script is part of NethServer. | ||
# | ||
# NethServer is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, | ||
# or any later version. | ||
# | ||
# NethServer is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with NethServer. If not, see COPYING. | ||
# | ||
|
||
# | ||
# Create a virtual host configuration | ||
# Input example: | ||
# {"instance": "module1", "url": "http://127.0.0.0:2000", "path": "/foo", "http2https": true} | ||
# | ||
|
||
import json | ||
import sys | ||
import os | ||
import agent | ||
import subprocess | ||
|
||
# Try to parse the stdin as JSON. | ||
# If parsing fails, output everything to stderr | ||
data = json.load(sys.stdin) | ||
|
||
agent_id = os.getenv("AGENT_ID", "") | ||
if not agent_id: | ||
raise Exception("AGENT_ID not found inside the environemnt") | ||
|
||
# Connect to redis | ||
r = agent.redis_connect(privileged=True).pipeline() | ||
|
||
restart_webapp = False | ||
|
||
webtop_request_https_certificate = os.environ["WEBTOP_REQUEST_HTTPS_CERTIFICATE"].lower() in ('true', '1', 't') | ||
if data.get("request_https_certificate") is not None: | ||
if data.get("request_https_certificate") != webtop_request_https_certificate: | ||
webtop_request_https_certificate = data["request_https_certificate"] | ||
agent.set_env("WEBTOP_REQUEST_HTTPS_CERTIFICATE", data["request_https_certificate"]) | ||
|
||
# Configure Traefik to route WebTop's host requests to the webtop module | ||
response = agent.tasks.run( | ||
agent_id=agent.resolve_agent_id('traefik@node'), | ||
action='set-route', | ||
data={ | ||
'instance': os.environ['MODULE_ID'], | ||
'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], | ||
'http2https': True, | ||
'lets_encrypt': webtop_request_https_certificate, | ||
'host': data["hostname"], | ||
}, | ||
) | ||
# Check if traefik configuration has been successfull | ||
agent.assert_exp(response['exit_code'] == 0) | ||
|
||
if data["hostname"] != os.getenv("WEBTOP_HOSTNAME"): | ||
|
||
public_url = 'https://' + data["hostname"] + '/webtop' | ||
dav_url = 'https://' + data["hostname"] + '/webtop-dav/server.php' | ||
|
||
with subprocess.Popen(['podman', 'exec', '-i', 'postgres', 'psql', '-U', 'postgres', 'webtop5'], stdin=subprocess.PIPE, text=True) as psql: | ||
print("DELETE FROM \"core\".\"settings\" WHERE service_id = 'com.sonicle.webtop.core' and key = 'public.url';\n", file=psql.stdin) | ||
print("INSERT INTO \"core\".\"settings\" (\"service_id\", \"key\", \"value\") VALUES ('com.sonicle.webtop.core', 'public.url', \'" + public_url + "\');\n", file=psql.stdin) | ||
|
||
print("DELETE FROM \"core\".\"settings\" WHERE service_id = 'com.sonicle.webtop.core' and key = 'davserver.url';\n", file=psql.stdin) | ||
print("INSERT INTO \"core\".\"settings\" (\"service_id\", \"key\", \"value\") VALUES ('com.sonicle.webtop.core', 'davserver.url',\'" + dav_url + "\');\n", file=psql.stdin) | ||
|
||
agent.assert_exp(psql.returncode == 0) # check the command is succesfull | ||
|
||
agent.set_env("WEBTOP_HOSTNAME", data["hostname"]) | ||
restart_webapp = True | ||
|
||
if restart_webapp: | ||
agent.run_helper("systemctl", "--user", "restart", "webapp").check_returncode() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "configure-module input", | ||
"$id": "http://schema.nethserver.org/webtop/configure-route-input.json", | ||
"description": "Configure webtop", | ||
"examples": [ | ||
{ | ||
"hostname": "example.com" | ||
}, | ||
{ | ||
"hostname": "example.com", | ||
"request_https_certificate": true | ||
} | ||
], | ||
"type": "object", | ||
"required": ["hostname"], | ||
"properties": { | ||
"hostname": { | ||
"type": "string", | ||
"format": "hostname", | ||
"title": "Hostname of the WebTop instance", | ||
"examples": [ | ||
"example.com" | ||
] | ||
}, | ||
"request_https_certificate": { | ||
"type": "boolean", | ||
"title": "Request a valid HTTPS certificate" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
wt-5.18.2 | ||
wt-5.18.3 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to use SPDX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix the license header in all files in other corrective commits.