Skip to content

Commit

Permalink
marhal allowed IPs into proper json
Browse files Browse the repository at this point in the history
  • Loading branch information
mjudeikis committed Nov 26, 2024
1 parent f6ac0c3 commit 3cebc12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/kgctl/connect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func runConnect(cmd *cobra.Command, args []string) error {
}
}
publicKey := privateKey.PublicKey()
level.Info(logger).Log("msg", "generated public key", "key", publicKey)
level.Info(logger).Log("msg", "generated public key", "key", publicKey.String())

if _, err := opts.kc.KiloV1alpha1().Peers().Get(ctx, peerName, metav1.GetOptions{}); apierrors.IsNotFound(err) {
peer := &v1alpha1.Peer{
Expand Down
14 changes: 13 additions & 1 deletion pkg/mesh/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package mesh

import (
"encoding/json"
"errors"
"net"
"sort"
Expand Down Expand Up @@ -95,6 +96,17 @@ type segment struct {
allowedLocationIPs []net.IPNet
}

type allowedIPs []net.IPNet

// MarshalJSON marshals the allowedIPs to a JSON array of strings.
func (a allowedIPs) MarshalJSON() ([]byte, error) {
var s []string
for _, ip := range a {
s = append(s, ip.String())
}
return json.Marshal(s)
}

// NewTopology creates a new Topology struct from a given set of nodes and peers.
func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Granularity, hostname string, port int, key wgtypes.Key, subnet *net.IPNet, serviceCIDRs []*net.IPNet, persistentKeepalive time.Duration, logger log.Logger) (*Topology, error) {
if logger == nil {
Expand Down Expand Up @@ -149,7 +161,7 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
if location == localLocation && topoMap[location][leader].Name == hostname {
t.leader = true
}
var allowedIPs []net.IPNet
var allowedIPs allowedIPs
allowedLocationIPsMap := make(map[string]struct{})
var allowedLocationIPs []net.IPNet
var cidrs []*net.IPNet
Expand Down

0 comments on commit 3cebc12

Please sign in to comment.