Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-daemon/cmd/validate-config.go
2498 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"encoding/json"
9
"fmt"
10
"io"
11
"os"
12
13
"github.com/spf13/cobra"
14
15
"github.com/gitpod-io/gitpod/common-go/log"
16
"github.com/gitpod-io/gitpod/ws-daemon/pkg/config"
17
)
18
19
// can be used with the helm-template like so:
20
// helm template ../../chart/ | sed -n '/ws-daemon-configmap.yaml/,$p' | sed '/---/q' | yq r - 'data[config.json]' | go run main.go validate-config
21
22
var validateConfigCmd = &cobra.Command{
23
Use: "validate-config",
24
Short: "reads a ws-daemon configuration from STDIN and validates it",
25
Run: func(cmd *cobra.Command, args []string) {
26
ctnt, err := io.ReadAll(os.Stdin)
27
if err != nil {
28
log.WithError(err).Fatal("cannot read configuration")
29
}
30
31
var cfg config.Config
32
err = json.Unmarshal(ctnt, &cfg)
33
if err != nil {
34
fmt.Println(string(ctnt))
35
log.WithError(err).Fatal("cannot unmarshal configuration")
36
}
37
38
enc := json.NewEncoder(os.Stdout)
39
enc.SetIndent("", " ")
40
_ = enc.Encode(cfg)
41
},
42
}
43
44
func init() {
45
rootCmd.AddCommand(validateConfigCmd)
46
}
47
48