check

package
v1.0.4-gitspaces-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxIdentifierLength = 100
)

Variables

View Source
var (
	ErrDisplayNameLength = &ValidationError{
		fmt.Sprintf("DisplayName has to be between %d and %d in length.", minDisplayNameLength, maxDisplayNameLength),
	}

	ErrDescriptionTooLong = &ValidationError{
		fmt.Sprintf("Description can be at most %d in length.", maxDescriptionLength),
	}

	ErrIdentifierLength = &ValidationError{
		fmt.Sprintf(
			"Identifier has to be between %d and %d in length.",
			minIdentifierLength,
			MaxIdentifierLength,
		),
	}
	ErrIdentifierRegex = &ValidationError{
		"Identifier can only contain the following characters [a-zA-Z0-9-_.].",
	}

	ErrEmailLen = &ValidationError{
		fmt.Sprintf("Email address has to be within %d and %d characters", minEmailLength, maxEmailLength),
	}

	ErrInvalidCharacters = &ValidationError{"Input contains invalid characters."}

	ErrIllegalRootSpaceIdentifier = &ValidationError{
		fmt.Sprintf("The following identifiers are not allowed for a root space: %v", illegalRootSpaceIdentifiers),
	}

	ErrIllegalRepoSpaceIdentifierSuffix = &ValidationError{
		fmt.Sprintf("Space and repository identifiers cannot end with %q.", illegalRepoSpaceIdentifierSuffix),
	}

	ErrIllegalPrincipalUID = &ValidationError{
		fmt.Sprintf("Principal UID is not allowed to be %q.", types.AnonymousPrincipalUID),
	}
)
View Source
var (
	ErrPathEmpty = &ValidationError{
		"Path can't be empty.",
	}
	ErrPathInvalidDepth = &ValidationError{
		fmt.Sprintf("A path can have at most %d segments (%d for spaces).",
			maxPathSegments, maxPathSegmentsForSpace),
	}
	ErrEmptyPathSegment = &ValidationError{
		"Empty segments are not allowed.",
	}
	ErrPathCantBeginOrEndWithSeparator = &ValidationError{
		fmt.Sprintf("Path can't start or end with the separator ('%s').", types.PathSeparator),
	}
)
View Source
var (
	ErrServiceAccountParentTypeIsInvalid = &ValidationError{
		"Provided parent type is invalid.",
	}
	ErrServiceAccountParentIDInvalid = &ValidationError{
		"ParentID required - Global service accounts are not supported.",
	}
)
View Source
var (
	ErrTokenLifeTimeOutOfBounds = &ValidationError{
		"The life time of a token has to be between 1 day and 365 days.",
	}
	ErrTokenLifeTimeRequired = &ValidationError{
		"The life time of a token is required.",
	}
)
View Source
var (
	ErrAny = &ValidationError{}
)
View Source
var (
	// ErrPasswordLength is returned when the password
	// is outside of the allowed length.
	ErrPasswordLength = &ValidationError{
		fmt.Sprintf("Password has to be within %d and %d characters", minPasswordLength, maxPasswordLength),
	}
)

WireSet provides a wire set for this package.

Functions

func Description

func Description(description string) error

Description checks the provided description and returns an error if it isn't valid.

func DisplayName

func DisplayName(displayName string) error

DisplayName checks the provided display name and returns an error if it isn't valid.

func Email

func Email(email string) error

Email checks the provided email and returns an error if it isn't valid.

func ForControlCharacters

func ForControlCharacters(s string) error

ForControlCharacters ensures that there are no control characters in the provided string.

func Identifier

func Identifier(identifier string) error

Identifier checks the provided identifier and returns an error if it isn't valid.

func IsPathTooDeep

func IsPathTooDeep(path string, isSpace bool) bool

IsPathTooDeep Checks if the provided path is too long. NOTE: A repository path can be one deeper than a space path (as otherwise the space would be useless).

func Password

func Password(pw string) error

Password returns true if the Password is valid. TODO: add proper password checks.

func Path

func Path(path string, isSpace bool, identifierCheck SpaceIdentifier) error

Path checks the provided path and returns an error in it isn't valid.

func PathDepth

func PathDepth(path string, isSpace bool) error

PathDepth Checks the depth of the provided path.

func PrincipalUIDDefault

func PrincipalUIDDefault(uid string) error

PrincipalUIDDefault performs the default Principal UID check.

func RepoIdentifierDefault

func RepoIdentifierDefault(identifier string) error

RepoIdentifierDefault performs the default Identifier check and also blocks illegal repo identifiers.

func ServiceAccountParent

func ServiceAccountParent(parentType enum.ParentResourceType, parentID int64) error

ServiceAccountParent verifies the remaining fields of a service account that aren't inhereted from principal.

func SpaceIdentifierDefault

func SpaceIdentifierDefault(identifier string, isRoot bool) error

SpaceIdentifierDefault performs the default Identifier check and also blocks illegal root space Identifiers.

func TokenLifetime

func TokenLifetime(lifetime *time.Duration, optional bool) error

TokenLifetime returns true if the lifetime is valid for a token.

Types

type PrincipalUID

type PrincipalUID func(uid string) error

PrincipalUID is an abstraction of a validation method that verifies principal UIDs. NOTE: Enables support for different principal UID formats.

func ProvidePrincipalUIDCheck

func ProvidePrincipalUIDCheck() PrincipalUID

type RepoIdentifier

type RepoIdentifier func(identifier string) error

func ProvideRepoIdentifierCheck

func ProvideRepoIdentifierCheck() RepoIdentifier

type SpaceIdentifier

type SpaceIdentifier func(identifier string, isRoot bool) error

SpaceIdentifier is an abstraction of a validation method that returns true iff the Identifier is valid to be used in a resource path for repo/space. NOTE: Enables support for different path formats.

func ProvideSpaceIdentifierCheck

func ProvideSpaceIdentifierCheck() SpaceIdentifier

type ValidationError

type ValidationError struct {
	// contains filtered or unexported fields
}

ValidationError is error returned for any validation errors. WARNING: This error will be printed to the user as is!

func NewValidationError

func NewValidationError(msg string) *ValidationError

func NewValidationErrorf

func NewValidationErrorf(format string, args ...interface{}) *ValidationError

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Is

func (e *ValidationError) Is(target error) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL