Skip to content

Commit

Permalink
Curation mvn enabled (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
asafambar authored Mar 3, 2024
1 parent cc8b9f3 commit d82ecc0
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 120 deletions.
78 changes: 64 additions & 14 deletions commands/curation/curationaudit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
config "github.com/jfrog/jfrog-cli-core/v2/utils/config"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -49,17 +50,57 @@ const (
"This package manager however isn't supported by this command."

TotalConcurrentRequests = 10

MinArtiMavenSupport = "7.82.0"
MinArtiXraySupport = "3.92.0"
)

var CurationOutputFormats = []string{string(outFormat.Table), string(outFormat.Json)}

var supportedTech = map[coreutils.Technology]func() (bool, error){
coreutils.Npm: func() (bool, error) { return true, nil },
coreutils.Maven: func() (bool, error) {
return clientutils.GetBoolEnvValue(utils.CurationMavenSupport, false)
var supportedTech = map[coreutils.Technology]func(ca *CurationAuditCommand) (bool, error){
coreutils.Npm: func(ca *CurationAuditCommand) (bool, error) { return true, nil },
coreutils.Maven: func(ca *CurationAuditCommand) (bool, error) {
return ca.checkSupportByVersionOrEnv(coreutils.Maven, MinArtiMavenSupport, MinArtiXraySupport, utils.CurationMavenSupport)
},
}

func (ca *CurationAuditCommand) checkSupportByVersionOrEnv(tech coreutils.Technology, minRtVersion, minXrayVersion, envName string) (bool, error) {
if flag, err := clientutils.GetBoolEnvValue(envName, false); flag {
return true, nil
} else if err != nil {
log.Error(err)
}
rtVersion, serverDetails, err := ca.getRtVersionAndServiceDetails(tech)
if err != nil {
return false, err
}

_, xrayVersion, err := utils.CreateXrayServiceManagerAndGetVersion(serverDetails)
if err != nil {
return false, err
}

xrayVersionErr := clientutils.ValidateMinimumVersion(clientutils.Xray, xrayVersion, minXrayVersion)
rtVersionErr := clientutils.ValidateMinimumVersion(clientutils.Artifactory, rtVersion, minRtVersion)
if xrayVersionErr != nil || rtVersionErr != nil {
// though artifactory or xray is not in the required version, the feature can be enabled with env variable.
return false, errors.Join(xrayVersionErr, rtVersionErr)
}
return true, nil
}

func (ca *CurationAuditCommand) getRtVersionAndServiceDetails(tech coreutils.Technology) (string, *config.ServerDetails, error) {
rtManager, serveDetails, err := ca.getRtManagerAndAuth(tech)
if err != nil {
return "", nil, err
}
rtVersion, err := rtManager.GetVersion()
if err != nil {
return "", nil, err
}
return rtVersion, serveDetails, err
}

type ErrorsResp struct {
Errors []ErrorResp `json:"errors"`
}
Expand Down Expand Up @@ -194,7 +235,7 @@ func (ca *CurationAuditCommand) doCurateAudit(results map[string][]*PackageStatu
log.Info(fmt.Sprintf(errorTemplateUnsupportedTech, tech))
continue
}
supported, err := supportedFunc()
supported, err := supportedFunc(ca)
if err != nil {
return err
}
Expand All @@ -210,6 +251,23 @@ func (ca *CurationAuditCommand) doCurateAudit(results map[string][]*PackageStatu
return nil
}

func (ca *CurationAuditCommand) getRtManagerAndAuth(tech coreutils.Technology) (rtManager artifactory.ArtifactoryServicesManager, serverDetails *config.ServerDetails, err error) {
if ca.PackageManagerConfig == nil {
if err = ca.SetRepo(tech); err != nil {
return
}
}
serverDetails, err = ca.PackageManagerConfig.ServerDetails()
if err != nil {
return
}
rtManager, err = rtUtils.CreateServiceManager(serverDetails, 2, 0, false)
if err != nil {
return
}
return
}

func (ca *CurationAuditCommand) getAuditParamsByTech(tech coreutils.Technology) utils.AuditParams {
switch tech {
case coreutils.Npm:
Expand All @@ -231,15 +289,7 @@ func (ca *CurationAuditCommand) auditTree(tech coreutils.Technology, results map
if len(fullDependenciesTrees) == 0 {
return errorutils.CheckErrorf("found no dependencies for the audited project using '%v' as the package manager", tech.String())
}
if err = ca.SetRepo(tech); err != nil {
return err
}
// Resolve the dependencies of the project.
serverDetails, err := ca.PackageManagerConfig.ServerDetails()
if err != nil {
return err
}
rtManager, err := rtUtils.CreateServiceManager(serverDetails, 2, 0, false)
rtManager, serverDetails, err := ca.getRtManagerAndAuth(tech)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit d82ecc0

Please sign in to comment.