Skip to content

Commit

Permalink
add command for generating wg public key from private key
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioBassem committed Sep 26, 2024
1 parent f1442cf commit f901712
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
14 changes: 14 additions & 0 deletions griddriver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,20 @@ func main() {
return generateWgPrivKey()
},
},
{
Name: "generate-wg-public-key",
Usage: "Generates wireguard public key",
Flags: []cli.Flag{
cli.StringFlag{
Name: "key",
Usage: "wireguard private key",
Required: true,
},
},
Action: func(c *cli.Context) error {
return generateWgPublicKey(c)
},
},
{
Name: "rmb",
Usage: "Make RMB call",
Expand Down
30 changes: 21 additions & 9 deletions griddriver/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ func deployVM() cli.ActionFunc {
}

func buildNetwork(name, solutionType string, nodes []uint32) workloads.ZNet {
return workloads.ZNet{
Name: name,
Nodes: nodes,
IPRange: gridtypes.NewIPNet(net.IPNet{
IP: net.IPv4(10, 20, 0, 0),
Mask: net.CIDRMask(16, 32),
}),
SolutionType: solutionType,
}
return workloads.ZNet{
Name: name,
Nodes: nodes,
IPRange: gridtypes.NewIPNet(net.IPNet{
IP: net.IPv4(10, 20, 0, 0),
Mask: net.CIDRMask(16, 32),
}),
SolutionType: solutionType,
}
}

func generateWgPrivKey() error {
Expand All @@ -95,3 +95,15 @@ func generateWgPrivKey() error {
return nil

}

func generateWgPublicKey(ctx *cli.Context) error {
keyStr := ctx.String("key")
key, err := wgtypes.ParseKey(keyStr)
if err != nil {
return fmt.Errorf("failed to parse private key: %w", err)
}

fmt.Printf("%s", key.PublicKey().String())
return nil

}
4 changes: 2 additions & 2 deletions griddriver/rmb.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func nodeTakenPorts(c *cli.Context, client *peer.RpcClient) (interface{}, error)
dst := uint32(c.Uint("dst"))
var takenPorts []uint16

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

if err := client.Call(ctx, dst, "zos.network.list_wg_ports", nil, &takenPorts); err != nil {
Expand Down Expand Up @@ -172,6 +172,6 @@ func getNodePublicConfig(c *cli.Context, client *peer.RpcClient) (interface{}, e
if err != nil {
return nil, fmt.Errorf("failed to marshal public configuration: %w", err)
}
fmt.Println(string(json))

return string(json), nil
}

0 comments on commit f901712

Please sign in to comment.