-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove go-ozzo/ozza-validation package
with that, we are no longer dependent on ozzo packages which is an external package and is no longer maintained without this, we are dependent on a external package that is very old
- Loading branch information
1 parent
75765fb
commit 6ed8c0b
Showing
4 changed files
with
87 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/base64" | ||
"errors" | ||
"net/url" | ||
"strconv" | ||
|
||
"github.com/ca-gip/kubi/pkg/types" | ||
) | ||
|
||
func validateBase64(s string) error { | ||
if _, err := base64.StdEncoding.DecodeString(s); err != nil { | ||
return errors.New("must be a valid base64 string") | ||
} | ||
return nil | ||
} | ||
|
||
func validateURL(s string) error { | ||
if _, err := url.ParseRequestURI(s); err != nil { | ||
return errors.New("must be a valid URL") | ||
} | ||
return nil | ||
} | ||
func validateLength(field string, min int, max int) error { | ||
length := len(field) | ||
if length < min || length > max { | ||
return errors.New("length must be between " + strconv.Itoa(min) + " and " + strconv.Itoa(max) + " characters") | ||
} | ||
return nil | ||
} | ||
|
||
func validateLdapConfig(ldapConfig *types.LdapConfig) error { | ||
if ldapConfig.UserBase == "" { | ||
return errors.New("UserBase is required") | ||
} | ||
if err := validateLength(ldapConfig.UserBase, 2, 200); err != nil { | ||
return err | ||
} | ||
if ldapConfig.GroupBase == "" { | ||
return errors.New("GroupBase is required") | ||
} | ||
if err := validateLength(ldapConfig.GroupBase, 2, 200); err != nil { | ||
return err | ||
} | ||
if ldapConfig.Host == "" { | ||
return errors.New("Host is required") | ||
Check failure on line 47 in internal/utils/validationConfig.go GitHub Actions / Build and test images (webhook, amd64)
Check failure on line 47 in internal/utils/validationConfig.go GitHub Actions / Build and test images (api, amd64)
|
||
} | ||
if err := validateURL(ldapConfig.Host); err != nil { | ||
return err | ||
} | ||
if ldapConfig.BindDN == "" { | ||
return errors.New("BindDN is required") | ||
} | ||
if err := validateLength(ldapConfig.BindDN, 2, 200); err != nil { | ||
return err | ||
} | ||
if ldapConfig.BindPassword == "" { | ||
return errors.New("BindPassword is required") | ||
} | ||
if err := validateLength(ldapConfig.BindPassword, 2, 200); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func validateConfig(config *types.Config) error { | ||
if config.KubeToken == "" { | ||
return errors.New("KubeToken is required") | ||
} | ||
if config.KubeCa == "" { | ||
return errors.New("KubeCa is required") | ||
} | ||
if err := validateBase64(config.KubeCa); err != nil { | ||
return err | ||
} | ||
if config.PublicApiServerURL == "" { | ||
return errors.New("PublicApiServerURL is required") | ||
} | ||
if err := validateURL(config.PublicApiServerURL); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |