Skip to content

Commit

Permalink
Advertise "users-admin" service
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DavidePrincipi committed Oct 16, 2023
1 parent 0f8ec9f commit 7d0d52e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ For instance:

https://<node FQDN>/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.
Expand Down
23 changes: 23 additions & 0 deletions imageroot/actions/configure-module/80start_amld
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
1 change: 1 addition & 0 deletions imageroot/actions/import-module/80start_amld
1 change: 1 addition & 0 deletions imageroot/actions/restore-module/80start_amld

0 comments on commit 7d0d52e

Please sign in to comment.