-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a big change, moving the top level enrich command to the ecosystems subcommand, and adding a snyk subcommand. Still some refactoring to do, but this is a working version.
- Loading branch information
Showing
14 changed files
with
2,158 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ $ cat testing/sbom.cyclonedx.json | |
"purl": "pkg:npm/[email protected]" | ||
} | ||
... | ||
$ cat testing/sbom.cyclonedx.json | parlay enrich - | jq | ||
$ cat testing/sbom.cyclonedx.json | parlay e enrich - | jq | ||
... | ||
{ | ||
"bom-ref": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
package commands | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/snyk/parlay/internal/commands/ecosystems" | ||
"github.com/snyk/parlay/internal/commands/snyk" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewDefaultCommand() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "parlay", | ||
Short: "", | ||
Long: ``, | ||
SilenceUsage: true, | ||
Use: "parlay", | ||
Short: "", | ||
Long: ``, | ||
SilenceUsage: true, | ||
DisableFlagsInUseLine: true, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
_ = cmd.Help() | ||
}, | ||
} | ||
|
||
logger := log.New(os.Stdout, "", log.LstdFlags) | ||
|
||
cmd.AddCommand(NewEnrichCommand(logger)) | ||
cmd.AddCommand(ecosystems.NewEcosystemsRootCommand()) | ||
cmd.AddCommand(snyk.NewSnykRootCommand()) | ||
|
||
return &cmd | ||
} |
2 changes: 1 addition & 1 deletion
2
internal/commands/enrich.go → internal/commands/ecosystems/enrich.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package commands | ||
package ecosystems | ||
|
||
import ( | ||
"bufio" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
package ecosystems | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewEcosystemsRootCommand() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "ecosystems", | ||
Short: "", | ||
Long: ``, | ||
SilenceUsage: true, | ||
Use: "ecosystems", | ||
Short: "", | ||
Long: ``, | ||
Aliases: []string{"e"}, | ||
DisableFlagsInUseLine: true, | ||
SilenceUsage: true, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
_ = cmd.Help() | ||
}, | ||
} | ||
logger := log.New(os.Stdout, "", log.LstdFlags) | ||
|
||
cmd.AddCommand(NewPackageCommand()) | ||
cmd.AddCommand(NewRepoCommand()) | ||
cmd.AddCommand(NewEnrichCommand(logger)) | ||
|
||
return &cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package snyk | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/snyk/parlay/lib" | ||
|
||
"github.com/package-url/packageurl-go" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewPackageCommand() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "package <purl> ", | ||
Short: "Return package vulnerabilities from Snyk", | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
purl, err := packageurl.FromString(args[0]) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
resp, err := lib.GetPackageVulnerabilities(purl) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Print(string(resp.Body)) | ||
}, | ||
} | ||
return &cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package snyk | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewSnykRootCommand() *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "snyk", | ||
Short: "", | ||
Long: ``, | ||
SilenceUsage: true, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
_ = cmd.Help() | ||
}, | ||
} | ||
cmd.AddCommand(NewPackageCommand()) | ||
|
||
return &cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package lib | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/snyk/parlay/snyk/users" | ||
|
||
"github.com/deepmap/oapi-codegen/pkg/securityprovider" | ||
"github.com/google/uuid" | ||
) | ||
|
||
const experimentalVersion = "2023-04-28~experimental" | ||
|
||
type selfDocument struct { | ||
Data struct { | ||
Attributes struct { | ||
AvatarURL string `json:"avatar_url,omitempty"` | ||
DefaultOrgContext string `json:"default_org_context,omitempty"` | ||
Name string `json:"name,omitempty"` | ||
Username string `json:"username,omitempty"` | ||
} `json:"attributes,omitempty"` | ||
ID string `json:"id,omitempty"` | ||
Type string `json:"type,omitempty"` | ||
} | ||
Jsonapi interface{} `json:"jsonapi,omitempty"` | ||
Links interface{} `json:"links,omitempty"` | ||
} | ||
|
||
func getSnykOrg(auth *securityprovider.SecurityProviderApiKey) (*uuid.UUID, error) { | ||
experimental, err := users.NewClientWithResponses(snykServer, users.WithRequestEditorFn(auth.Intercept)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
userParams := users.GetSelfParams{Version: experimentalVersion} | ||
self, err := experimental.GetSelfWithResponse(context.Background(), &userParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var userInfo selfDocument | ||
if err = json.Unmarshal(self.Body, &userInfo); err != nil { | ||
return nil, err | ||
} | ||
|
||
orgId := userInfo.Data.Attributes.DefaultOrgContext | ||
org, err := uuid.Parse(orgId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &org, nil | ||
} |
Oops, something went wrong.