github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/internal/packager/sbom/tools.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2021-Present The Jackal Authors
     3  
     4  // Package sbom contains tools for generating SBOMs.
     5  package sbom
     6  
     7  import (
     8  	"fmt"
     9  	"path/filepath"
    10  
    11  	"github.com/AlecAivazis/survey/v2"
    12  	"github.com/Racer159/jackal/src/pkg/message"
    13  	"github.com/Racer159/jackal/src/pkg/utils/exec"
    14  )
    15  
    16  // ViewSBOMFiles opens a browser to view the SBOM files and pauses for user input.
    17  func ViewSBOMFiles(directory string) {
    18  	sbomViewFiles, _ := filepath.Glob(filepath.Join(directory, "sbom-viewer-*"))
    19  
    20  	if len(sbomViewFiles) > 0 {
    21  		link := sbomViewFiles[0]
    22  		msg := fmt.Sprintf("This package has %d images with software bill-of-materials (SBOM) included. If your browser did not open automatically you can copy and paste this file location into your browser address bar to view them: %s\n\n", len(sbomViewFiles), link)
    23  		message.Note(msg)
    24  
    25  		if err := exec.LaunchURL(link); err != nil {
    26  			message.Debug(err)
    27  		}
    28  
    29  		// Use survey.Input to hang until user input
    30  		var value string
    31  		prompt := &survey.Input{
    32  			Message: "Hit the 'enter' key when you are done viewing the SBOM files",
    33  			Default: "",
    34  		}
    35  		_ = survey.AskOne(prompt, &value)
    36  	} else {
    37  		message.Note("There were no images with software bill-of-materials (SBOM) included.")
    38  	}
    39  }