Skip to content

delete and retry expired authorizations #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def load_file(directory, filename):
return False
return False

def delete_file(directory, filename):
try:
s3.Object(cfg.S3CONFIGBUCKET, directory + "/" + filename).delete()
return True
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'NoSuchKey':
return False
return False

# Verify the bucket exists
def check_bucket(bucketname):
Expand Down Expand Up @@ -165,6 +173,14 @@ def authorize_domain(user, domain):
authzr = AcmeAuthorization(user=user, domain=domain['DOMAIN'])
status = authzr.authorize()

# If authorization is expired, delete authzr file and try again with a new one
if (status == 'expired'):
logger.info('Authorization for {} expired, deleting and recreating'.format(domain['DOMAIN']))
if delete_file(domain['DOMAIN'], authzrfilename):
return authorize_domain(user, domain)
else:
logger.warn('Error deleting file: {}'.format(authzrfilename))

# save the (new/updated) authorization response
save_file(domain['DOMAIN'], authzrfilename, authzr.serialize())
logger.debug(authzr.serialize())
Expand Down
3 changes: 3 additions & 0 deletions simple_acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ def authorize(self):
for c in result['challenges']:
if 'error' in c:
logger.debug(c['error']['detail'])
elif status == 404 and result['detail'] == 'Expired authorization':
status = 'expired'

return status

def complete_challenges(self, challenge_type, func_challenge, func_verifier):
Expand Down