-
Notifications
You must be signed in to change notification settings - Fork 5
/
impl.go
42 lines (37 loc) · 1022 Bytes
/
impl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package http_proxy
import (
"errors"
"fmt"
"net/http"
"strings"
"github.com/Cloud-Foundations/golib/pkg/constants"
"github.com/Cloud-Foundations/golib/pkg/log"
)
func newResponder(acmeProxy string,
logger log.DebugLogger) (*Responder, error) {
return &Responder{acmeProxy, logger}, nil
}
func (r *Responder) cleanup() {
resp, err := http.DefaultClient.Post(
"http://"+r.acmeProxy+constants.AcmeProxyCleanupResponses, "", nil)
if err != nil {
r.logger.Println(err)
} else if resp.StatusCode != http.StatusOK {
r.logger.Println(resp.Status)
}
}
func (r *Responder) respond(key, value string) error {
if !strings.HasPrefix(key, constants.AcmePath) {
return errors.New("not an ACME challenge response")
}
url := "http://" + r.acmeProxy + constants.AcmeProxyRecordResponse + "?" +
key
resp, err := http.DefaultClient.Post(url, "", strings.NewReader(value))
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("%s: %s\n", url, resp.Status)
}
return nil
}