Skip to content

Commit 041d6ae

Browse files
committed
continue
1 parent 85bcef8 commit 041d6ae

File tree

4 files changed

+69
-54
lines changed

4 files changed

+69
-54
lines changed

resources/deptreemanager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package resources

technologies/technologies.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func ChangeTechDependencyVersion(tech techutils.Technology, directDependencyName
6161
}
6262

6363
func GetDependencyTree(params techutils.DetectDependencyTreeParams) (techutils.TechnologyDependencyTrees, error) {
64+
msg := fmt.Sprintf("Calculating %s dependencies...", params.Technology.ToFormal())
65+
if params.IncludeCuration {
66+
getCurationCacheFolderAndLogMsg(params.Technology)
67+
}
68+
6469
if handler, err := GetTechHandler(params.Technology); err == nil {
6570
log.Info(fmt.Sprintf("Handler Calculating %s dependencies...", params.Technology.ToFormal()))
6671
if tree, err := handler.GetTechDependencyTree(params); err == nil {
@@ -210,10 +215,7 @@ func logDeps(uniqueDeps any) (err error) {
210215
return
211216
}
212217

213-
func getCurationCacheFolderAndLogMsg(params utils.AuditParams, tech techutils.Technology) (logMessage string, curationCacheFolder string, err error) {
214-
if !params.IsCurationCmd() {
215-
return
216-
}
218+
func getCurationCacheFolderAndLogMsg(tech techutils.Technology) (logMessage string, curationCacheFolder string, err error) {
217219
if curationCacheFolder, err = getCurationCacheByTech(tech); err != nil || curationCacheFolder == "" {
218220
return
219221
}

utils/techutils/techhandler.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package techutils
2+
3+
import (
4+
"github.com/owenrumney/go-sarif/v2/sarif"
5+
6+
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
7+
8+
xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils"
9+
)
10+
11+
// In order to support a new technology with the security commands, you need to implement this interface.
12+
type TechnologyHandler interface {
13+
// Get a dependency tree for each descriptor file, the tree will have a root node id with the descriptor/project id, second level nodes are the direct dependencies...
14+
// If no descriptor files are provided, the handler will try to use cwd as the context to find the dependencies.
15+
GetTechDependencyTree(params DetectDependencyTreeParams) (TechnologyDependencyTrees, error)
16+
// Get the locations of the direct dependency in the given descriptor files. if no descriptor files are provided, the handler will try to find at cwd.
17+
GetTechDependencyLocations(directDependencyName, directDependencyVersion string, descriptorPaths ...string) ([]*sarif.Location, error) // maybe ([]formats.ComponentRow, error)
18+
// Change a direct dependency version in the given descriptor files. if no descriptor files are provided, the handler will try to find at cwd.
19+
ChangeTechDependencyVersion(directDependencyName, directDependencyVersion, fixVersion string, descriptorPaths ...string) error
20+
}
21+
22+
type DetectDependencyTreeParams struct {
23+
Technology Technology `json:"technology"`
24+
// If the tech need to create temp file for the output of the command it should output it to this path.
25+
OutputDirPath string `json:"outputDirPath,omitempty"`
26+
// Files that the technology handlers use to detect the project's dependencies.
27+
Descriptors []string `json:"descriptors"`
28+
// Artifactory related options
29+
DependenciesRepository string `json:"dependenciesRepository,omitempty"`
30+
// Curation related options
31+
IncludeCuration bool `json:"includeCuration,omitempty"`
32+
ServerDetails *config.ServerDetails `json:"artifactoryServerDetails,omitempty"`
33+
CurationCacheFolder string `json:"curationCacheFolder,omitempty"`
34+
35+
// Common Tech options
36+
UseWrapper bool `json:"useWrapper,omitempty"`
37+
38+
// Specific Maven options
39+
IsMavenDepTreeInstalled bool `json:"isMavenDepTreeInstalled,omitempty"`
40+
}
41+
42+
type TechnologyDependencyTrees struct {
43+
UniqueDependencies []string `json:"uniqueDependencies"`
44+
DownloadUrls map[string]string `json:"downloadUrls,omitempty"`
45+
// descriptor path -> dependency tree
46+
DependencyTrees map[string]*xrayUtils.GraphNode `json:"dependencyTrees,omitempty"`
47+
}
48+
49+
func (tdr TechnologyDependencyTrees) GetAsXrayScaScanParam() *xrayUtils.GraphNode {
50+
return &xrayUtils.GraphNode{
51+
Id: "root",
52+
}
53+
}
54+
55+
func (tdr TechnologyDependencyTrees) GetUnifiedTree() []*xrayUtils.GraphNode {
56+
return []*xrayUtils.GraphNode{}
57+
}

utils/techutils/techutils.go

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ import (
88
"regexp"
99
"strings"
1010

11-
"github.com/owenrumney/go-sarif/v2/sarif"
1211
"golang.org/x/exp/maps"
1312
"golang.org/x/text/cases"
1413
"golang.org/x/text/language"
1514

1615
"github.com/jfrog/gofrog/datastructures"
1716
"github.com/jfrog/jfrog-cli-core/v2/common/project"
18-
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
17+
1918
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
2019
"github.com/jfrog/jfrog-client-go/artifactory/services/fspatterns"
2120
"github.com/jfrog/jfrog-client-go/utils/errorutils"
2221
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
2322
"github.com/jfrog/jfrog-client-go/utils/log"
24-
xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils"
2523
)
2624

2725
type Technology string
@@ -72,53 +70,6 @@ var TechToProjectType = map[Technology]project.ProjectType{
7270
Dotnet: project.Dotnet,
7371
}
7472

75-
type DetectDependencyTreeParams struct {
76-
Technology Technology `json:"technology"`
77-
// If the tech need to create temp file for the output of the command it should output it to this path.
78-
OutputDirPath string `json:"outputDirPath,omitempty"`
79-
// Files that the technology handlers use to detect the project's dependencies.
80-
Descriptors []string `json:"descriptors"`
81-
// Artifactory related options
82-
DependenciesRepository string `json:"dependenciesRepository,omitempty"`
83-
// Curation related options
84-
IncludeCuration bool `json:"includeCuration,omitempty"`
85-
ServerDetails *config.ServerDetails `json:"artifactoryServerDetails,omitempty"`
86-
CurationCacheFolder string `json:"curationCacheFolder,omitempty"`
87-
88-
// Common Tech options
89-
UseWrapper bool `json:"useWrapper,omitempty"`
90-
91-
// Specific Maven options
92-
IsMavenDepTreeInstalled bool `json:"isMavenDepTreeInstalled,omitempty"`
93-
}
94-
95-
type TechnologyDependencyTrees struct {
96-
UniqueDependencies []string `json:"uniqueDependencies"`
97-
DownloadUrls map[string]string `json:"downloadUrls,omitempty"`
98-
// descriptor path -> dependency tree
99-
DependencyTrees map[string]*xrayUtils.GraphNode `json:"dependencyTrees,omitempty"`
100-
}
101-
102-
func (tdr TechnologyDependencyTrees) GetAsXrayScaScanParam() *xrayUtils.GraphNode {
103-
return &xrayUtils.GraphNode{
104-
Id: "root",
105-
}
106-
}
107-
108-
func (tdr TechnologyDependencyTrees) GetUnifiedTree() []*xrayUtils.GraphNode {
109-
return []*xrayUtils.GraphNode{}
110-
}
111-
112-
type TechnologyHandler interface {
113-
// Get a dependency tree for each descriptor file, the tree will have a root node id with the descriptor/project id, second level nodes are the direct dependencies...
114-
// If no descriptor files are provided, the handler will try to use cwd as the context to find the dependencies.
115-
GetTechDependencyTree(params DetectDependencyTreeParams) (TechnologyDependencyTrees, error)
116-
// Get the locations of the direct dependency in the given descriptor files. if no descriptor files are provided, the handler will try to find at cwd.
117-
GetTechDependencyLocations(directDependencyName, directDependencyVersion string, descriptorPaths ...string) ([]*sarif.Location, error) // maybe ([]formats.ComponentRow, error)
118-
// Change a direct dependency version in the given descriptor files. if no descriptor files are provided, the handler will try to find at cwd.
119-
ChangeTechDependencyVersion(directDependencyName, directDependencyVersion, fixVersion string, descriptorPaths ...string) error
120-
}
121-
12273
type TechData struct {
12374
techIdentifier string
12475

@@ -286,6 +237,10 @@ func (tech Technology) String() string {
286237
return string(tech)
287238
}
288239

240+
func (tech Technology) GetIdentifier() string {
241+
return technologiesData[tech].techIdentifier
242+
}
243+
289244
func (tech Technology) GetExecCommandName() string {
290245
if technologiesData[tech].execCommand == "" {
291246
return tech.String()

0 commit comments

Comments
 (0)