mirror of https://github.com/portainer/portainer
chore(nil): remove unnecessary nil checks EE-4847 (#8254)
parent
e529327851
commit
137ce37096
|
@ -139,7 +139,7 @@ func (manager *ComposeStackManager) fetchEndpointProxy(endpoint *portainer.Endpo
|
|||
// createEnvFile creates a file that would hold both "in-place" and default environment variables.
|
||||
// It will return the name of the file if the stack has "in-place" env vars, otherwise empty string.
|
||||
func createEnvFile(stack *portainer.Stack) (string, error) {
|
||||
if stack.Env == nil || len(stack.Env) == 0 {
|
||||
if len(stack.Env) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,10 @@ func (payload *edgeGroupCreatePayload) Validate(r *http.Request) error {
|
|||
if govalidator.IsNull(payload.Name) {
|
||||
return errors.New("invalid Edge group name")
|
||||
}
|
||||
if payload.Dynamic && (payload.TagIDs == nil || len(payload.TagIDs) == 0) {
|
||||
if payload.Dynamic && len(payload.TagIDs) == 0 {
|
||||
return errors.New("tagIDs is mandatory for a dynamic Edge group")
|
||||
}
|
||||
if !payload.Dynamic && (payload.Endpoints == nil || len(payload.Endpoints) == 0) {
|
||||
if !payload.Dynamic && len(payload.Endpoints) == 0 {
|
||||
return errors.New("environment is mandatory for a static Edge group")
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -27,10 +27,10 @@ func (payload *edgeGroupUpdatePayload) Validate(r *http.Request) error {
|
|||
if govalidator.IsNull(payload.Name) {
|
||||
return errors.New("invalid Edge group name")
|
||||
}
|
||||
if payload.Dynamic && (payload.TagIDs == nil || len(payload.TagIDs) == 0) {
|
||||
if payload.Dynamic && len(payload.TagIDs) == 0 {
|
||||
return errors.New("tagIDs is mandatory for a dynamic Edge group")
|
||||
}
|
||||
if !payload.Dynamic && (payload.Endpoints == nil || len(payload.Endpoints) == 0) {
|
||||
if !payload.Dynamic && len(payload.Endpoints) == 0 {
|
||||
return errors.New("environments is mandatory for a static Edge group")
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -69,7 +69,7 @@ func (payload *edgeJobCreateFromFileContentPayload) Validate(r *http.Request) er
|
|||
return errors.New("invalid cron expression")
|
||||
}
|
||||
|
||||
if (payload.Endpoints == nil || len(payload.Endpoints) == 0) && (payload.EdgeGroups == nil || len(payload.EdgeGroups) == 0) {
|
||||
if len(payload.Endpoints) == 0 && len(payload.EdgeGroups) == 0 {
|
||||
return errors.New("no environments or groups have been provided")
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ func (payload *edgeJobCreateFromFilePayload) Validate(r *http.Request) error {
|
|||
}
|
||||
payload.EdgeGroups = edgeGroups
|
||||
|
||||
if (payload.Endpoints == nil || len(payload.Endpoints) == 0) && (payload.EdgeGroups == nil || len(payload.EdgeGroups) == 0) {
|
||||
if len(payload.Endpoints) == 0 && len(payload.EdgeGroups) == 0 {
|
||||
return errors.New("no environments or groups have been provided")
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ func (payload *swarmStackFromFileContentPayload) Validate(r *http.Request) error
|
|||
if govalidator.IsNull(payload.StackFileContent) {
|
||||
return &InvalidPayloadError{msg: "Invalid stack file content"}
|
||||
}
|
||||
if payload.EdgeGroups == nil || len(payload.EdgeGroups) == 0 {
|
||||
if len(payload.EdgeGroups) == 0 {
|
||||
return &InvalidPayloadError{msg: "Edge Groups are mandatory for an Edge stack"}
|
||||
}
|
||||
return nil
|
||||
|
@ -221,7 +221,7 @@ func (payload *swarmStackFromGitRepositoryPayload) Validate(r *http.Request) err
|
|||
payload.FilePathInRepository = filesystem.ManifestFileDefaultName
|
||||
}
|
||||
}
|
||||
if payload.EdgeGroups == nil || len(payload.EdgeGroups) == 0 {
|
||||
if len(payload.EdgeGroups) == 0 {
|
||||
return &InvalidPayloadError{msg: "Edge Groups are mandatory for an Edge stack"}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -27,7 +27,7 @@ func (payload *updateEdgeStackPayload) Validate(r *http.Request) error {
|
|||
if payload.StackFileContent == "" {
|
||||
return errors.New("Invalid stack file content")
|
||||
}
|
||||
if payload.EdgeGroups != nil && len(payload.EdgeGroups) == 0 {
|
||||
if len(payload.EdgeGroups) == 0 {
|
||||
return errors.New("Edge Groups are mandatory for an Edge stack")
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -199,7 +199,7 @@ func (bouncer *RequestBouncer) mwCheckPortainerAuthorizations(next http.Handler,
|
|||
}
|
||||
|
||||
_, err = bouncer.dataStore.User().User(tokenData.ID)
|
||||
if err != nil && bouncer.dataStore.IsErrObjectNotFound(err) {
|
||||
if bouncer.dataStore.IsErrObjectNotFound(err) {
|
||||
httperror.WriteError(w, http.StatusUnauthorized, "Unauthorized", httperrors.ErrUnauthorized)
|
||||
return
|
||||
} else if err != nil {
|
||||
|
|
|
@ -44,10 +44,7 @@ func (service *Service) CleanNAPWithOverridePolicies(
|
|||
}
|
||||
|
||||
if hasChange {
|
||||
err = kubecli.UpdateNamespaceAccessPolicies(accessPolicies)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return kubecli.UpdateNamespaceAccessPolicies(accessPolicies)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue