Skip to content

Commit

Permalink
Merge pull request #1 from Estivador/fix/upgrade_to_traeffik_2
Browse files Browse the repository at this point in the history
Fix/upgrade to traeffik 2
  • Loading branch information
zxpower authored Jun 30, 2020
2 parents a33a96e + 84cfb31 commit f44a050
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Daniel Huisman
Copyright (c) 2018 Daniel Huisman, (c) 2020 Reinholds Zviedris

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Traefik Certificate Extractor

Tool to extract Let's Encrypt certificates from [Traefik](https://traefik.io/)'s ACME storage file. Can automatically restart containers using the Docker API.
Tool to extract Let's Encrypt certificates from [Traefik](https://traefik.io/)'s ACME storage file. Compatible with Traefik v1 and v2. Can automatically restart containers using the Docker API.

Originaly developed by [Daniel Huisman](https://github.com/DanielHuisman/traefik-certificate-extractor) and improved by [Marc Brückner](https://github.com/SnowMB).

Expand Down
19 changes: 18 additions & 1 deletion extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def createCerts(args):
# Read JSON file
data = json.loads(open(args.certificate).read())

# Determine Traefik version, extract data dictonary
key = 'Account'
if not key in data:
root_key = list(data.keys())[0]
data = data[root_key]
traefik_version = 2
else:
traefik_version = 1

# Determine ACME version
acme_version = 2 if 'acme-v02' in data['Account']['Registration']['uri'] else 1

Expand All @@ -107,11 +116,19 @@ def createCerts(args):
privatekey = c['Certificate']['PrivateKey']
fullchain = c['Certificate']['Certificate']
sans = c['Domains']['SANs']
elif acme_version == 2:
elif acme_version == 2 and traefik_version == 1:
name = c['Domain']['Main']
privatekey = c['Key']
fullchain = c['Certificate']
sans = c['Domain']['SANs']
elif acme_version and traefik_version == 2:
name = c['domain']['main']
privatekey = c['key']
fullchain = c['certificate']
if 'sans' in c['domain']:
sans = c['domain']['sans']
else:
sans = None

if (args.include and name not in args.include) or (args.exclude and name in args.exclude):
continue
Expand Down
7 changes: 7 additions & 0 deletions start_extractor.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/bash

docker run --name extractor -d \
-v /opt/traefik:/app/data \
-v ${PWD}/certs:/app/certs \
-v /var/run/docker.socket:/var/run/docker.socket \
estivadorio/traefik-certificate-extractor

0 comments on commit f44a050

Please sign in to comment.