Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions letsencrypt-aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# One day
PERSISTENT_SLEEP_INTERVAL = 60 * 60 * 24
DNS_TTL = 30
ENV_VAR = "LETSENCRYPT_AWS_CONFIG"
CONFIG_FILE = "config.json"


class Logger(object):
Expand Down Expand Up @@ -387,6 +389,32 @@ def acme_client_for_private_key(acme_directory_url, private_key):
)


def get_config():
logger = Logger()
aws_json = os.getenv(ENV_VAR)
if aws_json is not None:
try:
config = json.loads(aws_json)
return config
except ValueError:
logger.emit("Error parsing JSON")
else:
try:
script_dir = os.path.dirname(os.path.abspath(__file__))
except NameError:
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
try:
abs_file_path = os.path.join(script_dir, CONFIG_FILE)
try:
config = json.loads(open(abs_file_path).read())
return config
except ValueError:
logger.emit("Error parsing JSON")
except IOError:
logger.emit("AWS config cannot be found")
quit()


@click.group()
def cli():
pass
Expand Down Expand Up @@ -422,7 +450,7 @@ def update_certificates(persistent=False, force_issue=False):
# "acme_account_key": "s3://bucket/object",
# "acme_directory_url": "(optional)"
# }
config = json.loads(os.environ["LETSENCRYPT_AWS_CONFIG"])
config = get_config()
domains = config["domains"]
acme_directory_url = config.get(
"acme_directory_url", DEFAULT_ACME_DIRECTORY_URL
Expand Down Expand Up @@ -460,7 +488,7 @@ def update_certificates(persistent=False, force_issue=False):
)
def register(email, out):
logger = Logger()
config = json.loads(os.environ.get("LETSENCRYPT_AWS_CONFIG", "{}"))
config = get_config()
acme_directory_url = config.get(
"acme_directory_url", DEFAULT_ACME_DIRECTORY_URL
)
Expand Down