Skip to content

Commit

Permalink
Merge pull request #57 from ca-gip/revert-56-feat/remove-go-ozzo
Browse files Browse the repository at this point in the history
Revert "Remove go-ozzo/ozzo-validation package"
  • Loading branch information
evrardjp-cagip authored Dec 23, 2024
2 parents bea3378 + f409d9e commit 2468b6a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 87 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23.3

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
github.com/gorilla/mux v1.8.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.5
Expand All @@ -19,6 +20,7 @@ require (
)

require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand All @@ -20,6 +22,8 @@ github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible h1:msy24VGS42fKO9K1vLz82/GeYW1cILu7Nuuj1N3BBkE=
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down
22 changes: 19 additions & 3 deletions internal/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strings"

"github.com/ca-gip/kubi/pkg/types"
validation "github.com/go-ozzo/ozzo-validation"
"github.com/go-ozzo/ozzo-validation/is"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -166,16 +168,30 @@ func MakeConfig() (*types.Config, error) {
BlackWhitelistNamespace: getEnv("BLACK_WHITELIST_NAMESPACE", "default"),
}

err = validateConfig(config)
errLdap := validateLdapConfig(&ldapConfig)
// TODO: Remove validation through ozzo-validation
err = validation.ValidateStruct(config,
validation.Field(&config.KubeToken, validation.Required),
validation.Field(&config.KubeCa, validation.Required, is.Base64),
validation.Field(&config.PublicApiServerURL, validation.Required, is.URL),
)
// TODO: Get rid of Check method
Check(err)

errLdap := validation.ValidateStruct(&ldapConfig,
validation.Field(&ldapConfig.UserBase, validation.Required, validation.Length(2, 200)),
validation.Field(&ldapConfig.GroupBase, validation.Required, validation.Length(2, 200)),
validation.Field(&ldapConfig.Host, validation.Required, is.URL),
validation.Field(&ldapConfig.BindDN, validation.Required, validation.Length(2, 200)),
validation.Field(&ldapConfig.BindPassword, validation.Required, validation.Length(2, 200)),
)

if err != nil {
Log.Error().Msgf(strings.Replace(err.Error(), "; ", "\n", -1))
return nil, err
}
if errLdap != nil {
Log.Error().Msgf(strings.Replace(errLdap.Error(), "; ", "\n", -1))
return nil, errLdap
return nil, err
}
return config, nil
}
Expand Down
84 changes: 0 additions & 84 deletions internal/utils/validationConfig.go

This file was deleted.

0 comments on commit 2468b6a

Please sign in to comment.