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
a6783627
Commit
a6783627
authored
Jun 20, 2014
by
Jack Pearkes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vagrant-cloud: add api items
parent
7d4efdc2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
191 additions
and
23 deletions
+191
-23
post-processor/vagrant-cloud/box.go
post-processor/vagrant-cloud/box.go
+44
-0
post-processor/vagrant-cloud/client.go
post-processor/vagrant-cloud/client.go
+34
-21
post-processor/vagrant-cloud/post-processor.go
post-processor/vagrant-cloud/post-processor.go
+11
-2
post-processor/vagrant-cloud/provider.go
post-processor/vagrant-cloud/provider.go
+44
-0
post-processor/vagrant-cloud/version.go
post-processor/vagrant-cloud/version.go
+58
-0
No files found.
post-processor/vagrant-cloud/box.go
0 → 100644
View file @
a6783627
package
vagrantcloud
import
(
"fmt"
)
type
Box
struct
{
client
*
VagrantCloudClient
Tag
string
`json:"tag"`
}
// https://vagrantcloud.com/docs/boxes
func
(
v
VagrantCloudClient
)
Box
(
tag
string
)
(
*
Box
,
error
)
{
resp
,
err
:=
v
.
Get
(
tag
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error retrieving box: %s"
,
err
)
}
box
:=
&
Box
{}
if
err
=
decodeBody
(
resp
,
box
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error parsing box response: %s"
,
err
)
}
return
box
,
nil
}
// Save persist the provider over HTTP to Vagrant Cloud
func
(
b
Box
)
Save
(
tag
string
)
(
bool
,
error
)
{
resp
,
err
:=
b
.
client
.
Get
(
tag
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Error retrieving box: %s"
,
err
)
}
box
:=
&
Box
{}
if
err
=
decodeBody
(
resp
,
box
);
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Error parsing box response: %s"
,
err
)
}
return
true
,
nil
}
post-processor/vagrant-cloud/
api
.go
→
post-processor/vagrant-cloud/
client
.go
View file @
a6783627
...
...
@@ -11,10 +11,6 @@ import (
"strings"
)
type
Box
struct
{
Tag
string
`json:"tag"`
}
type
VagrantCloudClient
struct
{
// The http client for communicating
client
*
http
.
Client
...
...
@@ -55,32 +51,33 @@ func encodeBody(obj interface{}) (io.Reader, error) {
return
buf
,
nil
}
func
(
v
VagrantCloudClient
)
Box
(
tag
string
)
(
*
Box
,
error
)
{
resp
,
err
:=
v
.
Get
(
tag
)
func
(
v
VagrantCloudClient
)
Get
(
path
string
)
(
*
http
.
Response
,
error
)
{
params
:=
url
.
Values
{}
params
.
Set
(
"access_token"
,
v
.
AccessToken
)
reqUrl
:=
fmt
.
Sprintf
(
"%s/%s%s"
,
v
.
BaseURL
,
path
,
params
.
Encode
())
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error retrieving box: %s"
,
err
)
}
// Scrub API key for logs
scrubbedUrl
:=
strings
.
Replace
(
reqUrl
,
v
.
AccessToken
,
"ACCESS_TOKEN"
,
-
1
)
log
.
Printf
(
"Post-Processor Vagrant Cloud API GET: %s"
,
scrubbedUrl
)
box
:=
&
Box
{}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
reqUrl
,
nil
)
resp
,
err
:=
v
.
client
.
Do
(
req
)
if
err
=
decodeBody
(
resp
,
box
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error parsing box response: %s"
,
err
)
}
log
.
Printf
(
"Post-Processor Vagrant Cloud API Response:
\n\n
%s"
,
resp
)
return
box
,
nil
return
resp
,
err
}
func
(
v
VagrantCloudClient
)
Get
(
path
string
)
(
*
http
.
Response
,
error
)
{
func
(
v
VagrantCloudClient
)
Delete
(
path
string
)
(
*
http
.
Response
,
error
)
{
params
:=
url
.
Values
{}
params
.
Set
(
"access_token"
,
v
.
AccessToken
)
reqUrl
:=
fmt
.
Sprintf
(
"%s/%s%s"
,
v
.
BaseURL
,
path
,
params
.
Encode
())
// Scrub API key for logs
scrubbedUrl
:=
strings
.
Replace
(
reqUrl
,
v
.
AccessToken
,
"ACCESS_TOKEN"
,
-
1
)
log
.
Printf
(
"Post-Processor Vagrant Cloud API
GET
: %s"
,
scrubbedUrl
)
log
.
Printf
(
"Post-Processor Vagrant Cloud API
DELETE
: %s"
,
scrubbedUrl
)
req
,
err
:=
http
.
NewRequest
(
"
GET
"
,
reqUrl
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"
DELETE
"
,
reqUrl
,
nil
)
resp
,
err
:=
v
.
client
.
Do
(
req
)
log
.
Printf
(
"Post-Processor Vagrant Cloud API Response:
\n\n
%s"
,
resp
)
...
...
@@ -88,10 +85,26 @@ func (v VagrantCloudClient) Get(path string) (*http.Response, error) {
return
resp
,
err
}
func
(
v
VagrantCloudClient
)
Post
(
path
string
,
body
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
{
func
(
v
VagrantCloudClient
)
Post
(
path
string
,
body
interface
{})
(
*
http
.
Response
,
error
)
{
params
:=
url
.
Values
{}
params
.
Set
(
"access_token"
,
v
.
AccessToken
)
reqUrl
:=
fmt
.
Sprintf
(
"%s/%s%s"
,
v
.
BaseURL
,
path
,
params
.
Encode
())
encBody
,
err
:=
encodeBody
(
body
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error encoding body for request: %s"
,
err
)
}
// Scrub API key for logs
scrubbedUrl
:=
strings
.
Replace
(
path
,
v
.
AccessToken
,
"ACCESS_TOKEN"
,
-
1
)
log
.
Printf
(
"Post-Processor Vagrant Cloud API POST: %s.
\n\n
Body: %s"
,
scrubbedUrl
,
body
)
return
nil
,
nil
scrubbedUrl
:=
strings
.
Replace
(
reqUrl
,
v
.
AccessToken
,
"ACCESS_TOKEN"
,
-
1
)
log
.
Printf
(
"Post-Processor Vagrant Cloud API POST: %s.
\n\n
Body: %s"
,
scrubbedUrl
,
encBody
)
req
,
err
:=
http
.
NewRequest
(
"POST"
,
reqUrl
,
encBody
)
resp
,
err
:=
v
.
client
.
Do
(
req
)
log
.
Printf
(
"Post-Processor Vagrant Cloud API Response:
\n\n
%s"
,
resp
)
return
resp
,
err
}
post-processor/vagrant-cloud/post-processor.go
View file @
a6783627
...
...
@@ -81,6 +81,8 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
config
:=
p
.
config
fmt
.
Println
(
artifact
)
// Only accepts input from the vagrant post-processor
if
artifact
.
BuilderId
()
!=
"mitchellh.post-processor.vagrant"
{
return
nil
,
false
,
fmt
.
Errorf
(
...
...
@@ -89,7 +91,6 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
// The name of the provider for vagrant cloud, and vagrant
provider
:=
providerFromBuilderName
(
artifact
.
Id
())
version
:=
p
.
config
.
Version
tag
:=
p
.
config
.
Tag
// create the HTTP client
...
...
@@ -108,7 +109,14 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return
nil
,
false
,
err
}
ui
.
Say
(
fmt
.
Sprintf
(
"Creating Version %s"
,
version
))
ui
.
Say
(
fmt
.
Sprintf
(
"Creating Version %s"
,
p
.
config
.
Version
))
// Create the new version for the box
version
:=
Version
{
Version
:
p
.
config
.
Version
}
if
ok
,
err
:=
version
.
Create
();
!
ok
{
return
nil
,
false
,
err
}
ui
.
Say
(
fmt
.
Sprintf
(
"Creating Provider %s"
,
version
))
ui
.
Say
(
fmt
.
Sprintf
(
"Uploading Box %s"
,
version
))
ui
.
Say
(
fmt
.
Sprintf
(
"Verifying upload %s"
,
version
))
...
...
@@ -120,6 +128,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
// Runs a cleanup if the post processor fails to upload
func
(
p
*
PostProcessor
)
Cleanup
()
{
// Delete the version
}
// converts a packer builder name to the corresponding vagrant
...
...
post-processor/vagrant-cloud/provider.go
0 → 100644
View file @
a6783627
package
vagrantcloud
import
(
"fmt"
)
type
Provider
struct
{
client
*
VagrantCloudClient
Name
string
`json:"name"`
}
// https://vagrantcloud.com/docs/providers
func
(
v
VagrantCloudClient
)
Provider
(
tag
string
)
(
*
Box
,
error
)
{
resp
,
err
:=
v
.
Get
(
tag
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error retrieving box: %s"
,
err
)
}
box
:=
&
Box
{}
if
err
=
decodeBody
(
resp
,
box
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error parsing box response: %s"
,
err
)
}
return
box
,
nil
}
// Save persist the box over HTTP to Vagrant Cloud
func
(
p
Provider
)
Save
(
name
string
)
(
bool
,
error
)
{
resp
,
err
:=
p
.
client
.
Get
(
name
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Error retrieving box: %s"
,
err
)
}
provider
:=
&
Provider
{}
if
err
=
decodeBody
(
resp
,
provider
);
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Error parsing box response: %s"
,
err
)
}
return
true
,
nil
}
post-processor/vagrant-cloud/version.go
0 → 100644
View file @
a6783627
package
vagrantcloud
import
(
"fmt"
)
type
Version
struct
{
client
*
VagrantCloudClient
Version
string
`json:"version"`
Number
string
`json:"number"`
}
// https://vagrantcloud.com/docs/versions
func
(
v
VagrantCloudClient
)
Version
(
number
string
)
(
*
Version
,
error
)
{
resp
,
err
:=
v
.
Get
(
number
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error retrieving version: %s"
,
err
)
}
version
:=
&
Version
{}
if
err
=
decodeBody
(
resp
,
version
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"Error parsing version response: %s"
,
err
)
}
return
version
,
nil
}
// Save persists the Version over HTTP to Vagrant Cloud
func
(
v
Version
)
Create
()
(
bool
,
error
)
{
resp
,
err
:=
v
.
client
.
Post
(
v
.
Number
,
v
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Error retrieving box: %s"
,
err
)
}
if
err
=
decodeBody
(
resp
,
v
);
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Error parsing box response: %s"
,
err
)
}
return
true
,
nil
}
// Deletes the Version over HTTP to Vagrant Cloud
func
(
v
Version
)
Destroy
()
(
bool
,
error
)
{
resp
,
err
:=
v
.
client
.
Delete
(
v
.
Number
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Error destroying version: %s"
,
err
)
}
if
err
=
decodeBody
(
resp
,
v
);
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"Error parsing box response: %s"
,
err
)
}
return
true
,
nil
}
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