-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtypes.go
148 lines (118 loc) · 4.12 KB
/
types.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package internal
import (
"bytes"
"database/sql/driver"
"fmt"
"time"
"github.com/BurntSushi/toml"
)
type Settings struct {
TESTING bool `env:"TESTING"`
EMAIL string `env:"EMAIL,required"` // for Let's Encrypt
CONFIG_DIR string `env:"CONFIG_DIR,default=./config"`
CONFIG_RELOAD_TIME time.Duration `env:"CONFIG_RELOAD_TIME,default=5s"`
HTTPS_VALIDITY time.Duration `env:"HTTPS_VALIDITY,default=168h"` // 7 days
CONFIG_OUTPUT_DIR string `env:"CONFIG_OUTPUT_DIR,default=/etc/nginx/conf.d"`
LETSENCRYPT_CREDS_DIR string `env:"LETSENCRYPT_CREDS_DIR,default=./letsencrypt-credentials"`
LETSENCRYPT_DNS_PROPAGATION int `env:"LETSENCRYPT_DNS_PROPAGATION,default=120"`
SENTRY_DSN string `env:"SENTRY_DSN"`
}
type Config struct {
Service
Unique string
}
type ServiceMap map[string]Service
type Service struct {
Type string // HTTP, TCP default HTTP
Upstream []UpstreamServer
UpstreamOptions Options
// Parameters for HTTP proxy type
// Required for this type. Domains to proxy
Domains []string
// Default "/". will be used as "match" for default "Locations"
Location string
LocationOptions Options
Locations []Location
Ssl bool // Whether to generate HTTPS configutation
HttpsOnly bool // Wether to automatically redirect http to https. Default false
SslSource string // Required if Ssl = true. Options: manual, letsencrypt
CertPath string // If using manual sslSource
KeyPath string // If using manual sslSource
// If this is provided, the appropriate letsencrypt dns plugin is used
// NOTE: if using --dns-digitalocean, this should be "digitalocean" only
//
// Aside from the plugins from certbot, some other plugins have been implemented
// in this program (e.g. vultr)
LetsEncryptDNSPlugin string
// If these are provided, the manual certbot plugin will be used
// instead of the webroot or dns plugin which is automatic completed
// These should be paths to executables which will be the "hooks"
// See https://certbot.eff.org/docs/using.html#pre-and-post-validation-hooks
LetsEncryptAuthenticator string
LetsEncryptCleaner string
// parameters for TCP/UDP proxy type
Port uint // REQUIRED for this type
ServerOptions Options // Optional
// A http endpoint to send notifications about the configuration stauts
Webhook string
}
type Location struct {
// REQUIRED: the path of the request to proxy. See
Match string
// Optional: other options to be added in the location block
// See http://nginx.org/en/docs/http/ngx_http_core_module.html#location
Options Options
Upstream []UpstreamServer
// Optional: extra directives to the upstream block for fine tuning. See http://nginx.org/en/docs/http/ngx_http_upstream_module.html
UpstreamOptions Options
}
type UpstreamServer struct {
// REQUIRED: the address of the upstream server
// Must be reachable
Address string
// Optional: other parameters for the upstream. See http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server
Parameters []string
}
type Options = map[string]string
// Value implements the driver Valuer interface.
func (u ServiceMap) Value() (driver.Value, error) {
buf := &bytes.Buffer{}
err := toml.NewEncoder(buf).Encode(u)
return buf.Bytes(), err
}
// Scan implements the Scanner interface.
func (u *ServiceMap) Scan(value interface{}) error {
var err error
switch x := value.(type) {
case string:
_, err = toml.Decode(x, u)
case []byte:
_, err = toml.Decode(string(x), u)
case nil:
return nil
default:
err = fmt.Errorf("cannot scan type %T into type Service: %v", value, value)
}
return err
}
// Value implements the driver Valuer interface.
func (u Service) Value() (driver.Value, error) {
buf := &bytes.Buffer{}
err := toml.NewEncoder(buf).Encode(u)
return buf.Bytes(), err
}
// Scan implements the Scanner interface.
func (u *Service) Scan(value interface{}) error {
var err error
switch x := value.(type) {
case string:
_, err = toml.Decode(x, u)
case []byte:
_, err = toml.Decode(string(x), u)
case nil:
return nil
default:
err = fmt.Errorf("cannot scan type %T into type Service: %v", value, value)
}
return err
}