Skip to content
Snippets Groups Projects
Commit ec60f583 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Changed conf download step to use activation keys (refs #20621).

parent 2e7530fc
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import utils
def setup(interactive=True):
# Get requests module
cmds = [
'apt-get update',
'apt-get install -y python3-requests',
]
utils.run_commands(cmds)
import requests
# Check skyreach url
verify = utils.get_conf('SKYREACH_SSL_VERIFY') != '0'
sk_url = utils.get_conf('SKYREACH_HOST')
if not sk_url:
raise Exception('No URL defined to contact Panel / Skyreach.')
sk_url = 'https://' + sk_url
req = requests.head(sk_url, verify=verify, timeout=20)
if req.status_code != 301:
raise Exception('Unexpected response from "%s": code %s, should have been 301.' % (sk_url, req.status_code))
# Check version of skyreach
req = requests.head(sk_url + '/erp/credentials/envsetup-conf.sh', verify=verify, timeout=20)
use_activation_key = req.status_code == 403
if use_activation_key:
# Get conf using an activation key
act_key = utils.get_conf('SKYREACH_ACTIVATION_KEY')
if not act_key:
utils.log('\033[1;33m No activation key is set, skipping configuration download. \033[0m')
return
req = requests.get(sk_url + '/erp/credentials/envsetup-conf.sh', params=dict(key=act_key), verify=verify, timeout=20)
else:
# Get conf using an api key
# (deprecated, for compatibility, to be removed when Panel version will be > 5.2)
utils.log('\033[1;33m Using deprecated way to get envsetup conf. \033[0m')
api_key = utils.get_conf('SKYREACH_API_KEY')
if not api_key:
utils.log('\033[1;33m No API key is set, skipping configuration download. \033[0m')
return
req = requests.get(sk_url + '/erp/credentials/' + api_key + '/conf.sh', verify=verify, timeout=20)
# Write conf
if req.status_code != 200:
if len(req.text) > 300:
with open('/tmp/envsetup-conf-dl.txt', 'w') as fo:
fo.write(req.text)
raise Exception('Request on "%s" failed with status %s. Full response content available in "/tmp/envsetup-conf-dl.txt".' % (req.url, req.status_code))
else:
raise Exception('Request on "%s" failed with status %s. Response: "%s".' % (req.url, req.status_code, req.text))
path = os.path.join(os.path.dirname(os.path.dirname(utils.get_dir(__file__))), 'auto-generated-conf.sh')
utils.log('Configuration path: %s' % path)
with open(path, 'w') as fo:
fo.write(req.text)
utils.log('Configuration written.')
#!/bin/bash
source /root/envsetup/global-conf.sh
apt-get update
apt-get install -y -o Dpkg::Options::="--force-confold" curl
# Download config file from skyreach
if ( ! test -z ${SKYREACH_API_KEY} ); then
conf_url="https://$SKYREACH_HOST/erp/credentials/$SKYREACH_API_KEY/conf.sh"
if ( curl -I "$conf_url" >/dev/null ); then
wget -q "$conf_url" -O /root/envsetup/auto-generated-conf.sh
echo "Config file updated."
source /root/envsetup/global-conf.sh
else
echo "Failed to download configuration using url:"
echo " $conf_url"
fi
else
echo "No API key for $SKYREACH_HOST. The config will not be downloaded."
fi
......@@ -2,7 +2,6 @@
# DO NOT EDIT THIS FILE!
# Put your local configuration in conf.sh
# Default configuration values
# ----------------------------
......@@ -15,7 +14,9 @@ NC='\033[0m'
# -- System --
# Skyreach in which system looks for packages
SKYREACH_HOST='panel.ubicast.eu'
SKYREACH_SSL_VERIFY='1'
SKYREACH_API_KEY=
SKYREACH_ACTIVATION_KEY=
# NTP
NTP_SERVER='ntp.ubuntu.com'
# SSL certificate
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment