diff --git a/api/filesystem/serialize_per_dev_configs.go b/api/filesystem/serialize_per_dev_configs.go index c3f663c89..121c00710 100644 --- a/api/filesystem/serialize_per_dev_configs.go +++ b/api/filesystem/serialize_per_dev_configs.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/portainer/portainer/api" + portainer "github.com/portainer/portainer/api" ) type MultiFilterArgs []struct { diff --git a/api/filesystem/serialize_per_dev_configs_test.go b/api/filesystem/serialize_per_dev_configs_test.go index 394d39a14..6a2a5f33b 100644 --- a/api/filesystem/serialize_per_dev_configs_test.go +++ b/api/filesystem/serialize_per_dev_configs_test.go @@ -1,9 +1,10 @@ package filesystem import ( + "testing" + portainer "github.com/portainer/portainer/api" "github.com/stretchr/testify/assert" - "testing" ) func TestMultiFilterDirForPerDevConfigs(t *testing.T) { diff --git a/api/git/validate.go b/api/git/validate.go index 04a27a55a..8fc04abf6 100644 --- a/api/git/validate.go +++ b/api/git/validate.go @@ -8,7 +8,7 @@ import ( ) func ValidateRepoConfig(repoConfig *gittypes.RepoConfig) error { - if govalidator.IsNull(repoConfig.URL) || !govalidator.IsURL(repoConfig.URL) { + if len(repoConfig.URL) == 0 || !govalidator.IsURL(repoConfig.URL) { return httperrors.NewInvalidPayloadError("Invalid repository URL. Must correspond to a valid URL format") } @@ -17,7 +17,7 @@ func ValidateRepoConfig(repoConfig *gittypes.RepoConfig) error { } func ValidateRepoAuthentication(auth *gittypes.GitAuthentication) error { - if auth != nil && govalidator.IsNull(auth.Password) && auth.GitCredentialID == 0 { + if auth != nil && len(auth.Password) == 0 && auth.GitCredentialID == 0 { return httperrors.NewInvalidPayloadError("Invalid repository credentials. Password or GitCredentialID must be specified when authentication is enabled") } diff --git a/api/http/handler/auth/authenticate.go b/api/http/handler/auth/authenticate.go index b342f7b71..783d28691 100644 --- a/api/http/handler/auth/authenticate.go +++ b/api/http/handler/auth/authenticate.go @@ -12,7 +12,6 @@ import ( "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - "github.com/asaskevich/govalidator" "github.com/pkg/errors" "github.com/rs/zerolog/log" ) @@ -30,11 +29,11 @@ type authenticateResponse struct { } func (payload *authenticatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Username) { + if len(payload.Username) == 0 { return errors.New("Invalid username") } - if govalidator.IsNull(payload.Password) { + if len(payload.Password) == 0 { return errors.New("Invalid password") } diff --git a/api/http/handler/auth/authenticate_oauth.go b/api/http/handler/auth/authenticate_oauth.go index 58f18dd0e..bf5bbf9bf 100644 --- a/api/http/handler/auth/authenticate_oauth.go +++ b/api/http/handler/auth/authenticate_oauth.go @@ -9,7 +9,6 @@ import ( httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" - "github.com/asaskevich/govalidator" "github.com/rs/zerolog/log" ) @@ -19,7 +18,7 @@ type oauthPayload struct { } func (payload *oauthPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Code) { + if len(payload.Code) == 0 { return errors.New("Invalid OAuth authorization code") } diff --git a/api/http/handler/customtemplates/customtemplate_create.go b/api/http/handler/customtemplates/customtemplate_create.go index eed2d8b7e..22bff40bc 100644 --- a/api/http/handler/customtemplates/customtemplate_create.go +++ b/api/http/handler/customtemplates/customtemplate_create.go @@ -108,13 +108,13 @@ type customTemplateFromFileContentPayload struct { } func (payload *customTemplateFromFileContentPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Title) { + if len(payload.Title) == 0 { return errors.New("Invalid custom template title") } - if govalidator.IsNull(payload.Description) { + if len(payload.Description) == 0 { return errors.New("Invalid custom template description") } - if govalidator.IsNull(payload.FileContent) { + if len(payload.FileContent) == 0 { return errors.New("Invalid file content") } if payload.Type != portainer.KubernetesStack && payload.Platform != portainer.CustomTemplatePlatformLinux && payload.Platform != portainer.CustomTemplatePlatformWindows { @@ -132,7 +132,7 @@ func (payload *customTemplateFromFileContentPayload) Validate(r *http.Request) e } func isValidNote(note string) bool { - if govalidator.IsNull(note) { + if len(note) == 0 { return true } match, _ := regexp.MatchString(" tag is not supported") } - if payload.RepositoryAuthentication && (govalidator.IsNull(payload.RepositoryUsername) || govalidator.IsNull(payload.RepositoryPassword)) { + if payload.RepositoryAuthentication && (len(payload.RepositoryUsername) == 0 || len(payload.RepositoryPassword) == 0) { return errors.New("Invalid repository credentials. Username and password must be specified when authentication is enabled") } - if govalidator.IsNull(payload.ComposeFilePathInRepository) { + if len(payload.ComposeFilePathInRepository) == 0 { payload.ComposeFilePathInRepository = filesystem.ComposeFileDefaultName } diff --git a/api/http/handler/edgegroups/edgegroup_create.go b/api/http/handler/edgegroups/edgegroup_create.go index df12fc4c0..3988160f0 100644 --- a/api/http/handler/edgegroups/edgegroup_create.go +++ b/api/http/handler/edgegroups/edgegroup_create.go @@ -9,8 +9,6 @@ import ( "github.com/portainer/portainer/api/internal/endpointutils" httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" - - "github.com/asaskevich/govalidator" ) type edgeGroupCreatePayload struct { @@ -22,7 +20,7 @@ type edgeGroupCreatePayload struct { } func (payload *edgeGroupCreatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("invalid Edge group name") } diff --git a/api/http/handler/edgegroups/edgegroup_update.go b/api/http/handler/edgegroups/edgegroup_update.go index f4aaa5b92..c724a228c 100644 --- a/api/http/handler/edgegroups/edgegroup_update.go +++ b/api/http/handler/edgegroups/edgegroup_update.go @@ -12,8 +12,6 @@ import ( "github.com/portainer/portainer/api/slicesx" httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" - - "github.com/asaskevich/govalidator" ) type edgeGroupUpdatePayload struct { @@ -25,7 +23,7 @@ type edgeGroupUpdatePayload struct { } func (payload *edgeGroupUpdatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("invalid Edge group name") } diff --git a/api/http/handler/edgejobs/edgejob_create.go b/api/http/handler/edgejobs/edgejob_create.go index 631fc3426..6c019bd62 100644 --- a/api/http/handler/edgejobs/edgejob_create.go +++ b/api/http/handler/edgejobs/edgejob_create.go @@ -49,7 +49,7 @@ type edgeJobCreateFromFileContentPayload struct { } func (payload *edgeJobCreateFromFileContentPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("invalid Edge job name") } @@ -57,7 +57,7 @@ func (payload *edgeJobCreateFromFileContentPayload) Validate(r *http.Request) er return errors.New("invalid Edge job name format. Allowed characters are: [a-zA-Z0-9_.-]") } - if govalidator.IsNull(payload.CronExpression) { + if len(payload.CronExpression) == 0 { return errors.New("invalid cron expression") } @@ -65,7 +65,7 @@ func (payload *edgeJobCreateFromFileContentPayload) Validate(r *http.Request) er return errors.New("no environments or groups have been provided") } - if govalidator.IsNull(payload.FileContent) { + if len(payload.FileContent) == 0 { return errors.New("invalid script file content") } diff --git a/api/http/handler/edgestacks/edgestack_create_git.go b/api/http/handler/edgestacks/edgestack_create_git.go index de7b5199d..a1992db06 100644 --- a/api/http/handler/edgestacks/edgestack_create_git.go +++ b/api/http/handler/edgestacks/edgestack_create_git.go @@ -46,15 +46,15 @@ type edgeStackFromGitRepositoryPayload struct { } func (payload *edgeStackFromGitRepositoryPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return httperrors.NewInvalidPayloadError("Invalid stack name") } - if govalidator.IsNull(payload.RepositoryURL) || !govalidator.IsURL(payload.RepositoryURL) { + if len(payload.RepositoryURL) == 0 || !govalidator.IsURL(payload.RepositoryURL) { return httperrors.NewInvalidPayloadError("Invalid repository URL. Must correspond to a valid URL format") } - if payload.RepositoryAuthentication && govalidator.IsNull(payload.RepositoryPassword) { + if payload.RepositoryAuthentication && len(payload.RepositoryPassword) == 0 { return httperrors.NewInvalidPayloadError("Invalid repository credentials. Password must be specified when authentication is enabled") } @@ -62,7 +62,7 @@ func (payload *edgeStackFromGitRepositoryPayload) Validate(r *http.Request) erro return httperrors.NewInvalidPayloadError("Invalid deployment type") } - if govalidator.IsNull(payload.FilePathInRepository) { + if len(payload.FilePathInRepository) == 0 { switch payload.DeploymentType { case portainer.EdgeStackDeploymentCompose: payload.FilePathInRepository = filesystem.ComposeFileDefaultName diff --git a/api/http/handler/edgestacks/edgestack_create_string.go b/api/http/handler/edgestacks/edgestack_create_string.go index eb008c228..81f24fe95 100644 --- a/api/http/handler/edgestacks/edgestack_create_string.go +++ b/api/http/handler/edgestacks/edgestack_create_string.go @@ -10,7 +10,6 @@ import ( httperrors "github.com/portainer/portainer/api/http/errors" "github.com/portainer/portainer/pkg/libhttp/request" - "github.com/asaskevich/govalidator" "github.com/pkg/errors" ) @@ -33,11 +32,11 @@ type edgeStackFromStringPayload struct { } func (payload *edgeStackFromStringPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return httperrors.NewInvalidPayloadError("Invalid stack name") } - if govalidator.IsNull(payload.StackFileContent) { + if len(payload.StackFileContent) == 0 { return httperrors.NewInvalidPayloadError("Invalid stack file content") } diff --git a/api/http/handler/edgestacks/edgestack_status_update.go b/api/http/handler/edgestacks/edgestack_status_update.go index df51fb426..ab12aa09b 100644 --- a/api/http/handler/edgestacks/edgestack_status_update.go +++ b/api/http/handler/edgestacks/edgestack_status_update.go @@ -11,7 +11,6 @@ import ( "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - "github.com/asaskevich/govalidator" "github.com/rs/zerolog/log" ) @@ -31,7 +30,7 @@ func (payload *updateStatusPayload) Validate(r *http.Request) error { return errors.New("invalid EnvironmentID") } - if *payload.Status == portainer.EdgeStackStatusError && govalidator.IsNull(payload.Error) { + if *payload.Status == portainer.EdgeStackStatusError && len(payload.Error) == 0 { return errors.New("error message is mandatory when status is error") } diff --git a/api/http/handler/endpointgroups/endpointgroup_create.go b/api/http/handler/endpointgroups/endpointgroup_create.go index e5538a738..dde16910f 100644 --- a/api/http/handler/endpointgroups/endpointgroup_create.go +++ b/api/http/handler/endpointgroups/endpointgroup_create.go @@ -9,8 +9,6 @@ import ( httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - - "github.com/asaskevich/govalidator" ) type endpointGroupCreatePayload struct { @@ -25,7 +23,7 @@ type endpointGroupCreatePayload struct { } func (payload *endpointGroupCreatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("invalid environment group name") } diff --git a/api/http/handler/gitops/git_repo_file_preview.go b/api/http/handler/gitops/git_repo_file_preview.go index 0ce5b1cdc..28e8fafec 100644 --- a/api/http/handler/gitops/git_repo_file_preview.go +++ b/api/http/handler/gitops/git_repo_file_preview.go @@ -29,15 +29,15 @@ type repositoryFilePreviewPayload struct { } func (payload *repositoryFilePreviewPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Repository) || !govalidator.IsURL(payload.Repository) { + if len(payload.Repository) == 0 || !govalidator.IsURL(payload.Repository) { return errors.New("invalid repository URL. Must correspond to a valid URL format") } - if govalidator.IsNull(payload.Reference) { + if len(payload.Reference) == 0 { payload.Reference = "refs/heads/main" } - if govalidator.IsNull(payload.TargetFile) { + if len(payload.TargetFile) == 0 { return errors.New("invalid target filename") } diff --git a/api/http/handler/registries/registry_create.go b/api/http/handler/registries/registry_create.go index 1ca316b78..c9d73d4f9 100644 --- a/api/http/handler/registries/registry_create.go +++ b/api/http/handler/registries/registry_create.go @@ -11,8 +11,6 @@ import ( httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - - "github.com/asaskevich/govalidator" ) type registryCreatePayload struct { @@ -46,19 +44,19 @@ type registryCreatePayload struct { } func (payload *registryCreatePayload) Validate(_ *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("Invalid registry name") } - if govalidator.IsNull(payload.URL) { + if len(payload.URL) == 0 { return errors.New("Invalid registry URL") } if payload.Authentication { - if govalidator.IsNull(payload.Username) || govalidator.IsNull(payload.Password) { + if len(payload.Username) == 0 || len(payload.Password) == 0 { return errors.New("Invalid credentials. Username and password must be specified when authentication is enabled") } if payload.Type == portainer.EcrRegistry { - if govalidator.IsNull(payload.Ecr.Region) { + if len(payload.Ecr.Region) == 0 { return errors.New("invalid credentials: access key ID, secret access key and region must be specified when authentication is enabled") } } diff --git a/api/http/handler/resourcecontrols/resourcecontrol_create.go b/api/http/handler/resourcecontrols/resourcecontrol_create.go index fae0c7dd9..f4e03a109 100644 --- a/api/http/handler/resourcecontrols/resourcecontrol_create.go +++ b/api/http/handler/resourcecontrols/resourcecontrol_create.go @@ -8,8 +8,6 @@ import ( httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - - "github.com/asaskevich/govalidator" ) type resourceControlCreatePayload struct { @@ -33,7 +31,7 @@ type resourceControlCreatePayload struct { var errResourceControlAlreadyExists = errors.New("A resource control is already applied on this resource") //http/resourceControl func (payload *resourceControlCreatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.ResourceID) { + if len(payload.ResourceID) == 0 { return errors.New("invalid payload: invalid resource identifier") } diff --git a/api/http/handler/stacks/create_compose_stack.go b/api/http/handler/stacks/create_compose_stack.go index 38b383aca..dce39337a 100644 --- a/api/http/handler/stacks/create_compose_stack.go +++ b/api/http/handler/stacks/create_compose_stack.go @@ -32,11 +32,11 @@ type composeStackFromFileContentPayload struct { } func (payload *composeStackFromFileContentPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("Invalid stack name") } - if govalidator.IsNull(payload.StackFileContent) { + if len(payload.StackFileContent) == 0 { return errors.New("Invalid stack file content") } return nil @@ -202,13 +202,13 @@ func createStackPayloadFromComposeGitPayload(name, repoUrl, repoReference, repoU } func (payload *composeStackFromGitRepositoryPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("Invalid stack name") } - if govalidator.IsNull(payload.RepositoryURL) || !govalidator.IsURL(payload.RepositoryURL) { + if len(payload.RepositoryURL) == 0 || !govalidator.IsURL(payload.RepositoryURL) { return errors.New("Invalid repository URL. Must correspond to a valid URL format") } - if payload.RepositoryAuthentication && govalidator.IsNull(payload.RepositoryPassword) { + if payload.RepositoryAuthentication && len(payload.RepositoryPassword) == 0 { return errors.New("Invalid repository credentials. Password must be specified when authentication is enabled") } if err := update.ValidateAutoUpdateSettings(payload.AutoUpdate); err != nil { diff --git a/api/http/handler/stacks/create_kubernetes_stack.go b/api/http/handler/stacks/create_kubernetes_stack.go index 1375604c8..6be5c3ee1 100644 --- a/api/http/handler/stacks/create_kubernetes_stack.go +++ b/api/http/handler/stacks/create_kubernetes_stack.go @@ -88,7 +88,7 @@ func createStackPayloadFromK8sUrlPayload(name, namespace, manifestUrl string, co } func (payload *kubernetesStringDeploymentPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.StackFileContent) { + if len(payload.StackFileContent) == 0 { return errors.New("Invalid stack file content") } @@ -96,15 +96,15 @@ func (payload *kubernetesStringDeploymentPayload) Validate(r *http.Request) erro } func (payload *kubernetesGitDeploymentPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.RepositoryURL) || !govalidator.IsURL(payload.RepositoryURL) { + if len(payload.RepositoryURL) == 0 || !govalidator.IsURL(payload.RepositoryURL) { return errors.New("Invalid repository URL. Must correspond to a valid URL format") } - if payload.RepositoryAuthentication && govalidator.IsNull(payload.RepositoryPassword) { + if payload.RepositoryAuthentication && len(payload.RepositoryPassword) == 0 { return errors.New("Invalid repository credentials. Password must be specified when authentication is enabled") } - if govalidator.IsNull(payload.ManifestFile) { + if len(payload.ManifestFile) == 0 { return errors.New("Invalid manifest file in repository") } @@ -112,7 +112,7 @@ func (payload *kubernetesGitDeploymentPayload) Validate(r *http.Request) error { } func (payload *kubernetesManifestURLDeploymentPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.ManifestURL) || !govalidator.IsURL(payload.ManifestURL) { + if len(payload.ManifestURL) == 0 || !govalidator.IsURL(payload.ManifestURL) { return errors.New("Invalid manifest URL") } diff --git a/api/http/handler/stacks/create_swarm_stack.go b/api/http/handler/stacks/create_swarm_stack.go index b87339c9d..4603b6d6b 100644 --- a/api/http/handler/stacks/create_swarm_stack.go +++ b/api/http/handler/stacks/create_swarm_stack.go @@ -30,13 +30,13 @@ type swarmStackFromFileContentPayload struct { } func (payload *swarmStackFromFileContentPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("Invalid stack name") } - if govalidator.IsNull(payload.SwarmID) { + if len(payload.SwarmID) == 0 { return errors.New("Invalid Swarm ID") } - if govalidator.IsNull(payload.StackFileContent) { + if len(payload.StackFileContent) == 0 { return errors.New("Invalid stack file content") } return nil @@ -136,16 +136,16 @@ type swarmStackFromGitRepositoryPayload struct { } func (payload *swarmStackFromGitRepositoryPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("Invalid stack name") } - if govalidator.IsNull(payload.SwarmID) { + if len(payload.SwarmID) == 0 { return errors.New("Invalid Swarm ID") } - if govalidator.IsNull(payload.RepositoryURL) || !govalidator.IsURL(payload.RepositoryURL) { + if len(payload.RepositoryURL) == 0 || !govalidator.IsURL(payload.RepositoryURL) { return errors.New("Invalid repository URL. Must correspond to a valid URL format") } - if payload.RepositoryAuthentication && govalidator.IsNull(payload.RepositoryPassword) { + if payload.RepositoryAuthentication && len(payload.RepositoryPassword) == 0 { return errors.New("Invalid repository credentials. Password must be specified when authentication is enabled") } if err := update.ValidateAutoUpdateSettings(payload.AutoUpdate); err != nil { diff --git a/api/http/handler/stacks/stack_update.go b/api/http/handler/stacks/stack_update.go index c4ed63117..2ff44dfe8 100644 --- a/api/http/handler/stacks/stack_update.go +++ b/api/http/handler/stacks/stack_update.go @@ -14,7 +14,6 @@ import ( "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - "github.com/asaskevich/govalidator" "github.com/pkg/errors" "github.com/rs/zerolog/log" ) @@ -29,7 +28,7 @@ type updateComposeStackPayload struct { } func (payload *updateComposeStackPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.StackFileContent) { + if len(payload.StackFileContent) == 0 { return errors.New("Invalid stack file content") } @@ -48,7 +47,7 @@ type updateSwarmStackPayload struct { } func (payload *updateSwarmStackPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.StackFileContent) { + if len(payload.StackFileContent) == 0 { return errors.New("Invalid stack file content") } diff --git a/api/http/handler/stacks/update_kubernetes_stack.go b/api/http/handler/stacks/update_kubernetes_stack.go index a7e316b07..750efc21b 100644 --- a/api/http/handler/stacks/update_kubernetes_stack.go +++ b/api/http/handler/stacks/update_kubernetes_stack.go @@ -16,7 +16,6 @@ import ( httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" - "github.com/asaskevich/govalidator" "github.com/pkg/errors" "github.com/rs/zerolog/log" ) @@ -37,7 +36,7 @@ type kubernetesGitStackUpdatePayload struct { } func (payload *kubernetesFileStackUpdatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.StackFileContent) { + if len(payload.StackFileContent) == 0 { return errors.New("Invalid stack file content") } diff --git a/api/http/handler/tags/tag_create.go b/api/http/handler/tags/tag_create.go index ee5cabcab..d2daa5f85 100644 --- a/api/http/handler/tags/tag_create.go +++ b/api/http/handler/tags/tag_create.go @@ -8,8 +8,6 @@ import ( "github.com/portainer/portainer/api/dataservices" httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" - - "github.com/asaskevich/govalidator" ) type tagCreatePayload struct { @@ -17,7 +15,7 @@ type tagCreatePayload struct { } func (payload *tagCreatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("invalid tag name") } diff --git a/api/http/handler/teams/team_create.go b/api/http/handler/teams/team_create.go index 50f4be323..6cc16bb6f 100644 --- a/api/http/handler/teams/team_create.go +++ b/api/http/handler/teams/team_create.go @@ -8,8 +8,6 @@ import ( httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - - "github.com/asaskevich/govalidator" ) type teamCreatePayload struct { @@ -20,7 +18,7 @@ type teamCreatePayload struct { } func (payload *teamCreatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Name) { + if len(payload.Name) == 0 { return errors.New("Invalid team name") } return nil diff --git a/api/http/handler/templates/template_file_old.go b/api/http/handler/templates/template_file_old.go index 5c6d2e1bd..91ac038c5 100644 --- a/api/http/handler/templates/template_file_old.go +++ b/api/http/handler/templates/template_file_old.go @@ -8,8 +8,6 @@ import ( "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" "github.com/rs/zerolog/log" - - "github.com/asaskevich/govalidator" ) type filePayload struct { @@ -20,11 +18,11 @@ type filePayload struct { } func (payload *filePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.RepositoryURL) { + if len(payload.RepositoryURL) == 0 { return errors.New("Invalid repository url") } - if govalidator.IsNull(payload.ComposeFilePathInRepository) { + if len(payload.ComposeFilePathInRepository) == 0 { return errors.New("Invalid file path") } diff --git a/api/http/handler/users/admin_init.go b/api/http/handler/users/admin_init.go index 753ec97a6..f7d75931f 100644 --- a/api/http/handler/users/admin_init.go +++ b/api/http/handler/users/admin_init.go @@ -3,13 +3,12 @@ package users import ( "errors" "net/http" + "strings" portainer "github.com/portainer/portainer/api" httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - - "github.com/asaskevich/govalidator" ) type adminInitPayload struct { @@ -20,10 +19,10 @@ type adminInitPayload struct { } func (payload *adminInitPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Username) || govalidator.Contains(payload.Username, " ") { + if len(payload.Username) == 0 || strings.Contains(payload.Username, " ") { return errors.New("Invalid username. Must not contain any whitespace") } - if govalidator.IsNull(payload.Password) { + if len(payload.Password) == 0 { return errors.New("Invalid password") } return nil diff --git a/api/http/handler/users/user_create.go b/api/http/handler/users/user_create.go index 13da0f94c..627e00d15 100644 --- a/api/http/handler/users/user_create.go +++ b/api/http/handler/users/user_create.go @@ -3,13 +3,12 @@ package users import ( "errors" "net/http" + "strings" portainer "github.com/portainer/portainer/api" httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - - "github.com/asaskevich/govalidator" ) type userCreatePayload struct { @@ -20,7 +19,7 @@ type userCreatePayload struct { } func (payload *userCreatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Username) || govalidator.Contains(payload.Username, " ") { + if len(payload.Username) == 0 || strings.Contains(payload.Username, " ") { return errors.New("Invalid username. Must not contain any whitespace") } diff --git a/api/http/handler/users/user_create_access_token.go b/api/http/handler/users/user_create_access_token.go index ad67a0e83..a2e63cf5c 100644 --- a/api/http/handler/users/user_create_access_token.go +++ b/api/http/handler/users/user_create_access_token.go @@ -21,7 +21,7 @@ type userAccessTokenCreatePayload struct { } func (payload *userAccessTokenCreatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Description) { + if len(payload.Description) == 0 { return errors.New("invalid description: cannot be empty") } if govalidator.HasWhitespaceOnly(payload.Description) { @@ -100,7 +100,7 @@ func (handler *Handler) userCreateAccessToken(w http.ResponseWriter, r *http.Req if internalAuth { // Internal auth requires the password field and must not be empty - if govalidator.IsNull(payload.Password) { + if len(payload.Password) == 0 { return httperror.BadRequest("Invalid request payload", errors.New("invalid password: cannot be empty")) } diff --git a/api/http/handler/users/user_update.go b/api/http/handler/users/user_update.go index 30a0eda3d..cc290ddad 100644 --- a/api/http/handler/users/user_update.go +++ b/api/http/handler/users/user_update.go @@ -4,6 +4,7 @@ import ( "cmp" "errors" "net/http" + "strings" "time" portainer "github.com/portainer/portainer/api" @@ -12,8 +13,6 @@ import ( httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - - "github.com/asaskevich/govalidator" ) type themePayload struct { @@ -33,7 +32,7 @@ type userUpdatePayload struct { } func (payload *userUpdatePayload) Validate(r *http.Request) error { - if govalidator.Contains(payload.Username, " ") { + if strings.Contains(payload.Username, " ") { return errors.New("invalid username. Must not contain any whitespace") } diff --git a/api/http/handler/users/user_update_password.go b/api/http/handler/users/user_update_password.go index 3a73f74b6..6ca3905df 100644 --- a/api/http/handler/users/user_update_password.go +++ b/api/http/handler/users/user_update_password.go @@ -11,8 +11,6 @@ import ( httperror "github.com/portainer/portainer/pkg/libhttp/error" "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - - "github.com/asaskevich/govalidator" ) type userUpdatePasswordPayload struct { @@ -23,10 +21,10 @@ type userUpdatePasswordPayload struct { } func (payload *userUpdatePasswordPayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.Password) { + if len(payload.Password) == 0 { return errors.New("Invalid current password") } - if govalidator.IsNull(payload.NewPassword) { + if len(payload.NewPassword) == 0 { return errors.New("Invalid new password") } return nil diff --git a/api/http/handler/webhooks/webhook_create.go b/api/http/handler/webhooks/webhook_create.go index 8845a5a7c..b69e93db3 100644 --- a/api/http/handler/webhooks/webhook_create.go +++ b/api/http/handler/webhooks/webhook_create.go @@ -11,7 +11,6 @@ import ( "github.com/portainer/portainer/pkg/libhttp/request" "github.com/portainer/portainer/pkg/libhttp/response" - "github.com/asaskevich/govalidator" "github.com/gofrs/uuid" ) @@ -24,7 +23,7 @@ type webhookCreatePayload struct { } func (payload *webhookCreatePayload) Validate(r *http.Request) error { - if govalidator.IsNull(payload.ResourceID) { + if len(payload.ResourceID) == 0 { return errors.New("Invalid ResourceID") } if payload.EndpointID == 0 {