mirror of
https://github.com/portainer/portainer.git
synced 2025-07-20 05:49:40 +02:00
61 lines
2.4 KiB
Go
61 lines
2.4 KiB
Go
|
package endpointedge
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"path"
|
||
|
|
||
|
httperror "github.com/portainer/libhttp/error"
|
||
|
"github.com/portainer/libhttp/request"
|
||
|
"github.com/portainer/libhttp/response"
|
||
|
portainer "github.com/portainer/portainer/api"
|
||
|
)
|
||
|
|
||
|
type configResponse struct {
|
||
|
Prune bool
|
||
|
StackFileContent string
|
||
|
Name string
|
||
|
}
|
||
|
|
||
|
// GET request on api/endpoints/:id/edge/stacks/:stackId
|
||
|
func (handler *Handler) endpointEdgeStackInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
||
|
endpointID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
||
|
if err != nil {
|
||
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid endpoint identifier route variable", err}
|
||
|
}
|
||
|
|
||
|
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID))
|
||
|
if err == portainer.ErrObjectNotFound {
|
||
|
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
|
||
|
} else if err != nil {
|
||
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an endpoint with the specified identifier inside the database", err}
|
||
|
}
|
||
|
|
||
|
err = handler.requestBouncer.AuthorizedEdgeEndpointOperation(r, endpoint)
|
||
|
if err != nil {
|
||
|
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access endpoint", err}
|
||
|
}
|
||
|
|
||
|
edgeStackID, err := request.RetrieveNumericRouteVariableValue(r, "stackId")
|
||
|
if err != nil {
|
||
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid edge stack identifier route variable", err}
|
||
|
}
|
||
|
|
||
|
edgeStack, err := handler.EdgeStackService.EdgeStack(portainer.EdgeStackID(edgeStackID))
|
||
|
if err == portainer.ErrObjectNotFound {
|
||
|
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an edge stack with the specified identifier inside the database", err}
|
||
|
} else if err != nil {
|
||
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find an edge stack with the specified identifier inside the database", err}
|
||
|
}
|
||
|
|
||
|
stackFileContent, err := handler.FileService.GetFileContent(path.Join(edgeStack.ProjectPath, edgeStack.EntryPoint))
|
||
|
if err != nil {
|
||
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve Compose file from disk", err}
|
||
|
}
|
||
|
|
||
|
return response.JSON(w, configResponse{
|
||
|
Prune: edgeStack.Prune,
|
||
|
StackFileContent: string(stackFileContent),
|
||
|
Name: edgeStack.Name,
|
||
|
})
|
||
|
}
|