|
|
|
|
@ -34,13 +34,7 @@ type driverGCE struct {
|
|
|
|
|
ui packer.Ui
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getDriverScopes(iap bool) []string {
|
|
|
|
|
ds := []string{"https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.full_control"}
|
|
|
|
|
// if iap {
|
|
|
|
|
// ds = append(ds, "https://www.googleapis.com/auth/iap.tunnelResourceAccessor")
|
|
|
|
|
// }
|
|
|
|
|
return ds
|
|
|
|
|
}
|
|
|
|
|
var DriverScopes = []string{"https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.full_control"}
|
|
|
|
|
|
|
|
|
|
// Define a TokenSource that gets tokens from Vault
|
|
|
|
|
type OauthTokenSource struct {
|
|
|
|
|
@ -75,7 +69,7 @@ func (ots OauthTokenSource) Token() (*oauth2.Token, error) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewClientGCE(conf *jwt.Config, vaultOauth string, iap bool) (*http.Client, error) {
|
|
|
|
|
func NewClientGCE(conf *jwt.Config, vaultOauth string) (*http.Client, error) {
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
var client *http.Client
|
|
|
|
|
@ -90,7 +84,7 @@ func NewClientGCE(conf *jwt.Config, vaultOauth string, iap bool) (*http.Client,
|
|
|
|
|
// Auth with AccountFile if provided
|
|
|
|
|
log.Printf("[INFO] Requesting Google token via account_file...")
|
|
|
|
|
log.Printf("[INFO] -- Email: %s", conf.Email)
|
|
|
|
|
log.Printf("[INFO] -- Scopes: %s", getDriverScopes(iap))
|
|
|
|
|
log.Printf("[INFO] -- Scopes: %s", DriverScopes)
|
|
|
|
|
log.Printf("[INFO] -- Private Key Length: %d", len(conf.PrivateKey))
|
|
|
|
|
|
|
|
|
|
// Initiate an http.Client. The following GET request will be
|
|
|
|
|
@ -99,7 +93,7 @@ func NewClientGCE(conf *jwt.Config, vaultOauth string, iap bool) (*http.Client,
|
|
|
|
|
client = conf.Client(context.TODO())
|
|
|
|
|
} else {
|
|
|
|
|
log.Printf("[INFO] Requesting Google token via GCE API Default Client Token Source...")
|
|
|
|
|
client, err = google.DefaultClient(context.TODO(), getDriverScopes(iap)...)
|
|
|
|
|
client, err = google.DefaultClient(context.TODO(), DriverScopes...)
|
|
|
|
|
// The DefaultClient uses the DefaultTokenSource of the google lib.
|
|
|
|
|
// The DefaultTokenSource uses the "Application Default Credentials"
|
|
|
|
|
// It looks for credentials in the following places, preferring the first location found:
|
|
|
|
|
@ -121,8 +115,8 @@ func NewClientGCE(conf *jwt.Config, vaultOauth string, iap bool) (*http.Client,
|
|
|
|
|
return client, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewDriverGCE(ui packer.Ui, p string, conf *jwt.Config, vaultOauth string, iap bool) (Driver, error) {
|
|
|
|
|
client, err := NewClientGCE(conf, vaultOauth, iap)
|
|
|
|
|
func NewDriverGCE(ui packer.Ui, p string, conf *jwt.Config, vaultOauth string) (Driver, error) {
|
|
|
|
|
client, err := NewClientGCE(conf, vaultOauth)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|