style: use list comprehensions and unpacking

This commit is contained in:
ptrcnull 2024-07-27 20:13:10 +02:00
parent e9f14a7525
commit 5564a44d0d
4 changed files with 6 additions and 6 deletions

View file

@ -64,7 +64,8 @@ def main() -> None:
'--type', 'EC', '--type', 'EC',
# '--force', # '--force',
'issue', 'issue',
] + uacme_domains, env=env) *uacme_domains,
], env=env)
if res.returncode == 0: if res.returncode == 0:
acquired = True acquired = True

View file

@ -17,12 +17,12 @@ class CloudflareHandler(Handler):
self.secret = config.get_secret('cloudflare') self.secret = config.get_secret('cloudflare')
servers = dns.resolver.resolve(zone_name, 'NS') servers = dns.resolver.resolve(zone_name, 'NS')
self.nameservers = list(map(lambda rdata: str(rdata.target).strip('.'), servers)) self.nameservers = [ str(rdata.target).strip('.') for rdata in servers ]
def run(self, args: list[str]) -> Any: def run(self, args: list[str]) -> Any:
env = os.environ.copy() env = os.environ.copy()
env['CF_API_TOKEN'] = self.secret env['CF_API_TOKEN'] = self.secret
res = subprocess.run(['flarectl', '--json'] + args, check=True, stdout=subprocess.PIPE, env=env) res = subprocess.run(['flarectl', '--json', *args], check=True, stdout=subprocess.PIPE, env=env)
try: try:
return json.loads(res.stdout) return json.loads(res.stdout)
except json.decoder.JSONDecodeError as ex: except json.decoder.JSONDecodeError as ex:

View file

@ -7,10 +7,9 @@ from .base import Handler
class HEHandler(Handler): class HEHandler(Handler):
nameservers = ['ns1.he.net', 'ns2.he.net', 'ns3.he.net', 'ns4.he.net', 'ns5.he.net']
def __init__(self, zone_name: str, config: Config, token: str) -> None: def __init__(self, zone_name: str, config: Config, token: str) -> None:
super().__init__(zone_name, config, token) super().__init__(zone_name, config, token)
self.nameservers = ['ns1.he.net', 'ns2.he.net', 'ns3.he.net', 'ns4.he.net', 'ns5.he.net']
self.password = config.get_secret('he') self.password = config.get_secret('he')
def set_record(self, record_name: str, value: str) -> Any: def set_record(self, record_name: str, value: str) -> Any:

View file

@ -62,7 +62,7 @@ def main() -> None:
log.info('checking DNS (attempt %d/5)', i+1) log.info('checking DNS (attempt %d/5)', i+1)
try: try:
res = resolver.resolve(record_name, 'TXT') res = resolver.resolve(record_name, 'TXT')
values = list(map(lambda rdata: rdata.to_text().strip('"'), res)) values = [ rdata.to_text().strip('"') for rdata in res ]
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer): except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
values = [] values = []
log.info('response from DNS: %s', values) log.info('response from DNS: %s', values)