-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
87 lines (67 loc) · 2.38 KB
/
config.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
package main
import (
"io"
"github.com/BurntSushi/toml"
)
type tomlConfig struct {
// Depot contains configuration for the application itself
Depot depotConfig `toml:"depot"`
// Repositories is a map of repository names to their info
Repositories map[string]*repositoryInfo `toml:"repositories"`
}
type depotConfig struct {
// An address where HTTP server should listen on
ListenAddress string `toml:"listen_address"`
// Whether listing repositories should be allowed or not
RepositoryListing bool `toml:"repository_listing"`
// Whether JSON REST API queries are allowed or not
APIEnabled bool `toml:"api_enabled"`
// Whether to save configuration changes done on runtime on Depot exit or not
SaveConfigChanges bool `toml:"save_config_changes"`
}
type repositoryInfo struct {
// Path specifies the repository location on filesystem
Path string `toml:"path"`
// Credentials are used for generic repository access authentication. If empty, then repository
// can be accessed freely by anyone
// Note that these credentials do not grant deployment access.
Credentials []string `toml:"credentials"`
// Deploy configures whether deployment to said repository is allowed or not
Deploy bool `toml:"deploy"`
// DeployCredentials are used to authenticate deployments.
// These credentials grant both access and deployment
DeployCredentials []string `toml:"deploy_credentials"`
// MaxArtifactSize defines maximum deployable file size in bytes. By default it's 32 megabytes
MaxArtifactSize uint64 `toml:"max_artifact_size"`
}
// Validates configuration
func (t *tomlConfig) Validate() error {
// Validate listen address
if len(t.Depot.ListenAddress) == 0 {
t.Depot.ListenAddress = ":5000"
}
// Validate repository information
for _, info := range t.Repositories {
if info.MaxArtifactSize == 0 {
info.MaxArtifactSize = 32 << 20
}
// Work around toml library not encoding nil arrays
if info.Credentials == nil || len(info.Credentials) == 0 {
info.Credentials = []string{}
}
if info.DeployCredentials == nil || len(info.DeployCredentials) == 0 {
info.DeployCredentials = []string{}
}
}
return nil
}
// Dumps configuration
func (t *tomlConfig) Dump(writer io.Writer) error {
w := toml.NewEncoder(writer)
w.Indent = " "
return w.Encode(t)
}
// Returns whether given repository is public or not
func (i *repositoryInfo) IsPublic() bool {
return len(i.Credentials) == 0
}