packer/command/core_wrapper.go

73 lines
2.2 KiB
Go
Raw Normal View History

package command
import (
"fmt"
"github.com/hashicorp/hcl/v2"
packerregistry "github.com/hashicorp/packer/internal/registry"
"github.com/hashicorp/packer/packer"
plugingetter "github.com/hashicorp/packer/packer/plugin-getter"
)
// CoreWrapper wraps a packer.Core in order to have it's Initialize func return
// a diagnostic.
type CoreWrapper struct {
*packer.Core
}
2021-01-20 04:37:16 -05:00
func (c *CoreWrapper) Initialize(_ packer.InitializeOptions) hcl.Diagnostics {
err := c.Core.Initialize()
if err != nil {
return hcl.Diagnostics{
&hcl.Diagnostic{
Detail: err.Error(),
Severity: hcl.DiagError,
},
}
}
return nil
}
func (c *CoreWrapper) PluginRequirements() (plugingetter.Requirements, hcl.Diagnostics) {
return nil, hcl.Diagnostics{
&hcl.Diagnostic{
Add `packer plugins` command and subcommands to interact with plugins (#11553) * add basic docs for plugins command * refactor docs Co-Authored-By: Wilken Rivera <1749304+nywilken@users.noreply.github.com> * add plugins command * add plugins subcommands they do nothing for now * add plugins installed command + tests * add plugins install command * add remove plugin command * better docs for the plugins install command * remove duplicate content * better output for installed plugins * add plugins required command * Update plugins_install.go * add newline after `Usage:` * Update plugins_remove.go * Update plugins_required.go * Update plugins_remove.go * Update plugins_installed.go * Update plugins_install.go * add docs * Update plugins_install.go * fix typos * Update plugins_test.go * fix typos Co-Authored-By: Wilken Rivera <1749304+nywilken@users.noreply.github.com> * Update core_wrapper.go Co-Authored-By: Wilken Rivera <1749304+nywilken@users.noreply.github.com> * Update website/content/docs/commands/plugins/remove.mdx Co-authored-by: Wilken Rivera <wilken@hashicorp.com> * Update website/content/docs/commands/plugins/required.mdx Co-authored-by: Wilken Rivera <wilken@hashicorp.com> * Update website/content/docs/commands/plugins/required.mdx Co-authored-by: Wilken Rivera <wilken@hashicorp.com> * Update plugins_required.go * Update install.mdx * Update required.mdx * plugins requirement, warn when no plugin was found * Update website/content/docs/commands/plugins/required.mdx Co-authored-by: Wilken Rivera <wilken@hashicorp.com> Co-authored-by: Wilken Rivera <1749304+nywilken@users.noreply.github.com> Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
2022-02-10 16:53:50 -05:00
Summary: "Packer plugins currently only works with HCL2 configuration templates",
Detail: "Please manually install plugins with the plugins command or use a HCL2 configuration that will do that for you.",
Severity: hcl.DiagError,
},
}
}
// ConfiguredArtifactMetadataPublisher returns a configured image bucket that can be used for publishing
// build image artifacts to a configured Packer Registry destination.
func (c *CoreWrapper) ConfiguredArtifactMetadataPublisher() (*packerregistry.Bucket, hcl.Diagnostics) {
bucket := c.Core.GetRegistryBucket()
// If at this point the bucket is nil, it means the HCP Packer registry is not enabled
if bucket == nil {
return nil, hcl.Diagnostics{
&hcl.Diagnostic{
Summary: "Publishing build artifacts to HCP Packer Registry not enabled",
Detail: "No Packer Registry configuration detected; skipping all publishing steps " +
"See publishing to a Packer registry for Packer configuration details",
Severity: hcl.DiagWarning,
},
}
}
err := bucket.Validate()
if err != nil {
return nil, hcl.Diagnostics{
&hcl.Diagnostic{
Summary: "Invalid HCP Packer configuration",
Detail: fmt.Sprintf("Packer could not validate the provided "+
"HCP Packer registry configuration. Check the error message for details "+
"or contact HCP Packer support for further assistance.\nError: %s", err),
Severity: hcl.DiagError,
},
}
}
return bucket, nil
}