Files
Packer-Cn/packer/cmd_datasource.go
T
fb8fa2b0fe [COMPLIANCE] Add/Update Copyright Headers (#13699)
* [COMPLIANCE] Add/Update Copyright Headers

* make generate update

* make generate

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: sanya <[email protected]>
Co-authored-by: Sanya <[email protected]>
2026-09-15 17:10:54 +05:30

62 lines
1.1 KiB
Go

// Copyright IBM Corp. 2024, 2026
// SPDX-License-Identifier: BUSL-1.1
package packer
import (
"log"
"github.com/hashicorp/hcl/v2/hcldec"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/zclconf/go-cty/cty"
)
type cmdDatasource struct {
d packersdk.Datasource
client *PluginClient
}
func (d *cmdDatasource) ConfigSpec() hcldec.ObjectSpec {
defer func() {
r := recover()
d.checkExit(r, nil)
}()
return d.d.ConfigSpec()
}
func (d *cmdDatasource) Configure(configs ...interface{}) error {
defer func() {
r := recover()
d.checkExit(r, nil)
}()
return d.d.Configure(configs...)
}
func (d *cmdDatasource) OutputSpec() hcldec.ObjectSpec {
defer func() {
r := recover()
d.checkExit(r, nil)
}()
return d.d.OutputSpec()
}
func (d *cmdDatasource) Execute() (cty.Value, error) {
defer func() {
r := recover()
d.checkExit(r, nil)
}()
return d.d.Execute()
}
func (d *cmdDatasource) checkExit(p interface{}, cb func()) {
if d.client.Exited() && cb != nil {
cb()
} else if p != nil && !Killed {
log.Panic(p)
}
}