-
Notifications
You must be signed in to change notification settings - Fork 126
/
server.go
138 lines (102 loc) · 4.77 KB
/
server.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
package server
import (
"crypto/tls"
"github.com/hatchet-dev/hatchet/internal/auth/cookie"
"github.com/hatchet-dev/hatchet/internal/config/database"
"github.com/hatchet-dev/hatchet/internal/config/shared"
"github.com/hatchet-dev/hatchet/internal/services/ingestor"
"github.com/hatchet-dev/hatchet/internal/taskqueue"
"github.com/hatchet-dev/hatchet/internal/validator"
"github.com/rs/zerolog"
"github.com/spf13/viper"
)
type ServerConfigFile struct {
Auth ConfigFileAuth `mapstructure:"auth" json:"auth,omitempty"`
Runtime ConfigFileRuntime `mapstructure:"runtime" json:"runtime,omitempty"`
TaskQueue TaskQueueConfigFile `mapstructure:"taskQueue" json:"taskQueue,omitempty"`
Services []string `mapstructure:"services" json:"services,omitempty" default:"[\"ticker\", \"grpc\", \"eventscontroller\", \"jobscontroller\"]"`
TLS shared.TLSConfigFile `mapstructure:"tls" json:"tls,omitempty"`
}
// General server runtime options
type ConfigFileRuntime struct {
// Port is the port that the core server listens on
Port int `mapstructure:"port" json:"port,omitempty" default:"8080"`
// ServerURL is the full server URL of the instance, including protocol.
ServerURL string `mapstructure:"url" json:"url,omitempty" default:"http://localhost:8080"`
// GRPCPort is the port that the grpc service listens on
GRPCPort int `mapstructure:"grpcPort" json:"grpcPort,omitempty" default:"7070"`
// GRPCBindAddress is the address that the grpc server binds to. Should set to 0.0.0.0 if binding in docker container.
GRPCBindAddress string `mapstructure:"grpcBindAddress" json:"grpcBindAddress,omitempty" default:"127.0.0.1"`
}
type ConfigFileAuth struct {
// RestrictedEmailDomains sets the restricted email domains for the instance.
RestrictedEmailDomains []string `mapstructure:"restrictedEmailDomains" json:"restrictedEmailDomains,omitempty"`
// BasedAuthEnabled controls whether email and password-based login is enabled for this
// Hatchet instance
BasicAuthEnabled bool `mapstructure:"basicAuthEnabled" json:"basicAuthEnabled,omitempty" default:"true"`
// SetEmailVerified controls whether the user's email is automatically set to verified
SetEmailVerified bool `mapstructure:"setEmailVerified" json:"setEmailVerified,omitempty" default:"false"`
// Configuration options for the cookie
Cookie ConfigFileAuthCookie `mapstructure:"cookie" json:"cookie,omitempty"`
}
type ConfigFileAuthCookie struct {
Name string `mapstructure:"name" json:"name,omitempty" default:"hatchet"`
Domain string `mapstructure:"domain" json:"domain,omitempty"`
Secrets string `mapstructure:"secrets" json:"secrets,omitempty"`
Insecure bool `mapstructure:"insecure" json:"insecure,omitempty" default:"false"`
}
type TaskQueueConfigFile struct {
Kind string `mapstructure:"kind" json:"kind,omitempty" validate:"required"`
RabbitMQ RabbitMQConfigFile `mapstructure:"rabbitmq" json:"rabbitmq,omitempty" validate:"required"`
}
type RabbitMQConfigFile struct {
URL string `mapstructure:"url" json:"url,omitempty" validate:"required" default:"amqp://user:password@localhost:5672/"`
}
type ServerConfig struct {
*database.Config
Auth ConfigFileAuth
Runtime ConfigFileRuntime
Services []string
Namespaces []string
TaskQueue taskqueue.TaskQueue
Logger *zerolog.Logger
TLSConfig *tls.Config
SessionStore *cookie.UserSessionStore
Validator validator.Validator
Ingestor ingestor.Ingestor
}
func (c *ServerConfig) HasService(name string) bool {
for _, s := range c.Services {
if s == name {
return true
}
}
return false
}
func BindAllEnv(v *viper.Viper) {
// runtime options
v.BindEnv("runtime.port", "SERVER_PORT")
v.BindEnv("runtime.url", "SERVER_URL")
v.BindEnv("runtime.grpcPort", "SERVER_GRPC_PORT")
v.BindEnv("runtime.grpcBindAddress", "SERVER_GRPC_BIND_ADDRESS")
v.BindEnv("services", "SERVER_SERVICES")
// auth options
v.BindEnv("auth.restrictedEmailDomains", "SERVER_AUTH_RESTRICTED_EMAIL_DOMAINS")
v.BindEnv("auth.basicAuthEnabled", "SERVER_AUTH_BASIC_AUTH_ENABLED")
v.BindEnv("auth.setEmailVerified", "SERVER_AUTH_SET_EMAIL_VERIFIED")
v.BindEnv("auth.cookie.name", "SERVER_AUTH_COOKIE_NAME")
v.BindEnv("auth.cookie.domain", "SERVER_AUTH_COOKIE_DOMAIN")
v.BindEnv("auth.cookie.secrets", "SERVER_AUTH_COOKIE_SECRETS")
v.BindEnv("auth.cookie.insecure", "SERVER_AUTH_COOKIE_INSECURE")
// task queue options
v.BindEnv("taskQueue.kind", "SERVER_TASKQUEUE_KIND")
v.BindEnv("taskQueue.rabbitmq.url", "SERVER_TASKQUEUE_RABBITMQ_URL")
// tls options
v.BindEnv("tls.tlsCert", "SERVER_TLS_CERT")
v.BindEnv("tls.tlsCertFile", "SERVER_TLS_CERT_FILE")
v.BindEnv("tls.tlsKey", "SERVER_TLS_KEY")
v.BindEnv("tls.tlsKeyFile", "SERVER_TLS_KEY_FILE")
v.BindEnv("tls.tlsRootCA", "SERVER_TLS_ROOT_CA")
v.BindEnv("tls.tlsRootCAFile", "SERVER_TLS_ROOT_CA_FILE")
v.BindEnv("tls.tlsServerName", "SERVER_TLS_SERVER_NAME")
}