formatted code with black

This commit is contained in:
K4YT3X 2021-01-12 20:47:40 -05:00
parent bea7a4bbe7
commit a08d831cc4
4 changed files with 22 additions and 18 deletions

View File

@ -1 +1 @@
from .wg_meshconf import main
from .wg_meshconf import main

View File

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
Name: Database Manager
Dev: K4YT3X
Creator: K4YT3X
Date Created: July 19, 2020
Last Modified: November 15, 2020
"""
@ -63,7 +63,7 @@ class DatabaseManager:
self.wireguard = WireGuard()
def read_database(self):
""" read database file into dict
"""read database file into dict
Returns:
dict: content of database file in dict format
@ -75,7 +75,7 @@ class DatabaseManager:
return json.load(database_file)
def write_database(self, data: dict):
""" dump data into database file
"""dump data into database file
Args:
data (dict): content of database

View File

@ -2,13 +2,13 @@
# -*- coding: utf-8 -*-
"""
Name: wg-meshconf
Dev: K4YT3X
Creator: K4YT3X
Date Created: July 19, 2020
Last Modified: November 15, 2020
Last Modified: January 12, 2021
Licensed under the GNU General Public License Version 3 (GNU GPL v3),
available at: https://www.gnu.org/licenses/gpl-3.0.txt
(C) 2018-2020 K4YT3X
(C) 2018-2021 K4YT3X
"""
# built-in imports
@ -21,8 +21,7 @@ from .database_manager import DatabaseManager
def parse_arguments():
""" parse CLI arguments
"""
"""parse CLI arguments"""
parser = argparse.ArgumentParser(
prog="wg-meshconf", formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
@ -45,7 +44,9 @@ def parse_arguments():
"--address", help="address of the server", action="append", required=True
)
addpeer.add_argument("--endpoint", help="peer's public endpoint address")
addpeer.add_argument("--allowedips", help="additional allowed IP addresses", action="append")
addpeer.add_argument(
"--allowedips", help="additional allowed IP addresses", action="append"
)
addpeer.add_argument("--privatekey", help="private key of server interface")
addpeer.add_argument("--listenport", help="port to listen on", default=51820)
addpeer.add_argument("--fwmark", help="fwmark for outgoing packets")
@ -68,7 +69,9 @@ def parse_arguments():
updatepeer.add_argument("name", help="Name used to identify this node")
updatepeer.add_argument("--address", help="address of the server", action="append")
updatepeer.add_argument("--endpoint", help="peer's public endpoint address")
updatepeer.add_argument("--allowedips", help="additional allowed IP addresses", action="append")
updatepeer.add_argument(
"--allowedips", help="additional allowed IP addresses", action="append"
)
updatepeer.add_argument("--privatekey", help="private key of server interface")
updatepeer.add_argument("--listenport", help="port to listen on")
updatepeer.add_argument("--fwmark", help="fwmark for outgoing packets")
@ -93,7 +96,9 @@ def parse_arguments():
# showpeers prints a table of all peers and their configurations
showpeers = subparsers.add_parser("showpeers")
showpeers.add_argument(
"name", help="Name of the peer to query", nargs="?",
"name",
help="Name of the peer to query",
nargs="?",
)
showpeers.add_argument(
"--style",

View File

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
Name: WireGuard Python Bindings
Dev: K4YT3X
Creator: K4YT3X
Date Created: October 11, 2019
Last Modified: July 19, 2020
"""
@ -13,7 +13,7 @@ import subprocess
class WireGuard:
""" WireGuard utility controller
"""WireGuard utility controller
This class handles the interactions with the wg binary,
including:
@ -35,7 +35,7 @@ class WireGuard:
self.wg_binary = wg_binary
def genkey(self):
""" generate WG private key
"""generate WG private key
Generate a new wireguard private key via
wg command.
@ -51,7 +51,7 @@ class WireGuard:
)
def pubkey(self, privkey: str) -> str:
""" convert WG private key into public key
"""convert WG private key into public key
Uses wg pubkey command to convert the wg private
key into a public key.
@ -74,8 +74,7 @@ class WireGuard:
)
def genpsk(self):
""" generate a random base64 PSK
"""
"""generate a random base64 PSK"""
return (
subprocess.run(
[str(self.wg_binary.absolute()), "genpsk"],