Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
Émile Ré
2025-12-11 16:58:42 +01:00
parent 5eddc95703
commit cab9d6f2ed
5 changed files with 33 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "pkg/validator/data/disposable-email-domains"]
path = pkg/validator/data/disposable-email-domains
url = git@github.com:disposable-email-domains/disposable-email-domains.git

View File

@@ -31,6 +31,7 @@ import (
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/probo"
"go.probo.inc/probo/pkg/statelesstoken"
"go.probo.inc/probo/pkg/validator"
)
type (
@@ -54,6 +55,14 @@ const (
TrustCenterAccessURLFormat = "https://%s/organizations/%s/trust-center/access"
)
func (tcar *TrustCenterAccessRequest) Validate() error {
v := validator.New()
v.Check(tcar.Email, "email", validator.NotOneOfSlice([]string{}))
return nil
}
func (s TrustCenterAccessService) ValidateToken(
ctx context.Context,
trustCenterID gid.GID,

View File

@@ -0,0 +1 @@
package validator

View File

@@ -225,6 +225,25 @@ func OneOfSlice[T any](allowed []T) ValidatorFunc {
}
}
// NotOneOfSlice validates that a value is not one of the values in the slice.
// Accepts a slice of any type. Compares by value first, then by string representation.
func NotOneOfSlice[T any](disallowed []T) ValidatorFunc {
oneOfSlice := OneOfSlice(disallowed)
return func(value any) *ValidationError {
err := oneOfSlice(disallowed)
if err == nil {
return newValidationError(
ErrorCodeInvalidEnum,
"must not be one of the disallowed values",
)
}
return nil
}
}
// OneOf validates that a value is one of the allowed values.
// Accepts strings or types that implement fmt.Stringer as variadic arguments.
func OneOf(allowed ...any) ValidatorFunc {