chore(nil): remove unnecessary nil checks EE-4847 (#8254)

pull/8259/head
andres-portainer 2 years ago committed by GitHub
parent e529327851
commit 137ce37096
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -81,9 +81,9 @@ func (bouncer *RequestBouncer) RestrictedAccess(h http.Handler) http.Handler {
// TeamLeaderAccess defines a security check for APIs require team leader privilege
//
// Bouncer operations are applied backwards:
// - Parse the JWT from the request and stored in context, user has to be authenticated
// - Upgrade to the restricted request
// - User is admin or team leader
// - Parse the JWT from the request and stored in context, user has to be authenticated
// - Upgrade to the restricted request
// - User is admin or team leader
func (bouncer *RequestBouncer) TeamLeaderAccess(h http.Handler) http.Handler {
h = bouncer.mwIsTeamLeader(h)
h = bouncer.mwUpgradeToRestrictedRequest(h)
@ -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…
Cancel
Save