Skip to content

Commit

Permalink
Create validate command
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Nov 2, 2023
1 parent 3837384 commit 4c10fc0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
62 changes: 62 additions & 0 deletions cmd/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright © 2023
//
// 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.

package cmd

import (
"fmt"

"github.com/equinor/radix-operator/pkg/apis/radixvalidators"
"github.com/equinor/radix-operator/pkg/apis/utils"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

// logoutCmd represents the logout command
var validateCmd = &cobra.Command{
Use: "validate",
Short: "Validate radixconfig.yaml",
Long: `Make sure the radixconfig.yaml file has correct structure, but doe not check for logic errors in the configuration`,
RunE: func(cmd *cobra.Command, args []string) error {

cmd.SilenceUsage = true

radixconfig, err := cmd.Flags().GetString("radixconfig")
if err != nil {
return err
}

ra, err := utils.GetRadixApplicationFromFile(radixconfig)
if err != nil {
fmt.Println(err)
return errors.New("Radix Config is invalid")
}

err = radixvalidators.IsRadixApplicationValid(ra)
if err == nil {
fmt.Println("Radixconfig is valid")
return nil
}

fmt.Println(err)

return errors.New("Radix Config is invalid")
},
}

func init() {
rootCmd.AddCommand(validateCmd)
validateCmd.Flags().StringP("radixconfig", "c", "radixconfig.yaml", "Path to radixconfig.yaml")
setVerbosePersistentFlag(validateCmd)
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.21.0
require (
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0
github.com/equinor/radix-common v1.5.0
github.com/equinor/radix-operator v1.43.0
github.com/equinor/radix-operator v1.99.1000-0.20231102102524-b631c3a617bb
github.com/fatih/color v1.15.0
github.com/go-openapi/errors v0.20.4
github.com/go-openapi/runtime v0.26.0
Expand All @@ -27,6 +27,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ github.com/equinor/radix-common v1.5.0 h1:z5hQHlKG2x16/NnV4b9ynf9n5ZageYUewE4MAN
github.com/equinor/radix-common v1.5.0/go.mod h1:UZ69U56VFtTxABi5JjGdaqn9Df5ilfTTqzUQ0riofVM=
github.com/equinor/radix-operator v1.43.0 h1:25vXiqy0BZrTu1VjA/kFgP7IGQ/UoFAtx0QCq0Irm8E=
github.com/equinor/radix-operator v1.43.0/go.mod h1:fa1yXgnhluKtqlBP+k/VldbkpFRpkK5eBGfGhuilqNc=
github.com/equinor/radix-operator v1.99.1000-0.20231102102524-b631c3a617bb h1:DYIK/6f7McCNF2tMAhsFfA/ml841NEItjzVCV7o1lug=
github.com/equinor/radix-operator v1.99.1000-0.20231102102524-b631c3a617bb/go.mod h1:j/Lb9bcof4L+KjtHVv5GD6MqYVsxHSGsliIP6C2F8YU=
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
Expand Down

0 comments on commit 4c10fc0

Please sign in to comment.