mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-30 11:44:01 -04:00
Fix lint
This commit is contained in:
+4
-18
@@ -7,7 +7,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/packer-plugin-sdk/common"
|
||||
@@ -52,19 +51,13 @@ type CoreBuild struct {
|
||||
l sync.Mutex
|
||||
prepareCalled bool
|
||||
|
||||
SBOMFileName string
|
||||
SBOMFileCompressed []byte
|
||||
}
|
||||
|
||||
type SBOM struct {
|
||||
FileName string
|
||||
CompressedData []byte
|
||||
SBOMFilesCompressed [][]byte
|
||||
}
|
||||
|
||||
type BuildMetadata struct {
|
||||
PackerVersion string
|
||||
Plugins map[string]PluginDetails
|
||||
SBOM SBOM
|
||||
SBOMs [][]byte
|
||||
}
|
||||
|
||||
func (b *CoreBuild) getPluginsMetadata() map[string]PluginDetails {
|
||||
@@ -98,10 +91,7 @@ func (b *CoreBuild) GetMetadata() BuildMetadata {
|
||||
metadata := BuildMetadata{
|
||||
PackerVersion: version.FormattedVersion(),
|
||||
Plugins: b.getPluginsMetadata(),
|
||||
SBOM: SBOM{
|
||||
FileName: b.SBOMFileName,
|
||||
CompressedData: b.SBOMFileCompressed,
|
||||
},
|
||||
SBOMs: b.SBOMFilesCompressed,
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
@@ -320,11 +310,7 @@ func (b *CoreBuild) Run(ctx context.Context, originalUi packersdk.Ui) ([]packers
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
b.SBOMFileName = filepath.Base(sbomInternalProvisioner.TempFileLoc)
|
||||
b.SBOMFileCompressed = sbomInternalProvisioner.CompressedData
|
||||
|
||||
fmt.Printf("==== SBOM File Name: %v ====\n", b.SBOMFileName)
|
||||
fmt.Printf("==== SBOM Compressed Data: %v ====\n", len(sbomInternalProvisioner.CompressedData))
|
||||
b.SBOMFilesCompressed = append(b.SBOMFilesCompressed, sbomInternalProvisioner.CompressedData)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-4
@@ -6,10 +6,12 @@ package packer
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/klauspost/compress/zstd"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
@@ -267,10 +269,16 @@ func (p *SBOMInternalProvisioner) Provision(
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create internal temporary file for Packer SBOM: %s", err)
|
||||
}
|
||||
defer tmpFile.Close()
|
||||
defer func(name string) {
|
||||
fileRemoveErr := os.Remove(name)
|
||||
if fileRemoveErr != nil {
|
||||
log.Printf("Error removing SBOM temporary file %s: %s", name, fileRemoveErr)
|
||||
}
|
||||
}(p.TempFileLoc)
|
||||
|
||||
generatedData["dst"] = tmpFile.Name()
|
||||
p.TempFileLoc = tmpFile.Name()
|
||||
ctx = context.WithValue(ctx, "sbomFilePath", tmpFile.Name())
|
||||
tmpFile.Close()
|
||||
|
||||
err = p.Provisioner.Provision(ctx, ui, comm, generatedData)
|
||||
if err != nil {
|
||||
@@ -282,7 +290,6 @@ func (p *SBOMInternalProvisioner) Provision(
|
||||
return err
|
||||
}
|
||||
p.CompressedData = compressedData
|
||||
os.Remove(p.TempFileLoc)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,15 +11,16 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
"github.com/hashicorp/packer-plugin-sdk/common"
|
||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer-plugin-sdk/template/config"
|
||||
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
|
||||
@@ -3,10 +3,11 @@ package hcp_sbom
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
type MockUi struct {
|
||||
|
||||
Reference in New Issue
Block a user