bundlewrap/bundles/icinga2/metadata.py
Franziska Kunsmann 12cf03e03f
Some checks failed
bundlewrap/pipeline/head There was a failure building this commit
bundles/icinga2: generate icinga_users from users.json
2020-11-21 21:46:41 +01:00

75 lines
2 KiB
Python

from json import loads
from os.path import join
defaults = {
'apt': {
'repos': {
'icinga2': {
'items': {
'deb http://packages.icinga.com/{os} icinga-{os_release} main',
'deb-src http://packages.icinga.com/{os} icinga-{os_release} main',
},
},
},
'packages': {
'icinga2': {},
'icinga2-ido-pgsql': {},
'icingaweb2': {},
'icingaweb2-module-monitoring': {},
# needed for check_rbl
'libdata-validate-ip-perl': {},
'libdata-validate-ip-perl': {},
'libmonitoring-plugin-perl': {},
'libnet-dns-perl': {},
'libreadonly-perl': {},
}
},
'icinga2': {
'api_users': {
'root': repo.vault.password_for(f'{node.name} icinga2 api root'),
},
},
'icingaweb2': {
'setup-token': repo.vault.password_for(f'{node.name} icingaweb2 setup-token'),
},
'postgresql': {
'roles': {
'icinga2': {
'password': repo.vault.password_for(f'{node.name} postgresql icinga2'),
},
},
'databases': {
'icingaweb2': {
'owner': 'icinga2',
},
'icinga2': {
'owner': 'icinga2',
},
},
},
}
@metadata_reactor
def add_users_from_json(metadata):
with open(join(repo.path, 'users.json'), 'r') as f:
json = loads(f.read())
users = {}
for uname, config in json.items():
users[uname] = {
'email': '',
'phone': '',
'is_admin': config.get('is_admin', False),
}
if 'email' in config:
users[uname]['email'] = repo.vault.decrypt(config['email'])
if 'phone' in config:
users[uname]['phone'] = repo.vault.decrypt(config['phone'])
return {
'icinga2': {
'icinga_users': users,
},
}