mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 16:50:08 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package file
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
|
|
registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
|
|
)
|
|
|
|
type FileArtifact struct {
|
|
source string
|
|
filename string
|
|
}
|
|
|
|
func (*FileArtifact) BuilderId() string {
|
|
return BuilderId
|
|
}
|
|
|
|
func (a *FileArtifact) Files() []string {
|
|
return []string{a.filename}
|
|
}
|
|
|
|
func (a *FileArtifact) Id() string {
|
|
return "File"
|
|
}
|
|
|
|
func (a *FileArtifact) String() string {
|
|
return fmt.Sprintf("Stored file: %s", a.filename)
|
|
}
|
|
|
|
func (a *FileArtifact) State(name string) interface{} {
|
|
if name == registryimage.ArtifactStateURI {
|
|
img, err := registryimage.FromArtifact(a,
|
|
registryimage.WithID(path.Base(a.filename)),
|
|
registryimage.WithRegion(path.Dir(a.filename)),
|
|
registryimage.WithSourceID(a.source),
|
|
)
|
|
|
|
if err != nil {
|
|
log.Printf("[DEBUG] error encountered when creating a registry image %v", err)
|
|
return nil
|
|
}
|
|
|
|
return img
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (a *FileArtifact) Destroy() error {
|
|
log.Printf("Deleting %s", a.filename)
|
|
return os.Remove(a.filename)
|
|
}
|