diff --git a/imageroot/actions/configure-module/20configure b/imageroot/actions/configure-module/20configure index 207520c..b5a253d 100755 --- a/imageroot/actions/configure-module/20configure +++ b/imageroot/actions/configure-module/20configure @@ -100,6 +100,10 @@ agent.assert_exp(response['exit_code'] == 0) with open('config.json', 'w') as cfp: cfp.write(json.dumps(config | request)) +# Load subscription info +rdb = agent.redis_connect(privileged=False) +subscription = rdb.hgetall('cluster/subscription') + with open('config.env', 'w') as env: env.write(f'ADMIN_USER={request["api_user"]}\n') env.write(f'ADMIN_PASSWORD={request["api_password"]}\n') @@ -111,6 +115,10 @@ with open('config.env', 'w') as env: env.write(f'WEBSSH_PATH={config["webssh_path"]}/\n') env.write(f'GRAFANA_PATH=/grafana\n') env.write(f'DATA_DIR=/nethsecurity-api/data\n') + if subscription: + env.write(f'VALID_SUBSCRIPTION=true\n') + else: + env.write(f'VALID_SUBSCRIPTION=false\n') server_address = request["ovpn_network"].removesuffix('.0') + '.1' with open('promtail.env', 'w') as promtail: diff --git a/imageroot/actions/configure-module/30subscription b/imageroot/actions/configure-module/30subscription new file mode 100755 index 0000000..8ac5460 --- /dev/null +++ b/imageroot/actions/configure-module/30subscription @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import agent + +rdb = agent.redis_connect(privileged=False) + +subscription = rdb.hgetall('cluster/subscription') + +with open('subscription.env', 'w') as env: + if subscription: + env.write(f'VALID_SUBSCRIPTION=true\n') + else: + env.write(f'VALID_SUBSCRIPTION=false\n') + diff --git a/imageroot/events/subscription-changed/30subscription b/imageroot/events/subscription-changed/30subscription new file mode 120000 index 0000000..e0e147d --- /dev/null +++ b/imageroot/events/subscription-changed/30subscription @@ -0,0 +1 @@ +../../actions/configure-module/30subscription \ No newline at end of file diff --git a/imageroot/events/subscription-changed/80start_services b/imageroot/events/subscription-changed/80start_services new file mode 120000 index 0000000..f1130f7 --- /dev/null +++ b/imageroot/events/subscription-changed/80start_services @@ -0,0 +1 @@ +../../actions/configure-module/80start_services \ No newline at end of file