From 3e1a5dc04b649b51b0ce2a6742c5295613832382 Mon Sep 17 00:00:00 2001 From: xenolf Date: Tue, 3 Nov 2015 00:02:47 +0100 Subject: [PATCH] Add hooks to SimpleHTTP --- acme/simple_http_challenge.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/acme/simple_http_challenge.go b/acme/simple_http_challenge.go index 4d367085..a6b9b265 100644 --- a/acme/simple_http_challenge.go +++ b/acme/simple_http_challenge.go @@ -14,6 +14,12 @@ import ( "time" ) +// OnSimpleHTTPStart hook will get called BEFORE SimpleHTTP starts to listen on a port. +var OnSimpleHTTPStart func(string) + +// OnSimpleHTTPEnd hook will get called AFTER SimpleHTTP determined the status of the domain. +var OnSimpleHTTPEnd func(bool) + type simpleHTTPChallenge struct { jws *jws optPort string @@ -59,11 +65,17 @@ Loop: switch challengeResponse.Status { case "valid": + if OnSimpleHTTPEnd != nil { + OnSimpleHTTPEnd(true) + } logger().Print("The server validated our request") break Loop case "pending": break case "invalid": + if OnSimpleHTTPEnd != nil { + OnSimpleHTTPEnd(true) + } return errors.New("The server could not validate our request.") default: return errors.New("The server returned an unexpected state.") @@ -102,6 +114,9 @@ func (s *simpleHTTPChallenge) startHTTPSServer(domain string, token string) (net tlsConf.Certificates = []tls.Certificate{tempKeyPair} path := "/.well-known/acme-challenge/" + token + if OnSimpleHTTPStart != nil { + OnSimpleHTTPStart(path) + } // Allow for CLI override port := ":443"