style: introduce a linter

This commit is contained in:
ptrcnull 2024-04-07 11:25:32 +02:00
parent 3559c81560
commit 6f492ef480
8 changed files with 44 additions and 15 deletions

View file

@ -1,3 +1,4 @@
#!/usr/bin/env python3
from nyacme.hook import main
main()

View file

@ -1,8 +1,8 @@
import argparse
import os.path
import subprocess
import logging
import os.path
import shutil
import subprocess
from datetime import datetime
from pathlib import Path
@ -35,7 +35,8 @@ def main() -> None:
cert_path = output_dir / domain / 'cert.pem'
if cert_path.is_file():
out = subprocess.run([ 'openssl', 'x509', '-enddate', '-noout', '-in', cert_path ], stdout=subprocess.PIPE, check=True).stdout.decode('utf-8').strip()
cmd = [ 'openssl', 'x509', '-enddate', '-noout', '-in', cert_path ]
out = subprocess.run(cmd, stdout=subprocess.PIPE, check=True).stdout.decode('utf-8').strip()
date = datetime.strptime(out, 'notAfter=%b %d %H:%M:%S %Y %Z')
# if more than 1 month, skip
delta = date - datetime.now()

View file

@ -1,8 +1,9 @@
from typing import Optional
import tomllib
import logging
import sys
import os
import sys
from typing import Optional
import tomllib
log = logging.getLogger(__name__)

View file

@ -2,6 +2,7 @@ import logging
from ..config import Config
class Handler:
zone: str
config: Config

View file

@ -1,9 +1,10 @@
import urllib.request
import json
from typing import Optional, Any
import urllib.request
from typing import Any, Optional
from .base import Handler
from ..config import Config
from .base import Handler
class HetznerHandler(Handler):
# discovered

View file

@ -1,7 +1,8 @@
import os
from .base import Handler
from ..config import Config
from .base import Handler
class HTTPHandler(Handler):
def __init__(self, zone: str, config: Config, token: str) -> None:

View file

@ -1,15 +1,14 @@
import argparse
import logging
from itertools import chain
import time
import sys
import time
from itertools import chain
import dns.resolver
from .config import read_config
from .handlers import HetznerHandler
logging.basicConfig(level=logging.INFO, format='> [%(levelname)s] %(name)s: %(message)s')
log = logging.getLogger('nyacme_hook')
@ -49,7 +48,9 @@ def main() -> None:
if args.type == 'dns-01':
resolver = dns.resolver.Resolver('', configure=False)
resolver.nameservers = list(chain.from_iterable(list(map(resolve4, handler.nameservers)) + list(map(resolve6, handler.nameservers))))
ns4 = list(map(resolve4, handler.nameservers))
ns6 = list(map(resolve6, handler.nameservers))
resolver.nameservers = list(chain.from_iterable(ns4 + ns6))
for i in range(5):
log.info('checking DNS (attempt %d/5)', i+1)
try:

22
ruff.toml Normal file
View file

@ -0,0 +1,22 @@
line-length = 120
# https://docs.astral.sh/ruff/rules/
[lint]
extend-select = [
"Q", # quotes
"PT", # pytest
"I", # isort
"F", # pyflakes
"E", # pycodestyle (errors)
"W", # pycodestyle (warnings)
"UP", # pyupgrade
"ISC", # implicit string concat
"T20", # no print/pprint
"G001", # no str.format in logging
"C901", # check for complexity
]
[lint.flake8-quotes]
inline-quotes = "single"
docstring-quotes = "single"