-
Notifications
You must be signed in to change notification settings - Fork 19
/
config.go
160 lines (143 loc) · 7.14 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
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
// Copyright 2024 Fraunhofer AISEC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// $$\ $$\ $$\ $$\
// $$ | $$ |\__| $$ |
// $$$$$$$\ $$ | $$$$$$\ $$\ $$\ $$$$$$$ |$$\ $$$$$$\ $$$$$$\ $$$$$$\
// $$ _____|$$ |$$ __$$\ $$ | $$ |$$ __$$ |$$ |\_$$ _| $$ __$$\ $$ __$$\
// $$ / $$ |$$ / $$ |$$ | $$ |$$ / $$ |$$ | $$ | $$ / $$ |$$ | \__|
// $$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$\ $$ | $$ |$$ |
// \$$$$$$\ $$ |\$$$$$ |\$$$$$ |\$$$$$$ |$$ | \$$$ |\$$$$$ |$$ |
// \_______|\__| \______/ \______/ \_______|\__| \____/ \______/ \__|
//
// This file is part of Clouditor Community Edition.
package config
import (
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/oauth2/clientcredentials"
)
const (
APIDefaultUserFlag = "api-default-user"
APIDefaultPasswordFlag = "api-default-password"
APIKeyPasswordFlag = "api-key-password"
APIKeyPathFlag = "api-key-path"
APIKeySaveOnCreateFlag = "api-key-save-on-create"
APIgRPCPortFlag = "api-grpc-port"
APIHTTPPortFlag = "api-http-port"
APICORSAllowedOriginsFlags = "api-cors-allowed-origins"
APICORSAllowedHeadersFlags = "api-cors-allowed-headers"
APICORSAllowedMethodsFlags = "api-cors-allowed-methods"
APIJWKSURLFlag = "api-jwks-url"
APIStartEmbeddedOAuth2ServerFlag = "api-start-embedded-oauth-server"
ServiceOAuth2EndpointFlag = "service-oauth2-token-endpoint"
ServiceOAuth2ClientIDFlag = "service-oauth2-client-id"
ServiceOAuth2ClientSecretFlag = "service-oauth2-client-secret"
CloudServiceIDFlag = "cloud-service-id"
AssessmentURLFlag = "assessment-url"
OrchestratorURLFlag = "orchestrator-url"
EvidenceStoreURLFlag = "evidence-store-url"
DBUserNameFlag = "db-user-name"
DBPasswordFlag = "db-password"
DBHostFlag = "db-host"
DBNameFlag = "db-name"
DBPortFlag = "db-port"
DBSSLModeFlag = "db-ssl-mode"
DBInMemoryFlag = "db-in-memory"
CreateDefaultTargetFlag = "target-default-create"
DiscoveryAutoStartFlag = "discovery-auto-start"
DiscoveryProviderFlag = "discovery-provider"
DiscoveryResourceGroupFlag = "discovery-resource-group"
DiscoveryCSAFDomainFlag = "discovery-csaf-domain"
DashboardURLFlag = "dashboard-url"
LogLevelFlag = "log-level"
DefaultAPIDefaultUser = "clouditor"
DefaultAPIDefaultPassword = "clouditor"
DefaultAPIgRPCPort uint16 = 9090
DefaultAPIgRPCPortOrchestrator uint16 = 9090
DefaultAPIgRPCPortDiscovery uint16 = 9091
DefaultAPIgRPCPortEvidenceStore uint16 = 9092
DefaultAPIgRPCPortAssessment uint16 = 9093
DefaultAPIgRPCPortEvaluation uint16 = 9094
DefaultAPIHTTPPortOrchestrator uint16 = 8080
DefaultAPIHTTPPortDiscovery uint16 = 8081
DefaultAPIHTTPPortEvidenceStore uint16 = 8082
DefaultAPIHTTPPortAssessment uint16 = 8083
DefaultAPIHTTPPortEvaluation uint16 = 8084
DefaultAPIStartEmbeddedOAuth2Server = true
DefaultServiceOAuth2Endpoint = "http://localhost:8080/v1/auth/token"
DefaultServiceOAuth2ClientID = "clouditor"
DefaultServiceOAuth2ClientSecret = "clouditor"
DefaultOrchestratorURL = "localhost:9090"
DefaultEvidenceStoreURL = "localhost:9090"
DefaultAssessmentURL = "localhost:9090"
DefaultDBUserName = "postgres"
DefaultDBPassword = "postgres"
DefaultDBHost = "localhost"
DefaultDBName = "postgres"
DefaultDBPort uint16 = 5432
DefaultDBSSLMode = "disable"
DefaultDBInMemory = false
DefaultCreateDefaultTarget = true
DefaultDiscoveryAutoStart = false
DefaultDiscoveryResourceGroup = ""
DefaultCSAFDomain = ""
DefaultDashboardURL = "http://localhost:8080"
DefaultLogLevel = "info"
EnvPrefix = "CLOUDITOR"
)
var (
// DefaultAllowedOrigins contains a nil slice, as per default, no origins are allowed.
DefaultAllowedOrigins []string = nil
// DefaultAllowedHeaders contains sensible defaults for the Access-Control-Allow-Headers header.
// Please adjust accordingly in production using WithAllowedHeaders.
DefaultAllowedHeaders = []string{"Content-Type", "Accept", "Authorization"}
// DefaultAllowedMethods contains sensible defaults for the Access-Control-Allow-Methods header.
// Please adjust accordingly in production using WithAllowedMethods.
DefaultAllowedMethods = []string{"GET", "POST", "PUT", "DELETE"}
// DefaultAPIHTTPPort specifies the default port for the REST API.
DefaultAPIHTTPPort uint16 = 8080
)
const (
// DefaultCloudServiceID is the default service ID. Currently, our discoverers have no way to differentiate between different
// services, but we need this feature in the future. This serves as a default to already prepare the necessary
// structures for this feature.
DefaultCloudServiceID = "00000000-0000-0000-0000-000000000000"
EvidenceCollectorToolId = "Clouditor Evidences Collection"
)
func init() {
cobra.OnInitialize(InitConfig)
}
func InitCobra(engineCmd *cobra.Command) {
engineCmd.Flags().Bool(APIStartEmbeddedOAuth2ServerFlag, DefaultAPIStartEmbeddedOAuth2Server, "Specifies whether the embedded OAuth 2.0 authorization server is started as part of the REST gateway. For production workloads, an external authorization server is recommended.")
_ = viper.BindPFlag(APIStartEmbeddedOAuth2ServerFlag, engineCmd.Flags().Lookup(APIStartEmbeddedOAuth2ServerFlag))
}
func InitConfig() {
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.SetEnvPrefix(EnvPrefix)
viper.SetConfigName("clouditor")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AutomaticEnv()
_ = viper.ReadInConfig()
}
// ClientCredentials configures the OAuth 2.0 client credentials for a service
func ClientCredentials() *clientcredentials.Config {
return &clientcredentials.Config{
ClientID: viper.GetString(ServiceOAuth2ClientIDFlag),
ClientSecret: viper.GetString(ServiceOAuth2ClientSecretFlag),
TokenURL: viper.GetString(ServiceOAuth2EndpointFlag),
}
}