-
Notifications
You must be signed in to change notification settings - Fork 6
/
restic.go
69 lines (57 loc) · 1.83 KB
/
restic.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package restic
import (
"net/http"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
restserver "github.com/restic/rest-server"
)
func init() {
caddy.RegisterModule(ResticModule{})
}
type ResticModule struct {
RepositoryPath string `json:"repository_path,omitempty"`
AppendOnly bool `json:"append_only,omitempty"`
Debug bool `json:"debug,omitempty"`
MaxRepoSize int64 `json:"max_repo_size,omitempty"`
NoVerifyUpload bool `json:"no_verify_upload,omitempty"`
PrivateRepos bool `json:"private_repos,omitempty"`
Prometheus bool `json:"prometheus,omitempty"`
PrometheusNoAuth bool `json:"prometheus_no_auth,omitempty"`
HtpasswdPath string `json:"htpasswd_path,omitempty"`
NoAuth bool `json:"no_auth,omitempty"`
resticHandler http.Handler
}
func (ResticModule) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "http.handlers.restic",
New: func() caddy.Module { return new(ResticModule) },
}
}
func (m *ResticModule) Provision(ctx caddy.Context) error {
restConfig := restserver.Server{
Path: m.RepositoryPath,
NoAuth: m.NoAuth,
HtpasswdPath: m.HtpasswdPath,
AppendOnly: m.AppendOnly,
Debug: m.Debug,
MaxRepoSize: m.MaxRepoSize,
NoVerifyUpload: m.NoVerifyUpload,
PrivateRepos: m.PrivateRepos,
Prometheus: m.Prometheus,
PrometheusNoAuth: m.PrometheusNoAuth,
}
handler, err := restserver.NewHandler(&restConfig)
if err != nil {
return err
}
m.resticHandler = handler
return nil
}
func (m ResticModule) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
m.resticHandler.ServeHTTP(w, r)
return nil
}
var (
_ caddy.Provisioner = (*ResticModule)(nil)
_ caddyhttp.MiddlewareHandler = (*ResticModule)(nil)
)