isle/go/daemon/config.go

57 lines
1.2 KiB
Go
Raw Normal View History

package daemon
import (
"context"
"fmt"
"isle/bootstrap"
"isle/daemon/daecommon"
"isle/daemon/network"
)
func pickNetworkConfig(
networkConfigs map[string]daecommon.NetworkConfig,
creationParams bootstrap.CreationParams,
) *daecommon.NetworkConfig {
if len(networkConfigs) == 1 { // DEPRECATED
if c, ok := networkConfigs[daecommon.DeprecatedNetworkID]; ok {
return &c
}
}
for searchStr, networkConfig := range networkConfigs {
if creationParams.Matches(searchStr) {
return &networkConfig
}
}
return nil
}
func validateConfig(
ctx context.Context,
networkLoader network.Loader,
daemonConfig daecommon.Config,
loadableNetworks []bootstrap.CreationParams,
) error {
givenConfigs := daemonConfig.Networks
daemonConfig.Networks = map[string]daecommon.NetworkConfig{}
for _, creationParams := range loadableNetworks {
id := creationParams.ID
if c := pickNetworkConfig(givenConfigs, creationParams); c != nil {
daemonConfig.Networks[id] = *c
continue
}
c, err := networkLoader.StoredConfig(ctx, id)
if err != nil {
return fmt.Errorf("getting stored config for %q: %w", id, err)
}
daemonConfig.Networks[id] = c
}
return daemonConfig.Validate()
}