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.
|
// 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.
|
// 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) {
|
func createEnvFile(stack *portainer.Stack) (string, error) {
|
||||||
if stack.Env == nil || len(stack.Env) == 0 {
|
if len(stack.Env) == 0 {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ func (payload *edgeGroupCreatePayload) Validate(r *http.Request) error {
|
||||||
if govalidator.IsNull(payload.Name) {
|
if govalidator.IsNull(payload.Name) {
|
||||||
return errors.New("invalid Edge group 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")
|
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 errors.New("environment is mandatory for a static Edge group")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -27,10 +27,10 @@ func (payload *edgeGroupUpdatePayload) Validate(r *http.Request) error {
|
||||||
if govalidator.IsNull(payload.Name) {
|
if govalidator.IsNull(payload.Name) {
|
||||||
return errors.New("invalid Edge group 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")
|
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 errors.New("environments is mandatory for a static Edge group")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -69,7 +69,7 @@ func (payload *edgeJobCreateFromFileContentPayload) Validate(r *http.Request) er
|
||||||
return errors.New("invalid cron expression")
|
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")
|
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
|
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")
|
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) {
|
if govalidator.IsNull(payload.StackFileContent) {
|
||||||
return &InvalidPayloadError{msg: "Invalid stack file content"}
|
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 &InvalidPayloadError{msg: "Edge Groups are mandatory for an Edge stack"}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -221,7 +221,7 @@ func (payload *swarmStackFromGitRepositoryPayload) Validate(r *http.Request) err
|
||||||
payload.FilePathInRepository = filesystem.ManifestFileDefaultName
|
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 &InvalidPayloadError{msg: "Edge Groups are mandatory for an Edge stack"}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (payload *updateEdgeStackPayload) Validate(r *http.Request) error {
|
||||||
if payload.StackFileContent == "" {
|
if payload.StackFileContent == "" {
|
||||||
return errors.New("Invalid stack file content")
|
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 errors.New("Edge Groups are mandatory for an Edge stack")
|
||||||
}
|
}
|
||||||
return nil
|
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
|
// TeamLeaderAccess defines a security check for APIs require team leader privilege
|
||||||
//
|
//
|
||||||
// Bouncer operations are applied backwards:
|
// Bouncer operations are applied backwards:
|
||||||
// - Parse the JWT from the request and stored in context, user has to be authenticated
|
// - Parse the JWT from the request and stored in context, user has to be authenticated
|
||||||
// - Upgrade to the restricted request
|
// - Upgrade to the restricted request
|
||||||
// - User is admin or team leader
|
// - User is admin or team leader
|
||||||
func (bouncer *RequestBouncer) TeamLeaderAccess(h http.Handler) http.Handler {
|
func (bouncer *RequestBouncer) TeamLeaderAccess(h http.Handler) http.Handler {
|
||||||
h = bouncer.mwIsTeamLeader(h)
|
h = bouncer.mwIsTeamLeader(h)
|
||||||
h = bouncer.mwUpgradeToRestrictedRequest(h)
|
h = bouncer.mwUpgradeToRestrictedRequest(h)
|
||||||
|
@ -199,7 +199,7 @@ func (bouncer *RequestBouncer) mwCheckPortainerAuthorizations(next http.Handler,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = bouncer.dataStore.User().User(tokenData.ID)
|
_, 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)
|
httperror.WriteError(w, http.StatusUnauthorized, "Unauthorized", httperrors.ErrUnauthorized)
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|
|
@ -44,10 +44,7 @@ func (service *Service) CleanNAPWithOverridePolicies(
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasChange {
|
if hasChange {
|
||||||
err = kubecli.UpdateNamespaceAccessPolicies(accessPolicies)
|
return kubecli.UpdateNamespaceAccessPolicies(accessPolicies)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue