~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/gce/google/instance.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import (
7
7
        "fmt"
8
8
        "path"
9
 
        "strings"
10
9
 
11
 
        "github.com/juju/errors"
12
10
        "google.golang.org/api/compute/v1"
13
11
 
14
12
        "github.com/juju/juju/network"
177
175
        return gi.InstanceSummary.Metadata
178
176
}
179
177
 
180
 
// FormatAuthorizedKeys returns our authorizedKeys with
181
 
// the username prepended to it. This is the format that
182
 
// GCE expects when we upload sshKeys metadata. The sshKeys
183
 
// metadata is what is used by our scripts and commands
184
 
// like juju ssh to connect to juju machines.
185
 
func FormatAuthorizedKeys(rawAuthorizedKeys, user string) (string, error) {
186
 
        if rawAuthorizedKeys == "" {
187
 
                return "", errors.New("empty rawAuthorizedKeys")
188
 
        }
189
 
        if user == "" {
190
 
                return "", errors.New("empty user")
191
 
        }
192
 
 
193
 
        var userKeys string
194
 
        keys := strings.Split(rawAuthorizedKeys, "\n")
195
 
        for _, key := range keys {
196
 
                userKeys += user + ":" + key + "\n"
197
 
        }
198
 
        return userKeys, nil
199
 
}
200
 
 
201
178
// packMetadata composes the provided data into the format required
202
179
// by the GCE API.
203
180
func packMetadata(data map[string]string) *compute.Metadata {