From 7d0d52ef19dfec6560ec982e4736bd3be510929d Mon Sep 17 00:00:00 2001 From: Davide Principi Date: Mon, 16 Oct 2023 19:49:28 +0200 Subject: [PATCH] Advertise "users-admin" service The users management portal can be discovered like other services and if its settings are added, or changed the `service-users-admin-changed` event is raised. --- README.md | 10 ++++++++ .../actions/configure-module/80start_amld | 23 +++++++++++++++++++ imageroot/actions/import-module/80start_amld | 1 + imageroot/actions/restore-module/80start_amld | 1 + 4 files changed, 35 insertions(+) mode change 100644 => 100755 imageroot/actions/configure-module/80start_amld create mode 120000 imageroot/actions/import-module/80start_amld create mode 120000 imageroot/actions/restore-module/80start_amld diff --git a/README.md b/README.md index 62e159e..590922a 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,16 @@ For instance: https:///users-admin/domain.test/ +The backend endpoint is advertised as `users-admin` service and can be +discovered in the usual ways, as documented in [Service +discovery](https://nethserver.github.io/ns8-core/modules/service_providers/#service-discovery). +For instance: + + api-cli run module/mymodule1/list-service-providers --data '{"service":"users-admin", "filter":{"domain":"dp.nethserver.net","node":"1"}}' + +The event `service-users-admin-changed` is raised when the serivice +becomes available or is changed. + The backend of the module runs under the `api-moduled.service` Systemd unit supervision. Refer also to `api-moduled` documentation, provided by `ns8-core` repository. diff --git a/imageroot/actions/configure-module/80start_amld b/imageroot/actions/configure-module/80start_amld old mode 100644 new mode 100755 index ae8fbe3..69fba78 --- a/imageroot/actions/configure-module/80start_amld +++ b/imageroot/actions/configure-module/80start_amld @@ -11,7 +11,12 @@ import sys import os import string import secrets +import json +agent_id = os.environ['AGENT_ID'] +node_id = int(os.environ['NODE_ID']) +domain = os.environ['LDAP_DOMAIN'] +ip_address = os.environ['LDAP_IPADDR'] _, amld_port, _ = (os.environ['TCP_PORTS'] + ',,').split(",", 2) @@ -41,4 +46,22 @@ response = agent.tasks.run( }, ) +# Add the `users-admin` service discovery information, and advertise this +# new service instance: +rdb = agent.redis_connect(privileged=True) +trx = rdb.pipeline() +trx.delete(agent_id + '/srv/http/users-admin') +trx.hset(agent_id + '/srv/http/users-admin', mapping={ + "port": amld_port, + "url": f"http://{ip_address}:{amld_port}", + "domain": domain, + "node": node_id, +}) +trx.publish(agent_id + '/event/service-users-admin-changed', json.dumps({ + 'domain': domain, + 'node': node_id, + 'key': agent_id + '/srv/http/users-admin', +})) +trx.execute() + agent.run_helper("systemctl", "-T", "--user", "enable", "--now", "api-moduled.service") diff --git a/imageroot/actions/import-module/80start_amld b/imageroot/actions/import-module/80start_amld new file mode 120000 index 0000000..b7be522 --- /dev/null +++ b/imageroot/actions/import-module/80start_amld @@ -0,0 +1 @@ +../configure-module/80start_amld \ No newline at end of file diff --git a/imageroot/actions/restore-module/80start_amld b/imageroot/actions/restore-module/80start_amld new file mode 120000 index 0000000..b7be522 --- /dev/null +++ b/imageroot/actions/restore-module/80start_amld @@ -0,0 +1 @@ +../configure-module/80start_amld \ No newline at end of file