forked from gitploy-io/gitploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
95 lines (76 loc) · 2.43 KB
/
config.go
File metadata and controls
95 lines (76 loc) · 2.43 KB
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
package main
import (
"log"
"entgo.io/ent/dialect"
"github.com/kelseyhightower/envconfig"
)
type (
Config struct {
Server
Store
Github
Slack
Webhook
Prometheus
}
Server struct {
DebugMode bool `default:"false" split_words:"true"`
ServerHost string `required:"true" split_words:"true"`
ServerProto string `required:"true" default:"https" split_words:"true"`
ServerProxyHost string `split_words:"true"`
ServerProxyProto string `default:"https" split_words:"true"`
OrganizationEntries []string `split_words:"true"`
MemberEntries []string `split_words:"true"`
AdminUsers []string `split_words:"true"`
License string `split_words:"true"`
TLSCert string `split_words:"true"`
TLSKey string `split_words:"true"`
}
Store struct {
StoreDriver string `required:"true" default:"sqlite3" split_words:"true"`
StoreSource string `required:"true" default:"file:/data/sqlite3.db?cache=shared&_fk=1" split_words:"true"`
}
Github struct {
GithubClientID string `split_words:"true"`
GithubClientSecret string `split_words:"true"`
GithubScopes []string `split_words:"true" default:"repo,read:user,read:org"`
GithubBaseURL string `split_words:"true"`
}
Slack struct {
SlackClientID string `split_words:"true"`
SlackClientSecret string `split_words:"true"`
SlackUserScopes []string `split_words:"true" default:""`
SlackBotScopes []string `split_words:"true" default:"commands,chat:write"`
}
Webhook struct {
WebhookSecret string `split_words:"true"`
}
Prometheus struct {
PrometheusEnabled bool `split_words:"true"`
PrometheusAuthSecret string `split_words:"true"`
}
)
func NewConfigFromEnv() (*Config, error) {
c := &Config{}
err := envconfig.Process("gitploy", c)
return c, err
}
func (c *Config) Validate() {
if !(c.ServerProto == "http" || c.ServerProto == "https") {
log.Fatal("GITPLOY_SERVER_PROTO have to be \"http\" or \"https\".")
}
if driver := c.Store.StoreDriver; driver != dialect.SQLite &&
driver != dialect.MySQL &&
driver != dialect.Postgres {
log.Fatal("GITPLOY_STORE_DRIVER have to be one of them: sqlite3, mysql, or postgres.")
}
}
func (c *Config) isGithubEnabled() bool {
return c.GithubClientID != "" && c.GithubClientSecret != ""
}
func (c *Config) isSlackEnabled() bool {
return c.SlackClientID != "" && c.SlackClientSecret != ""
}
func (c *Config) hasTLS() bool {
return c.TLSCert != "" && c.TLSKey != ""
}