Skip to content

Commit 6be39ba

Browse files
committed
feat: add new persistent flag: --store-upload-sbom=/path/to.json
1 parent 8cffb00 commit 6be39ba

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

api/sbom_commit.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package api
22

33
import (
4+
"bufio"
45
"context"
6+
"encoding/json"
7+
"github.com/murphysecurity/murphysec/env"
58
"github.com/murphysecurity/murphysec/model"
69
"github.com/murphysecurity/murphysec/scanerr"
710
"github.com/murphysecurity/murphysec/utils"
811
"github.com/murphysecurity/murphysec/utils/must"
12+
"os"
913
)
1014

1115
func SubmitSBOM(ctx context.Context, client *Client, subtaskId string, modules []model.Module, codeFragments []model.ComponentCodeFragment) error {
@@ -17,5 +21,13 @@ func SubmitSBOM(ctx context.Context, client *Client, subtaskId string, modules [
1721
"code_fragments": utils.NoNilSlice(codeFragments),
1822
"scan_warnings": scanerr.GetAll(ctx),
1923
}
24+
if env.StorageUploadSBom != "" {
25+
var f = must.A(os.OpenFile(env.StorageUploadSBom, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666))
26+
var bf = bufio.NewWriter(f)
27+
var encoder = json.NewEncoder(bf)
28+
must.M(encoder.Encode(req))
29+
must.M(bf.Flush())
30+
must.M(f.Close())
31+
}
2032
return client.DoJson(client.PostJson(joinURL(client.baseUrl, "/platform3/v3/client/upload_data"), req), nil)
2133
}

cmd/murphy/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func rootCmd() *cobra.Command {
5757
c.PersistentFlags().StringVar(&common.CliServerAddressOverride, "server", "", "specify server address")
5858
c.PersistentFlags().BoolVarP(&env.CliTlsAllowInsecure, "allow-insecure", "x", false, "Allow insecure TLS connection")
5959
c.PersistentFlags().BoolVar(&env.NoWait, "no-wait", false, "do not wait scan result")
60+
c.PersistentFlags().StringVar(&env.StorageUploadSBom, "store-upload-sbom", "", "")
6061

6162
c.AddCommand(auth.Cmd())
6263
c.AddCommand(scan.Cmd())

env/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var envTlsAllowInsecure bool
2525
var CliTlsAllowInsecure bool
2626
var DoNotBuild bool
2727
var WaitAfterScannerScan bool
28+
var StorageUploadSBom string
2829

2930
func init() {
3031
ctm := os.Getenv("COMMAND_TIMEOUT")

0 commit comments

Comments
 (0)