Fix the Hetzner provider in the metadata package

There were some mistakes made in the initial code where writes didn't work, this commit fixes that.

Signed-off-by: Simon Fridlund <simon@fridlund.email>
This commit is contained in:
Simon Fridlund 2019-10-15 22:34:14 +02:00
parent afff608c49
commit 4005082664
No known key found for this signature in database
GPG Key ID: F68EEAFE7927D3FF

View File

@ -1,7 +1,6 @@
package main
import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
@ -128,17 +127,15 @@ func (p *ProviderHetzner) handleSSH() error {
return fmt.Errorf("Failed to create %s: %s", SSH, err)
}
fileHandle, _ := os.OpenFile(path.Join(ConfigPath, SSH, "authorized_keys"), os.O_CREATE|os.O_APPEND, 0600)
writer := bufio.NewWriter(fileHandle)
fileHandle, _ := os.OpenFile(path.Join(ConfigPath, SSH, "authorized_keys"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
defer fileHandle.Close()
for _, sshKey := range sshKeys {
_, err = fmt.Fprintln(writer, sshKey)
_, err = fileHandle.WriteString(sshKey + "\n")
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}
}
writer.Flush()
return nil
}