Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions pkg/helpers/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,32 @@ func MachineCreateRequestFromCLI(c *config.Config) (*apiv2.MachineServiceCreateR
allocationType apiv2.MachineAllocationType
firewallSpec *apiv2.FirewallSpec

sshPublicKeyArgument = viper.GetString("ssh-public-key")
sshPublicKeyArgument = viper.GetStringSlice("ssh-public-key")
dnsServersArgument = viper.GetStringSlice("dns-servers")
ntpServersArgument = viper.GetStringSlice("ntp-servers")
)

if strings.HasPrefix(sshPublicKeyArgument, "@") {
var err error
sshPublicKeyArgument, err = readFromFile(c.Fs, sshPublicKeyArgument[1:])
if err != nil {
return nil, err
for _, k := range sshPublicKeyArgument {
if strings.HasPrefix(k, "@") {
var err error
k, err = readFromFile(c.Fs, k[1:])
if err != nil {
return nil, err
}
}
keys = append(keys, k)
}

if len(sshPublicKeyArgument) == 0 {
if len(keys) == 0 {
sshKey, err := SearchSSHKey()
if err != nil {
return nil, err
}
sshPublicKey := sshKey + ".pub"
sshPublicKeyArgument, err = readFromFile(c.Fs, sshPublicKey)
key, err := readFromFile(c.Fs, sshPublicKey)
if err != nil {
return nil, err
}
}

if sshPublicKeyArgument != "" {
keys = append(keys, sshPublicKeyArgument)
keys = append(keys, key)
}

userDataArgument := viper.GetString("userdata")
Expand Down Expand Up @@ -548,9 +547,10 @@ func AddMachineCreateFlags(cmd *cobra.Command, name string, completion *completi
cmd.Flags().StringP("project", "p", "", "Project where the "+name+" should belong to. [required]")
cmd.Flags().String("size", "", "Size of the "+name+". [required, except for reserved machines]")
cmd.Flags().String("allocation-type", "machine", "allocation type, can be either machine|firewall")
cmd.Flags().StringP("ssh-public-key", "i", "",
cmd.Flags().StringArrayP("ssh-public-key", "i", []string{},
`SSH public key for access via ssh and console. [optional]
Can be either the public key as string, or pointing to the public key file to use e.g.: "@~/.ssh/id_rsa.pub".
Multiple keys can be passed by doing -i [key] -i [key] ...
Can be either the public keys as strings, or pointing to the public keys file to use e.g.: "@~/.ssh/id_rsa.pub".
If ~/.ssh/[id_ed25519.pub | id_rsa.pub | id_dsa.pub] is present it will be picked as default, matching the first one in this order.`)
cmd.Flags().StringSlice("labels", []string{}, "labels to add to the "+name+", use it like: --labels \"a=b\" or --labels \"a=\".")
cmd.Flags().String("userdata", "", `cloud-init.io compatible userdata. [optional]
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/admin/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func Test_MachineCmd_Create(t *testing.T) {
"--partition", testresources.Machine2().Partition.Id,
"--size", testresources.Machine2().Size.Id,
"--ssh-public-key", "@.ssh/id_rsa.pub",
"--ssh-public-key", "ssh-ed25519 AAAA test",
"--labels", "a=b",
"--userdata", "@ignition.json",
"--placement-labels", "cluster-id=cluster-uuid",
Expand All @@ -311,7 +312,7 @@ func Test_MachineCmd_Create(t *testing.T) {
Size: &testresources.Machine2().Size.Id,
Image: testresources.Machine2().Allocation.Image.Id,
FilesystemLayout: new("fsl1"),
SshPublicKeys: []string{"12345"},
SshPublicKeys: []string{"12345", "ssh-ed25519 AAAA test"},
Userdata: new(base64.StdEncoding.EncodeToString([]byte("{}"))),
Labels: &apiv2.Labels{
Labels: map[string]string{
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/api/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func Test_MachineCmd_Create(t *testing.T) {
"--partition", testresources.Machine2().Partition.Id,
"--size", testresources.Machine2().Size.Id,
"--ssh-public-key", "@.ssh/id_rsa.pub",
"--ssh-public-key", "ssh-ed25519 AAAA test",
"--labels", "a=b",
"--userdata", "@ignition.json",
"--placement-labels", "cluster-id=cluster-uuid",
Expand All @@ -163,7 +164,7 @@ func Test_MachineCmd_Create(t *testing.T) {
Size: &testresources.Machine2().Size.Id,
Image: testresources.Machine2().Allocation.Image.Id,
FilesystemLayout: new("fsl1"),
SshPublicKeys: []string{"12345"},
SshPublicKeys: []string{"12345", "ssh-ed25519 AAAA test"},
Userdata: new(base64.StdEncoding.EncodeToString([]byte("{}"))),
Labels: &apiv2.Labels{
Labels: map[string]string{
Expand Down
Loading