Skip to content

Commit a237148

Browse files
committed
feat: add flag --distribution
1 parent 4968a10 commit a237148

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

api/create_sub_task.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package api
22

33
import (
4+
"time"
5+
46
"github.com/murphysecurity/murphysec/model"
57
"github.com/murphysecurity/murphysec/version"
6-
"time"
78
)
89

910
type CreateSubTaskRequest struct {
@@ -29,6 +30,7 @@ type CreateSubTaskRequest struct {
2930
WebhookMode *string `json:"webhook_mode,omitempty"`
3031
ExtraData *string `json:"extra_data,omitempty"`
3132
IsAutonomous bool `json:"is_autonomous"`
33+
Distribution string `json:"distribution"`
3234
}
3335

3436
type CreateSubTaskResponse struct {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package common
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"strconv"
7+
"strings"
8+
9+
"github.com/spf13/pflag"
10+
)
11+
12+
type DistributionFlag struct {
13+
name string
14+
}
15+
16+
func (d *DistributionFlag) String() string {
17+
if d == nil {
18+
return ""
19+
}
20+
return d.name
21+
}
22+
23+
func (d *DistributionFlag) Set(s string) error {
24+
s = strings.ToLower(strings.TrimSpace(s))
25+
switch s {
26+
case "external", "internal", "saas", "open_source", "":
27+
d.name = s
28+
default:
29+
return fmt.Errorf("invalid distribution: %s", strconv.Quote(s))
30+
}
31+
return nil
32+
}
33+
34+
func (d *DistributionFlag) Type() string {
35+
return "DistributionFlag"
36+
}
37+
38+
func (d *DistributionFlag) IsExternal() bool {
39+
return d.name == "external"
40+
}
41+
42+
func (d *DistributionFlag) IsInternal() bool {
43+
return d.name == "internal"
44+
}
45+
46+
func (d *DistributionFlag) IsSaaS() bool {
47+
return d.name == "saas"
48+
}
49+
50+
func (d *DistributionFlag) IsOpenSource() bool {
51+
return d.name == "open_source"
52+
}
53+
54+
func (d DistributionFlag) MarshalJSON() ([]byte, error) {
55+
return json.Marshal(d.name)
56+
}
57+
58+
func (d *DistributionFlag) UnmarshalJSON(b []byte) error {
59+
var s string
60+
if err := json.Unmarshal(b, &s); err != nil {
61+
return err
62+
}
63+
return d.Set(s)
64+
}
65+
66+
var _ pflag.Value = (*DistributionFlag)(nil)
67+
var _ json.Marshaler = (*DistributionFlag)(nil)
68+
var _ json.Unmarshaler = (*DistributionFlag)(nil)

cmd/murphy/internal/scan/cmd.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
"io"
10+
"os"
11+
"path/filepath"
12+
913
"github.com/murphysecurity/murphysec/api"
1014
"github.com/murphysecurity/murphysec/cmd/murphy/internal/common"
1115
"github.com/murphysecurity/murphysec/cmd/murphy/internal/cv"
@@ -22,9 +26,6 @@ import (
2226
"github.com/repeale/fp-go"
2327
"github.com/samber/lo"
2428
"github.com/spf13/cobra"
25-
"io"
26-
"os"
27-
"path/filepath"
2829
)
2930

3031
var jsonOutput bool
@@ -49,6 +50,7 @@ var branch string
4950
var mavenModuleName []string
5051
var binaryOnly bool
5152
var scanProcess bool
53+
var distribution common.DistributionFlag
5254

5355
func Cmd() *cobra.Command {
5456
var c cobra.Command
@@ -69,6 +71,7 @@ func Cmd() *cobra.Command {
6971
c.Flags().IntVarP(&concurrentNumber, "max-concurrent-uploads", "j", 1, "Set the maximum number of parallel uploads.")
7072
c.Flags().StringVar(&webhookAddr, "webhook-addr", "", "specify the webhook address")
7173
c.Flags().Var(&webhookMode, "webhook-mode", "specify the webhook mode, currently supports: simple, full")
74+
c.Flags().Var(&distribution, "distribution", "specify the distribution, currently supports: external, internal, saas, open_source")
7275
c.Flags().StringVar(&extraData, "extra-data", "", "specify the extra data")
7376
c.Flags().BoolVar(&scanCodeHash, "scan-snippets", false, "Enable scanning of code snippets to detect SBOM and vulnerabilities. Disabled by default")
7477
c.Flags().BoolVar(&binaryOnly, "binary-only", false, "only scan binary files, skip source code scanning")
@@ -95,6 +98,7 @@ func DfCmd() *cobra.Command {
9598
c.Flags().Var(&sbomOutputType, "sbom-format", "(Required) specify the SBOM format, currently supports: msdx1.1+json")
9699
c.Flags().StringVar(&webhookAddr, "webhook-addr", "", "specify the webhook address")
97100
c.Flags().Var(&webhookMode, "webhook-mode", "specify the webhook mode, currently supports: simple, full(default)")
101+
c.Flags().Var(&distribution, "distribution", "specify the distribution, currently supports: external, internal, saas, open_source")
98102
c.Flags().StringVar(&extraData, "extra-data", "", "specify the extra data")
99103
c.Flags().BoolVar(&scanCodeHash, "scan-snippets", false, "Enable scanning of code snippets to detect SBOM and vulnerabilities. Disabled by default")
100104
c.Flags().StringArrayVar(&gradleProjectFilter.ProjectNames, "gradle-project-name", make([]string, 0), "specify the name of the Gradle project")

cmd/murphy/internal/scan/scan.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"github.com/murphysecurity/murphysec/codehash"
87
"os"
98
"path/filepath"
109

10+
"github.com/murphysecurity/murphysec/codehash"
11+
1112
"github.com/murphysecurity/murphysec/api"
1213
"github.com/murphysecurity/murphysec/chunkupload"
1314
"github.com/murphysecurity/murphysec/cmd/murphy/internal/common"
@@ -156,6 +157,8 @@ func scan(ctx context.Context, dir string, accessType model.AccessType, mode mod
156157
createSubtask.PackagePrivateName = privateSourceName
157158
createSubtask.ProjectTagNames = projectTagNames
158159
createSubtask.IsAutonomous = scanCodeHash
160+
createSubtask.Distribution = distribution.String()
161+
159162
if createSubtask.ProjectTagNames == nil {
160163
createSubtask.ProjectTagNames = make([]string, 0)
161164
}

0 commit comments

Comments
 (0)