Add GetConfig method to Network

This commit is contained in:
Brian Picciano 2024-10-23 20:18:11 +02:00
parent 9e9e98584f
commit bbae88ab4b
4 changed files with 57 additions and 0 deletions

View File

@ -9,6 +9,7 @@ package daemon
import (
"context"
"isle/bootstrap"
"isle/daemon/daecommon"
"isle/daemon/jsonrpc2"
"isle/daemon/network"
"isle/nebula"
@ -59,6 +60,15 @@ func (c *rpcClient) CreateNetwork(ctx context.Context, name string, domain strin
return
}
func (c *rpcClient) GetConfig(ctx context.Context) (n1 daecommon.NetworkConfig, err error) {
err = c.client.Call(
ctx,
&n1,
"GetConfig",
)
return
}
func (c *rpcClient) GetGarageClientParams(ctx context.Context) (g1 network.GarageClientParams, err error) {
err = c.client.Call(
ctx,

View File

@ -439,6 +439,24 @@ func (d *Daemon) CreateNebulaCertificate(
)
}
func (d *Daemon) GetConfig(
ctx context.Context,
) (
daecommon.NetworkConfig, error,
) {
return withNetwork(
ctx,
d,
func(
ctx context.Context, n network.Network,
) (
daecommon.NetworkConfig, error,
) {
return n.GetConfig(ctx)
},
)
}
// Shutdown blocks until all resources held or created by the daemon,
// including child processes it has started, have been cleaned up.
//

View File

@ -110,6 +110,9 @@ type RPC interface {
) (
nebula.Certificate, error,
)
// GetConfig returns the configuration currently in use.
GetConfig(context.Context) (daecommon.NetworkConfig, error)
}
// Network manages membership in a single micropelago network. Each Network
@ -880,6 +883,10 @@ func (n *network) CreateNebulaCertificate(
})
}
func (n *network) GetConfig(context.Context) (daecommon.NetworkConfig, error) {
return n.networkConfig, nil
}
func (n *network) GetNetworkCreationParams(
ctx context.Context,
) (

View File

@ -82,3 +82,25 @@ func TestJoin(t *testing.T) {
)
}
}
func TestNetwork_GetConfig(t *testing.T) {
var (
h = newIntegrationHarness(t)
network = h.createNetwork(t, "primus", nil)
)
config, err := network.GetConfig(h.ctx)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(config, network.networkConfig) {
t.Fatalf(
"Config doesn't match the one used to create the Network\n"+
"exp: %+v\n"+
"got: %+v",
config,
network.networkConfig,
)
}
}