/
model.go
117 lines (99 loc) · 3.23 KB
/
model.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
package config
import (
"fmt"
"os"
"strings"
)
const (
ExecutableGo = "go"
ForwarderKubernetes = "kubernetes"
ForwarderKubernetesRemote = "kubernetes-remote"
ForwarderProxy = "proxy"
ForwarderSSH = "ssh"
ForwarderSSHRemote = "ssh-remote"
)
var (
// AvailableForwarders lists all ready-to-use forwarders
AvailableForwarders = map[string]bool{
ForwarderKubernetes: true,
ForwarderKubernetesRemote: true,
ForwarderProxy: true,
ForwarderSSH: true,
ForwarderSSHRemote: true,
}
// ProxifiedForwarders lists all forwarders that will use the proxy
ProxifiedForwarders = map[string]bool{
ForwarderKubernetes: true,
ForwarderKubernetesRemote: true,
ForwarderProxy: true,
ForwarderSSH: true,
}
)
// Config represents the root configuration item
type Config struct {
GoPath string `yaml:"gopath"`
Projects []*Project `yaml:"projects"`
Watcher *Watcher `yaml:"watcher"`
}
// Project represents a project name, that could be a group of multiple projects
type Project struct {
Name string `yaml:"name"`
Applications []*Application `yaml:"local"`
Forwards []*Forward `yaml:"forward"`
}
// Application represents application information
type Application struct {
Name string `yaml:"name"`
Path string `yaml:"path"`
Executable string `yaml:"executable"`
Args []string `yaml:"args"`
StopExecutable string `yaml:"stop_executable"`
StopArgs []string `yaml:"stop_args"`
Hostname string `yaml:"hostname"`
Watch bool `yaml:"watch"`
Env map[string]string `yaml:"env"`
Setup []string `yaml:"setup"`
}
// GetPath returns the path dependending on overrided value or not
func (a *Application) GetPath() string {
path := a.Path
if strings.Contains(a.Path, "~") {
path = strings.Replace(a.Path, "~", "$HOME", -1)
}
switch a.Executable {
case ExecutableGo:
// First try to use the given directory, else, add the Go's $GOPATH
if _, err := os.Stat(path); os.IsNotExist(err) {
path = fmt.Sprintf("$GOPATH/src/%s", a.Path)
}
}
path = os.ExpandEnv(path)
return path
}
type Forward struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Values ForwardValues `yaml:"values"`
}
// IsProxified indicates if the current forward rule will use the proxy
func (f *Forward) IsProxified() bool {
if value, ok := ProxifiedForwarders[f.Type]; ok && value {
return true
}
return false
}
// ForwardValues represents the available values for each forward type
type ForwardValues struct {
Context string `yaml:"context"`
Namespace string `yaml:"namespace"`
Labels map[string]string `yaml:"labels"`
Hostname string `yaml:"hostname"`
ProxyHostname string `yaml:"proxy_hostname"`
Ports []string `yaml:"ports"`
Remote string `yaml:"remote"`
Args []string `yaml:"args"`
}
// Watcher represents the configuration values for the file watcher component
type Watcher struct {
Exclude []string `yaml:"exclude"`
}