Various fixes to bugs in admin create-network

This commit is contained in:
Brian Picciano 2022-11-03 14:54:46 +01:00
parent 6ba8b948c2
commit b935457439
3 changed files with 12 additions and 10 deletions

View File

@ -36,7 +36,8 @@ func (b Bootstrap) GaragePeers() []garage.RemotePeer {
func (b Bootstrap) GarageRPCPeerAddrs() []string { func (b Bootstrap) GarageRPCPeerAddrs() []string {
var addrs []string var addrs []string
for _, peer := range b.GaragePeers() { for _, peer := range b.GaragePeers() {
addrs = append(addrs, peer.RPCPeerAddr()) addr := peer.RPCPeerAddr()
addrs = append(addrs, addr)
} }
return addrs return addrs
} }

View File

@ -69,14 +69,14 @@ var subCmdAdminCreateNetwork = subCmd{
"Domain name that should be used as the root domain in the network.", "Domain name that should be used as the root domain in the network.",
) )
subnetStr := flags.StringP( ipNetStr := flags.StringP(
"subnet", "s", "", "ip-net", "i", "",
"CIDR which denotes the subnet that IPs hosts on the network can be assigned.", `IP+prefix (e.g. "10.10.0.1/16") which denotes the IP of this host, which will be the first host in the network, and the range of IPs which other hosts in the network can be assigned`,
) )
hostName := flags.StringP( hostName := flags.StringP(
"name", "n", "", "name", "n", "",
"Name of the host which will be the first host in the network", "Name of this host, which will be the first host in the network",
) )
if err := flags.Parse(subCmdCtx.args); err != nil { if err := flags.Parse(subCmdCtx.args); err != nil {
@ -87,15 +87,15 @@ var subCmdAdminCreateNetwork = subCmd{
return daemon.CopyDefaultConfig(os.Stdout, envAppDirPath) return daemon.CopyDefaultConfig(os.Stdout, envAppDirPath)
} }
if *domain == "" || *subnetStr == "" || *hostName == "" { if *domain == "" || *ipNetStr == "" || *hostName == "" {
return errors.New("--domain, --subnet, and --name are required") return errors.New("--domain, --ip-net, and --name are required")
} }
*domain = strings.TrimRight(strings.TrimLeft(*domain, "."), ".") *domain = strings.TrimRight(strings.TrimLeft(*domain, "."), ".")
ip, subnet, err := net.ParseCIDR(*subnetStr) ip, subnet, err := net.ParseCIDR(*ipNetStr)
if err != nil { if err != nil {
return fmt.Errorf("parsing %q as a CIDR: %w", *subnetStr, err) return fmt.Errorf("parsing %q as a CIDR: %w", *ipNetStr, err)
} }
if err := validateHostName(*hostName); err != nil { if err := validateHostName(*hostName); err != nil {

View File

@ -59,6 +59,7 @@ func InitAlloc(metaDirPath string) (string, error) {
return false return false
} else if _, err = os.Stat(path); errors.Is(err, fs.ErrNotExist) { } else if _, err = os.Stat(path); errors.Is(err, fs.ErrNotExist) {
err = nil
return false return false
} else if err != nil { } else if err != nil {
@ -100,5 +101,5 @@ func InitAlloc(metaDirPath string) (string, error) {
return "", fmt.Errorf("writing public key to %q: %w", nodeKeyPubPath, err) return "", fmt.Errorf("writing public key to %q: %w", nodeKeyPubPath, err)
} }
return "", nil return hex.EncodeToString(pubKey), nil
} }