1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 05:19:39 +02:00
portainer/pkg/edge/utils.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
671 B
Go
Raw Normal View History

package edge
import (
"encoding/base64"
"errors"
"strconv"
"strings"
)
// GetPortainerURLFromEdgeKey returns the portainer URL from an edge key
// format: <portainer_instance_url>|<tunnel_server_addr>|<tunnel_server_fingerprint>|<endpoint_id>
func GetPortainerURLFromEdgeKey(edgeKey string) (string, error) {
decodedKey, err := base64.RawStdEncoding.DecodeString(edgeKey)
if err != nil {
return "", err
}
keyInfo := strings.Split(string(decodedKey), "|")
if len(keyInfo) != 4 {
return "", errors.New("invalid key format")
}
_, err = strconv.Atoi(keyInfo[3])
if err != nil {
return "", errors.New("invalid key format")
}
return keyInfo[0], nil
}