-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use snyk service in commands
- Loading branch information
1 parent
30168fc
commit 3fb71c0
Showing
5 changed files
with
96 additions
and
43 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
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
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 snyk | ||
|
||
import ( | ||
"github.com/deepmap/oapi-codegen/pkg/securityprovider" | ||
"github.com/google/uuid" | ||
"github.com/package-url/packageurl-go" | ||
"github.com/rs/zerolog" | ||
|
||
"github.com/snyk/parlay/lib/sbom" | ||
"github.com/snyk/parlay/snyk/issues" | ||
) | ||
|
||
type Service interface { | ||
EnrichSBOM(*sbom.SBOMDocument) *sbom.SBOMDocument | ||
GetPackageVulnerabilities(*packageurl.PackageURL) (*issues.FetchIssuesPerPurlResponse, error) | ||
} | ||
|
||
type serviceImpl struct { | ||
cfg *Config | ||
logger *zerolog.Logger | ||
} | ||
|
||
var _ Service = (*serviceImpl)(nil) | ||
|
||
func NewService(cfg *Config, logger *zerolog.Logger) Service { | ||
return &serviceImpl{cfg, logger} | ||
} | ||
|
||
func (svc *serviceImpl) EnrichSBOM(doc *sbom.SBOMDocument) *sbom.SBOMDocument { | ||
return EnrichSBOM(svc.cfg, doc, svc.logger) | ||
} | ||
|
||
func (svc *serviceImpl) GetPackageVulnerabilities(purl *packageurl.PackageURL) (*issues.FetchIssuesPerPurlResponse, error) { | ||
auth, err := svc.getAuth() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
orgID, err := svc.getOrgID(auth) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return GetPackageVulnerabilities(svc.cfg, purl, auth, orgID) | ||
} | ||
|
||
func (svc *serviceImpl) getAuth() (*securityprovider.SecurityProviderApiKey, error) { | ||
return AuthFromToken(svc.cfg.APIToken) | ||
} | ||
|
||
func (svc *serviceImpl) getOrgID(auth *securityprovider.SecurityProviderApiKey) (*uuid.UUID, error) { | ||
return SnykOrgID(svc.cfg, auth) | ||
} |