Merge pull request #3431 from zimme/metadata-fix-provider-hetzner

Fix the Hetzner provider in the metadata package
This commit is contained in:
Rolf Neugebauer 2019-12-19 17:39:45 +00:00 committed by GitHub
commit 725dc47a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
}