2018-06-11 13:13:19 +00:00
|
|
|
package endpoints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-09-10 10:01:38 +00:00
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/libhttp/request"
|
|
|
|
"github.com/portainer/libhttp/response"
|
2021-01-25 19:16:53 +00:00
|
|
|
portainer "github.com/portainer/portainer/api"
|
2020-07-07 21:57:52 +00:00
|
|
|
"github.com/portainer/portainer/api/bolt/errors"
|
2018-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
2021-02-23 03:21:39 +00:00
|
|
|
// @id EndpointInspect
|
|
|
|
// @summary Inspect an endpoint
|
|
|
|
// @description Retrieve details about an endpoint.
|
|
|
|
// @description **Access policy**: restricted
|
|
|
|
// @tags endpoints
|
|
|
|
// @security jwt
|
|
|
|
// @produce json
|
|
|
|
// @param id path int true "Endpoint identifier"
|
|
|
|
// @success 200 {object} portainer.Endpoint "Success"
|
|
|
|
// @failure 400 "Invalid request"
|
|
|
|
// @failure 404 "Endpoint not found"
|
|
|
|
// @failure 500 "Server error"
|
|
|
|
// @router /endpoints/{id} [get]
|
2018-06-11 13:13:19 +00:00
|
|
|
func (handler *Handler) endpointInspect(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}
|
|
|
|
}
|
|
|
|
|
2020-05-20 05:23:15 +00:00
|
|
|
endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
|
2020-07-07 21:57:52 +00:00
|
|
|
if err == errors.ErrObjectNotFound {
|
2018-06-11 13:13:19 +00:00
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2020-08-11 05:41:37 +00:00
|
|
|
err = handler.requestBouncer.AuthorizedEndpointOperation(r, endpoint)
|
2018-07-25 18:47:33 +00:00
|
|
|
if err != nil {
|
2019-05-24 06:04:58 +00:00
|
|
|
return &httperror.HandlerError{http.StatusForbidden, "Permission denied to access endpoint", err}
|
2018-07-25 18:47:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hideFields(endpoint)
|
2021-01-25 19:16:53 +00:00
|
|
|
endpoint.ComposeSyntaxMaxVersion = handler.ComposeStackManager.ComposeSyntaxMaxVersion()
|
2018-07-25 18:47:33 +00:00
|
|
|
|
2018-06-11 13:13:19 +00:00
|
|
|
return response.JSON(w, endpoint)
|
|
|
|
}
|