Skip to content

Commit

Permalink
Depend on newer autocert package
Browse files Browse the repository at this point in the history
  • Loading branch information
Artyom Pervukhin committed Oct 29, 2016
1 parent b99f9b4 commit d1c3570
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Install:

Run:

leproxy -addr :https -map /path/to/mapping.yml -cache /path/to/letsencrypt.cache
leproxy -addr :https -map /path/to/mapping.yml -cacheDir /path/to/letsencrypt

`mapping.yml` contains host-to-backend mapping, where backend can be specified as:

Expand Down
27 changes: 15 additions & 12 deletions leproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@ import (
"sync"
"time"

"rsc.io/letsencrypt"

"gopkg.in/yaml.v2"

"github.com/artyom/autoflags"
"golang.org/x/crypto/acme/autocert"
"gopkg.in/yaml.v2"
)

func main() {
params := struct {
Addr string `flag:"addr,address to listen at"`
Conf string `flag:"map,file with host/backend mapping"`
Cache string `flag:"cache,path to letsencypt cache file"`
Cache string `flag:"cacheDir,path to directory to cache key and certificates"`
HSTS bool `flag:"hsts,add Strict-Transport-Security header"`
Email string `flag:"email,contact email address presented to letsencrypt CA"`

RTo time.Duration `flag:"rto,maximum duration before timing out read of the request"`
WTo time.Duration `flag:"wto,maximum duration before timing out write of the response"`
}{
Addr: ":https",
Conf: "mapping.yml",
Cache: "letsencrypt.cache",
Cache: "/var/cache/letsencrypt",
RTo: time.Minute,
WTo: 5 * time.Minute,
}
Expand All @@ -48,7 +47,7 @@ func main() {
if params.Cache == "" {
log.Fatal("no cache specified")
}
srv, err := setupServer(params.Addr, params.Conf, params.Cache, params.HSTS)
srv, err := setupServer(params.Addr, params.Conf, params.Cache, params.Email, params.HSTS)
if err != nil {
log.Fatal(err)
}
Expand All @@ -61,7 +60,7 @@ func main() {
log.Fatal(srv.ListenAndServeTLS("", ""))
}

func setupServer(addr, mapfile, cachefile string, hsts bool) (*http.Server, error) {
func setupServer(addr, mapfile, cacheDir, email string, hsts bool) (*http.Server, error) {
mapping, err := readMapping(mapfile)
if err != nil {
return nil, err
Expand All @@ -73,11 +72,15 @@ func setupServer(addr, mapfile, cachefile string, hsts bool) (*http.Server, erro
if hsts {
proxy = &hstsProxy{proxy}
}
var m letsencrypt.Manager
if err := m.CacheFile(cachefile); err != nil {
return nil, err
if fi, err := os.Stat(cacheDir); err == nil && !fi.IsDir() {
return nil, fmt.Errorf("path %q already exists and is not a directory", cacheDir)
}
m := autocert.Manager{
Prompt: autocert.AcceptTOS,
Cache: autocert.DirCache(cacheDir),
HostPolicy: autocert.HostWhitelist(keys(mapping)...),
Email: email,
}
m.SetHosts(keys(mapping))
srv := &http.Server{
Handler: proxy,
Addr: addr,
Expand Down

0 comments on commit d1c3570

Please sign in to comment.