-
Notifications
You must be signed in to change notification settings - Fork 12
/
gw_name.go
66 lines (53 loc) · 1.54 KB
/
gw_name.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
package zos
import (
"fmt"
"io"
"github.com/pkg/errors"
"github.com/threefoldtech/zos/pkg/gridtypes"
)
// GatewayNameProxy definition. this will proxy name.<zos.domain> to backends
type GatewayNameProxy struct {
// Name the fully qualified domain name to use (cannot be present with Name)
Name string `json:"name"`
// Passthroug whether to pass tls traffic or not
TLSPassthrough bool `json:"tls_passthrough"`
// Backends are list of backend ips
Backends []Backend `json:"backends"`
}
func (g GatewayNameProxy) Valid(getter gridtypes.WorkloadGetter) error {
if !gwNameRegex.MatchString(g.Name) {
return fmt.Errorf("invalid name")
}
if len(g.Backends) == 0 {
return fmt.Errorf("backends list can not be empty")
}
for _, backend := range g.Backends {
if err := backend.Valid(); err != nil {
return errors.Wrapf(err, "failed to validate backend '%s'", backend)
}
}
return nil
}
func (g GatewayNameProxy) Challenge(w io.Writer) error {
if _, err := fmt.Fprintf(w, "%s", g.Name); err != nil {
return err
}
if _, err := fmt.Fprintf(w, "%t", g.TLSPassthrough); err != nil {
return err
}
for _, backend := range g.Backends {
if _, err := fmt.Fprintf(w, "%s", string(backend)); err != nil {
return err
}
}
return nil
}
func (g GatewayNameProxy) Capacity() (gridtypes.Capacity, error) {
// this has to be calculated per bytes served over the gw. so
// a special handler in reporting that need to calculate and report
// this.
return gridtypes.Capacity{}, nil
}
// GatewayProxyResult results
type GatewayFQDNResult struct {
}