Skip to content

Commit

Permalink
Merge pull request #21 from mercedes-benz/tagOnUpload
Browse files Browse the repository at this point in the history
tag spdx on upload
  • Loading branch information
mebel123 authored Jun 24, 2024
2 parents 8b3425f + d67de22 commit dd8166f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/onDemandCheckSBOM.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var onDemandCheckSBOM = &cobra.Command{
fmt.Println("Missing filename of SBOM upload")
os.Exit(1)
}
msg := helper.DiscoApiMultipartPost(helper.GetProjectAPIURL("/sbomcheck"), fileName)
msg := helper.SbomUploadFormData(helper.GetProjectAPIURL("/sbomcheck"), fileName, "")
helper.WriteMessageToOut(cmd, ""+helper.PrettyJSONString(msg))
},
}
8 changes: 6 additions & 2 deletions cmd/sbomUpload.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@ import (
)

var sbomUploadCmd = &cobra.Command{
Use: "sbomUpload [FileName]",
Use: "sbomUpload [FileName] [Tag]",
Short: "Uploads SBOM file to a project version",
Long: `Uploads SBOM file to a project version`,
Run: func(cmd *cobra.Command, args []string) {
projectVersion := conf.Config.ProjectVersion
fileName := ""
tag := ""
if len(projectVersion) <= 0 {
fmt.Println("Missing project version")
os.Exit(1)
}
if len(args) > 0 {
fileName = args[0]
if len(args) > 1 {
tag = args[1]
}
} else {
fmt.Println("Missing filename of SBOM upload")
os.Exit(1)
}
msg := helper.DiscoApiMultipartPost(helper.GetProjectVersionAPIURL(projectVersion, "sboms"), fileName)
msg := helper.SbomUploadFormData(helper.GetProjectVersionAPIURL(projectVersion, "sboms"), fileName, tag)
helper.WriteMessageToOut(cmd, ""+helper.PrettyJSONString(msg))
},
}
Binary file added disclosure-cli
Binary file not shown.
10 changes: 8 additions & 2 deletions pkg/helper/apiRequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ import (
"github.com/mercedes-benz/disclosure-cli/conf"
)

func DiscoApiMultipartPost(url string, completeFilename string) string {
func SbomUploadFormData(url string, completeFilename string, tag string) string {
client := &http.Client{}
r, w := io.Pipe()
m := multipart.NewWriter(w)
go func() {
defer w.Close()
defer m.Close()

if len(tag) > 0 {
err := m.WriteField("sbomTag", tag)
if err != nil {
fmt.Println("Error adding tag field " + err.Error())
os.Exit(1)
}
}
_, fileName := path.Split(completeFilename)
part, err := m.CreateFormFile("file", fileName)
if err != nil {
Expand Down

0 comments on commit dd8166f

Please sign in to comment.