1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-05 22:05:23 +02:00

feat(support): collect system info bundle to assist support troubleshooting [r8s-157] (#154)

This commit is contained in:
Malcolm Lockyer 2024-12-06 15:38:10 +13:00 committed by GitHub
parent 17648d12fe
commit 783ab253af
17 changed files with 1367 additions and 440 deletions

30
pkg/edge/utils.go Normal file
View file

@ -0,0 +1,30 @@
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
}

29
pkg/edge/utils_test.go Normal file
View file

@ -0,0 +1,29 @@
package edge
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetPortainerURLFromEdgeKey(t *testing.T) {
tests := []struct {
name string
edgeKey string
expected string
}{
{
name: "ValidEdgeKey",
edgeKey: "aHR0cHM6Ly9wb3J0YWluZXIuaW98cG9ydGFpbmVyLmlvOjgwMDB8YXNkZnwx",
expected: "https://portainer.io",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := GetPortainerURLFromEdgeKey(tt.edgeKey)
assert.NoError(t, err)
assert.Equal(t, tt.expected, result)
})
}
}