Fetch nebula CAPublicCredentials from daemon

This commit is contained in:
Brian Picciano 2024-07-12 16:11:42 +02:00
parent 30c8ca332a
commit 7ca8ff3467
3 changed files with 44 additions and 43 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"isle/jsonutil" "isle/jsonutil"
"isle/nebula"
"os" "os"
) )
@ -16,12 +17,20 @@ var subCmdNebulaShow = subCmd{
return fmt.Errorf("parsing flags: %w", err) return fmt.Errorf("parsing flags: %w", err)
} }
hostBootstrap, err := loadHostBootstrap() hosts, err := subCmdCtx.getHosts()
if err != nil { if err != nil {
return fmt.Errorf("loading host bootstrap: %w", err) return fmt.Errorf("getting hosts: %w", err)
} }
caCert := hostBootstrap.CAPublicCredentials.Cert.Unwrap() var caPublicCreds nebula.CAPublicCredentials
err = subCmdCtx.daemonRCPClient.Call(
subCmdCtx.ctx, &caPublicCreds, "GetNebulaCAPublicCredentials", nil,
)
if err != nil {
return fmt.Errorf("calling GetNebulaCAPublicCredentials: %w", err)
}
caCert := caPublicCreds.Cert.Unwrap()
caCertPEM, err := caCert.MarshalToPEM() caCertPEM, err := caCert.MarshalToPEM()
if err != nil { if err != nil {
return fmt.Errorf("marshaling CA cert to PEM: %w", err) return fmt.Errorf("marshaling CA cert to PEM: %w", err)
@ -50,7 +59,7 @@ var subCmdNebulaShow = subCmd{
SubnetCIDR: subnet.String(), SubnetCIDR: subnet.String(),
} }
for _, h := range hostBootstrap.Hosts { for _, h := range hosts.Hosts {
if h.Nebula.PublicAddr == "" { if h.Nebula.PublicAddr == "" {
continue continue
} }

View File

@ -49,20 +49,8 @@ type Daemon interface {
// - ErrAlreadyJoined // - ErrAlreadyJoined
JoinNetwork(context.Context, bootstrap.Bootstrap) error JoinNetwork(context.Context, bootstrap.Bootstrap) error
// GetBootstrapHosts returns the hosts stored in the bootstrap. // GetBootstraps returns the currently active Bootstrap.
GetBootstrapHosts( GetBootstrap(context.Context) (bootstrap.Bootstrap, error)
ctx context.Context,
) (
map[nebula.HostName]bootstrap.Host, error,
)
// GetGarageClientParams returns a GarageClientParams based on the current
// network topology.
GetGarageClientParams(
ctx context.Context,
) (
bootstrap.GarageClientParams, error,
)
// Shutdown blocks until all resources held or created by the daemon, // Shutdown blocks until all resources held or created by the daemon,
// including child processes it has started, have been cleaned up. // including child processes it has started, have been cleaned up.
@ -573,31 +561,13 @@ func (d *daemon) JoinNetwork(
} }
} }
func (d *daemon) GetBootstrapHosts( func (d *daemon) GetBootstrap(ctx context.Context) (bootstrap.Bootstrap, error) {
ctx context.Context,
) (
map[nebula.HostName]bootstrap.Host, error,
) {
return withCurrBootstrap(d, func( return withCurrBootstrap(d, func(
currBootstrap bootstrap.Bootstrap, currBootstrap bootstrap.Bootstrap,
) ( ) (
map[nebula.HostName]bootstrap.Host, error, bootstrap.Bootstrap, error,
) { ) {
return currBootstrap.Hosts, nil return currBootstrap, nil
})
}
func (d *daemon) GetGarageClientParams(
ctx context.Context,
) (
bootstrap.GarageClientParams, error,
) {
return withCurrBootstrap(d, func(
currBootstrap bootstrap.Bootstrap,
) (
bootstrap.GarageClientParams, error,
) {
return currBootstrap.GarageClientParams(), nil
}) })
} }

View File

@ -73,12 +73,12 @@ func (r *RPC) GetHosts(
) ( ) (
GetHostsResult, error, GetHostsResult, error,
) { ) {
hostsMap, err := r.daemon.GetBootstrapHosts(ctx) b, err := r.daemon.GetBootstrap(ctx)
if err != nil { if err != nil {
return GetHostsResult{}, fmt.Errorf("retrieving hosts: %w", err) return GetHostsResult{}, fmt.Errorf("retrieving bootstrap: %w", err)
} }
hosts := maps.Values(hostsMap) hosts := maps.Values(b.Hosts)
slices.SortFunc(hosts, func(a, b bootstrap.Host) int { slices.SortFunc(hosts, func(a, b bootstrap.Host) int {
return cmp.Compare(a.Name, b.Name) return cmp.Compare(a.Name, b.Name)
}) })
@ -92,5 +92,27 @@ func (r *RPC) GetGarageClientParams(
) ( ) (
bootstrap.GarageClientParams, error, bootstrap.GarageClientParams, error,
) { ) {
return r.daemon.GetGarageClientParams(ctx) b, err := r.daemon.GetBootstrap(ctx)
if err != nil {
return bootstrap.GarageClientParams{}, fmt.Errorf(
"retrieving bootstrap: %w", err,
)
}
return b.GarageClientParams(), nil
}
func (r *RPC) GetNebulaCAPublicCredentials(
ctx context.Context, req struct{},
) (
nebula.CAPublicCredentials, error,
) {
b, err := r.daemon.GetBootstrap(ctx)
if err != nil {
return nebula.CAPublicCredentials{}, fmt.Errorf(
"retrieving bootstrap: %w", err,
)
}
return b.CAPublicCredentials, nil
} }