cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
config/model.go
44lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "crypto/sha256" |
| 5 | "fmt" |
| 6 | "io" |
| 7 | ) |
| 8 | |
| 9 | // Forwarder represents a client side listener to forward traffic to the edge |
| 10 | type Forwarder struct { |
| 11 | URL string `json:"url"` |
| 12 | Listener string `json:"listener"` |
| 13 | TokenClientID string `json:"service_token_id" yaml:"serviceTokenID"` |
| 14 | TokenSecret string `json:"secret_token_id" yaml:"serviceTokenSecret"` |
| 15 | Destination string `json:"destination"` |
| 16 | IsFedramp bool `json:"is_fedramp" yaml:"isFedramp"` |
| 17 | } |
| 18 | |
| 19 | // Tunnel represents a tunnel that should be started |
| 20 | type Tunnel struct { |
| 21 | URL string `json:"url"` |
| 22 | Origin string `json:"origin"` |
| 23 | ProtocolType string `json:"type"` |
| 24 | } |
| 25 | |
| 26 | // Root is the base options to configure the service. |
| 27 | type Root struct { |
| 28 | LogDirectory string `json:"log_directory" yaml:"logDirectory,omitempty"` |
| 29 | LogLevel string `json:"log_level" yaml:"logLevel,omitempty"` |
| 30 | Forwarders []Forwarder `json:"forwarders,omitempty" yaml:"forwarders,omitempty"` |
| 31 | Tunnels []Tunnel `json:"tunnels,omitempty" yaml:"tunnels,omitempty"` |
| 32 | // `resolver` key is reserved for a removed feature (proxy-dns) and should not be used. |
| 33 | } |
| 34 | |
| 35 | // Hash returns the computed values to see if the forwarder values change |
| 36 | func (f *Forwarder) Hash() string { |
| 37 | h := sha256.New() |
| 38 | _, _ = io.WriteString(h, f.URL) |
| 39 | _, _ = io.WriteString(h, f.Listener) |
| 40 | _, _ = io.WriteString(h, f.TokenClientID) |
| 41 | _, _ = io.WriteString(h, f.TokenSecret) |
| 42 | _, _ = io.WriteString(h, f.Destination) |
| 43 | return fmt.Sprintf("%x", h.Sum(nil)) |
| 44 | } |