-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
1,739 additions
and
647 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ hosts | |
*.retry | ||
credentials.yml | ||
docker-cred.yml | ||
security-cred.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[server] | ||
domain = localhost | ||
root_url = https://%(domain)s/grafana/ | ||
|
||
[auth.anonymous] | ||
enabled = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Description=Restore iptables firewall rules | ||
Before=network-pre.target | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/sbin/ip6tables-restore -n /etc/ip6tables.conf | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Description=Restore iptables firewall rules | ||
Before=network-pre.target | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/sbin/iptables-restore -n /etc/iptables.conf | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[Unit] | ||
Description=MiCADO | ||
After=docker.service | ||
Requires=docker.service | ||
|
||
[Service] | ||
User=root | ||
Type=simple | ||
ExecStart=/usr/local/bin/docker-compose -f /var/lib/micado/docker-compose.yml up | ||
StandardOutput=syslog | ||
StandardError=syslog | ||
|
||
ExecStop=/usr/local/bin/docker-compose -f /var/lib/micado/docker-compose.yml stop | ||
TimeoutStartSec=60min | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import click | ||
import requests | ||
from terminaltables import AsciiTable | ||
import re | ||
import subprocess | ||
|
||
|
||
def call_api_endpoint(cmd, method='get', data=None): | ||
r = session.request(method, API.format(cmd), data=data) | ||
try: | ||
r_body = r.json() | ||
except ValueError: | ||
r_body = dict() | ||
return r.ok, r_body | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
"""mictl is used to manage MiCADO configuration""" | ||
pass | ||
|
||
|
||
@cli.group() | ||
@click.option('--api', default='http://localhost:5001/v1.1/', help='Base URL for credman API') | ||
def users(api): | ||
"""Manage users""" | ||
global API | ||
API = api+'{}' | ||
global session | ||
session = requests.Session() | ||
|
||
@users.command('list') | ||
def user_list(): | ||
"""List users""" | ||
ok, result = call_api_endpoint('listusers') | ||
if ok: | ||
data = [['Username', 'E-mail', 'Role', 'Locked']] | ||
data.extend([(entry.get('username', ''), | ||
entry.get('email', '-'), | ||
entry.get('role', '-'), | ||
entry.get('locked', 'unlocked')) | ||
for entry in result | ||
]) | ||
table = AsciiTable(data) | ||
click.echo(table.table) | ||
else: | ||
click.echo(result.get('user message', 'Failed')) | ||
|
||
|
||
@users.command('add', short_help='Add a new user') | ||
@click.argument('user') | ||
@click.argument('password', default='') | ||
@click.option('--email', default=None, help='E-mail address of the user') | ||
def user_add(user, password, email): | ||
""" | ||
Add a new user. | ||
If a password is not provided one will be generated. | ||
""" | ||
payload = {'username': user, 'email': email} | ||
if password: | ||
payload['password'] = password | ||
ok, result = call_api_endpoint('adduser', 'post', payload) | ||
if ok: | ||
if not password: | ||
password = re.match('Password is auto-generated. Its value is: (\S+)$', | ||
result.get('developer message', '') | ||
).group(1) | ||
click.echo("Success!\nNew password: '{}'".format(password)) | ||
else: | ||
click.echo(result.get('user message', 'Failed')) | ||
|
||
|
||
@users.command('chrole') | ||
@click.argument('user') | ||
@click.argument('role', type=click.Choice(['user', 'admin'])) | ||
def user_chrole(user, role): | ||
"""Change users's role""" | ||
payload = {'username': user, 'newrole': role} | ||
ok, result = call_api_endpoint('changerole', 'put', payload) | ||
if ok: | ||
click.echo("Success!") | ||
else: | ||
click.echo(result.get('user message', 'Failed')) | ||
|
||
|
||
@users.command('resetpwd') | ||
@click.argument('user') | ||
def user_resetpwd(user): | ||
"""Reset user's password""" | ||
payload = {'username': user} | ||
ok, result = call_api_endpoint('resetpwd', 'put', payload) | ||
if ok: | ||
password = result.get('new password', '') | ||
click.echo("Success!\nNew password: '{}'".format(password)) | ||
click.echo(result) | ||
else: | ||
click.echo(result.get('user message', 'Failed')) | ||
|
||
|
||
@users.command('del') | ||
@click.argument('user') | ||
def user_del(user): | ||
"""Delete a user""" | ||
payload = {'username': user} | ||
ok, result = call_api_endpoint('deleteuser', 'put', payload) | ||
if ok: | ||
click.echo("Success!") | ||
else: | ||
click.echo(result.get('user message', 'Failed')) | ||
|
||
@cli.group() | ||
def service(): | ||
"""Manage MiCADO services""" | ||
pass | ||
|
||
def _handle_service(command): | ||
try: | ||
subprocess.check_call("systemctl %s micado" % command, shell=True) | ||
except subprocess.CalledProcessError as e: | ||
print("Failed to %s MiCADO services; error='%s'" % (command, e)) | ||
exit(e.returncode) | ||
|
||
@service.command('start') | ||
def service_start(): | ||
"""Start MiCADO services""" | ||
_handle_service("start") | ||
|
||
@service.command('stop') | ||
def service_start(): | ||
"""Stop MiCADO services""" | ||
_handle_service("stop") | ||
|
||
@service.command('restart') | ||
def service_start(): | ||
"""Restart MiCADO services""" | ||
_handle_service("restart") | ||
|
||
@service.command('status') | ||
def service_status(): | ||
"""Query the status of MiCADO services""" | ||
_handle_service("status") | ||
|
||
|
||
if __name__ == '__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/bin/bash | ||
|
||
while [[ `ps aufx | grep -v "grep" | grep "apt.systemd.daily" | wc -l` -gt 0 ]]; do | ||
echo "The unattended-upgrades are running..." | ||
sleep 1 | ||
done |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.