mirror of
https://github.com/SnowMB/traefik-certificate-extractor.git
synced 2025-01-31 12:19:31 +08:00
indentation fixes
This commit is contained in:
parent
75f2bf5cce
commit
129e2377a4
31
extractor.py
31
extractor.py
@ -11,6 +11,7 @@ from watchdog.observers import Observer
|
|||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class PathType(object):
|
class PathType(object):
|
||||||
def __init__(self, exists=True, type='file', dash_ok=True):
|
def __init__(self, exists=True, type='file', dash_ok=True):
|
||||||
'''exists:
|
'''exists:
|
||||||
@ -22,7 +23,8 @@ class PathType(object):
|
|||||||
dash_ok: whether to allow "-" as stdin/stdout'''
|
dash_ok: whether to allow "-" as stdin/stdout'''
|
||||||
|
|
||||||
assert exists in (True, False, None)
|
assert exists in (True, False, None)
|
||||||
assert type in ('file','dir','symlink',None) or hasattr(type,'__call__')
|
assert type in ('file', 'dir', 'symlink',
|
||||||
|
None) or hasattr(type, '__call__')
|
||||||
|
|
||||||
self._exists = exists
|
self._exists = exists
|
||||||
self._type = type
|
self._type = type
|
||||||
@ -32,9 +34,11 @@ class PathType(object):
|
|||||||
if string == '-':
|
if string == '-':
|
||||||
# the special argument "-" means sys.std{in,out}
|
# the special argument "-" means sys.std{in,out}
|
||||||
if self._type == 'dir':
|
if self._type == 'dir':
|
||||||
raise err('standard input/output (-) not allowed as directory path')
|
raise err(
|
||||||
|
'standard input/output (-) not allowed as directory path')
|
||||||
elif self._type == 'symlink':
|
elif self._type == 'symlink':
|
||||||
raise err('standard input/output (-) not allowed as symlink path')
|
raise err(
|
||||||
|
'standard input/output (-) not allowed as symlink path')
|
||||||
elif not self._dash_ok:
|
elif not self._dash_ok:
|
||||||
raise err('standard input/output (-) not allowed')
|
raise err('standard input/output (-) not allowed')
|
||||||
else:
|
else:
|
||||||
@ -70,6 +74,7 @@ class PathType(object):
|
|||||||
|
|
||||||
|
|
||||||
def restartContainerWithDomain(domain):
|
def restartContainerWithDomain(domain):
|
||||||
|
return
|
||||||
# client = docker.from_env()
|
# client = docker.from_env()
|
||||||
# container = client.containers.list(filters = {"label" : "com.github.SnowMB.traefik-certificate-extractor.restart_domain"})
|
# container = client.containers.list(filters = {"label" : "com.github.SnowMB.traefik-certificate-extractor.restart_domain"})
|
||||||
# for c in container:
|
# for c in container:
|
||||||
@ -79,7 +84,6 @@ def restartContainerWithDomain(domain):
|
|||||||
# c.restart()
|
# c.restart()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def createCerts(file):
|
def createCerts(file):
|
||||||
# Read JSON file
|
# Read JSON file
|
||||||
data = json.loads(open(file).read())
|
data = json.loads(open(file).read())
|
||||||
@ -153,12 +157,11 @@ def createCerts(file):
|
|||||||
with open(directory + name + '.chain.pem', 'w') as f:
|
with open(directory + name + '.chain.pem', 'w') as f:
|
||||||
f.write(chain)
|
f.write(chain)
|
||||||
|
|
||||||
print('Extracted certificate for: ' + name + (', ' + ', '.join(sans) if sans else ''))
|
print('Extracted certificate for: ' + name +
|
||||||
|
(', ' + ', '.join(sans) if sans else ''))
|
||||||
restartContainerWithDomain(name)
|
restartContainerWithDomain(name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Handler(FileSystemEventHandler):
|
class Handler(FileSystemEventHandler):
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
@ -180,10 +183,14 @@ class Handler(FileSystemEventHandler):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Extract traefik letsencrypt certificates.')
|
parser = argparse.ArgumentParser(
|
||||||
parser.add_argument('FILE', nargs='?', default='acme.json', type= PathType(exists=True), help='file that contains the traefik certificates (default acme.json)')
|
description='Extract traefik letsencrypt certificates.')
|
||||||
parser.add_argument('OUTPUT', nargs='?', default='.', type=PathType(type='dir'), help='output folder')
|
parser.add_argument('FILE', nargs='?', default='acme.json', type=PathType(
|
||||||
parser.add_argument('-f', '--flat',action='store_true', help='outputs all certificates into one folder')
|
exists=True), help='file that contains the traefik certificates (default acme.json)')
|
||||||
|
parser.add_argument('OUTPUT', nargs='?', default='.',
|
||||||
|
type=PathType(type='dir'), help='output folder')
|
||||||
|
parser.add_argument('-f', '--flat', action='store_true',
|
||||||
|
help='outputs all certificates into one folder')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print('DEBUG: watching path: ' + str(args.FILE))
|
print('DEBUG: watching path: ' + str(args.FILE))
|
||||||
@ -196,8 +203,6 @@ if __name__ == "__main__":
|
|||||||
if error.errno != errno.EEXIST:
|
if error.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Create event handler and observer
|
# Create event handler and observer
|
||||||
event_handler = Handler(args)
|
event_handler = Handler(args)
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user