From a21c5667773bcf90214a13bb679021ffd7abcc01 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 12 Apr 2017 14:52:27 +0100 Subject: [PATCH] metadata: Make sure the ssh directory exists before writing to it Signed-off-by: Rolf Neugebauer --- pkg/metadata/provider_gcp.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/metadata/provider_gcp.go b/pkg/metadata/provider_gcp.go index cf393d3cb..6aa3ae359 100644 --- a/pkg/metadata/provider_gcp.go +++ b/pkg/metadata/provider_gcp.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "log" "net/http" + "os" "path" "strings" "time" @@ -57,6 +58,10 @@ func (p *ProviderGCP) Extract() ([]byte, error) { // container construct those users sshKeys, err := gcpGet(project + "attributes/sshKeys") if err == nil { + if err := os.Mkdir(path.Join(ConfigPath, SSH), 0755); err != nil { + log.Printf("Failed to create %s: %s", SSH, err) + goto ErrorSSH + } rootKeys := "" for _, line := range strings.Split(string(sshKeys), "\n") { parts := strings.SplitN(line, ":", 2) @@ -71,6 +76,7 @@ func (p *ProviderGCP) Extract() ([]byte, error) { } } +ErrorSSH: // Generic userdata userData, err := gcpGet(instance + "attributes/userdata") if err != nil {