Add Name field to admin.CreationParams

This commit is contained in:
Brian Picciano 2022-11-05 12:34:49 +01:00
parent bd5a5552bc
commit c0ebca193d
5 changed files with 31 additions and 20 deletions

View File

@ -44,7 +44,7 @@ following command from their own host:
```
cryptic-net hosts make-bootstrap \
--name <name> \
--hostname <name> \
--ip <ip> \
--admin-path <path to admin.yml> \
> bootstrap.yml
@ -67,7 +67,7 @@ generate a `bootstrap.yml`:
```
gpg -d <path to admin.yml.gpg> | cryptic-net hosts make-boostrap \
--name <name> \
--hostname <name> \
--ip <ip> \
--admin-path - \
> bootstrap.yml

View File

@ -61,6 +61,9 @@ There are some key parameters which must be chosen when creating a new network.
These will remain constant throughout the lifetime of the network, and so should
be chosen with care.
* Name: A human-readable name for the network. This will only be used for
display purposes.
* Subnet: The IP subnet (or CIDR) will look something like `10.10.0.0/16`, where
the `/16` indicates that all IPs from `10.10.0.0` to `10.10.255.255` are
included. It's recommended to choose from the [ranges reserved for private
@ -102,9 +105,10 @@ you can run:
```
sudo cryptic-net admin create-network \
--config /path/to/daemon.yml \
--domain <domain> \
--name <name> \
--ip <ip/subnet-prefix> \
--name <hostname> \
--domain <domain> \
--hostname <hostname> \
| gpg -e -r <my gpg email> \
> admin.yml.gpg
```

View File

@ -13,6 +13,7 @@ import (
// are available to all hosts within the network via their bootstrap files.
type CreationParams struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Domain string `yaml:"domain"`
}

View File

@ -64,6 +64,11 @@ var subCmdAdminCreateNetwork = subCmd{
"Write the default configuration file to stdout and exit.",
)
name := flags.StringP(
"name", "n", "",
"Human-readable name to identify the network as.",
)
domain := flags.StringP(
"domain", "d", "",
"Domain name that should be used as the root domain in the network.",
@ -75,7 +80,7 @@ var subCmdAdminCreateNetwork = subCmd{
)
hostName := flags.StringP(
"name", "n", "",
"hostname", "h", "",
"Name of this host, which will be the first host in the network",
)
@ -87,8 +92,8 @@ var subCmdAdminCreateNetwork = subCmd{
return daemon.CopyDefaultConfig(os.Stdout, envAppDirPath)
}
if *domain == "" || *ipNetStr == "" || *hostName == "" {
return errors.New("--domain, --ip-net, and --name are required")
if *name == "" || *domain == "" || *ipNetStr == "" || *hostName == "" {
return errors.New("--name, --domain, --ip-net, and --hostname are required")
}
*domain = strings.TrimRight(strings.TrimLeft(*domain, "."), ".")
@ -129,6 +134,7 @@ var subCmdAdminCreateNetwork = subCmd{
adminCreationParams := admin.CreationParams{
ID: randStr(32),
Name: *name,
Domain: *domain,
}
@ -235,8 +241,8 @@ var subCmdAdminMakeBootstrap = subCmd{
flags := subCmdCtx.flagSet(false)
name := flags.StringP(
"name", "n", "",
hostName := flags.StringP(
"hostname", "h", "",
"Name of the host to generate bootstrap.yml for",
)
@ -254,12 +260,12 @@ var subCmdAdminMakeBootstrap = subCmd{
return fmt.Errorf("parsing flags: %w", err)
}
if *name == "" || *ipStr == "" || *adminPath == "" {
return errors.New("--name, --ip, and --admin-path are required")
if *hostName == "" || *ipStr == "" || *adminPath == "" {
return errors.New("--hostname, --ip, and --admin-path are required")
}
if err := validateHostName(*name); err != nil {
return fmt.Errorf("invalid hostname %q: %w", *name, err)
if err := validateHostName(*hostName); err != nil {
return fmt.Errorf("invalid hostname %q: %w", *hostName, err)
}
ip := net.ParseIP(*ipStr)
@ -278,7 +284,7 @@ var subCmdAdminMakeBootstrap = subCmd{
return fmt.Errorf("loading host bootstrap: %w", err)
}
nebulaHostCreds, err := nebula.NewHostCredentials(adm.Nebula.CACredentials, *name, ip)
nebulaHostCreds, err := nebula.NewHostCredentials(adm.Nebula.CACredentials, *hostName, ip)
if err != nil {
return fmt.Errorf("creating new nebula host key/cert: %w", err)
}
@ -287,7 +293,7 @@ var subCmdAdminMakeBootstrap = subCmd{
AdminCreationParams: adm.CreationParams,
Hosts: hostBootstrap.Hosts,
HostName: *name,
HostName: *hostName,
}
newHostBootstrap.Nebula.HostCredentials = nebulaHostCreds

View File

@ -57,8 +57,8 @@ var subCmdHostsDelete = subCmd{
flags := subCmdCtx.flagSet(false)
name := flags.StringP(
"name", "n", "",
hostName := flags.StringP(
"hostname", "h", "",
"Name of the host to delete",
)
@ -66,8 +66,8 @@ var subCmdHostsDelete = subCmd{
return fmt.Errorf("parsing flags: %w", err)
}
if *name == "" {
return errors.New("--name is required")
if *hostName == "" {
return errors.New("--hostname is required")
}
hostBootstrap, err := loadHostBootstrap()
@ -77,7 +77,7 @@ var subCmdHostsDelete = subCmd{
client := hostBootstrap.GlobalBucketS3APIClient()
return bootstrap.RemoveGarageBootstrapHost(subCmdCtx.ctx, client, *name)
return bootstrap.RemoveGarageBootstrapHost(subCmdCtx.ctx, client, *hostName)
},
}