|
|
@ -20,6 +20,8 @@ import (
|
|
|
|
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
|
|
|
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
|
|
|
"github.com/portainer/portainer/pkg/libhttp/request"
|
|
|
|
"github.com/portainer/portainer/pkg/libhttp/request"
|
|
|
|
"github.com/portainer/portainer/pkg/libhttp/response"
|
|
|
|
"github.com/portainer/portainer/pkg/libhttp/response"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type stackStatusResponse struct {
|
|
|
|
type stackStatusResponse struct {
|
|
|
@ -93,6 +95,8 @@ func (handler *Handler) endpointEdgeStatusInspect(w http.ResponseWriter, r *http
|
|
|
|
return httperror.Forbidden("Permission denied to access environment", errors.New("the device has not been trusted yet"))
|
|
|
|
return httperror.Forbidden("Permission denied to access environment", errors.New("the device has not been trusted yet"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
firstConn := endpoint.LastCheckInDate == 0
|
|
|
|
|
|
|
|
|
|
|
|
err = handler.requestBouncer.AuthorizedEdgeEndpointOperation(r, endpoint)
|
|
|
|
err = handler.requestBouncer.AuthorizedEdgeEndpointOperation(r, endpoint)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return httperror.Forbidden("Permission denied to access environment", err)
|
|
|
|
return httperror.Forbidden("Permission denied to access environment", err)
|
|
|
@ -107,7 +111,7 @@ func (handler *Handler) endpointEdgeStatusInspect(w http.ResponseWriter, r *http
|
|
|
|
|
|
|
|
|
|
|
|
var statusResponse *endpointEdgeStatusInspectResponse
|
|
|
|
var statusResponse *endpointEdgeStatusInspectResponse
|
|
|
|
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
|
|
|
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
|
|
|
statusResponse, err = handler.inspectStatus(tx, r, portainer.EndpointID(endpointID))
|
|
|
|
statusResponse, err = handler.inspectStatus(tx, r, portainer.EndpointID(endpointID), firstConn)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -122,7 +126,7 @@ func (handler *Handler) endpointEdgeStatusInspect(w http.ResponseWriter, r *http
|
|
|
|
return cacheResponse(w, endpoint.ID, *statusResponse)
|
|
|
|
return cacheResponse(w, endpoint.ID, *statusResponse)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (handler *Handler) inspectStatus(tx dataservices.DataStoreTx, r *http.Request, endpointID portainer.EndpointID) (*endpointEdgeStatusInspectResponse, error) {
|
|
|
|
func (handler *Handler) inspectStatus(tx dataservices.DataStoreTx, r *http.Request, endpointID portainer.EndpointID, firstConn bool) (*endpointEdgeStatusInspectResponse, error) {
|
|
|
|
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
|
|
|
endpoint, err := tx.Endpoint().Endpoint(endpointID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -134,8 +138,10 @@ func (handler *Handler) inspectStatus(tx dataservices.DataStoreTx, r *http.Reque
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Take an initial snapshot
|
|
|
|
// Take an initial snapshot
|
|
|
|
if endpoint.LastCheckInDate == 0 {
|
|
|
|
if firstConn {
|
|
|
|
handler.ReverseTunnelService.Open(endpoint)
|
|
|
|
if err := handler.ReverseTunnelService.Open(endpoint); err != nil {
|
|
|
|
|
|
|
|
log.Error().Err(err).Msg("could not open the tunnel")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
agentPlatform, agentPlatformErr := parseAgentPlatform(r)
|
|
|
|
agentPlatform, agentPlatformErr := parseAgentPlatform(r)
|
|
|
|