2023-08-27 14:09:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-06-10 16:56:36 +00:00
|
|
|
"isle/jsonutil"
|
2023-08-27 14:09:03 +00:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var subCmdNebulaShow = subCmd{
|
|
|
|
name: "show",
|
2024-06-10 16:56:36 +00:00
|
|
|
descr: "Writes nebula network information to stdout in JSON format",
|
2023-08-27 14:09:03 +00:00
|
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
|
|
|
|
flags := subCmdCtx.flagSet(false)
|
|
|
|
if err := flags.Parse(subCmdCtx.args); err != nil {
|
|
|
|
return fmt.Errorf("parsing flags: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
hostBootstrap, err := loadHostBootstrap()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("loading host bootstrap: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-06-23 12:37:10 +00:00
|
|
|
caCert := hostBootstrap.CAPublicCredentials.Cert.Unwrap()
|
2024-06-15 21:02:24 +00:00
|
|
|
caCertPEM, err := caCert.MarshalToPEM()
|
2023-08-27 14:09:03 +00:00
|
|
|
if err != nil {
|
2024-06-15 21:02:24 +00:00
|
|
|
return fmt.Errorf("marshaling CA cert to PEM: %w", err)
|
2023-08-27 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(caCert.Details.Subnets) != 1 {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"malformed ca.crt, contains unexpected subnets %#v",
|
|
|
|
caCert.Details.Subnets,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
subnet := caCert.Details.Subnets[0]
|
|
|
|
|
|
|
|
type outLighthouse struct {
|
2024-06-10 16:56:36 +00:00
|
|
|
PublicAddr string
|
|
|
|
IP string
|
2023-08-27 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out := struct {
|
2024-06-10 16:56:36 +00:00
|
|
|
CACert string
|
|
|
|
SubnetCIDR string
|
|
|
|
Lighthouses []outLighthouse
|
2023-08-27 14:09:03 +00:00
|
|
|
}{
|
2024-06-15 21:02:24 +00:00
|
|
|
CACert: string(caCertPEM),
|
2023-08-27 14:09:03 +00:00
|
|
|
SubnetCIDR: subnet.String(),
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, h := range hostBootstrap.Hosts {
|
|
|
|
if h.Nebula.PublicAddr == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
out.Lighthouses = append(out.Lighthouses, outLighthouse{
|
|
|
|
PublicAddr: h.Nebula.PublicAddr,
|
|
|
|
IP: h.IP().String(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-10 16:56:36 +00:00
|
|
|
if err := jsonutil.WriteIndented(os.Stdout, out); err != nil {
|
|
|
|
return fmt.Errorf("encoding to stdout: %w", err)
|
2023-08-27 14:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var subCmdNebula = subCmd{
|
|
|
|
name: "nebula",
|
|
|
|
descr: "Sub-commands related to the nebula VPN",
|
|
|
|
do: func(subCmdCtx subCmdCtx) error {
|
|
|
|
return subCmdCtx.doSubCmd(
|
|
|
|
subCmdNebulaShow,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|