-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.go
224 lines (189 loc) · 5.3 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package model
import "reflect"
// Wizard represents a wizard configuration.
type Wizard struct {
Name string
Provider string
Plan string
Region string
SSH string `survey:"ssh"`
SSHPort string `survey:"ssh_port"`
BanTime string `survey:"fail2ban_bantime"`
MaxRetry string `survey:"fail2ban_maxretry"`
Features []string
Java string
Heap string
RconPw string `survey:"rconpw"`
Edition string
Version string
Properties string
}
// Spec represents a specification configuration.
type Spec struct {
Monitoring Monitoring `json:"monitoring"`
Server Server `yaml:"server"`
Minecraft Minecraft `yaml:"minecraft"`
Proxy Proxy `yaml:"proxy"`
}
// Proxy represents a proxy configuration.
type Proxy struct {
Java Java `yaml:"java"`
Type string `yaml:"type"`
Version string `yaml:"version"`
}
// Monitoring represents a monitoring configuration.
type Monitoring struct {
Enabled bool `json:"enabled"`
}
// Server represents a server configuration.
type Server struct {
Size string `yaml:"size"`
SSH SSH `yaml:"ssh"`
Cloud string `yaml:"cloud"`
Region string `yaml:"region"`
Port int `yaml:"port"`
VolumeSize int `yaml:"volumeSize"`
Spot bool `yaml:"spot"`
Arm bool `yaml:"arm"`
}
// SSH represents a SSH configuration.
type SSH struct {
Port int `yaml:"port"`
PublicKeyFile string `yaml:"publickeyfile"`
PublicKey string `yaml:"publickey"`
Fail2ban Fail2ban `yaml:"fail2ban"`
}
// Fail2ban represents a fail2ban configuration.
type Fail2ban struct {
Bantime int `yaml:"bantime"`
Maxretry int `yaml:"maxretry"`
Ignoreip string `yaml:"ignoreip"`
}
// Minecraft represents a minecraft configuration.
type Minecraft struct {
Java Java `yaml:"java"`
Properties string `yaml:"properties"`
Edition string `yaml:"edition"`
Version string `yaml:"version"`
Eula bool `yaml:"eula"`
}
// Java represents a java configuration.
type Java struct {
Xmx string `yaml:"xmx"`
Xms string `yaml:"xms"`
Options []string `yaml:"options"`
OpenJDK int `yaml:"openjdk"`
Rcon Rcon `yaml:"rcon"`
}
// Rcon represents a rcon configuration.
type Rcon struct {
Password string `yaml:"password"`
Enabled bool `yaml:"enabled"`
Port int `yaml:"port"`
Broadcast bool `yaml:"broadcast"`
}
// Metadata represents a metadata configuration.
type Metadata struct {
Name string `yaml:"name"`
}
// MinecraftResource represents a minecraft resource.
type MinecraftResource struct {
Spec Spec `yaml:"spec"`
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Metadata Metadata `yaml:"metadata"`
}
func (m *MinecraftResource) GetProperties() string {
return m.Spec.Minecraft.Properties
}
func (m *MinecraftResource) GetName() string {
return m.Metadata.Name
}
func (m *MinecraftResource) GetCloud() string {
return m.Spec.Server.Cloud
}
func (m *MinecraftResource) GetSSHPort() int {
return m.Spec.Server.SSH.Port
}
func (m *MinecraftResource) GetSSHKeyFile() string {
return m.Spec.Server.SSH.PublicKeyFile
}
func (m *MinecraftResource) GetSSHPublicKey() string {
return m.Spec.Server.SSH.PublicKey
}
func (m *MinecraftResource) GetFail2Ban() Fail2ban {
return m.Spec.Server.SSH.Fail2ban
}
func (m *MinecraftResource) GetRegion() string {
return m.Spec.Server.Region
}
func (m *MinecraftResource) GetSize() string {
return m.Spec.Server.Size
}
func (m *MinecraftResource) GetEdition() string {
if m.IsProxyServer() {
return m.Spec.Proxy.Type
}
return m.Spec.Minecraft.Edition
}
func (m *MinecraftResource) GetVolumeSize() int {
return m.Spec.Server.VolumeSize
}
func (m *MinecraftResource) GetVersion() string {
return m.Spec.Minecraft.Version
}
func (m *MinecraftResource) GetPort() int {
return m.Spec.Server.Port
}
func (m *MinecraftResource) GetJDKVersion() int {
return m.Spec.Minecraft.Java.OpenJDK
}
func (m *MinecraftResource) GetRCONPort() int {
if m.IsProxyServer() {
return m.Spec.Proxy.Java.Rcon.Port
}
return m.Spec.Minecraft.Java.Rcon.Port
}
func (m *MinecraftResource) HasRCON() bool {
if m.IsProxyServer() {
return m.Spec.Proxy.Java.Rcon.Enabled
}
return m.Spec.Minecraft.Java.Rcon.Enabled
}
func (m *MinecraftResource) HasMonitoring() bool {
return m.Spec.Monitoring.Enabled
}
func (m *MinecraftResource) GetRCONPassword() string {
if m.IsProxyServer() {
return m.Spec.Proxy.Java.Rcon.Password
}
return m.Spec.Minecraft.Java.Rcon.Password
}
func (m *MinecraftResource) IsProxyServer() bool {
return reflect.DeepEqual(m.Spec.Minecraft, Minecraft{})
}
func (m *MinecraftResource) IsSpot() bool {
return m.Spec.Server.Spot
}
func (m *MinecraftResource) IsArm() bool {
return m.Spec.Server.Arm
}
const (
PROVIDER_HETZNER = "hetzner"
PROVIDER_DIGITALOCEAN = "do"
PROVIDER_CIVO = "civo"
PROVIDER_SCALEWAY = "scaleway"
PROVIDER_AKAMAI = "akamai"
PROVIDER_OVH = "ovh"
PROVIDER_EQUINIX = "equinix"
PROVIDER_GCE = "gce"
PROVIDER_VULTR = "vultr"
PROVIDER_AZURE = "azure"
PROVIDER_OCI = "oci"
PROVIDER_IONOS = "ionos"
PROVIDER_AWS = "aws"
PROVIDER_VEXXHOST = "vexxhost"
PROVIDER_FUGA = "fuga"
PROVIDER_EXOSCALE = "exoscale"
PROVIDER_MULTIPASS = "multipass"
)