Skip to content

Commit a285673

Browse files
committed
FEATURE/MINOR: cluster: new format of bootstrapkey
1 parent 8ed1968 commit a285673

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

configuration/cluster_sync.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ func (c *ClusterSync) monitorCertificateRefresh() {
9292
log.Warning(err)
9393
continue
9494
}
95-
if len(data) != 8 {
96-
log.Warning("bottstrap key in unrecognized format")
97-
continue
98-
}
99-
url := fmt.Sprintf("%s://%s", data[0], data[1])
95+
url := fmt.Sprintf("%s://%s", data["schema"], data["address"])
10096

10197
csr, key, err := generateCSR()
10298
if err != nil {
@@ -108,7 +104,7 @@ func (c *ClusterSync) monitorCertificateRefresh() {
108104
log.Warning(err)
109105
continue
110106
}
111-
err = c.issueRefreshRequest(url, data[2], data[3], data[4], csr, key)
107+
err = c.issueRefreshRequest(url, data["port"], data["api-base-path"], data["path"], csr, key)
112108
if err != nil {
113109
log.Warning(err)
114110
continue
@@ -202,17 +198,13 @@ func (c *ClusterSync) monitorBootstrapKey() {
202198
if err != nil {
203199
log.Warning(err)
204200
}
205-
if len(data) != 8 {
206-
log.Warning("bootstrap key in unrecognized format")
207-
continue
208-
}
209-
url := fmt.Sprintf("%s://%s", data[0], data[1])
201+
url := fmt.Sprintf("%s://%s", data["schema"], data["address"])
210202
c.cfg.Cluster.URL.Store(url)
211-
c.cfg.Cluster.Port.Store(data[2])
212-
c.cfg.Cluster.APIBasePath.Store(data[3])
213-
c.cfg.Cluster.APINodesPath.Store(data[4])
214-
c.cfg.Cluster.Name.Store(data[5])
215-
c.cfg.Cluster.Description.Store(data[6])
203+
c.cfg.Cluster.Port.Store(data["port"])
204+
c.cfg.Cluster.APIBasePath.Store(data["api-base-path"])
205+
c.cfg.Cluster.APINodesPath.Store(data["path"])
206+
c.cfg.Cluster.Name.Store(data["name"])
207+
c.cfg.Cluster.Description.Store(data["description"])
216208
c.cfg.Mode.Store("cluster")
217209
err = c.cfg.Save()
218210
if err != nil {
@@ -237,7 +229,7 @@ func (c *ClusterSync) monitorBootstrapKey() {
237229
if err != nil {
238230
log.Panic(err)
239231
}
240-
err = c.issueJoinRequest(url, data[2], data[3], data[4], csr, key)
232+
err = c.issueJoinRequest(url, data["port"], data["api-base-path"], data["path"], csr, key)
241233
if err != nil {
242234
log.Warning(err)
243235
continue

configuration/misc.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@ package configuration
22

33
import (
44
"encoding/base64"
5+
"encoding/json"
56
"fmt"
6-
"strings"
77
)
88

9-
func decodeBootstrapKey(key string) ([]string, error) {
10-
base64Data := strings.Split(key, ".")
11-
if len(base64Data) != 8 {
12-
return nil, fmt.Errorf("bottstrap key in unrecognized format")
9+
func decodeBootstrapKey(key string) (map[string]string, error) {
10+
raw, err := base64.StdEncoding.DecodeString(key)
11+
if err != nil {
12+
return nil, fmt.Errorf("%s - %w", key, err)
1313
}
14-
result := make([]string, len(base64Data))
15-
for i, val := range base64Data {
16-
raw, err := base64.StdEncoding.DecodeString(val)
17-
if err != nil {
18-
return nil, fmt.Errorf("%s - %w", val, err)
19-
}
20-
result[i] = string(raw)
14+
var decodedKey map[string]string
15+
err = json.Unmarshal(raw, &decodedKey)
16+
if err != nil {
17+
return nil, fmt.Errorf("%s - %w", key, err)
2118
}
22-
return result, nil
19+
return decodedKey, nil
2320
}

0 commit comments

Comments
 (0)