Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
982934df
Commit
982934df
authored
Apr 17, 2015
by
Dave Cunningham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new Google API and OAuth libs, add UserAgent string
parent
b49d74d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
15 deletions
+38
-15
builder/googlecompute/driver_gce.go
builder/googlecompute/driver_gce.go
+38
-15
No files found.
builder/googlecompute/driver_gce.go
View file @
982934df
...
@@ -4,16 +4,15 @@ import (
...
@@ -4,16 +4,15 @@ import (
"fmt"
"fmt"
"log"
"log"
"net/http"
"net/http"
"runtime"
"time"
"time"
"code.google.com/p/google-api-go-client/compute/v1"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
// oauth2 "github.com/rasa/oauth2-fork-b3f9a68"
"golang.org/x/oauth2"
"github.com/rasa/oauth2-fork-b3f9a68"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
// oauth2 "github.com/rasa/oauth2-fork-b3f9a68/google"
"google.golang.org/api/compute/v1"
"github.com/rasa/oauth2-fork-b3f9a68/google"
)
)
// driverGCE is a Driver implementation that actually talks to GCE.
// driverGCE is a Driver implementation that actually talks to GCE.
...
@@ -27,9 +26,10 @@ type driverGCE struct {
...
@@ -27,9 +26,10 @@ type driverGCE struct {
var
DriverScopes
=
[]
string
{
"https://www.googleapis.com/auth/compute"
,
"https://www.googleapis.com/auth/devstorage.full_control"
}
var
DriverScopes
=
[]
string
{
"https://www.googleapis.com/auth/compute"
,
"https://www.googleapis.com/auth/devstorage.full_control"
}
func
NewDriverGCE
(
ui
packer
.
Ui
,
p
string
,
a
*
accountFile
)
(
Driver
,
error
)
{
func
NewDriverGCE
(
ui
packer
.
Ui
,
p
string
,
a
*
accountFile
)
(
Driver
,
error
)
{
var
f
*
oauth2
.
Options
var
err
error
var
err
error
var
client
*
http
.
Client
// Auth with AccountFile first if provided
// Auth with AccountFile first if provided
if
a
.
PrivateKey
!=
""
{
if
a
.
PrivateKey
!=
""
{
log
.
Printf
(
"[INFO] Requesting Google token via AccountFile..."
)
log
.
Printf
(
"[INFO] Requesting Google token via AccountFile..."
)
...
@@ -37,22 +37,45 @@ func NewDriverGCE(ui packer.Ui, p string, a *accountFile) (Driver, error) {
...
@@ -37,22 +37,45 @@ func NewDriverGCE(ui packer.Ui, p string, a *accountFile) (Driver, error) {
log
.
Printf
(
"[INFO] -- Scopes: %s"
,
DriverScopes
)
log
.
Printf
(
"[INFO] -- Scopes: %s"
,
DriverScopes
)
log
.
Printf
(
"[INFO] -- Private Key Length: %d"
,
len
(
a
.
PrivateKey
))
log
.
Printf
(
"[INFO] -- Private Key Length: %d"
,
len
(
a
.
PrivateKey
))
f
,
err
=
oauth2
.
New
(
conf
:=
jwt
.
Config
{
oauth2
.
JWTClient
(
a
.
ClientEmail
,
[]
byte
(
a
.
PrivateKey
)),
Email
:
a
.
ClientEmail
,
oauth2
.
Scope
(
DriverScopes
...
),
PrivateKey
:
[]
byte
(
a
.
PrivateKey
),
google
.
JWTEndpoint
())
Scopes
:
DriverScopes
,
TokenURL
:
"https://accounts.google.com/o/oauth2/token"
,
}
// Initiate an http.Client. The following GET request will be
// authorized and authenticated on the behalf of
// your service account.
client
=
conf
.
Client
(
oauth2
.
NoContext
)
}
else
{
}
else
{
log
.
Printf
(
"[INFO] Requesting Google token via GCE Service Role..."
)
log
.
Printf
(
"[INFO] Requesting Google token via GCE Service Role..."
)
client
=
&
http
.
Client
{
f
,
err
=
oauth2
.
New
(
google
.
ComputeEngineAccount
(
""
))
Transport
:
&
oauth2
.
Transport
{
// Fetch from Google Compute Engine's metadata server to retrieve
// an access token for the provided account.
// If no account is specified, "default" is used.
Source
:
google
.
ComputeTokenSource
(
""
),
},
}
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
log
.
Printf
(
"[INFO] Instantiating GCE client using..."
)
log
.
Printf
(
"[INFO] Instantiating GCE client..."
)
service
,
err
:=
compute
.
New
(
&
http
.
Client
{
Transport
:
f
.
NewTransport
()})
service
,
err
:=
compute
.
New
(
client
)
// Set UserAgent
versionString
:=
"0.0.0"
// TODO(dcunnin): Use Packer's version code from version.go
// versionString := main.Version
// if main.VersionPrerelease != "" {
// versionString = fmt.Sprintf("%s-%s", versionString, main.VersionPrerelease)
// }
service
.
UserAgent
=
fmt
.
Sprintf
(
"(%s %s) Packer/%s"
,
runtime
.
GOOS
,
runtime
.
GOARCH
,
versionString
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment