mirror of
https://github.com/portainer/portainer.git
synced 2025-08-01 03:45:22 +02:00
chore(edgestacks): clean up EE-4851 (#8260)
This commit is contained in:
parent
137ce37096
commit
2fc518f221
7 changed files with 23 additions and 35 deletions
|
@ -340,11 +340,9 @@ func (handler *Handler) storeManifestFromGitRepository(stackFolder string, relat
|
||||||
projectPath = handler.FileService.GetEdgeStackProjectPath(stackFolder)
|
projectPath = handler.FileService.GetEdgeStackProjectPath(stackFolder)
|
||||||
repositoryUsername := ""
|
repositoryUsername := ""
|
||||||
repositoryPassword := ""
|
repositoryPassword := ""
|
||||||
if repositoryConfig.Authentication != nil {
|
if repositoryConfig.Authentication != nil && repositoryConfig.Authentication.Password != "" {
|
||||||
if repositoryConfig.Authentication.Password != "" {
|
repositoryUsername = repositoryConfig.Authentication.Username
|
||||||
repositoryUsername = repositoryConfig.Authentication.Username
|
repositoryPassword = repositoryConfig.Authentication.Password
|
||||||
repositoryPassword = repositoryConfig.Authentication.Password
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = handler.GitService.CloneRepository(projectPath, repositoryConfig.URL, repositoryConfig.ReferenceName, repositoryUsername, repositoryPassword)
|
err = handler.GitService.CloneRepository(projectPath, repositoryConfig.URL, repositoryConfig.ReferenceName, repositoryUsername, repositoryPassword)
|
||||||
|
|
|
@ -33,10 +33,8 @@ func (handler *Handler) edgeStackFile(w http.ResponseWriter, r *http.Request) *h
|
||||||
}
|
}
|
||||||
|
|
||||||
stack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID))
|
stack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID))
|
||||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
if err != nil {
|
||||||
return httperror.NotFound("Unable to find an edge stack with the specified identifier inside the database", err)
|
return handler.handlerDBErr(err, "Unable to find an edge stack with the specified identifier inside the database")
|
||||||
} else if err != nil {
|
|
||||||
return httperror.InternalServerError("Unable to find an edge stack with the specified identifier inside the database", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := stack.EntryPoint
|
fileName := stack.EntryPoint
|
||||||
|
|
|
@ -29,10 +29,8 @@ func (handler *Handler) edgeStackInspect(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeStack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(edgeStackID))
|
edgeStack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(edgeStackID))
|
||||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
if err != nil {
|
||||||
return httperror.NotFound("Unable to find an edge stack with the specified identifier inside the database", err)
|
return handler.handlerDBErr(err, "Unable to find an edge stack with the specified identifier inside the database")
|
||||||
} else if err != nil {
|
|
||||||
return httperror.InternalServerError("Unable to find an edge stack with the specified identifier inside the database", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.JSON(w, edgeStack)
|
return response.JSON(w, edgeStack)
|
||||||
|
|
|
@ -10,16 +10,6 @@ import (
|
||||||
"github.com/portainer/portainer/api/http/middlewares"
|
"github.com/portainer/portainer/api/http/middlewares"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (handler *Handler) handlerDBErr(err error, msg string) *httperror.HandlerError {
|
|
||||||
httpErr := httperror.InternalServerError(msg, err)
|
|
||||||
|
|
||||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
|
||||||
httpErr.StatusCode = http.StatusNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return httpErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// @id EdgeStackStatusDelete
|
// @id EdgeStackStatusDelete
|
||||||
// @summary Delete an EdgeStack status
|
// @summary Delete an EdgeStack status
|
||||||
// @description Authorized only if the request is done by an Edge Environment(Endpoint)
|
// @description Authorized only if the request is done by an Edge Environment(Endpoint)
|
||||||
|
|
|
@ -60,10 +60,8 @@ func (handler *Handler) edgeStackStatusUpdate(w http.ResponseWriter, r *http.Req
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint, err := handler.DataStore.Endpoint().Endpoint(payload.EndpointID)
|
endpoint, err := handler.DataStore.Endpoint().Endpoint(payload.EndpointID)
|
||||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
if err != nil {
|
||||||
return httperror.NotFound("Unable to find an environment with the specified identifier inside the database", err)
|
return handler.handlerDBErr(err, "Unable to find an environment with the specified identifier inside the database")
|
||||||
} else if err != nil {
|
|
||||||
return httperror.InternalServerError("Unable to find an environment with the specified identifier inside the database", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = handler.requestBouncer.AuthorizedEdgeEndpointOperation(r, endpoint)
|
err = handler.requestBouncer.AuthorizedEdgeEndpointOperation(r, endpoint)
|
||||||
|
@ -98,10 +96,8 @@ func (handler *Handler) edgeStackStatusUpdate(w http.ResponseWriter, r *http.Req
|
||||||
|
|
||||||
stack = *edgeStack
|
stack = *edgeStack
|
||||||
})
|
})
|
||||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
if err != nil {
|
||||||
return httperror.NotFound("Unable to find a stack with the specified identifier inside the database", err)
|
return handler.handlerDBErr(err, "Unable to persist the stack changes inside the database")
|
||||||
} else if err != nil {
|
|
||||||
return httperror.InternalServerError("Unable to persist the stack changes inside the database", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.JSON(w, stack)
|
return response.JSON(w, stack)
|
||||||
|
|
|
@ -55,10 +55,8 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
stack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID))
|
stack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID))
|
||||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
if err != nil {
|
||||||
return httperror.NotFound("Unable to find a stack with the specified identifier inside the database", err)
|
return handler.handlerDBErr(err, "Unable to find a stack with the specified identifier inside the database")
|
||||||
} else if err != nil {
|
|
||||||
return httperror.InternalServerError("Unable to find a stack with the specified identifier inside the database", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var payload updateEdgeStackPayload
|
var payload updateEdgeStackPayload
|
||||||
|
|
|
@ -85,3 +85,13 @@ func (handler *Handler) convertAndStoreKubeManifestIfNeeded(stackFolder string,
|
||||||
|
|
||||||
return komposeFileName, nil
|
return komposeFileName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (handler *Handler) handlerDBErr(err error, msg string) *httperror.HandlerError {
|
||||||
|
httpErr := httperror.InternalServerError(msg, err)
|
||||||
|
|
||||||
|
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||||
|
httpErr.StatusCode = http.StatusNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpErr
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue