From 8397157ec31384a1d65fc761db345655fd5167c5 Mon Sep 17 00:00:00 2001 From: ArrisLee Date: Tue, 15 Jun 2021 12:06:57 +1200 Subject: [PATCH] update payload validation rules --- api/http/handler/stacks/create_kubernetes_stack.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/http/handler/stacks/create_kubernetes_stack.go b/api/http/handler/stacks/create_kubernetes_stack.go index a8f924f75..23536980c 100644 --- a/api/http/handler/stacks/create_kubernetes_stack.go +++ b/api/http/handler/stacks/create_kubernetes_stack.go @@ -17,6 +17,8 @@ import ( "github.com/portainer/portainer/api/filesystem" ) +const defaultReferenceName = "refs/heads/master" + type kubernetesStringDeploymentPayload struct { ComposeFormat bool Namespace string @@ -51,12 +53,15 @@ func (payload *kubernetesGitDeploymentPayload) Validate(r *http.Request) error { if govalidator.IsNull(payload.RepositoryURL) || !govalidator.IsURL(payload.RepositoryURL) { return errors.New("Invalid repository URL. Must correspond to a valid URL format") } - if payload.RepositoryAuthentication && (govalidator.IsNull(payload.RepositoryUsername) || govalidator.IsNull(payload.RepositoryPassword)) { - return errors.New("Invalid repository credentials. Username and password must be specified when authentication is enabled") + if payload.RepositoryAuthentication && govalidator.IsNull(payload.RepositoryPassword) { + return errors.New("Invalid repository credentials. Password must be specified when authentication is enabled") } if govalidator.IsNull(payload.FilePathInRepository) { return errors.New("Invalid file path in repository") } + if govalidator.IsNull(payload.RepositoryReferenceName) { + payload.RepositoryReferenceName = defaultReferenceName + } return nil }