style: introduce a linter
This commit is contained in:
parent
3559c81560
commit
6f492ef480
8 changed files with 44 additions and 15 deletions
|
@ -1,3 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
from nyacme.hook import main
|
||||
|
||||
main()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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__)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
|||
|
||||
from ..config import Config
|
||||
|
||||
|
||||
class Handler:
|
||||
zone: str
|
||||
config: Config
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
22
ruff.toml
Normal 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"
|
Loading…
Reference in a new issue