Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curation mvn enabled #31

Merged
merged 8 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
asafambar marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor values as consts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a matter of consts in my opinion, thats what the function want, just read its signature

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
Loading