Files

50 lines
949 B
Go
Raw Permalink Normal View History

package packer
2013-06-18 13:49:07 -07:00
import (
2019-03-22 14:56:02 +01:00
"context"
2013-06-18 13:49:07 -07:00
"log"
2018-01-22 17:21:10 -08:00
2019-12-17 11:25:56 +01:00
"github.com/hashicorp/hcl/v2/hcldec"
2020-12-17 13:29:25 -08:00
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
2013-06-18 13:49:07 -07:00
)
type cmdPostProcessor struct {
p packersdk.PostProcessor
client *PluginClient
2013-06-18 13:49:07 -07:00
}
2019-12-17 11:25:56 +01:00
func (b *cmdPostProcessor) ConfigSpec() hcldec.ObjectSpec {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
return b.p.ConfigSpec()
}
func (c *cmdPostProcessor) Configure(config ...interface{}) error {
2013-06-18 13:49:07 -07:00
defer func() {
r := recover()
c.checkExit(r, nil)
}()
return c.p.Configure(config...)
2013-06-18 13:49:07 -07:00
}
2020-11-19 12:17:11 -08:00
func (c *cmdPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a packersdk.Artifact) (packersdk.Artifact, bool, bool, error) {
2013-06-18 13:49:07 -07:00
defer func() {
r := recover()
c.checkExit(r, nil)
}()
2019-03-22 14:56:02 +01:00
return c.p.PostProcess(ctx, ui, a)
2013-06-18 13:49:07 -07:00
}
func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) {
if c.client.Exited() && cb != nil {
2013-06-18 13:49:07 -07:00
cb()
} else if p != nil && !Killed {
2013-06-18 13:49:07 -07:00
log.Panic(p)
}
}