Skip to content

Commit

Permalink
feat(api): prevent endpoint creation with already paired agent (#3159)
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantony committed Sep 20, 2019
1 parent 07505fa commit 1f68aad
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api/http/handler/endpoints/endpoint_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package endpoints

import (
"errors"
"log"
"net"
"net/http"
"net/url"
"runtime"
"strconv"
"strings"

httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
Expand Down Expand Up @@ -344,8 +344,10 @@ func (handler *Handler) snapshotAndPersistEndpoint(endpoint *portainer.Endpoint)
snapshot, err := handler.Snapshotter.CreateSnapshot(endpoint)
endpoint.Status = portainer.EndpointStatusUp
if err != nil {
log.Printf("http error: endpoint snapshot error (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err)
endpoint.Status = portainer.EndpointStatusDown
if strings.Contains(err.Error(), "Invalid request signature") {
err = errors.New("agent already paired with another Portainer instance")
}
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to initiate communications with endpoint", err}
}

if snapshot != nil {
Expand Down

0 comments on commit 1f68aad

Please sign in to comment.