From 4122a7ccf83de478663797e5d45e83845aee45d9 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sun, 5 Feb 2023 17:30:58 +0100 Subject: [PATCH] isort the repo --- bundles/backup-server/items.py | 1 + bundles/bird/metadata.py | 1 + bundles/icinga2/files/check_freifunk_node | 3 ++- bundles/icinga2/files/check_sipgate_account_balance | 3 ++- bundles/icinga2/files/check_spam_blocklist | 4 +--- bundles/icinga2/files/scripts/icinga_notification_wrapper | 3 ++- bundles/matrix-synapse/files/synapse-purge-unused-rooms | 2 +- bundles/mosquitto/files/tasmota-telegraf-plugin | 1 - bundles/mosquitto/metadata.py | 1 - bundles/octoprint/files/check_octoprint_update | 3 ++- bundles/postfix/files/postfix-telegraf-queue | 1 - bundles/powerdns/metadata.py | 2 +- bundles/pppd/files/dyndns | 3 ++- bundles/pretalx/files/pretalx-administrators-from-group | 3 ++- bundles/rspamd/files/telegraf-rspamd-plugin | 3 ++- bundles/smartd/files/telegraf_plugin | 2 +- bundles/sshmon/files/check_http_wget | 2 +- bundles/sshmon/files/check_mounts | 1 - bundles/users/items.py | 2 +- bundles/wireguard/metadata.py | 1 - bundles/zfs/files/check_zpool_space | 2 +- bundles/zfs/files/zfs-auto-snapshot | 1 - bundles/zfs/items.py | 1 - hooks/test_backup_metadata.py | 1 + hooks/test_metadata_dashes_vs_underscores.py | 1 + libs/faults.py | 2 +- libs/firewall.py | 2 +- libs/keys.py | 5 ++++- libs/tools.py | 5 +++-- nodes.py | 1 + scripts/encrypt_file | 1 - scripts/list-all-ips | 1 - scripts/passwords-for | 3 +-- 33 files changed, 36 insertions(+), 32 deletions(-) diff --git a/bundles/backup-server/items.py b/bundles/backup-server/items.py index c70512c..11d0624 100644 --- a/bundles/backup-server/items.py +++ b/bundles/backup-server/items.py @@ -1,6 +1,7 @@ repo.libs.tools.require_bundle(node, 'zfs') from os.path import join + from bundlewrap.metadata import metadata_to_json dataset = node.metadata.get('backup-server/zfs-base') diff --git a/bundles/bird/metadata.py b/bundles/bird/metadata.py index fd285d3..a5547d4 100644 --- a/bundles/bird/metadata.py +++ b/bundles/bird/metadata.py @@ -1,4 +1,5 @@ from ipaddress import ip_network + from bundlewrap.exceptions import NoSuchNode from bundlewrap.metadata import atomic diff --git a/bundles/icinga2/files/check_freifunk_node b/bundles/icinga2/files/check_freifunk_node index 2723f13..22725b7 100644 --- a/bundles/icinga2/files/check_freifunk_node +++ b/bundles/icinga2/files/check_freifunk_node @@ -1,8 +1,9 @@ #!/usr/bin/env python3 -from requests import get from sys import argv, exit +from requests import get + meshviewer_url = argv[1] node_id = argv[2] node = None diff --git a/bundles/icinga2/files/check_sipgate_account_balance b/bundles/icinga2/files/check_sipgate_account_balance index 8e8ce2d..843dfd9 100644 --- a/bundles/icinga2/files/check_sipgate_account_balance +++ b/bundles/icinga2/files/check_sipgate_account_balance @@ -1,8 +1,9 @@ #!/usr/bin/env python3 -from requests import get from sys import exit +from requests import get + SIPGATE_USER = '${node.metadata['icinga2']['sipgate_user']}' SIPGATE_PASS = '${node.metadata['icinga2']['sipgate_pass']}' diff --git a/bundles/icinga2/files/check_spam_blocklist b/bundles/icinga2/files/check_spam_blocklist index bf14a82..5cb350d 100644 --- a/bundles/icinga2/files/check_spam_blocklist +++ b/bundles/icinga2/files/check_spam_blocklist @@ -1,12 +1,10 @@ #!/usr/bin/env python3 from concurrent.futures import ThreadPoolExecutor, as_completed -from ipaddress import ip_address, IPv6Address +from ipaddress import IPv6Address, ip_address from subprocess import check_output from sys import argv, exit - - BLOCKLISTS = [ '0spam.fusionzero.com', 'bl.mailspike.org', diff --git a/bundles/icinga2/files/scripts/icinga_notification_wrapper b/bundles/icinga2/files/scripts/icinga_notification_wrapper index f988be8..72ab749 100644 --- a/bundles/icinga2/files/scripts/icinga_notification_wrapper +++ b/bundles/icinga2/files/scripts/icinga_notification_wrapper @@ -4,10 +4,11 @@ import email.mime.text import smtplib from argparse import ArgumentParser from json import dumps -from requests import post from subprocess import run from sys import argv +from requests import post + SIPGATE_USER='${node.metadata['icinga2']['sipgate_user']}' SIPGATE_PASS='${node.metadata['icinga2']['sipgate_pass']}' diff --git a/bundles/matrix-synapse/files/synapse-purge-unused-rooms b/bundles/matrix-synapse/files/synapse-purge-unused-rooms index aa54ebb..4e5f1e1 100644 --- a/bundles/matrix-synapse/files/synapse-purge-unused-rooms +++ b/bundles/matrix-synapse/files/synapse-purge-unused-rooms @@ -1,9 +1,9 @@ #!/usr/bin/env python3 from os import environ -from requests import get, post from sys import argv, exit +from requests import get, post SYNAPSE_MAX_ROOMS_TO_GET = 20000 SYNAPSE_HOST = 'http://[::1]:20080/' diff --git a/bundles/mosquitto/files/tasmota-telegraf-plugin b/bundles/mosquitto/files/tasmota-telegraf-plugin index 3aef6d6..4927002 100644 --- a/bundles/mosquitto/files/tasmota-telegraf-plugin +++ b/bundles/mosquitto/files/tasmota-telegraf-plugin @@ -7,7 +7,6 @@ from time import sleep import paho.mqtt.client as mqtt - BROKER_HOST = argv[1] BROKER_TOPIC = argv[2] diff --git a/bundles/mosquitto/metadata.py b/bundles/mosquitto/metadata.py index 08bd6de..c07a446 100644 --- a/bundles/mosquitto/metadata.py +++ b/bundles/mosquitto/metadata.py @@ -1,6 +1,5 @@ from bundlewrap.metadata import atomic - defaults = { 'apt': { 'packages': { diff --git a/bundles/octoprint/files/check_octoprint_update b/bundles/octoprint/files/check_octoprint_update index c7ae90a..ff89a3e 100644 --- a/bundles/octoprint/files/check_octoprint_update +++ b/bundles/octoprint/files/check_octoprint_update @@ -1,8 +1,9 @@ #!/usr/bin/env python3 -from requests import get from sys import exit +from requests import get + api_key = '${api_key}' try: diff --git a/bundles/postfix/files/postfix-telegraf-queue b/bundles/postfix/files/postfix-telegraf-queue index f5abfe7..16b64e5 100644 --- a/bundles/postfix/files/postfix-telegraf-queue +++ b/bundles/postfix/files/postfix-telegraf-queue @@ -4,7 +4,6 @@ from json import loads from subprocess import check_output - queue_counts = {} queue_json = check_output(['sudo', '/usr/sbin/postqueue', '-j']) diff --git a/bundles/powerdns/metadata.py b/bundles/powerdns/metadata.py index 5a2cc41..e93c7de 100644 --- a/bundles/powerdns/metadata.py +++ b/bundles/powerdns/metadata.py @@ -1,4 +1,4 @@ -from ipaddress import ip_address, IPv4Address, IPv6Address +from ipaddress import IPv4Address, IPv6Address, ip_address from bundlewrap.metadata import atomic diff --git a/bundles/pppd/files/dyndns b/bundles/pppd/files/dyndns index a88d7c5..f1760d8 100644 --- a/bundles/pppd/files/dyndns +++ b/bundles/pppd/files/dyndns @@ -1,8 +1,9 @@ #!/usr/bin/env python3 -import requests from sys import argv +import requests + INTERFACE = argv[1] LOCAL_IP = argv[4] diff --git a/bundles/pretalx/files/pretalx-administrators-from-group b/bundles/pretalx/files/pretalx-administrators-from-group index c1dcf80..3253000 100644 --- a/bundles/pretalx/files/pretalx-administrators-from-group +++ b/bundles/pretalx/files/pretalx-administrators-from-group @@ -1,9 +1,10 @@ #!/usr/bin/env python3 -import psycopg2 from configparser import ConfigParser from sys import argv, exit +import psycopg2 + def main(): try: diff --git a/bundles/rspamd/files/telegraf-rspamd-plugin b/bundles/rspamd/files/telegraf-rspamd-plugin index 9cb2c3d..23e5ccb 100644 --- a/bundles/rspamd/files/telegraf-rspamd-plugin +++ b/bundles/rspamd/files/telegraf-rspamd-plugin @@ -1,8 +1,9 @@ #!/usr/bin/env python3 -from requests import get from sys import argv, stderr +from requests import get + try: r = get('http://127.0.0.1:11334/stat') r.raise_for_status() diff --git a/bundles/smartd/files/telegraf_plugin b/bundles/smartd/files/telegraf_plugin index 5a7a1a5..5bd10f2 100644 --- a/bundles/smartd/files/telegraf_plugin +++ b/bundles/smartd/files/telegraf_plugin @@ -1,7 +1,7 @@ #!/usr/bin/env python -from subprocess import check_output from json import loads +from subprocess import check_output from sys import stderr devices = check_output(['smartctl', '--scan']).decode().splitlines() diff --git a/bundles/sshmon/files/check_http_wget b/bundles/sshmon/files/check_http_wget index ade5dbe..c259871 100644 --- a/bundles/sshmon/files/check_http_wget +++ b/bundles/sshmon/files/check_http_wget @@ -2,8 +2,8 @@ #this is actually a python https requests query, its called check_http_wget cause it got replaced -from sys import exit from argparse import ArgumentParser +from sys import exit import requests diff --git a/bundles/sshmon/files/check_mounts b/bundles/sshmon/files/check_mounts index f387ce4..bc2fc4b 100644 --- a/bundles/sshmon/files/check_mounts +++ b/bundles/sshmon/files/check_mounts @@ -5,7 +5,6 @@ from argparse import ArgumentParser from subprocess import check_output from tempfile import TemporaryFile - check_filesystem_types = { 'ext2', 'ext3', diff --git a/bundles/users/items.py b/bundles/users/items.py index 457c46a..d6df3cd 100644 --- a/bundles/users/items.py +++ b/bundles/users/items.py @@ -1,4 +1,4 @@ -from os.path import join, exists +from os.path import exists, join files = { '/etc/bash.bashrc': { diff --git a/bundles/wireguard/metadata.py b/bundles/wireguard/metadata.py index 21e9b8f..b19ca8c 100644 --- a/bundles/wireguard/metadata.py +++ b/bundles/wireguard/metadata.py @@ -3,7 +3,6 @@ from ipaddress import ip_network from bundlewrap.exceptions import NoSuchNode from bundlewrap.metadata import atomic - defaults = { 'apt': { 'packages': { diff --git a/bundles/zfs/files/check_zpool_space b/bundles/zfs/files/check_zpool_space index ff4b9bb..abb533e 100644 --- a/bundles/zfs/files/check_zpool_space +++ b/bundles/zfs/files/check_zpool_space @@ -1,9 +1,9 @@ #!/usr/bin/env python3 +import re from subprocess import check_output from sys import argv, exit -import re def to_bytes(size): diff --git a/bundles/zfs/files/zfs-auto-snapshot b/bundles/zfs/files/zfs-auto-snapshot index 4f1c919..8e38cf7 100644 --- a/bundles/zfs/files/zfs-auto-snapshot +++ b/bundles/zfs/files/zfs-auto-snapshot @@ -2,7 +2,6 @@ import re - from datetime import datetime from json import loads from subprocess import check_call, check_output diff --git a/bundles/zfs/items.py b/bundles/zfs/items.py index 8dda658..85ffdd7 100644 --- a/bundles/zfs/items.py +++ b/bundles/zfs/items.py @@ -1,5 +1,4 @@ from json import dumps -#from os.path import join from bundlewrap.metadata import MetadataJSONEncoder diff --git a/hooks/test_backup_metadata.py b/hooks/test_backup_metadata.py index 4937989..c8498eb 100644 --- a/hooks/test_backup_metadata.py +++ b/hooks/test_backup_metadata.py @@ -2,6 +2,7 @@ from bundlewrap.exceptions import BundleError from bundlewrap.utils.text import bold, green, yellow from bundlewrap.utils.ui import io + def test_node(repo, node, **kwargs): if not node.has_bundle('backup-client'): return diff --git a/hooks/test_metadata_dashes_vs_underscores.py b/hooks/test_metadata_dashes_vs_underscores.py index 698ab56..b7c7419 100644 --- a/hooks/test_metadata_dashes_vs_underscores.py +++ b/hooks/test_metadata_dashes_vs_underscores.py @@ -4,6 +4,7 @@ from bundlewrap.exceptions import BundleError from bundlewrap.utils.text import bold, green from bundlewrap.utils.ui import io + def test_underscore_vs_dash(node, metadata, path=[]): for k, v in metadata.items(): if not isinstance(k, str): diff --git a/libs/faults.py b/libs/faults.py index ad3735c..91d8b2f 100644 --- a/libs/faults.py +++ b/libs/faults.py @@ -1,4 +1,4 @@ -from json import loads, dumps +from json import dumps, loads from bundlewrap.metadata import metadata_to_json from bundlewrap.utils import Fault diff --git a/libs/firewall.py b/libs/firewall.py index 68b852d..b343824 100644 --- a/libs/firewall.py +++ b/libs/firewall.py @@ -1,5 +1,5 @@ +from ipaddress import IPv4Network, ip_network from os.path import abspath, dirname, join -from ipaddress import ip_network, IPv4Network REPO_PATH = dirname(dirname(abspath(__file__))) diff --git a/libs/keys.py b/libs/keys.py index 1565fee..4db382b 100644 --- a/libs/keys.py +++ b/libs/keys.py @@ -1,8 +1,11 @@ import base64 -from nacl.public import PrivateKey + from nacl.encoding import Base64Encoder +from nacl.public import PrivateKey + from bundlewrap.utils import Fault + def gen_privkey(repo, identifier): return repo.vault.random_bytes_as_base64_for(identifier) diff --git a/libs/tools.py b/libs/tools.py index 8e225a5..40afde2 100644 --- a/libs/tools.py +++ b/libs/tools.py @@ -1,9 +1,10 @@ -from ipaddress import ip_address, ip_network, IPv4Address, IPv4Network +from ipaddress import IPv4Address, IPv4Network, ip_address, ip_network -from bundlewrap.exceptions import NoSuchGroup, NoSuchNode, BundleError +from bundlewrap.exceptions import BundleError, NoSuchGroup, NoSuchNode from bundlewrap.utils.text import bold, red from bundlewrap.utils.ui import io + def resolve_identifier(repo, identifier): """ Try to resolve an identifier (group or node). Return a set of ip diff --git a/nodes.py b/nodes.py index 75e6f1f..b9110ad 100644 --- a/nodes.py +++ b/nodes.py @@ -3,6 +3,7 @@ from os.path import join from pathlib import Path import bwpass + from bundlewrap.metadata import atomic from bundlewrap.utils import error_context diff --git a/scripts/encrypt_file b/scripts/encrypt_file index 8fa272e..430aac0 100755 --- a/scripts/encrypt_file +++ b/scripts/encrypt_file @@ -5,7 +5,6 @@ from sys import argv from bundlewrap.repo import Repository - path = environ.get('BW_REPO_PATH', '.') repo = Repository(path) diff --git a/scripts/list-all-ips b/scripts/list-all-ips index f5f2bc5..04a05ea 100755 --- a/scripts/list-all-ips +++ b/scripts/list-all-ips @@ -5,7 +5,6 @@ from sys import argv from bundlewrap.repo import Repository from bundlewrap.utils.dicts import merge_dict - path = environ.get('BW_REPO_PATH', '.') repo = Repository(path) diff --git a/scripts/passwords-for b/scripts/passwords-for index 3aa0d53..c12fa7b 100755 --- a/scripts/passwords-for +++ b/scripts/passwords-for @@ -2,10 +2,9 @@ from os import environ from sys import argv +from bundlewrap.exceptions import FaultUnavailable from bundlewrap.repo import Repository from bundlewrap.utils import Fault -from bundlewrap.exceptions import FaultUnavailable - path = environ.get('BW_REPO_PATH', '.') repo = Repository(path)