Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Remove go-ozzo/ozzo-validation package" #57

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading