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
2fb08be1
Commit
2fb08be1
authored
May 26, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template: store Rawcontents
parent
26c7ac2d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
0 deletions
+15
-0
template/parse.go
template/parse.go
+9
-0
template/parse_test.go
template/parse_test.go
+3
-0
template/template.go
template/template.go
+3
-0
No files found.
template/parse.go
View file @
2fb08be1
package
template
import
(
"bytes"
"encoding/json"
"fmt"
"io"
...
...
@@ -23,6 +24,8 @@ type rawTemplate struct {
PostProcessors
[]
interface
{}
`mapstructure:"post-processors"`
Provisioners
[]
map
[
string
]
interface
{}
Variables
map
[
string
]
interface
{}
RawContents
[]
byte
}
// Template returns the actual Template object built from this raw
...
...
@@ -34,6 +37,7 @@ func (r *rawTemplate) Template() (*Template, error) {
// Copy some literals
result
.
Description
=
r
.
Description
result
.
MinVersion
=
r
.
MinVersion
result
.
RawContents
=
r
.
RawContents
// Gather the variables
if
len
(
r
.
Variables
)
>
0
{
...
...
@@ -252,6 +256,10 @@ func (r *rawTemplate) parsePostProcessor(
// Parse takes the given io.Reader and parses a Template object out of it.
func
Parse
(
r
io
.
Reader
)
(
*
Template
,
error
)
{
// Create a buffer to copy what we read
var
buf
bytes
.
Buffer
r
=
io
.
TeeReader
(
r
,
&
buf
)
// First, decode the object into an interface{}. We do this instead of
// the rawTemplate directly because we'd rather use mapstructure to
// decode since it has richer errors.
...
...
@@ -263,6 +271,7 @@ func Parse(r io.Reader) (*Template, error) {
// Create our decoder
var
md
mapstructure
.
Metadata
var
rawTpl
rawTemplate
rawTpl
.
RawContents
=
buf
.
Bytes
()
decoder
,
err
:=
mapstructure
.
NewDecoder
(
&
mapstructure
.
DecoderConfig
{
Metadata
:
&
md
,
Result
:
&
rawTpl
,
...
...
template/parse_test.go
View file @
2fb08be1
...
...
@@ -276,6 +276,9 @@ func TestParse(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
tpl
!=
nil
{
tpl
.
RawContents
=
nil
}
if
!
reflect
.
DeepEqual
(
tpl
,
tc
.
Result
)
{
t
.
Fatalf
(
"bad: %s
\n\n
%#v
\n\n
%#v"
,
tc
.
File
,
tpl
,
tc
.
Result
)
}
...
...
template/template.go
View file @
2fb08be1
...
...
@@ -19,6 +19,9 @@ type Template struct {
Provisioners
[]
*
Provisioner
PostProcessors
[][]
*
PostProcessor
Push
*
Push
// RawContents is just the raw data for this template
RawContents
[]
byte
}
// Builder represents a builder configured in the template
...
...
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