This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfiguration.go
101 lines (81 loc) · 2.28 KB
/
configuration.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
/*
Package config implements a way to to
handle configuration management using
viper.
*/
package config
import (
"strings"
"github.com/spf13/viper"
)
const (
authURI = "auth.uri"
serverHost = "server.host"
serverPort = "server.port"
metricsPort = "server.port"
sentryDSN = "sentry.dsn"
)
const (
defaultAuth = "https://auth.prod-preview.openshift.io"
defaultHost = "localhost"
defaultPort = "8099"
)
const (
prefix = "BUILD_TOOL_DETECTOR"
authKeysPath = "/api/token/keys"
)
// Configuration for build tool detector.
type Configuration struct {
viper *viper.Viper
}
// New returns a configuration with defaults set.
func New() *Configuration {
// Create new viper
configuration := Configuration{
viper: viper.New(),
}
// Setup configuration.
configuration.viper.SetEnvPrefix(prefix)
configuration.viper.AutomaticEnv()
configuration.viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
configuration.viper.SetTypeByDefaultValue(true)
configuration.setConfigDefaults()
return &configuration
}
// GetAuthServiceURL returns the server's port.
func (c *Configuration) GetAuthServiceURL() string {
return c.viper.GetString(authURI)
}
// GetHost returns the server's host.
func (c *Configuration) GetHost() string {
return c.viper.GetString(serverHost)
}
// GetPort returns the server's port.
func (c *Configuration) GetPort() string {
return c.viper.GetString(serverPort)
}
// GetMetricsPort returns the server's port.
func (c *Configuration) GetMetricsPort() string {
return c.viper.GetString(metricsPort)
}
// GetSentryDSN returs the github client id.
func (c *Configuration) GetSentryDSN() string {
return c.viper.GetString(sentryDSN)
}
// GetAuthKeysPath provides a URL path to be called for retrieving the keys.
func (c *Configuration) GetAuthKeysPath() string {
// Fixed with https://github.com/fabric8-services/fabric8-common/pull/25.
return authKeysPath
}
// GetDevModePrivateKey not used right now.
func (c *Configuration) GetDevModePrivateKey() []byte {
// No need for now
return nil
}
// setConfigDefaults sets defaults for configuration.
func (c *Configuration) setConfigDefaults() {
c.viper.SetDefault(authURI, defaultAuth)
c.viper.SetDefault(serverHost, defaultHost)
c.viper.SetDefault(serverPort, defaultPort)
c.viper.SetDefault(metricsPort, defaultPort)
}