-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathvalidate_config.go
71 lines (58 loc) · 1.7 KB
/
validate_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
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/gitpod-io/gitpod/common-go/log"
"github.com/gitpod-io/gitpod/installer/pkg/config"
"github.com/spf13/cobra"
)
var validateConfigOpts struct {
Config string
}
// validateConfigCmd represents the cluster command
var validateConfigCmd = &cobra.Command{
Use: "config",
Short: "Validate the deployment configuration",
RunE: func(cmd *cobra.Command, args []string) error {
if validateConfigOpts.Config == "" {
log.Fatal("missing --config")
}
_, cfgVersion, cfg, err := loadConfig(validateConfigOpts.Config)
if err != nil {
return err
}
if err = runConfigValidation(cfgVersion, cfg); err != nil {
return err
}
return nil
},
}
// runConfigValidation this will run the validation and print any validation errors
// It's silent if everything is fine
func runConfigValidation(version string, cfg interface{}) error {
apiVersion, err := config.LoadConfigVersion(version)
if err != nil {
return err
}
res, err := config.Validate(apiVersion, cfg)
if err != nil {
return err
}
res.Marshal(os.Stdout)
if len(res.Fatal) > 0 {
return fmt.Errorf("configuration invalid")
}
return nil
}
func init() {
validateCmd.AddCommand(validateConfigCmd)
dir, err := os.Getwd()
if err != nil {
log.WithError(err).Fatal("Failed to get working directory")
}
validateCmd.PersistentFlags().StringVarP(&validateConfigOpts.Config, "config", "c", getEnvvar("GITPOD_INSTALLER_CONFIG", filepath.Join(dir, "gitpod.config.yaml")), "path to the config file")
}