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
e66208c2
Commit
e66208c2
authored
Aug 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/fix: replace CreateTime with new timestamp
parent
4ddb4ab8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
1 deletion
+99
-1
command/fix/command.go
command/fix/command.go
+1
-0
command/fix/fixer.go
command/fix/fixer.go
+2
-1
command/fix/fixer_createtime.go
command/fix/fixer_createtime.go
+51
-0
command/fix/fixer_createtime_test.go
command/fix/fixer_createtime_test.go
+45
-0
No files found.
command/fix/command.go
View file @
e66208c2
...
...
@@ -52,6 +52,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
// Run the template through the various fixers
fixers
:=
[]
string
{
"iso-md5"
,
"createtime"
,
}
input
:=
templateData
...
...
command/fix/fixer.go
View file @
e66208c2
...
...
@@ -13,6 +13,7 @@ var Fixers map[string]Fixer
func
init
()
{
Fixers
=
map
[
string
]
Fixer
{
"iso-md5"
:
new
(
FixerISOMD5
),
"iso-md5"
:
new
(
FixerISOMD5
),
"createtime"
:
new
(
FixerCreateTime
),
}
}
command/fix/fixer_createtime.go
0 → 100644
View file @
e66208c2
package
fix
import
(
"github.com/mitchellh/mapstructure"
"regexp"
)
// FixerCreateTime is a Fixer that replaces the ".CreateTime" template
// calls with "{{timestamp}"
type
FixerCreateTime
struct
{}
func
(
FixerCreateTime
)
Fix
(
input
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
{
// Our template type we'll use for this fixer only
type
template
struct
{
Builders
[]
map
[
string
]
interface
{}
}
// Decode the input into our structure, if we can
var
tpl
template
if
err
:=
mapstructure
.
Decode
(
input
,
&
tpl
);
err
!=
nil
{
return
nil
,
err
}
badKeys
:=
[]
string
{
"ami_name"
,
"bundle_prefix"
,
"snapshot_name"
,
}
re
:=
regexp
.
MustCompile
(
`{{\s*\.CreateTime\s*}}`
)
// Go through each builder and replace CreateTime if we can
for
_
,
builder
:=
range
tpl
.
Builders
{
for
_
,
key
:=
range
badKeys
{
raw
,
ok
:=
builder
[
key
]
if
!
ok
{
continue
}
v
,
ok
:=
raw
.
(
string
)
if
!
ok
{
continue
}
builder
[
key
]
=
re
.
ReplaceAllString
(
v
,
"{{timestamp}}"
)
}
}
input
[
"builders"
]
=
tpl
.
Builders
return
input
,
nil
}
command/fix/fixer_createtime_test.go
0 → 100644
View file @
e66208c2
package
fix
import
(
"reflect"
"testing"
)
func
TestFixerCreateTime_Impl
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
new
(
FixerCreateTime
)
if
_
,
ok
:=
raw
.
(
Fixer
);
!
ok
{
t
.
Fatalf
(
"must be a Fixer"
)
}
}
func
TestFixerCreateTime_Fix
(
t
*
testing
.
T
)
{
var
f
FixerCreateTime
input
:=
map
[
string
]
interface
{}{
"builders"
:
[]
interface
{}{
map
[
string
]
string
{
"type"
:
"foo"
,
"ami_name"
:
"{{.CreateTime}} foo"
,
},
},
}
expected
:=
map
[
string
]
interface
{}{
"builders"
:
[]
map
[
string
]
interface
{}{
map
[
string
]
interface
{}{
"type"
:
"foo"
,
"ami_name"
:
"{{timestamp}} foo"
,
},
},
}
output
,
err
:=
f
.
Fix
(
input
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
output
,
expected
)
{
t
.
Fatalf
(
"unexpected: %#v
\n
expected: %#v
\n
"
,
output
,
expected
)
}
}
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