Skip to content

Commit

Permalink
hcp-sbom: make validation functions private
Browse files Browse the repository at this point in the history
Since the SBOM validation functions are now called only from the
provisioner itself, they don't need to be public anymore, so we make
them private to the package.
  • Loading branch information
lbajolet-hashicorp committed Nov 11, 2024
1 parent ba97eef commit 2b9084f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion provisioner/hcp-sbom/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (p *Provisioner) Provision(
return err
}

format, err := ValidateSBOM(buf.Bytes())
format, err := validateSBOM(buf.Bytes())
if err != nil {
return fmt.Errorf("validation failed for SBOM file: %s", err)
}
Expand Down
14 changes: 7 additions & 7 deletions provisioner/hcp-sbom/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (e *ValidationError) Unwrap() error {
}

// ValidateCycloneDX is a validation for CycloneDX in JSON format.
func ValidateCycloneDX(content []byte) error {
func validateCycloneDX(content []byte) error {
decoder := cyclonedx.NewBOMDecoder(bytes.NewBuffer(content), cyclonedx.BOMFileFormatJSON)
bom := new(cyclonedx.BOM)
if err := decoder.Decode(bom); err != nil {
Expand All @@ -44,8 +44,8 @@ func ValidateCycloneDX(content []byte) error {
return nil
}

// ValidateSPDX is a validation for SPDX in JSON format.
func ValidateSPDX(content []byte) error {
// validateSPDX is a validation for SPDX in JSON format.
func validateSPDX(content []byte) error {
doc, err := spdxjson.Read(bytes.NewBuffer(content))
if err != nil {
return fmt.Errorf("error parsing SPDX JSON file: %w", err)
Expand All @@ -60,10 +60,10 @@ func ValidateSPDX(content []byte) error {
return nil
}

// ValidateSBOM validates the SBOM file and returns the format of the SBOM.
func ValidateSBOM(content []byte) (string, error) {
// validateSBOM validates the SBOM file and returns the format of the SBOM.
func validateSBOM(content []byte) (string, error) {
// Try validating as SPDX
spdxErr := ValidateSPDX(content)
spdxErr := validateSPDX(content)
if spdxErr == nil {
return "spdx", nil
}
Expand All @@ -72,7 +72,7 @@ func ValidateSBOM(content []byte) (string, error) {
return "", vErr
}

cycloneDxErr := ValidateCycloneDX(content)
cycloneDxErr := validateCycloneDX(content)
if cycloneDxErr == nil {
return "cyclonedx", nil
}
Expand Down

0 comments on commit 2b9084f

Please sign in to comment.