diff --git a/artifactory/commands/buildinfo/adddependencies.go b/artifactory/commands/buildinfo/adddependencies.go
deleted file mode 100644
index d35d3731e..000000000
--- a/artifactory/commands/buildinfo/adddependencies.go
+++ /dev/null
@@ -1,339 +0,0 @@
-package buildinfo
-
-import (
- "errors"
- ioutils "github.com/jfrog/gofrog/io"
- regxp "regexp"
- "strconv"
-
- buildinfo "github.com/jfrog/build-info-go/entities"
- commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/artifactory/services/fspatterns"
- specutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type BuildAddDependenciesCommand struct {
- buildConfiguration *build.BuildConfiguration
- dependenciesSpec *spec.SpecFiles
- dryRun bool
- result *commandsutils.Result
- serverDetails *config.ServerDetails
-}
-
-func NewBuildAddDependenciesCommand() *BuildAddDependenciesCommand {
- return &BuildAddDependenciesCommand{result: new(commandsutils.Result)}
-}
-
-func (badc *BuildAddDependenciesCommand) Result() *commandsutils.Result {
- return badc.result
-}
-
-func (badc *BuildAddDependenciesCommand) CommandName() string {
- return "rt_build_add_dependencies"
-}
-
-func (badc *BuildAddDependenciesCommand) ServerDetails() (*config.ServerDetails, error) {
- if badc.serverDetails != nil {
- return badc.serverDetails, nil
- }
- return config.GetDefaultServerConf()
-}
-
-func (badc *BuildAddDependenciesCommand) Run() error {
- log.Info("Running Build Add Dependencies command...")
- var success int
- var fail int
- var err error
- if !badc.dryRun {
- buildName, err := badc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := badc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- if err = build.SaveBuildGeneralDetails(buildName, buildNumber, badc.buildConfiguration.GetProject()); err != nil {
- return err
- }
- }
- if badc.serverDetails != nil {
- log.Debug("Searching dependencies on Artifactory...")
- success, fail, err = badc.collectRemoteDependencies()
- } else {
- log.Debug("Searching dependencies on local file system...")
- success, fail, err = badc.collectLocalDependencies()
- }
- badc.result.SetSuccessCount(success)
- badc.result.SetFailCount(fail)
- return err
-}
-
-func (badc *BuildAddDependenciesCommand) SetDryRun(dryRun bool) *BuildAddDependenciesCommand {
- badc.dryRun = dryRun
- return badc
-}
-
-func (badc *BuildAddDependenciesCommand) SetDependenciesSpec(dependenciesSpec *spec.SpecFiles) *BuildAddDependenciesCommand {
- badc.dependenciesSpec = dependenciesSpec
- return badc
-}
-
-func (badc *BuildAddDependenciesCommand) SetServerDetails(serverDetails *config.ServerDetails) *BuildAddDependenciesCommand {
- badc.serverDetails = serverDetails
- return badc
-}
-
-func (badc *BuildAddDependenciesCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildAddDependenciesCommand {
- badc.buildConfiguration = buildConfiguration
- return badc
-}
-
-func collectDependenciesChecksums(dependenciesPaths map[string]string) (map[string]*fileutils.FileDetails, int) {
- failures := 0
- dependenciesDetails := make(map[string]*fileutils.FileDetails)
- for _, dependencyPath := range dependenciesPaths {
- var details *fileutils.FileDetails
- var err error
- if fileutils.IsPathSymlink(dependencyPath) {
- log.Info("Adding symlink dependency:", dependencyPath)
- details, err = fspatterns.CreateSymlinkFileDetails()
- } else {
- log.Info("Adding dependency:", dependencyPath)
- details, err = fileutils.GetFileDetails(dependencyPath, true)
- }
- if err != nil {
- log.Error(err)
- failures++
- continue
- }
- dependenciesDetails[dependencyPath] = details
- }
- return dependenciesDetails, failures
-}
-
-func (badc *BuildAddDependenciesCommand) collectLocalDependencies() (success, fail int, err error) {
- var dependenciesDetails map[string]*fileutils.FileDetails
- dependenciesPaths, errorOccurred := badc.doCollectLocalDependencies()
- dependenciesDetails, fail = collectDependenciesChecksums(dependenciesPaths)
- if !badc.dryRun {
- buildInfoDependencies := convertFileInfoToDependencies(dependenciesDetails)
- err = badc.savePartialBuildInfo(buildInfoDependencies)
- if err != nil {
- // Mark all as failures.
- fail = len(dependenciesDetails)
- return
- }
- }
- success = len(dependenciesDetails)
- if errorOccurred || fail > 0 {
- err = errors.New("build Add Dependencies command finished with errors. Please review the logs")
- }
- return
-}
-
-func (badc *BuildAddDependenciesCommand) collectRemoteDependencies() (success, fail int, err error) {
- servicesManager, err := utils.CreateServiceManager(badc.serverDetails, -1, 0, false)
- if err != nil {
- return
- }
- reader, err := searchItems(badc.dependenciesSpec, servicesManager)
- if err != nil {
- return
- }
- success, fail, err = badc.readRemoteDependencies(reader)
- return
-}
-
-func (badc *BuildAddDependenciesCommand) doCollectLocalDependencies() (map[string]string, bool) {
- errorOccurred := false
- dependenciesPaths := make(map[string]string)
- for _, specFile := range badc.dependenciesSpec.Files {
- params, err := prepareArtifactoryParams(specFile)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- continue
- }
- paths, err := getLocalDependencies(params)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- continue
- }
- for _, path := range paths {
- log.Debug("Found matching path:", path)
- dependenciesPaths[path] = path
- }
- }
- return dependenciesPaths, errorOccurred
-}
-
-func (badc *BuildAddDependenciesCommand) readRemoteDependencies(reader *content.ContentReader) (success, fail int, err error) {
- if badc.dryRun {
- success, err = reader.Length()
- return
- }
- count := 0
- var buildInfoDependencies []buildinfo.Dependency
- for resultItem := new(specutils.ResultItem); reader.NextRecord(resultItem) == nil; resultItem = new(specutils.ResultItem) {
- buildInfoDependencies = append(buildInfoDependencies, resultItem.ToDependency())
- count++
- if count > clientutils.MaxBufferSize {
- if err = badc.savePartialBuildInfo(buildInfoDependencies); err != nil {
- return
- }
- success += count
- count = 0
- buildInfoDependencies = nil
- }
- }
- if err = reader.GetError(); err != nil {
- return
- }
- if count > 0 {
- if err = badc.savePartialBuildInfo(buildInfoDependencies); err != nil {
- fail += len(buildInfoDependencies)
- return
- }
- }
- success += count
- return
-}
-
-func prepareArtifactoryParams(specFile spec.File) (*specutils.CommonParams, error) {
- params, err := specFile.ToCommonParams()
- if err != nil {
- return nil, err
- }
-
- recursive, err := clientutils.StringToBool(specFile.Recursive, true)
- if err != nil {
- return nil, err
- }
-
- params.Recursive = recursive
- regexp, err := clientutils.StringToBool(specFile.Regexp, false)
- if err != nil {
- return nil, err
- }
-
- params.Regexp = regexp
- return params, nil
-}
-
-func getLocalDependencies(addDepsParams *specutils.CommonParams) ([]string, error) {
- addDepsParams.SetPattern(clientutils.ReplaceTildeWithUserHome(addDepsParams.GetPattern()))
- // Save parentheses index in pattern, witch have corresponding placeholder.
- rootPath, err := fspatterns.GetRootPath(addDepsParams.GetPattern(), addDepsParams.GetTarget(), "", addDepsParams.GetPatternType(), false)
- if err != nil {
- return nil, err
- }
-
- isDir, err := fileutils.IsDirExists(rootPath, false)
- if err != nil {
- return nil, err
- }
-
- if !isDir || fileutils.IsPathSymlink(addDepsParams.GetPattern()) {
- artifact, err := fspatterns.GetSingleFileToUpload(rootPath, "", false)
- if err != nil {
- return nil, err
- }
- return []string{artifact.LocalPath}, nil
- }
- return collectPatternMatchingFiles(addDepsParams, rootPath)
-}
-
-func collectPatternMatchingFiles(addDepsParams *specutils.CommonParams, rootPath string) ([]string, error) {
- addDepsParams.SetPattern(clientutils.ConvertLocalPatternToRegexp(addDepsParams.Pattern, addDepsParams.GetPatternType()))
- excludePathPattern := fspatterns.PrepareExcludePathPattern(addDepsParams.Exclusions, addDepsParams.GetPatternType(), addDepsParams.IsRecursive())
- patternRegex, err := regxp.Compile(addDepsParams.Pattern)
- if errorutils.CheckError(err) != nil {
- return nil, err
- }
-
- paths, err := fspatterns.ListFiles(rootPath, addDepsParams.IsRecursive(), addDepsParams.IsIncludeDirs(), false, true, excludePathPattern)
- if err != nil {
- return nil, err
- }
- result := []string{}
-
- for _, path := range paths {
- matches, _, err := fspatterns.SearchPatterns(path, true, false, patternRegex)
- if err != nil {
- log.Error(err)
- continue
- }
- if len(matches) > 0 {
- result = append(result, path)
- }
- }
- return result, nil
-}
-
-func (badc *BuildAddDependenciesCommand) savePartialBuildInfo(dependencies []buildinfo.Dependency) error {
- log.Debug("Saving", strconv.Itoa(len(dependencies)), "dependencies.")
- populateFunc := func(partial *buildinfo.Partial) {
- partial.ModuleType = buildinfo.Generic
- partial.Dependencies = dependencies
- partial.ModuleId = badc.buildConfiguration.GetModule()
- }
- buildName, err := badc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := badc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- return build.SavePartialBuildInfo(buildName, buildNumber, badc.buildConfiguration.GetProject(), populateFunc)
-}
-
-func convertFileInfoToDependencies(files map[string]*fileutils.FileDetails) []buildinfo.Dependency {
- var buildDependencies []buildinfo.Dependency
- for filePath, fileInfo := range files {
- dependency := buildinfo.Dependency{}
- dependency.Md5 = fileInfo.Checksum.Md5
- dependency.Sha1 = fileInfo.Checksum.Sha1
- filename, _ := fileutils.GetFileAndDirFromPath(filePath)
- dependency.Id = filename
- buildDependencies = append(buildDependencies, dependency)
- }
- return buildDependencies
-}
-
-func searchItems(spec *spec.SpecFiles, servicesManager artifactory.ArtifactoryServicesManager) (resultReader *content.ContentReader, err error) {
- temp := []*content.ContentReader{}
- var searchParams services.SearchParams
- defer func() {
- for _, reader := range temp {
- ioutils.Close(reader, &err)
- }
- }()
- var reader *content.ContentReader
- for i := 0; i < len(spec.Files); i++ {
- searchParams, err = utils.GetSearchParams(spec.Get(i))
- if err != nil {
- return
- }
- reader, err = servicesManager.SearchFiles(searchParams)
- if err != nil {
- return
- }
- temp = append(temp, reader)
- }
- resultReader, err = content.MergeReaders(temp, content.DefaultKey)
- return
-}
diff --git a/artifactory/commands/buildinfo/addgit.go b/artifactory/commands/buildinfo/addgit.go
deleted file mode 100644
index ae7aeef0b..000000000
--- a/artifactory/commands/buildinfo/addgit.go
+++ /dev/null
@@ -1,490 +0,0 @@
-package buildinfo
-
-import (
- "errors"
- "io"
- "os"
- "os/exec"
- "strconv"
-
- buildinfo "github.com/jfrog/build-info-go/entities"
- gofrogcmd "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- utilsconfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- artclientutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
-
- "github.com/forPelevin/gomoji"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "github.com/spf13/viper"
-)
-
-const (
- GitLogLimit = 100
- ConfigIssuesPrefix = "issues."
- ConfigParseValueError = "Failed parsing %s from configuration file: %s"
- MissingConfigurationError = "Configuration file must contain: %s"
-)
-
-type BuildAddGitCommand struct {
- buildConfiguration *build.BuildConfiguration
- dotGitPath string
- configFilePath string
- serverId string
- issuesConfig *IssuesConfiguration
-}
-
-func NewBuildAddGitCommand() *BuildAddGitCommand {
- return &BuildAddGitCommand{}
-}
-
-func (config *BuildAddGitCommand) SetIssuesConfig(issuesConfig *IssuesConfiguration) *BuildAddGitCommand {
- config.issuesConfig = issuesConfig
- return config
-}
-
-func (config *BuildAddGitCommand) SetConfigFilePath(configFilePath string) *BuildAddGitCommand {
- config.configFilePath = configFilePath
- return config
-}
-
-func (config *BuildAddGitCommand) SetDotGitPath(dotGitPath string) *BuildAddGitCommand {
- config.dotGitPath = dotGitPath
- return config
-}
-
-func (config *BuildAddGitCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildAddGitCommand {
- config.buildConfiguration = buildConfiguration
- return config
-}
-
-func (config *BuildAddGitCommand) SetServerId(serverId string) *BuildAddGitCommand {
- config.serverId = serverId
- return config
-}
-
-func (config *BuildAddGitCommand) Run() error {
- log.Info("Reading the git branch, revision and remote URL and adding them to the build-info.")
- buildName, err := config.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := config.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- err = build.SaveBuildGeneralDetails(buildName, buildNumber, config.buildConfiguration.GetProject())
- if err != nil {
- return err
- }
-
- // Find .git if it wasn't provided in the command.
- if config.dotGitPath == "" {
- var exists bool
- config.dotGitPath, exists, err = fileutils.FindUpstream(".git", fileutils.Any)
- if err != nil {
- return err
- }
- if !exists {
- return errorutils.CheckErrorf("Could not find .git")
- }
- }
-
- // Collect URL, branch and revision into GitManager.
- gitManager := clientutils.NewGitManager(config.dotGitPath)
- err = gitManager.ReadConfig()
- if err != nil {
- return err
- }
-
- // Collect issues if required.
- var issues []buildinfo.AffectedIssue
- if config.configFilePath != "" {
- issues, err = config.collectBuildIssues(gitManager.GetUrl())
- if err != nil {
- return err
- }
- }
-
- // Populate partials with VCS info.
- populateFunc := func(partial *buildinfo.Partial) {
- partial.VcsList = append(partial.VcsList, buildinfo.Vcs{
- Url: gitManager.GetUrl(),
- Revision: gitManager.GetRevision(),
- Branch: gitManager.GetBranch(),
- Message: gomoji.RemoveEmojis(gitManager.GetMessage()),
- })
-
- if config.configFilePath != "" {
- partial.Issues = &buildinfo.Issues{
- Tracker: &buildinfo.Tracker{Name: config.issuesConfig.TrackerName, Version: ""},
- AggregateBuildIssues: config.issuesConfig.Aggregate,
- AggregationBuildStatus: config.issuesConfig.AggregationStatus,
- AffectedIssues: issues,
- }
- }
- }
- err = build.SavePartialBuildInfo(buildName, buildNumber, config.buildConfiguration.GetProject(), populateFunc)
- if err != nil {
- return err
- }
-
- // Done.
- log.Debug("Collected VCS details for", buildName+"/"+buildNumber+".")
- return nil
-}
-
-// Priorities for selecting server:
-// 1. 'server-id' flag.
-// 2. 'serverID' in config file.
-// 3. Default server.
-func (config *BuildAddGitCommand) ServerDetails() (*utilsconfig.ServerDetails, error) {
- var serverId string
- if config.serverId != "" {
- serverId = config.serverId
- } else if config.configFilePath != "" {
- // Get the server ID from the conf file.
- var vConfig *viper.Viper
- vConfig, err := project.ReadConfigFile(config.configFilePath, project.YAML)
- if err != nil {
- return nil, err
- }
- serverId = vConfig.GetString(ConfigIssuesPrefix + "serverID")
- }
- return utilsconfig.GetSpecificConfig(serverId, true, false)
-}
-
-func (config *BuildAddGitCommand) CommandName() string {
- return "rt_build_add_git"
-}
-
-func (config *BuildAddGitCommand) collectBuildIssues(vcsUrl string) ([]buildinfo.AffectedIssue, error) {
- log.Info("Collecting build issues from VCS...")
-
- // Check that git exists in path.
- _, err := exec.LookPath("git")
- if err != nil {
- return nil, errorutils.CheckError(err)
- }
-
- // Initialize issues-configuration.
- config.issuesConfig = new(IssuesConfiguration)
-
- // Create config's IssuesConfigurations from the provided spec file.
- err = config.createIssuesConfigs()
- if err != nil {
- return nil, err
- }
-
- // Get latest build's VCS revision from Artifactory.
- lastVcsRevision, err := config.getLatestVcsRevision(vcsUrl)
- if err != nil {
- return nil, err
- }
-
- // Run issues collection.
- return config.DoCollect(config.issuesConfig, lastVcsRevision)
-}
-
-func (config *BuildAddGitCommand) DoCollect(issuesConfig *IssuesConfiguration, lastVcsRevision string) (foundIssues []buildinfo.AffectedIssue, err error) {
- logRegExp, err := createLogRegExpHandler(issuesConfig, &foundIssues)
- if err != nil {
- return
- }
-
- errRegExp, err := createErrRegExpHandler(lastVcsRevision)
- if err != nil {
- return
- }
-
- // Get log with limit, starting from the latest commit.
- logCmd := &LogCmd{logLimit: issuesConfig.LogLimit, lastVcsRevision: lastVcsRevision}
-
- // Change working dir to where .git is.
- wd, err := os.Getwd()
- if errorutils.CheckError(err) != nil {
- return
- }
- defer func() {
- err = errors.Join(err, errorutils.CheckError(os.Chdir(wd)))
- }()
- err = os.Chdir(config.dotGitPath)
- if errorutils.CheckError(err) != nil {
- return
- }
-
- // Run git command.
- _, _, exitOk, err := gofrogcmd.RunCmdWithOutputParser(logCmd, false, logRegExp, errRegExp)
- if errorutils.CheckError(err) != nil {
- var revisionRangeError RevisionRangeError
- if errors.As(err, &revisionRangeError) {
- // Revision not found in range. Ignore and don't collect new issues.
- log.Info(err.Error())
- return []buildinfo.AffectedIssue{}, nil
- }
- return
- }
- if !exitOk {
- // May happen when trying to run git log for non-existing revision.
- err = errorutils.CheckErrorf("failed executing git log command")
- }
- return
-}
-
-// Creates a regexp handler to parse and fetch issues from the output of the git log command.
-func createLogRegExpHandler(issuesConfig *IssuesConfiguration, foundIssues *[]buildinfo.AffectedIssue) (*gofrogcmd.CmdOutputPattern, error) {
- // Create regex pattern.
- issueRegexp, err := clientutils.GetRegExp(issuesConfig.Regexp)
- if err != nil {
- return nil, err
- }
-
- // Create handler with exec function.
- logRegExp := gofrogcmd.CmdOutputPattern{
- RegExp: issueRegexp,
- ExecFunc: func(pattern *gofrogcmd.CmdOutputPattern) (string, error) {
- // Reached here - means no error occurred.
-
- // Check for out of bound results.
- if len(pattern.MatchedResults)-1 < issuesConfig.KeyGroupIndex || len(pattern.MatchedResults)-1 < issuesConfig.SummaryGroupIndex {
- return "", errors.New("unexpected result while parsing issues from git log. Make sure that the regular expression used to find issues, includes two capturing groups, for the issue ID and the summary")
- }
- // Create found Affected Issue.
- foundIssue := buildinfo.AffectedIssue{Key: pattern.MatchedResults[issuesConfig.KeyGroupIndex], Summary: pattern.MatchedResults[issuesConfig.SummaryGroupIndex], Aggregated: false}
- if issuesConfig.TrackerUrl != "" {
- foundIssue.Url = issuesConfig.TrackerUrl + pattern.MatchedResults[issuesConfig.KeyGroupIndex]
- }
- *foundIssues = append(*foundIssues, foundIssue)
- log.Debug("Found issue: " + pattern.MatchedResults[issuesConfig.KeyGroupIndex])
- return "", nil
- },
- }
- return &logRegExp, nil
-}
-
-// Error to be thrown when revision could not be found in the git revision range.
-type RevisionRangeError struct {
- ErrorMsg string
-}
-
-func (err RevisionRangeError) Error() string {
- return err.ErrorMsg
-}
-
-// Creates a regexp handler to handle the event of revision missing in the git revision range.
-func createErrRegExpHandler(lastVcsRevision string) (*gofrogcmd.CmdOutputPattern, error) {
- // Create regex pattern.
- invalidRangeExp, err := clientutils.GetRegExp(`fatal: Invalid revision range [a-fA-F0-9]+\.\.`)
- if err != nil {
- return nil, err
- }
-
- // Create handler with exec function.
- errRegExp := gofrogcmd.CmdOutputPattern{
- RegExp: invalidRangeExp,
- ExecFunc: func(pattern *gofrogcmd.CmdOutputPattern) (string, error) {
- // Revision could not be found in the revision range, probably due to a squash / revert. Ignore and don't collect new issues.
- errMsg := "Revision: '" + lastVcsRevision + "' that was fetched from latest build info does not exist in the git revision range. No new issues are added."
- return "", RevisionRangeError{ErrorMsg: errMsg}
- },
- }
- return &errRegExp, nil
-}
-
-func (config *BuildAddGitCommand) createIssuesConfigs() (err error) {
- // Read file's data.
- err = config.issuesConfig.populateIssuesConfigsFromSpec(config.configFilePath)
- if err != nil {
- return
- }
-
- // Use 'server-id' flag if provided.
- if config.serverId != "" {
- config.issuesConfig.ServerID = config.serverId
- }
-
- // Build ServerDetails from provided serverID.
- err = config.issuesConfig.setServerDetails()
- if err != nil {
- return
- }
-
- // Add '/' suffix to URL if required.
- if config.issuesConfig.TrackerUrl != "" {
- // Url should end with '/'
- config.issuesConfig.TrackerUrl = clientutils.AddTrailingSlashIfNeeded(config.issuesConfig.TrackerUrl)
- }
-
- return
-}
-
-func (config *BuildAddGitCommand) getLatestVcsRevision(vcsUrl string) (string, error) {
- // Get latest build's build-info from Artifactory
- buildInfo, err := config.getLatestBuildInfo(config.issuesConfig)
- if err != nil {
- return "", err
- }
-
- // Get previous VCS Revision from BuildInfo.
- lastVcsRevision := ""
- for _, vcs := range buildInfo.VcsList {
- if vcs.Url == vcsUrl {
- lastVcsRevision = vcs.Revision
- break
- }
- }
-
- return lastVcsRevision, nil
-}
-
-// Returns build info, or empty build info struct if not found.
-func (config *BuildAddGitCommand) getLatestBuildInfo(issuesConfig *IssuesConfiguration) (*buildinfo.BuildInfo, error) {
- // Create services manager to get build-info from Artifactory.
- sm, err := utils.CreateServiceManager(issuesConfig.ServerDetails, -1, 0, false)
- if err != nil {
- return nil, err
- }
-
- // Get latest build-info from Artifactory.
- buildName, err := config.buildConfiguration.GetBuildName()
- if err != nil {
- return nil, err
- }
- buildInfoParams := services.BuildInfoParams{BuildName: buildName, BuildNumber: artclientutils.LatestBuildNumberKey}
- publishedBuildInfo, found, err := sm.GetBuildInfo(buildInfoParams)
- if err != nil {
- return nil, err
- }
- if !found {
- return &buildinfo.BuildInfo{}, nil
- }
-
- return &publishedBuildInfo.BuildInfo, nil
-}
-
-func (ic *IssuesConfiguration) populateIssuesConfigsFromSpec(configFilePath string) (err error) {
- var vConfig *viper.Viper
- vConfig, err = project.ReadConfigFile(configFilePath, project.YAML)
- if err != nil {
- return err
- }
-
- // Validate that the config contains issues.
- if !vConfig.IsSet("issues") {
- return errorutils.CheckErrorf(MissingConfigurationError, "issues")
- }
-
- // Get server-id.
- if vConfig.IsSet(ConfigIssuesPrefix + "serverID") {
- ic.ServerID = vConfig.GetString(ConfigIssuesPrefix + "serverID")
- }
-
- // Set log limit.
- ic.LogLimit = GitLogLimit
-
- // Get tracker data
- if !vConfig.IsSet(ConfigIssuesPrefix + "trackerName") {
- return errorutils.CheckErrorf(MissingConfigurationError, ConfigIssuesPrefix+"trackerName")
- }
- ic.TrackerName = vConfig.GetString(ConfigIssuesPrefix + "trackerName")
-
- // Get issues pattern
- if !vConfig.IsSet(ConfigIssuesPrefix + "regexp") {
- return errorutils.CheckErrorf(MissingConfigurationError, ConfigIssuesPrefix+"regexp")
- }
- ic.Regexp = vConfig.GetString(ConfigIssuesPrefix + "regexp")
-
- // Get issues base url
- if vConfig.IsSet(ConfigIssuesPrefix + "trackerUrl") {
- ic.TrackerUrl = vConfig.GetString(ConfigIssuesPrefix + "trackerUrl")
- }
-
- // Get issues key group index
- if !vConfig.IsSet(ConfigIssuesPrefix + "keyGroupIndex") {
- return errorutils.CheckErrorf(MissingConfigurationError, ConfigIssuesPrefix+"keyGroupIndex")
- }
- ic.KeyGroupIndex, err = strconv.Atoi(vConfig.GetString(ConfigIssuesPrefix + "keyGroupIndex"))
- if err != nil {
- return errorutils.CheckErrorf(ConfigParseValueError, ConfigIssuesPrefix+"keyGroupIndex", err.Error())
- }
-
- // Get issues summary group index
- if !vConfig.IsSet(ConfigIssuesPrefix + "summaryGroupIndex") {
- return errorutils.CheckErrorf(MissingConfigurationError, ConfigIssuesPrefix+"summaryGroupIndex")
- }
- ic.SummaryGroupIndex, err = strconv.Atoi(vConfig.GetString(ConfigIssuesPrefix + "summaryGroupIndex"))
- if err != nil {
- return errorutils.CheckErrorf(ConfigParseValueError, ConfigIssuesPrefix+"summaryGroupIndex", err.Error())
- }
-
- // Get aggregation aggregate
- ic.Aggregate = false
- if vConfig.IsSet(ConfigIssuesPrefix + "aggregate") {
- ic.Aggregate, err = strconv.ParseBool(vConfig.GetString(ConfigIssuesPrefix + "aggregate"))
- if err != nil {
- return errorutils.CheckErrorf(ConfigParseValueError, ConfigIssuesPrefix+"aggregate", err.Error())
- }
- }
-
- // Get aggregation status
- if vConfig.IsSet(ConfigIssuesPrefix + "aggregationStatus") {
- ic.AggregationStatus = vConfig.GetString(ConfigIssuesPrefix + "aggregationStatus")
- }
-
- return nil
-}
-
-func (ic *IssuesConfiguration) setServerDetails() error {
- // If no server-id provided, use default server.
- serverDetails, err := utilsconfig.GetSpecificConfig(ic.ServerID, true, false)
- if err != nil {
- return err
- }
- ic.ServerDetails = serverDetails
- return nil
-}
-
-type IssuesConfiguration struct {
- ServerDetails *utilsconfig.ServerDetails
- Regexp string
- LogLimit int
- TrackerUrl string
- TrackerName string
- KeyGroupIndex int
- SummaryGroupIndex int
- Aggregate bool
- AggregationStatus string
- ServerID string
-}
-
-type LogCmd struct {
- logLimit int
- lastVcsRevision string
-}
-
-func (logCmd *LogCmd) GetCmd() *exec.Cmd {
- var cmd []string
- cmd = append(cmd, "git")
- cmd = append(cmd, "log", "--pretty=format:%s", "-"+strconv.Itoa(logCmd.logLimit))
- if logCmd.lastVcsRevision != "" {
- cmd = append(cmd, logCmd.lastVcsRevision+"..")
- }
- return exec.Command(cmd[0], cmd[1:]...)
-}
-
-func (logCmd *LogCmd) GetEnv() map[string]string {
- return map[string]string{}
-}
-
-func (logCmd *LogCmd) GetStdWriter() io.WriteCloser {
- return nil
-}
-
-func (logCmd *LogCmd) GetErrWriter() io.WriteCloser {
- return nil
-}
diff --git a/artifactory/commands/buildinfo/addgit_test.go b/artifactory/commands/buildinfo/addgit_test.go
deleted file mode 100644
index 8e6d3ccb1..000000000
--- a/artifactory/commands/buildinfo/addgit_test.go
+++ /dev/null
@@ -1,347 +0,0 @@
-package buildinfo
-
-import (
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "testing"
- "time"
-
- buildinfo "github.com/jfrog/build-info-go/entities"
- testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
-
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/log"
- "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
-)
-
-const (
- withGit = "git_test_.git_suffix"
- withoutGit = "git_test_no_.git_suffix"
- withBranch = "git_issues2_.git_suffix"
- withEmoji = "git_issues3_.git_suffix"
- buildName = "TestExtractGitUrl"
-)
-
-func init() {
- log.SetDefaultLogger()
-}
-
-func TestExtractGitUrlWithDotGit(t *testing.T) {
- runTest(t, withGit)
-}
-
-func TestExtractGitUrlWithoutDotGit(t *testing.T) {
- runTest(t, withoutGit)
-}
-
-func runTest(t *testing.T, originalDir string) {
- baseDir, dotGitPath := tests.PrepareDotGitDir(t, originalDir, filepath.Join("..", "testdata"))
- buildDir := getBuildDir(t)
- defer cleanUp(t, buildDir, dotGitPath, originalDir)
- err := runBuildAddGit(t, buildName, "1", baseDir, true)
- if err != nil {
- return
- }
- partials := getBuildInfoPartials(t, buildName, "1", "")
- checkVCSUrl(partials, t)
-}
-
-func TestBuildAddGitSubmodules(t *testing.T) {
- var projectPath string
- tmpDir, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t)
- defer createTempDirCallback()
- projectPath = testsutils.InitVcsSubmoduleTestDir(t, filepath.Join("..", "testdata", "git_test_submodule"), tmpDir)
-
- testsName := []string{"dotGitProvided", "dotGitSearched"}
- for _, test := range testsName {
- t.Run(test, func(t *testing.T) {
- tmpBuildName := test + "-Build-" + strconv.FormatInt(time.Now().Unix(), 10)
- err := runBuildAddGit(t, tmpBuildName, "1", projectPath, test == "dotGitProvided")
- require.NoError(t, err)
- partials := getBuildInfoPartials(t, tmpBuildName, "1", "")
- assertVcsSubmodules(t, partials)
- })
- }
-}
-
-func TestBuildAddGitVCSDetails(t *testing.T) {
- bagTests := []struct {
- name string
- originalDir string
- revision string
- branch string
- message string
- }{
- {"Test vcs details without branch", withGit, "6198a6294722fdc75a570aac505784d2ec0d1818", "", "TEST-2 - Adding text to file1.txt"},
- {"Test vcs details with branch", withBranch, "b033a0e508bdb52eee25654c9e12db33ff01b8ff", "master", "TEST-4 - Adding text to file2.txt"},
- {"Test vcs details with emoji in message", withEmoji, "f579f0fd274d687949c1f82a55e116eb566ec66d", "master", "TEST-5 - Adding text to file2.txt"},
- }
-
- for _, test := range bagTests {
- t.Run(test.name, func(t *testing.T) {
- baseDir, dotGitPath := tests.PrepareDotGitDir(t, test.originalDir, filepath.Join("..", "testdata"))
- buildDir := getBuildDir(t)
- defer cleanUp(t, buildDir, dotGitPath, test.originalDir)
- err := runBuildAddGit(t, buildName, "1", baseDir, true)
- if err != nil {
- return
- }
- partials := getBuildInfoPartials(t, buildName, "1", "")
- assertVCSDetails(partials, test.revision, test.branch, test.message, t)
- })
- }
-}
-
-func assertVCSDetails(partials buildinfo.Partials, revision, branch, message string, t *testing.T) {
- for _, partial := range partials {
- if partial.VcsList != nil {
- for _, vcs := range partial.VcsList {
- assert.Equal(t, revision, vcs.Revision)
- assert.Equal(t, branch, vcs.Branch)
- assert.Equal(t, message, vcs.Message)
- }
- } else {
- t.Error("VCS cannot be nil")
- break
- }
- }
-}
-
-func assertVcsSubmodules(t *testing.T, partials buildinfo.Partials) {
- assert.Len(t, partials, 1)
- vcsList := partials[0].VcsList
- assert.NotNil(t, vcsList)
- assert.Len(t, vcsList, 1)
- curVcs := vcsList[0]
- assert.Equal(t, "https://github.com/jfrog/jfrog-cli.git", curVcs.Url)
- assert.Equal(t, "6198a6294722fdc75a570aac505784d2ec0d1818", curVcs.Revision)
- assert.Equal(t, "submodule", curVcs.Branch)
- assert.Equal(t, "TEST-2 - Adding text to file1.txt", curVcs.Message)
-}
-
-func cleanUp(t *testing.T, buildDir, dotGitPath, originalDir string) {
- if buildDir != "" {
- tests.RemovePath(buildDir, t)
- }
- if dotGitPath != "" {
- tests.RenamePath(dotGitPath, filepath.Join("..", "testdata", originalDir), t)
- }
-}
-
-func getBuildInfoPartials(t *testing.T, buildName, buildNumber, projectKey string) buildinfo.Partials {
- partials, err := build.ReadPartialBuildInfoFiles(buildName, buildNumber, projectKey)
- if err != nil {
- assert.NoError(t, err)
- return nil
- }
- return partials
-}
-
-// Run BAG command. If setDotGit==true, provide baseDir to the command. Else, change wd to baseDir and make the command find .git manually.
-func runBuildAddGit(t *testing.T, buildName, buildNumber string, baseDir string, setDotGit bool) error {
- buildAddGitConfiguration := new(BuildAddGitCommand).SetBuildConfiguration(build.NewBuildConfiguration(buildName, buildNumber, "", ""))
- if setDotGit {
- buildAddGitConfiguration.SetDotGitPath(baseDir)
- } else {
- wd, err := os.Getwd()
- if err != nil {
- assert.Error(t, err)
- return err
- }
- defer testsutils.ChangeDirAndAssert(t, wd)
-
- err = os.Chdir(baseDir)
- if err != nil {
- assert.Error(t, err)
- return err
- }
- }
- err := buildAddGitConfiguration.Run()
- assert.NoError(t, err)
- return err
-}
-
-func getBuildDir(t *testing.T) string {
- buildDir, err := build.GetBuildDir(buildName, "1", "")
- if err != nil {
- t.Error("Cannot create temp dir due to: " + err.Error())
- return ""
- }
- return buildDir
-}
-
-func checkVCSUrl(partials buildinfo.Partials, t *testing.T) {
- for _, partial := range partials {
- if partial.VcsList != nil {
- for _, vcs := range partial.VcsList {
- url := vcs.Url
- urlSplitted := strings.Split(url, ".git")
- if len(urlSplitted) != 2 {
- t.Error("Arguments value is different than two: ", urlSplitted)
- break
- }
- }
- } else {
- t.Error("VCS cannot be nil")
- break
- }
- }
-}
-
-func TestPopulateIssuesConfigurations(t *testing.T) {
- // Test success scenario
- expectedIssuesConfiguration := &IssuesConfiguration{
- ServerID: "local",
- TrackerName: "TESTING",
- TrackerUrl: "http://TESTING.com",
- Regexp: `([a-zA-Z]+-[0-9]*)\s-\s(.*)`,
- KeyGroupIndex: 1,
- SummaryGroupIndex: 2,
- Aggregate: true,
- AggregationStatus: "RELEASE",
- LogLimit: 100,
- }
- ic := new(IssuesConfiguration)
- // Build config from file
- err := ic.populateIssuesConfigsFromSpec(filepath.Join("..", "testdata", "buildissues", "issuesconfig_success.yaml"))
- // Check they are equal
- if err != nil {
- t.Errorf("Reading configurations file ended with error: %s", err.Error())
- t.FailNow()
- }
- if *ic != *expectedIssuesConfiguration {
- t.Errorf("Failed reading configurations file. Expected: %+v Received: %+v", *expectedIssuesConfiguration, *ic)
- t.FailNow()
- }
-
- // Test failing scenarios
- failing := []string{
- filepath.Join("..", "testdata", "buildissues", "issuesconfig_fail_no_issues.yaml"),
- filepath.Join("..", "testdata", "buildissues", "issuesconfig_fail_invalid_groupindex.yaml"),
- filepath.Join("..", "testdata", "buildissues", "issuesconfig_fail_invalid_aggregate.yaml"),
- }
-
- for _, config := range failing {
- err = ic.populateIssuesConfigsFromSpec(config)
- if err == nil {
- t.Errorf("Reading configurations file was supposed to end with error: %s", config)
- t.FailNow()
- }
- }
-}
-
-func TestAddGitDoCollect(t *testing.T) {
- // Create git folder with files
- originalFolder := "git_issues_.git_suffix"
- baseDir, dotGitPath := tests.PrepareDotGitDir(t, originalFolder, filepath.Join("..", "testdata"))
-
- // Create BuildAddGitCommand
- config := BuildAddGitCommand{
- issuesConfig: &IssuesConfiguration{
- LogLimit: 100,
- Aggregate: false,
- SummaryGroupIndex: 2,
- KeyGroupIndex: 1,
- Regexp: `(.+-[0-9]+)\s-\s(.+)`,
- TrackerName: "test",
- },
- buildConfiguration: build.NewBuildConfiguration("cli-tests-rt-build1", "1", "", ""),
- configFilePath: "",
- dotGitPath: dotGitPath,
- }
-
- // Collect issues
- issues, err := config.DoCollect(config.issuesConfig, "")
- if err != nil {
- t.Error(err)
- }
- if len(issues) != 2 {
- // Error - should be empty
- t.Errorf("Issues list expected to have 2 issues, instead found %d issues: %v", len(issues), issues)
- }
-
- // Clean previous git path
- tests.RenamePath(dotGitPath, filepath.Join(baseDir, originalFolder), t)
- // Check if needs to fail
- if t.Failed() {
- t.FailNow()
- }
- // Set new git path
- originalFolder = "git_issues2_.git_suffix"
- baseDir, dotGitPath = tests.PrepareDotGitDir(t, originalFolder, filepath.Join("..", "testdata"))
-
- // Collect issues - we pass a revision, so only 2 of the 4 existing issues should be collected
- issues, err = config.DoCollect(config.issuesConfig, "6198a6294722fdc75a570aac505784d2ec0d1818")
- if err != nil {
- t.Error(err)
- }
- if len(issues) != 2 {
- // Error - should find 2 issues
- t.Errorf("Issues list expected to have 2 issues, instead found %d issues: %v", len(issues), issues)
- }
-
- // Test collection with a made up revision - the command should not throw an error, and 0 issues should be returned.
- issues, err = config.DoCollect(config.issuesConfig, "abcdefABCDEF1234567890123456789012345678")
- assert.NoError(t, err)
- assert.Empty(t, issues)
-
- // Clean git path
- tests.RenamePath(dotGitPath, filepath.Join(baseDir, originalFolder), t)
-}
-
-func TestServerDetailsFromConfigFile(t *testing.T) {
- expectedUrl := "http://localhost:8081/artifactory/"
- expectedUser := "admin"
-
- homeEnv := os.Getenv(coreutils.HomeDir)
- defer testsutils.SetEnvAndAssert(t, coreutils.HomeDir, homeEnv)
- baseDir, err := os.Getwd()
- assert.NoError(t, err, "Failed to get current dir")
- testsutils.SetEnvAndAssert(t, coreutils.HomeDir, filepath.Join(baseDir, "..", "testdata"))
- configFilePath := filepath.Join("..", "testdata", "buildissues", "issuesconfig_success.yaml")
- config := BuildAddGitCommand{
- configFilePath: configFilePath,
- }
- details, err := config.ServerDetails()
- if err != nil {
- t.Error(err)
- }
-
- if details.ArtifactoryUrl != expectedUrl {
- t.Errorf("Expected %s, got %s", expectedUrl, details.ArtifactoryUrl)
- }
- if details.User != expectedUser {
- t.Errorf("Expected %s, got %s", details.User, expectedUser)
- }
-}
-
-func TestServerDetailsWithoutConfigFile(t *testing.T) {
- expectedUrl := "http://localhost:8082/artifactory/"
- expectedUser := "admin2"
-
- homeEnv := os.Getenv(coreutils.HomeDir)
- defer testsutils.SetEnvAndAssert(t, coreutils.HomeDir, homeEnv)
-
- baseDir, err := os.Getwd()
- assert.NoError(t, err, "Failed to get current dir")
- testsutils.SetEnvAndAssert(t, coreutils.HomeDir, filepath.Join(baseDir, "..", "testdata"))
-
- config := BuildAddGitCommand{}
- details, err := config.ServerDetails()
- if err != nil {
- t.Error(err)
- }
-
- if details.ArtifactoryUrl != expectedUrl {
- t.Errorf("Expected %s, got %s", expectedUrl, details.ArtifactoryUrl)
- }
-
- if details.User != expectedUser {
- t.Errorf("Expected %s, got %s", details.User, expectedUser)
- }
-}
diff --git a/artifactory/commands/buildinfo/buildappend.go b/artifactory/commands/buildinfo/buildappend.go
deleted file mode 100644
index ef9b1af52..000000000
--- a/artifactory/commands/buildinfo/buildappend.go
+++ /dev/null
@@ -1,174 +0,0 @@
-package buildinfo
-
-import (
- "encoding/json"
- "errors"
- "fmt"
- "io"
- "strconv"
- "time"
-
- buildinfo "github.com/jfrog/build-info-go/entities"
- "github.com/jfrog/jfrog-client-go/artifactory"
- servicesutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type BuildAppendCommand struct {
- buildConfiguration *build.BuildConfiguration
- serverDetails *config.ServerDetails
- buildNameToAppend string
- buildNumberToAppend string
-}
-
-func NewBuildAppendCommand() *BuildAppendCommand {
- return &BuildAppendCommand{}
-}
-
-func (bac *BuildAppendCommand) CommandName() string {
- return "rt_build_append"
-}
-
-func (bac *BuildAppendCommand) ServerDetails() (*config.ServerDetails, error) {
- return config.GetDefaultServerConf()
-}
-
-func (bac *BuildAppendCommand) Run() error {
- log.Info("Running Build Append command...")
- buildName, err := bac.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := bac.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- if err = build.SaveBuildGeneralDetails(buildName, buildNumber, bac.buildConfiguration.GetProject()); err != nil {
- return err
- }
-
- // Create services manager to get build-info from Artifactory.
- servicesManager, err := utils.CreateServiceManager(bac.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
-
- // Calculate build timestamp
- timestamp, err := bac.getBuildTimestamp(servicesManager)
- if err != nil {
- return err
- }
-
- // Get checksum values from the build info artifact
- checksumDetails, err := bac.getChecksumDetails(servicesManager, timestamp)
- if err != nil {
- return err
- }
-
- log.Debug("Appending build", bac.buildNameToAppend+"/"+bac.buildNumberToAppend, "to build info")
- populateFunc := func(partial *buildinfo.Partial) {
- partial.ModuleType = buildinfo.Build
- partial.ModuleId = bac.buildNameToAppend + "/" + bac.buildNumberToAppend
- partial.Checksum = buildinfo.Checksum{
- Sha1: checksumDetails.Sha1,
- Md5: checksumDetails.Md5,
- }
- }
- err = build.SavePartialBuildInfo(buildName, buildNumber, bac.buildConfiguration.GetProject(), populateFunc)
- if err == nil {
- log.Info("Build", bac.buildNameToAppend+"/"+bac.buildNumberToAppend, "successfully appended to", buildName+"/"+buildNumber)
- }
- return err
-}
-
-func (bac *BuildAppendCommand) SetServerDetails(serverDetails *config.ServerDetails) *BuildAppendCommand {
- bac.serverDetails = serverDetails
- return bac
-}
-
-func (bac *BuildAppendCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildAppendCommand {
- bac.buildConfiguration = buildConfiguration
- return bac
-}
-
-func (bac *BuildAppendCommand) SetBuildNameToAppend(buildName string) *BuildAppendCommand {
- bac.buildNameToAppend = buildName
- return bac
-}
-
-func (bac *BuildAppendCommand) SetBuildNumberToAppend(buildNumber string) *BuildAppendCommand {
- bac.buildNumberToAppend = buildNumber
- return bac
-}
-
-// Get build timestamp of the build to append. The build timestamp has to be converted to milliseconds from epoch.
-// For example, start time of: 2020-11-27T14:33:38.538+0200 should be converted to 1606480418538.
-func (bac *BuildAppendCommand) getBuildTimestamp(servicesManager artifactory.ArtifactoryServicesManager) (int64, error) {
- // Get published build-info from Artifactory.
- buildInfoParams := services.BuildInfoParams{BuildName: bac.buildNameToAppend, BuildNumber: bac.buildNumberToAppend, ProjectKey: bac.buildConfiguration.GetProject()}
- buildInfo, found, err := servicesManager.GetBuildInfo(buildInfoParams)
- if err != nil {
- return 0, err
- }
- buildString := fmt.Sprintf("Build %s/%s", bac.buildNameToAppend, bac.buildNumberToAppend)
- if bac.buildConfiguration.GetProject() != "" {
- buildString = buildString + " of project: " + bac.buildConfiguration.GetProject()
- }
- if !found {
- return 0, errorutils.CheckErrorf(buildString + " not found in Artifactory.")
- }
-
- buildTime, err := time.Parse(buildinfo.TimeFormat, buildInfo.BuildInfo.Started)
- if errorutils.CheckError(err) != nil {
- return 0, err
- }
-
- // Convert from nanoseconds to milliseconds
- timestamp := buildTime.UnixNano() / 1000000
- log.Debug(buildString + ". Started: " + buildInfo.BuildInfo.Started + ". Calculated timestamp: " + strconv.FormatInt(timestamp, 10))
-
- return timestamp, err
-}
-
-// Download MD5 and SHA1 from the build info artifact.
-func (bac *BuildAppendCommand) getChecksumDetails(servicesManager artifactory.ArtifactoryServicesManager, timestamp int64) (buildinfo.Checksum, error) {
- // Run AQL query for build
- stringTimestamp := strconv.FormatInt(timestamp, 10)
- aqlQuery := servicesutils.CreateAqlQueryForBuildInfoJson(bac.buildConfiguration.GetProject(), bac.buildNameToAppend, bac.buildNumberToAppend, stringTimestamp)
- stream, err := servicesManager.Aql(aqlQuery)
- if err != nil {
- return buildinfo.Checksum{}, err
- }
- defer func() {
- err = errors.Join(err, errorutils.CheckError(stream.Close()))
- }()
-
- // Parse AQL results
- aqlResults, err := io.ReadAll(stream)
- if err != nil {
- return buildinfo.Checksum{}, errorutils.CheckError(err)
- }
- parsedResult := new(servicesutils.AqlSearchResult)
- if err = json.Unmarshal(aqlResults, parsedResult); err != nil {
- return buildinfo.Checksum{}, errorutils.CheckError(err)
- }
- if len(parsedResult.Results) == 0 {
- return buildinfo.Checksum{}, errorutils.CheckErrorf("Build '%s/%s' could not be found", bac.buildNameToAppend, bac.buildNumberToAppend)
- }
-
- // Verify checksum exist
- sha1 := parsedResult.Results[0].Actual_Sha1
- md5 := parsedResult.Results[0].Actual_Md5
- if sha1 == "" || md5 == "" {
- return buildinfo.Checksum{}, errorutils.CheckErrorf("Missing checksums for build-info: '%s/%s', sha1: '%s', md5: '%s'", bac.buildNameToAppend, bac.buildNumberToAppend, sha1, md5)
- }
-
- // Return checksums
- return buildinfo.Checksum{Sha1: sha1, Md5: md5}, nil
-}
diff --git a/artifactory/commands/buildinfo/builddiscard.go b/artifactory/commands/buildinfo/builddiscard.go
deleted file mode 100644
index f45427455..000000000
--- a/artifactory/commands/buildinfo/builddiscard.go
+++ /dev/null
@@ -1,42 +0,0 @@
-package buildinfo
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
-)
-
-type BuildDiscardCommand struct {
- serverDetails *config.ServerDetails
- services.DiscardBuildsParams
-}
-
-func NewBuildDiscardCommand() *BuildDiscardCommand {
- return &BuildDiscardCommand{}
-}
-
-func (buildDiscard *BuildDiscardCommand) SetServerDetails(serverDetails *config.ServerDetails) *BuildDiscardCommand {
- buildDiscard.serverDetails = serverDetails
- return buildDiscard
-}
-
-func (buildDiscard *BuildDiscardCommand) SetDiscardBuildsParams(params services.DiscardBuildsParams) *BuildDiscardCommand {
- buildDiscard.DiscardBuildsParams = params
- return buildDiscard
-}
-
-func (buildDiscard *BuildDiscardCommand) Run() error {
- servicesManager, err := utils.CreateServiceManager(buildDiscard.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- return servicesManager.DiscardBuilds(buildDiscard.DiscardBuildsParams)
-}
-
-func (buildDiscard *BuildDiscardCommand) ServerDetails() (*config.ServerDetails, error) {
- return buildDiscard.serverDetails, nil
-}
-
-func (buildDiscard *BuildDiscardCommand) CommandName() string {
- return "rt_build_discard"
-}
diff --git a/artifactory/commands/buildinfo/clean.go b/artifactory/commands/buildinfo/clean.go
deleted file mode 100644
index efb4ab0e1..000000000
--- a/artifactory/commands/buildinfo/clean.go
+++ /dev/null
@@ -1,47 +0,0 @@
-package buildinfo
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type BuildCleanCommand struct {
- buildConfiguration *build.BuildConfiguration
-}
-
-func NewBuildCleanCommand() *BuildCleanCommand {
- return &BuildCleanCommand{}
-}
-
-func (bcc *BuildCleanCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildCleanCommand {
- bcc.buildConfiguration = buildConfiguration
- return bcc
-}
-
-func (bcc *BuildCleanCommand) CommandName() string {
- return "rt_build_clean"
-}
-
-// Returns the default Artifactory server
-func (bcc *BuildCleanCommand) ServerDetails() (*config.ServerDetails, error) {
- return config.GetDefaultServerConf()
-}
-
-func (bcc *BuildCleanCommand) Run() error {
- log.Info("Cleaning build info...")
- buildName, err := bcc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := bcc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- err = build.RemoveBuildDir(buildName, buildNumber, bcc.buildConfiguration.GetProject())
- if err != nil {
- return err
- }
- log.Info("Cleaned build info", buildName+"/"+buildNumber+".")
- return nil
-}
diff --git a/artifactory/commands/buildinfo/collectenv.go b/artifactory/commands/buildinfo/collectenv.go
deleted file mode 100644
index d4e28ee48..000000000
--- a/artifactory/commands/buildinfo/collectenv.go
+++ /dev/null
@@ -1,53 +0,0 @@
-package buildinfo
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type BuildCollectEnvCommand struct {
- buildConfiguration *build.BuildConfiguration
-}
-
-func NewBuildCollectEnvCommand() *BuildCollectEnvCommand {
- return &BuildCollectEnvCommand{}
-}
-
-func (bcec *BuildCollectEnvCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildCollectEnvCommand {
- bcec.buildConfiguration = buildConfiguration
- return bcec
-}
-
-func (bcec *BuildCollectEnvCommand) Run() error {
- log.Info("Collecting environment variables...")
- buildInfoService := build.CreateBuildInfoService()
- buildName, err := bcec.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := bcec.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- build, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, bcec.buildConfiguration.GetProject())
- if err != nil {
- return errorutils.CheckError(err)
- }
- err = build.CollectEnv()
- if err != nil {
- return errorutils.CheckError(err)
- }
- log.Info("Collected environment variables for", buildName+"/"+buildNumber+".")
- return nil
-}
-
-// Returns the default configured Artifactory server
-func (bcec *BuildCollectEnvCommand) ServerDetails() (*config.ServerDetails, error) {
- return config.GetDefaultServerConf()
-}
-
-func (bcec *BuildCollectEnvCommand) CommandName() string {
- return "rt_build_collect_env"
-}
diff --git a/artifactory/commands/buildinfo/distribute.go b/artifactory/commands/buildinfo/distribute.go
deleted file mode 100644
index e32bbb510..000000000
--- a/artifactory/commands/buildinfo/distribute.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package buildinfo
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
-)
-
-type BuildDistributeCommnad struct {
- serverDetails *config.ServerDetails
- services.BuildDistributionParams
- dryRun bool
-}
-
-func NewBuildDistributeCommnad() *BuildDistributeCommnad {
- return &BuildDistributeCommnad{}
-}
-
-func (bdc *BuildDistributeCommnad) SetServerDetails(serverDetails *config.ServerDetails) *BuildDistributeCommnad {
- bdc.serverDetails = serverDetails
- return bdc
-}
-
-func (bdc *BuildDistributeCommnad) SetDryRun(dryRun bool) *BuildDistributeCommnad {
- bdc.dryRun = dryRun
- return bdc
-}
-
-func (bdc *BuildDistributeCommnad) SetBuildDistributionParams(buildDistributeParams services.BuildDistributionParams) *BuildDistributeCommnad {
- bdc.BuildDistributionParams = buildDistributeParams
- return bdc
-}
-
-func (bdc *BuildDistributeCommnad) Run() error {
- servicesManager, err := utils.CreateServiceManager(bdc.serverDetails, -1, 0, bdc.dryRun)
- if err != nil {
- return err
- }
- return servicesManager.DistributeBuild(bdc.BuildDistributionParams)
-}
-
-func (bdc *BuildDistributeCommnad) ServerDetails() (*config.ServerDetails, error) {
- return bdc.serverDetails, nil
-}
-
-func (bdc *BuildDistributeCommnad) CommandName() string {
- return "rt_build_distribute"
-}
diff --git a/artifactory/commands/buildinfo/promote.go b/artifactory/commands/buildinfo/promote.go
deleted file mode 100644
index 347e0c0fb..000000000
--- a/artifactory/commands/buildinfo/promote.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package buildinfo
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
-)
-
-type BuildPromotionCommand struct {
- services.PromotionParams
- buildConfiguration *build.BuildConfiguration
- serverDetails *config.ServerDetails
- dryRun bool
-}
-
-func NewBuildPromotionCommand() *BuildPromotionCommand {
- return &BuildPromotionCommand{}
-}
-
-func (bpc *BuildPromotionCommand) SetDryRun(dryRun bool) *BuildPromotionCommand {
- bpc.dryRun = dryRun
- return bpc
-}
-
-func (bpc *BuildPromotionCommand) SetServerDetails(serverDetails *config.ServerDetails) *BuildPromotionCommand {
- bpc.serverDetails = serverDetails
- return bpc
-}
-
-func (bpc *BuildPromotionCommand) SetPromotionParams(params services.PromotionParams) *BuildPromotionCommand {
- bpc.PromotionParams = params
- return bpc
-}
-
-func (bpc *BuildPromotionCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildPromotionCommand {
- bpc.buildConfiguration = buildConfiguration
- return bpc
-}
-
-func (bpc *BuildPromotionCommand) Run() error {
- servicesManager, err := utils.CreateServiceManager(bpc.serverDetails, -1, 0, bpc.dryRun)
- if err != nil {
- return err
- }
- if err := bpc.buildConfiguration.ValidateBuildParams(); err != nil {
- return err
- }
- buildName, err := bpc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := bpc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- bpc.BuildName, bpc.BuildNumber, bpc.ProjectKey = buildName, buildNumber, bpc.buildConfiguration.GetProject()
- return servicesManager.PromoteBuild(bpc.PromotionParams)
-}
-
-func (bpc *BuildPromotionCommand) ServerDetails() (*config.ServerDetails, error) {
- return bpc.serverDetails, nil
-}
-
-func (bpc *BuildPromotionCommand) CommandName() string {
- return "rt_build_promote"
-}
diff --git a/artifactory/commands/buildinfo/publish.go b/artifactory/commands/buildinfo/publish.go
deleted file mode 100644
index ab016595f..000000000
--- a/artifactory/commands/buildinfo/publish.go
+++ /dev/null
@@ -1,251 +0,0 @@
-package buildinfo
-
-import (
- "errors"
- "fmt"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/commandsummary"
- "net/url"
- "strconv"
- "strings"
- "time"
-
- buildinfo "github.com/jfrog/build-info-go/entities"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/formats"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/artifactory"
- biconf "github.com/jfrog/jfrog-client-go/artifactory/buildinfo"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- artclientutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type BuildPublishCommand struct {
- buildConfiguration *build.BuildConfiguration
- serverDetails *config.ServerDetails
- config *biconf.Configuration
- detailedSummary bool
- summary *clientutils.Sha256Summary
-}
-
-func NewBuildPublishCommand() *BuildPublishCommand {
- return &BuildPublishCommand{}
-}
-
-func (bpc *BuildPublishCommand) SetConfig(config *biconf.Configuration) *BuildPublishCommand {
- bpc.config = config
- return bpc
-}
-
-func (bpc *BuildPublishCommand) SetServerDetails(serverDetails *config.ServerDetails) *BuildPublishCommand {
- bpc.serverDetails = serverDetails
- return bpc
-}
-
-func (bpc *BuildPublishCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildPublishCommand {
- bpc.buildConfiguration = buildConfiguration
- return bpc
-}
-
-func (bpc *BuildPublishCommand) SetSummary(summary *clientutils.Sha256Summary) *BuildPublishCommand {
- bpc.summary = summary
- return bpc
-}
-
-func (bpc *BuildPublishCommand) GetSummary() *clientutils.Sha256Summary {
- return bpc.summary
-}
-
-func (bpc *BuildPublishCommand) SetDetailedSummary(detailedSummary bool) *BuildPublishCommand {
- bpc.detailedSummary = detailedSummary
- return bpc
-}
-
-func (bpc *BuildPublishCommand) IsDetailedSummary() bool {
- return bpc.detailedSummary
-}
-
-func (bpc *BuildPublishCommand) CommandName() string {
- autoPublishedTriggered, err := clientutils.GetBoolEnvValue(coreutils.UsageAutoPublishedBuild, false)
- if err != nil {
- log.Warn("Failed to get the value of the environment variable: " + coreutils.UsageAutoPublishedBuild + ". " + err.Error())
- }
- if autoPublishedTriggered {
- return "rt_build_publish_auto"
- }
- return "rt_build_publish"
-}
-
-func (bpc *BuildPublishCommand) ServerDetails() (*config.ServerDetails, error) {
- return bpc.serverDetails, nil
-}
-
-func (bpc *BuildPublishCommand) Run() error {
- servicesManager, err := utils.CreateServiceManager(bpc.serverDetails, -1, 0, bpc.config.DryRun)
- if err != nil {
- return err
- }
-
- buildInfoService := build.CreateBuildInfoService()
- buildName, err := bpc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := bpc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- build, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, bpc.buildConfiguration.GetProject())
- if errorutils.CheckError(err) != nil {
- return err
- }
-
- build.SetAgentName(coreutils.GetCliUserAgentName())
- build.SetAgentVersion(coreutils.GetCliUserAgentVersion())
- build.SetBuildAgentVersion(coreutils.GetClientAgentVersion())
- build.SetPrincipal(bpc.serverDetails.User)
- build.SetBuildUrl(bpc.config.BuildUrl)
-
- buildInfo, err := build.ToBuildInfo()
- if errorutils.CheckError(err) != nil {
- return err
- }
- err = buildInfo.IncludeEnv(strings.Split(bpc.config.EnvInclude, ";")...)
- if errorutils.CheckError(err) != nil {
- return err
- }
- err = buildInfo.ExcludeEnv(strings.Split(bpc.config.EnvExclude, ";")...)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if bpc.buildConfiguration.IsLoadedFromConfigFile() {
- buildInfo.Number, err = bpc.getNextBuildNumber(buildInfo.Name, servicesManager)
- if errorutils.CheckError(err) != nil {
- return err
- }
- bpc.buildConfiguration.SetBuildNumber(buildInfo.Number)
- }
- summary, err := servicesManager.PublishBuildInfo(buildInfo, bpc.buildConfiguration.GetProject())
- if bpc.IsDetailedSummary() {
- bpc.SetSummary(summary)
- }
- if err != nil || bpc.config.DryRun {
- return err
- }
-
- majorVersion, err := utils.GetRtMajorVersion(servicesManager)
- if err != nil {
- return err
- }
-
- buildLink, err := bpc.constructBuildInfoUiUrl(majorVersion, buildInfo.Started)
- if err != nil {
- return err
- }
-
- err = build.Clean()
- if err != nil {
- return err
- }
-
- if err = recordCommandSummary(buildInfo, buildLink); err != nil {
- return err
- }
-
- logMsg := "Build info successfully deployed."
- if bpc.IsDetailedSummary() {
- log.Info(logMsg + " Browse it in Artifactory under " + buildLink)
- return nil
- }
-
- log.Info(logMsg)
- return logJsonOutput(buildLink)
-}
-
-func logJsonOutput(buildInfoUiUrl string) error {
- output := formats.BuildPublishOutput{BuildInfoUiUrl: buildInfoUiUrl}
- results, err := output.JSON()
- if err != nil {
- return errorutils.CheckError(err)
- }
- log.Output(clientutils.IndentJson(results))
- return nil
-}
-
-func (bpc *BuildPublishCommand) constructBuildInfoUiUrl(majorVersion int, buildInfoStarted string) (string, error) {
- buildTime, err := time.Parse(buildinfo.TimeFormat, buildInfoStarted)
- if errorutils.CheckError(err) != nil {
- return "", err
- }
- return bpc.getBuildInfoUiUrl(majorVersion, buildTime)
-}
-
-func (bpc *BuildPublishCommand) getBuildInfoUiUrl(majorVersion int, buildTime time.Time) (string, error) {
- buildName, err := bpc.buildConfiguration.GetBuildName()
- if err != nil {
- return "", err
- }
- buildNumber, err := bpc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return "", err
- }
-
- baseUrl := bpc.serverDetails.GetUrl()
- if baseUrl == "" {
- baseUrl = strings.TrimSuffix(strings.TrimSuffix(bpc.serverDetails.GetArtifactoryUrl(), "/"), "artifactory")
- }
- baseUrl = clientutils.AddTrailingSlashIfNeeded(baseUrl)
-
- project := bpc.buildConfiguration.GetProject()
- buildName, buildNumber, project = url.PathEscape(buildName), url.PathEscape(buildNumber), url.QueryEscape(project)
-
- if majorVersion <= 6 {
- return fmt.Sprintf("%vartifactory/webapp/#/builds/%v/%v",
- baseUrl, buildName, buildNumber), nil
- }
- timestamp := buildTime.UnixMilli()
- if project != "" {
- return fmt.Sprintf("%vui/builds/%v/%v/%v/published?buildRepo=%v-build-info&projectKey=%v",
- baseUrl, buildName, buildNumber, strconv.FormatInt(timestamp, 10), project, project), nil
- }
- return fmt.Sprintf("%vui/builds/%v/%v/%v/published?buildRepo=artifactory-build-info",
- baseUrl, buildName, buildNumber, strconv.FormatInt(timestamp, 10)), nil
-}
-
-// Return the next build number based on the previously published build.
-// Return "1" if no build is found
-func (bpc *BuildPublishCommand) getNextBuildNumber(buildName string, servicesManager artifactory.ArtifactoryServicesManager) (string, error) {
- publishedBuildInfo, found, err := servicesManager.GetBuildInfo(services.BuildInfoParams{BuildName: buildName, BuildNumber: artclientutils.LatestBuildNumberKey})
- if err != nil {
- return "", err
- }
- if !found || publishedBuildInfo.BuildInfo.Number == "" {
- return "1", nil
- }
- latestBuildNumber, err := strconv.Atoi(publishedBuildInfo.BuildInfo.Number)
- if errorutils.CheckError(err) != nil {
- if errors.Is(err, strconv.ErrSyntax) {
- log.Warn("The latest build number is " + publishedBuildInfo.BuildInfo.Number + ". Since it is not an integer, and therefore cannot be incremented to automatically generate the next build number, setting the next build number to 1.")
- return "1", nil
- }
- return "", err
- }
- latestBuildNumber++
- return strconv.Itoa(latestBuildNumber), nil
-}
-
-func recordCommandSummary(buildInfo *buildinfo.BuildInfo, buildLink string) (err error) {
- if !commandsummary.ShouldRecordSummary() {
- return
- }
- buildInfo.BuildUrl = buildLink
- buildInfoSummary, err := commandsummary.NewBuildInfoSummary()
- if err != nil {
- return
- }
- return buildInfoSummary.Record(buildInfo)
-}
diff --git a/artifactory/commands/buildinfo/publish_test.go b/artifactory/commands/buildinfo/publish_test.go
deleted file mode 100644
index d3b7e13d5..000000000
--- a/artifactory/commands/buildinfo/publish_test.go
+++ /dev/null
@@ -1,56 +0,0 @@
-package buildinfo
-
-import (
- "strconv"
- "testing"
- "time"
-
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/stretchr/testify/assert"
-)
-
-func TestPrintBuildInfoLink(t *testing.T) {
- timeNow := time.Now()
- buildTime := strconv.FormatInt(timeNow.UnixNano()/1000000, 10)
- var linkTypes = []struct {
- majorVersion int
- buildTime time.Time
- buildInfoConf *build.BuildConfiguration
- serverDetails config.ServerDetails
- expected string
- }{
- // Test platform URL
- {5, timeNow, build.NewBuildConfiguration("test", "1", "6", "cli"),
- config.ServerDetails{Url: "http://localhost:8081/"}, "http://localhost:8081/artifactory/webapp/#/builds/test/1"},
- {6, timeNow, build.NewBuildConfiguration("test", "1", "6", "cli"),
- config.ServerDetails{Url: "http://localhost:8081/"}, "http://localhost:8081/artifactory/webapp/#/builds/test/1"},
- {7, timeNow, build.NewBuildConfiguration("test", "1", "6", ""),
- config.ServerDetails{Url: "http://localhost:8082/"}, "http://localhost:8082/ui/builds/test/1/" + buildTime + "/published?buildRepo=artifactory-build-info"},
- {7, timeNow, build.NewBuildConfiguration("test", "1", "6", "cli"),
- config.ServerDetails{Url: "http://localhost:8082/"}, "http://localhost:8082/ui/builds/test/1/" + buildTime + "/published?buildRepo=cli-build-info&projectKey=cli"},
-
- // Test Artifactory URL
- {5, timeNow, build.NewBuildConfiguration("test", "1", "6", "cli"),
- config.ServerDetails{ArtifactoryUrl: "http://localhost:8081/artifactory"}, "http://localhost:8081/artifactory/webapp/#/builds/test/1"},
- {6, timeNow, build.NewBuildConfiguration("test", "1", "6", "cli"),
- config.ServerDetails{ArtifactoryUrl: "http://localhost:8081/artifactory/"}, "http://localhost:8081/artifactory/webapp/#/builds/test/1"},
- {7, timeNow, build.NewBuildConfiguration("test", "1", "6", ""),
- config.ServerDetails{ArtifactoryUrl: "http://localhost:8082/artifactory"}, "http://localhost:8082/ui/builds/test/1/" + buildTime + "/published?buildRepo=artifactory-build-info"},
- {7, timeNow, build.NewBuildConfiguration("test", "1", "6", "cli"),
- config.ServerDetails{ArtifactoryUrl: "http://localhost:8082/artifactory/"}, "http://localhost:8082/ui/builds/test/1/" + buildTime + "/published?buildRepo=cli-build-info&projectKey=cli"},
- }
-
- for i := range linkTypes {
- buildPubConf := &BuildPublishCommand{
- linkTypes[i].buildInfoConf,
- &linkTypes[i].serverDetails,
- nil,
- true,
- nil,
- }
- buildPubComService, err := buildPubConf.getBuildInfoUiUrl(linkTypes[i].majorVersion, linkTypes[i].buildTime)
- assert.NoError(t, err)
- assert.Equal(t, buildPubComService, linkTypes[i].expected)
- }
-}
diff --git a/artifactory/commands/buildinfo/xrayscan.go b/artifactory/commands/buildinfo/xrayscan.go
deleted file mode 100644
index 8fbaec4ac..000000000
--- a/artifactory/commands/buildinfo/xrayscan.go
+++ /dev/null
@@ -1,112 +0,0 @@
-package buildinfo
-
-import (
- "encoding/json"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-// Deprecated BuildScan Command. The new build scan command is "xray/commands/scan/buildscan"
-type BuildScanLegacyCommand struct {
- buildConfiguration *build.BuildConfiguration
- failBuild bool
- serverDetails *config.ServerDetails
-}
-
-func NewBuildScanLegacyCommand() *BuildScanLegacyCommand {
- return &BuildScanLegacyCommand{}
-}
-
-func (bsc *BuildScanLegacyCommand) SetServerDetails(serverDetails *config.ServerDetails) *BuildScanLegacyCommand {
- bsc.serverDetails = serverDetails
- return bsc
-}
-
-func (bsc *BuildScanLegacyCommand) SetFailBuild(failBuild bool) *BuildScanLegacyCommand {
- bsc.failBuild = failBuild
- return bsc
-}
-
-func (bsc *BuildScanLegacyCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildScanLegacyCommand {
- bsc.buildConfiguration = buildConfiguration
- return bsc
-}
-
-func (bsc *BuildScanLegacyCommand) CommandName() string {
- return "rt_build_scan_legacy"
-}
-
-func (bsc *BuildScanLegacyCommand) ServerDetails() (*config.ServerDetails, error) {
- return bsc.serverDetails, nil
-}
-
-func (bsc *BuildScanLegacyCommand) Run() error {
- log.Info("Triggered Xray build scan... The scan may take a few minutes.")
- servicesManager, err := utils.CreateServiceManager(bsc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
-
- xrayScanParams, err := getXrayScanParams(*bsc.buildConfiguration)
- if err != nil {
- return err
- }
- result, err := servicesManager.XrayScanBuild(xrayScanParams)
- if err != nil {
- return err
- }
-
- var scanResults scanResult
- err = json.Unmarshal(result, &scanResults)
- if errorutils.CheckError(err) != nil {
- return err
- }
-
- log.Info("Xray scan completed.")
- log.Output(clientutils.IndentJson(result))
-
- // Check if should fail build
- if bsc.failBuild && scanResults.Summary.FailBuild {
- // We're specifically returning the 'buildScanError' and not a regular error
- // to indicate that Xray indeed scanned the build, and the failure is not due to
- // networking connectivity or other issues.
- return errorutils.CheckError(utils.GetBuildScanError())
- }
-
- return err
-}
-
-// To unmarshal xray scan summary result
-type scanResult struct {
- Summary scanSummary `json:"summary,omitempty"`
-}
-
-type scanSummary struct {
- TotalAlerts int `json:"total_alerts,omitempty"`
- FailBuild bool `json:"fail_build,omitempty"`
- Message string `json:"message,omitempty"`
- Url string `json:"more_details_url,omitempty"`
-}
-
-func getXrayScanParams(buildConfiguration build.BuildConfiguration) (services.XrayScanParams, error) {
- xrayScanParams := services.NewXrayScanParams()
- buildName, err := buildConfiguration.GetBuildName()
- if err != nil {
- return xrayScanParams, err
- }
- buildNumber, err := buildConfiguration.GetBuildNumber()
- if err != nil {
- return xrayScanParams, err
- }
- xrayScanParams.BuildName = buildName
- xrayScanParams.BuildNumber = buildNumber
- xrayScanParams.ProjectKey = buildConfiguration.GetProject()
-
- return xrayScanParams, nil
-}
diff --git a/artifactory/commands/container/buildcreate.go b/artifactory/commands/container/buildcreate.go
deleted file mode 100644
index 47024147f..000000000
--- a/artifactory/commands/container/buildcreate.go
+++ /dev/null
@@ -1,73 +0,0 @@
-package container
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type BuildDockerCreateCommand struct {
- ContainerCommandBase
- manifestSha256 string
-}
-
-func NewBuildDockerCreateCommand() *BuildDockerCreateCommand {
- return &BuildDockerCreateCommand{}
-}
-
-// Set tag and manifest sha256 of an image in Artifactory.
-// This file can be generated by Kaniko using the'--image-name-with-digest-file' flag
-// or by buildx CLI using '--metadata-file' flag.
-// Tag and Sha256 will be used later on to search the image in Artifactory.
-func (bdc *BuildDockerCreateCommand) SetImageNameWithDigest(filePath string) (err error) {
- bdc.image, bdc.manifestSha256, err = container.GetImageTagWithDigest(filePath)
- return
-}
-
-func (bdc *BuildDockerCreateCommand) Run() error {
- if err := bdc.init(); err != nil {
- return err
- }
- serverDetails, err := bdc.ServerDetails()
- if err != nil {
- return err
- }
- buildName, err := bdc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := bdc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- project := bdc.BuildConfiguration().GetProject()
- serviceManager, err := utils.CreateServiceManager(serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- repo, err := bdc.GetRepo()
- if err != nil {
- return err
- }
- if err = build.SaveBuildGeneralDetails(buildName, buildNumber, project); err != nil {
- return err
- }
- builder, err := container.NewRemoteAgentBuildInfoBuilder(bdc.image, repo, buildName, buildNumber, project, serviceManager, bdc.manifestSha256)
- if err != nil {
- return err
- }
- buildInfo, err := builder.Build(bdc.BuildConfiguration().GetModule())
- if err != nil {
- return err
- }
- return build.SaveBuildInfo(buildName, buildNumber, project, buildInfo)
-}
-
-func (bdc *BuildDockerCreateCommand) CommandName() string {
- return "rt_build_docker_create"
-}
-
-func (bdc *BuildDockerCreateCommand) ServerDetails() (*config.ServerDetails, error) {
- return bdc.serverDetails, nil
-}
diff --git a/artifactory/commands/container/containermanagerbase.go b/artifactory/commands/container/containermanagerbase.go
deleted file mode 100644
index 9169d83dc..000000000
--- a/artifactory/commands/container/containermanagerbase.go
+++ /dev/null
@@ -1,102 +0,0 @@
-package container
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
-)
-
-const (
- // Artifactory 'MinRtVersionForRepoFetching' version and above, returns the image's repository in Artifactory.
- MinRtVersionForRepoFetching = "7.33.3"
-)
-
-type ContainerCommandBase struct {
- image *container.Image
- repo string
- buildConfiguration *build.BuildConfiguration
- serverDetails *config.ServerDetails
-}
-
-func (ccb *ContainerCommandBase) ImageTag() string {
- return ccb.image.Name()
-}
-
-func (ccb *ContainerCommandBase) SetImageTag(imageTag string) *ContainerCommandBase {
- ccb.image = container.NewImage(imageTag)
- return ccb
-}
-
-// Returns the repository name that contains this image.
-func (ccb *ContainerCommandBase) GetRepo() (string, error) {
- // The repository name is saved after first calling this function.
- if ccb.repo != "" {
- return ccb.repo, nil
- }
-
- serviceManager, err := utils.CreateServiceManager(ccb.serverDetails, -1, 0, false)
- if err != nil {
- return "", err
- }
- ccb.repo, err = ccb.image.GetRemoteRepo(serviceManager)
- return ccb.repo, err
-}
-
-func (ccb *ContainerCommandBase) SetRepo(repo string) *ContainerCommandBase {
- ccb.repo = repo
- return ccb
-}
-
-// Since 'RtMinVersion' version of Artifactory we can fetch the docker repository without the user input (witch is deprecated).
-func (ccb *ContainerCommandBase) IsGetRepoSupported() (bool, error) {
- serviceManager, err := utils.CreateServiceManager(ccb.serverDetails, -1, 0, false)
- if err != nil {
- return false, err
- }
- currentVersion, err := serviceManager.GetVersion()
- if err != nil {
- return false, err
- }
- err = clientutils.ValidateMinimumVersion(clientutils.Artifactory, currentVersion, MinRtVersionForRepoFetching)
- return err == nil, nil
-}
-
-func (ccb *ContainerCommandBase) BuildConfiguration() *build.BuildConfiguration {
- return ccb.buildConfiguration
-}
-
-func (ccb *ContainerCommandBase) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *ContainerCommandBase {
- ccb.buildConfiguration = buildConfiguration
- return ccb
-}
-
-func (ccb *ContainerCommandBase) ServerDetails() *config.ServerDetails {
- return ccb.serverDetails
-}
-
-func (ccb *ContainerCommandBase) SetServerDetails(serverDetails *config.ServerDetails) *ContainerCommandBase {
- ccb.serverDetails = serverDetails
- return ccb
-}
-
-func (ccb *ContainerCommandBase) init() error {
- toCollect, err := ccb.buildConfiguration.IsCollectBuildInfo()
- if err != nil || !toCollect {
- return err
- }
- if ccb.repo != "" {
- return nil
- }
- // Check we have all we need to collect build-info.
- ok, err := ccb.IsGetRepoSupported()
- if err != nil {
- return err
- }
- if !ok {
- return errorutils.CheckErrorf("Collecting docker build-info with this command requires Artifactory version %s or higher", MinRtVersionForRepoFetching)
- }
- return nil
-}
diff --git a/artifactory/commands/container/containermanagercommand.go b/artifactory/commands/container/containermanagercommand.go
deleted file mode 100644
index eb4e74efe..000000000
--- a/artifactory/commands/container/containermanagercommand.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package container
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-// General utils for docker/podman commands
-type ContainerCommand struct {
- ContainerCommandBase
- skipLogin bool
- cmdParams []string
- containerManagerType container.ContainerManagerType
-}
-
-func NewContainerManagerCommand(containerManagerType container.ContainerManagerType) *ContainerCommand {
- return &ContainerCommand{
- containerManagerType: containerManagerType,
- }
-}
-
-func (cm *ContainerCommand) SetSkipLogin(skipLogin bool) *ContainerCommand {
- cm.skipLogin = skipLogin
- return cm
-}
-
-func (cm *ContainerCommand) SetCmdParams(cmdParams []string) *ContainerCommand {
- cm.cmdParams = cmdParams
- return cm
-}
-
-func (cm *ContainerCommand) PerformLogin(serverDetails *config.ServerDetails, containerManagerType container.ContainerManagerType) error {
- if !cm.skipLogin {
- // Exclude refreshable tokens when working with external tools (build tools, curl, etc)
- // Otherwise refresh Token may be expireted and docker login will fail.
- if serverDetails.ServerId != "" {
- var err error
- serverDetails, err = config.GetSpecificConfig(serverDetails.ServerId, true, true)
- if err != nil {
- return err
- }
- }
- loginConfig := &container.ContainerManagerLoginConfig{ServerDetails: serverDetails}
- imageRegistry, err := cm.image.GetRegistry()
- if err != nil {
- return err
- }
- return container.ContainerManagerLogin(imageRegistry, loginConfig, containerManagerType)
- }
- return nil
-}
diff --git a/artifactory/commands/container/promote.go b/artifactory/commands/container/promote.go
deleted file mode 100644
index 1e31a2d41..000000000
--- a/artifactory/commands/container/promote.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package container
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
-)
-
-type DockerPromoteCommand struct {
- serverDetails *config.ServerDetails
- params services.DockerPromoteParams
-}
-
-func NewDockerPromoteCommand() *DockerPromoteCommand {
- return &DockerPromoteCommand{}
-}
-
-func (dp *DockerPromoteCommand) Run() error {
- // Create Service Manager
- servicesManager, err := utils.CreateServiceManager(dp.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- // Promote docker
- return servicesManager.PromoteDocker(dp.params)
-}
-
-func (dp *DockerPromoteCommand) CommandName() string {
- return "rt_docker_promote"
-}
-
-func (dp *DockerPromoteCommand) ServerDetails() (*config.ServerDetails, error) {
- return dp.serverDetails, nil
-}
-
-func (dp *DockerPromoteCommand) SetServerDetails(serverDetails *config.ServerDetails) *DockerPromoteCommand {
- dp.serverDetails = serverDetails
- return dp
-}
-
-func (dp *DockerPromoteCommand) SetParams(params services.DockerPromoteParams) *DockerPromoteCommand {
- dp.params = params
- return dp
-}
diff --git a/artifactory/commands/container/pull.go b/artifactory/commands/container/pull.go
deleted file mode 100644
index 957a7bd89..000000000
--- a/artifactory/commands/container/pull.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package container
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
-)
-
-type PullCommand struct {
- ContainerCommand
-}
-
-func NewPullCommand(containerManagerType container.ContainerManagerType) *PullCommand {
- return &PullCommand{
- ContainerCommand: ContainerCommand{
- containerManagerType: containerManagerType,
- },
- }
-}
-
-func (pc *PullCommand) Run() error {
- if err := pc.init(); err != nil {
- return err
- }
- if pc.containerManagerType == container.DockerClient {
- err := container.ValidateClientApiVersion()
- if err != nil {
- return err
- }
- }
- serverDetails, err := pc.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return err
- }
- // Perform login
- if err := pc.PerformLogin(serverDetails, pc.containerManagerType); err != nil {
- return err
- }
- // Perform pull.
- cm := container.NewManager(pc.containerManagerType)
- err = cm.RunNativeCmd(pc.cmdParams)
- if err != nil {
- return err
- }
- toCollect, err := pc.buildConfiguration.IsCollectBuildInfo()
- if err != nil || !toCollect {
- return err
- }
- buildName, err := pc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := pc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- project := pc.BuildConfiguration().GetProject()
- serviceManager, err := utils.CreateServiceManager(serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- repo, err := pc.GetRepo()
- if err != nil {
- return err
- }
- builder, err := container.NewLocalAgentBuildInfoBuilder(pc.image, repo, buildName, buildNumber, project, serviceManager, container.Pull, cm)
- if err != nil {
- return err
- }
- if err := build.SaveBuildGeneralDetails(buildName, buildNumber, project); err != nil {
- return err
- }
- buildInfoModule, err := builder.Build(pc.BuildConfiguration().GetModule())
- if err != nil || buildInfoModule == nil {
- return err
- }
- return build.SaveBuildInfo(buildName, buildNumber, project, buildInfoModule)
-}
-
-func (pc *PullCommand) CommandName() string {
- return "rt_docker_pull"
-}
-
-func (pc *PullCommand) ServerDetails() (*config.ServerDetails, error) {
- return pc.serverDetails, nil
-}
diff --git a/artifactory/commands/container/push.go b/artifactory/commands/container/push.go
deleted file mode 100644
index 1179c4f4f..000000000
--- a/artifactory/commands/container/push.go
+++ /dev/null
@@ -1,165 +0,0 @@
-package container
-
-import (
- "path"
-
- commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- servicesutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
-)
-
-type PushCommand struct {
- ContainerCommand
- threads int
- detailedSummary bool
- result *commandsutils.Result
-}
-
-func NewPushCommand(containerManagerType container.ContainerManagerType) *PushCommand {
- return &PushCommand{
- ContainerCommand: ContainerCommand{
- containerManagerType: containerManagerType,
- },
- }
-}
-
-func (pc *PushCommand) Threads() int {
- return pc.threads
-}
-
-func (pc *PushCommand) SetThreads(threads int) *PushCommand {
- pc.threads = threads
- return pc
-}
-
-func (pc *PushCommand) SetDetailedSummary(detailedSummary bool) *PushCommand {
- pc.detailedSummary = detailedSummary
- return pc
-}
-
-func (pc *PushCommand) IsDetailedSummary() bool {
- return pc.detailedSummary
-}
-
-func (pc *PushCommand) Result() *commandsutils.Result {
- return pc.result
-}
-
-func (pc *PushCommand) SetResult(result *commandsutils.Result) *PushCommand {
- pc.result = result
- return pc
-}
-
-func (pc *PushCommand) Run() error {
- if err := pc.init(); err != nil {
- return err
- }
- if pc.containerManagerType == container.DockerClient {
- err := container.ValidateClientApiVersion()
- if err != nil {
- return err
- }
- }
- serverDetails, err := pc.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return err
- }
- // Perform login
- if err := pc.PerformLogin(serverDetails, pc.containerManagerType); err != nil {
- return err
- }
- // Perform push.
- cm := container.NewManager(pc.containerManagerType)
- err = cm.RunNativeCmd(pc.cmdParams)
- if err != nil {
- return err
- }
- toCollect, err := pc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
- if !toCollect && !pc.IsDetailedSummary() {
- return nil
- }
- buildName, err := pc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := pc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- serviceManager, err := utils.CreateServiceManagerWithThreads(serverDetails, false, pc.threads, -1, 0)
- if err != nil {
- return err
- }
- repo, err := pc.GetRepo()
- if err != nil {
- return err
- }
- builder, err := container.NewLocalAgentBuildInfoBuilder(pc.image, repo, buildName, buildNumber, pc.BuildConfiguration().GetProject(), serviceManager, container.Push, cm)
- if err != nil {
- return err
- }
- if toCollect {
- if err := build.SaveBuildGeneralDetails(buildName, buildNumber, pc.buildConfiguration.GetProject()); err != nil {
- return err
- }
- buildInfoModule, err := builder.Build(pc.BuildConfiguration().GetModule())
- if err != nil || buildInfoModule == nil {
- return err
- }
- if err = build.SaveBuildInfo(buildName, buildNumber, pc.BuildConfiguration().GetProject(), buildInfoModule); err != nil {
- return err
- }
- }
- if pc.IsDetailedSummary() {
- if !toCollect {
- // The build-info collection hasn't been triggered at this point, and we do need it for handling the detailed summary.
- // We are therefore skipping setting mage build name/number props before running build-info collection.
- builder.SetSkipTaggingLayers(true)
- _, err = builder.Build("")
- if err != nil {
- return err
- }
- }
- return pc.layersMapToFileTransferDetails(serverDetails.ArtifactoryUrl, builder.GetLayers())
- }
- return nil
-}
-
-func (pc *PushCommand) layersMapToFileTransferDetails(artifactoryUrl string, layers *[]servicesutils.ResultItem) error {
- var details []clientutils.FileTransferDetails
- for _, layer := range *layers {
- sha256 := ""
- for _, property := range layer.Properties {
- if property.Key == "sha256" {
- sha256 = property.Value
- }
- }
- details = append(details, clientutils.FileTransferDetails{TargetPath: path.Join(layer.Repo, layer.Path, layer.Name), RtUrl: artifactoryUrl, Sha256: sha256})
- }
- tempFile, err := clientutils.SaveFileTransferDetailsInTempFile(&details)
- if err != nil {
- return err
- }
- result := new(commandsutils.Result)
- result.SetReader(content.NewContentReader(tempFile, "files"))
- result.SetSuccessCount(len(details))
- pc.SetResult(result)
- return nil
-}
-
-func (pc *PushCommand) CommandName() string {
- return "rt_docker_push"
-}
-
-func (pc *PushCommand) ServerDetails() (*config.ServerDetails, error) {
- return pc.serverDetails, nil
-}
diff --git a/artifactory/commands/curl/curl.go b/artifactory/commands/curl/curl.go
deleted file mode 100644
index e1a32f66c..000000000
--- a/artifactory/commands/curl/curl.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package curl
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/common/commands"
-)
-
-type RtCurlCommand struct {
- commands.CurlCommand
-}
-
-func NewRtCurlCommand(curlCommand commands.CurlCommand) *RtCurlCommand {
- return &RtCurlCommand{curlCommand}
-}
-
-func (curlCmd *RtCurlCommand) CommandName() string {
- return "rt_curl"
-}
diff --git a/artifactory/commands/dotnet/dotnetcommand.go b/artifactory/commands/dotnet/dotnetcommand.go
deleted file mode 100644
index 6c72ff6a3..000000000
--- a/artifactory/commands/dotnet/dotnetcommand.go
+++ /dev/null
@@ -1,386 +0,0 @@
-package dotnet
-
-import (
- "errors"
- "fmt"
- "github.com/jfrog/build-info-go/build"
- "github.com/jfrog/build-info-go/build/utils/dotnet"
- frogio "github.com/jfrog/gofrog/io"
- commonBuild "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/auth"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "net/url"
- "os"
- "path"
- "path/filepath"
- "strings"
-)
-
-const (
- // SourceName should match the one in the config file template.
- SourceName = "JFrogCli"
- configFilePattern = "jfrog.cli.nuget."
-
- dotnetTestError = `the command failed with an error.
-Note that JFrog CLI does not restore dependencies during a 'dotnet test' command, so if needed, run a preceding 'dotnet restore'.
-The initial error is:
-`
- noRestoreFlag = "--no-restore"
-)
-
-type DotnetCommand struct {
- toolchainType dotnet.ToolchainType
- subCommand string
- argAndFlags []string
- repoName string
- solutionPath string
- useNugetV2 bool
- // By default, package sources are required to use HTTPS. This option allows sources to use HTTP.
- allowInsecureConnections bool
- buildConfiguration *commonBuild.BuildConfiguration
- serverDetails *config.ServerDetails
-}
-
-func (dc *DotnetCommand) SetServerDetails(serverDetails *config.ServerDetails) *DotnetCommand {
- dc.serverDetails = serverDetails
- return dc
-}
-
-func (dc *DotnetCommand) SetBuildConfiguration(buildConfiguration *commonBuild.BuildConfiguration) *DotnetCommand {
- dc.buildConfiguration = buildConfiguration
- return dc
-}
-
-func (dc *DotnetCommand) SetToolchainType(toolchainType dotnet.ToolchainType) *DotnetCommand {
- dc.toolchainType = toolchainType
- return dc
-}
-
-func (dc *DotnetCommand) SetSolutionPath(solutionPath string) *DotnetCommand {
- dc.solutionPath = solutionPath
- return dc
-}
-
-func (dc *DotnetCommand) SetRepoName(repoName string) *DotnetCommand {
- dc.repoName = repoName
- return dc
-}
-
-func (dc *DotnetCommand) SetUseNugetV2(useNugetV2 bool) *DotnetCommand {
- dc.useNugetV2 = useNugetV2
- return dc
-}
-
-func (dc *DotnetCommand) SetAllowInsecureConnections(allowInsecureConnections bool) *DotnetCommand {
- dc.allowInsecureConnections = allowInsecureConnections
- return dc
-}
-
-func (dc *DotnetCommand) SetArgAndFlags(argAndFlags []string) *DotnetCommand {
- dc.argAndFlags = argAndFlags
- return dc
-}
-
-func (dc *DotnetCommand) SetBasicCommand(subCommand string) *DotnetCommand {
- dc.subCommand = subCommand
- return dc
-}
-
-func (dc *DotnetCommand) ServerDetails() (*config.ServerDetails, error) {
- return dc.serverDetails, nil
-}
-
-func (dc *DotnetCommand) GetToolchain() dotnet.ToolchainType {
- return dc.toolchainType
-}
-
-func (dc *DotnetCommand) CommandName() string {
- return "rt_" + dc.toolchainType.String()
-}
-
-// Exec all consume type nuget commands, install, update, add, restore.
-func (dc *DotnetCommand) Exec() (err error) {
- log.Info("Running " + dc.toolchainType.String() + "...")
- buildName, err := dc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := dc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
-
- buildInfoService := commonBuild.CreateBuildInfoService()
- dotnetBuild, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, dc.buildConfiguration.GetProject())
- if err != nil {
- return errorutils.CheckError(err)
- }
- buildInfoModule, err := dotnetBuild.AddDotnetModules(dc.solutionPath)
- if err != nil {
- return errorutils.CheckError(err)
- }
- callbackFunc, err := dc.prepareDotnetBuildInfoModule(buildInfoModule)
- if err != nil {
- return err
- }
- defer func() {
- if callbackFunc != nil {
- err = errors.Join(err, callbackFunc())
- }
- }()
- if err = buildInfoModule.CalcDependencies(); err != nil {
- if dc.isDotnetTestCommand() {
- return errors.New(dotnetTestError + err.Error())
- }
- return err
- }
- log.Info(fmt.Sprintf("%s finished successfully.", dc.toolchainType))
- return nil
-}
-
-// prepareDotnetBuildInfoModule prepare dotnet modules with the provided cli parameters.
-// In case no config file was provided - creates a temporary one.
-func (dc *DotnetCommand) prepareDotnetBuildInfoModule(buildInfoModule *build.DotnetModule) (func() error, error) {
- callbackFunc, err := dc.prepareConfigFileIfNeeded()
- if err != nil {
- return nil, err
- }
- buildInfoModule.SetName(dc.buildConfiguration.GetModule())
- buildInfoModule.SetSubcommand(dc.subCommand)
- buildInfoModule.SetArgAndFlags(dc.argAndFlags)
- buildInfoModule.SetToolchainType(dc.toolchainType)
- return callbackFunc, nil
-}
-
-// Changes the working directory if provided.
-// Returns the path to the solution
-func changeWorkingDir(newWorkingDir string) (string, error) {
- var err error
- if newWorkingDir != "" {
- err = os.Chdir(newWorkingDir)
- } else {
- newWorkingDir, err = os.Getwd()
- }
-
- return newWorkingDir, errorutils.CheckError(err)
-}
-
-// Runs nuget/dotnet source add command
-func AddSourceToNugetConfig(cmdType dotnet.ToolchainType, sourceUrl, user, password, customConfigPath string) error {
- cmd, err := dotnet.CreateDotnetAddSourceCmd(cmdType, sourceUrl)
- if err != nil {
- return err
- }
-
- flagPrefix := cmdType.GetTypeFlagPrefix()
- cmd.CommandFlags = append(cmd.CommandFlags, flagPrefix+"name", SourceName)
- cmd.CommandFlags = append(cmd.CommandFlags, flagPrefix+"username", user)
- cmd.CommandFlags = append(cmd.CommandFlags, flagPrefix+"password", password)
-
- if customConfigPath != "" {
- addConfigFileFlag(cmd, customConfigPath)
- }
-
- _, _, _, err = frogio.RunCmdWithOutputParser(cmd, false)
- if err != nil {
- return fmt.Errorf("failed to add source: %w", err)
- }
- return nil
-}
-
-// RemoveSourceFromNugetConfigIfExists runs the nuget/dotnet source remove command.
-// Removes the source if it exists in the configuration.
-func RemoveSourceFromNugetConfigIfExists(cmdType dotnet.ToolchainType, customConfigPath string) error {
- cmd, err := dotnet.NewToolchainCmd(cmdType)
- if err != nil {
- return err
- }
- if cmdType == dotnet.DotnetCore {
- cmd.Command = append(cmd.Command, "nuget", "remove", "source", SourceName)
- } else {
- cmd.Command = append(cmd.Command, "sources", "remove")
- cmd.CommandFlags = append(cmd.CommandFlags, "-name", SourceName)
- }
-
- if customConfigPath != "" {
- addConfigFileFlag(cmd, customConfigPath)
- }
-
- stdOut, stdErr, _, err := frogio.RunCmdWithOutputParser(cmd, false)
- if err != nil {
- if strings.Contains(stdOut+stdErr, "Unable to find") || strings.Contains(stdOut+stdErr, "does not exist") {
- return nil
- }
- return errorutils.CheckErrorf("failed to remove source: %s", err.Error())
- }
- return nil
-}
-
-// GetConfigPathFromEnvIfProvided returns the path to the custom NuGet.Config file if it was provided by the user.
-func GetConfigPathFromEnvIfProvided(cmdType dotnet.ToolchainType) string {
- if cmdType == dotnet.DotnetCore {
- if customDotnetDir := os.Getenv("DOTNET_CLI_HOME"); customDotnetDir != "" {
- return filepath.Join(customDotnetDir, "NuGet.Config")
- }
- }
- return os.Getenv("NUGET_CONFIG_FILE")
-}
-
-// CreateConfigFileIfNeeded creates a new config file if it does not exist.
-func CreateConfigFileIfNeeded(customConfigPath string) error {
- // Ensure the file exists
- exists, err := fileutils.IsFileExists(customConfigPath, false)
- if err != nil || exists {
- return err
- }
- // If the file does not exist, create it
- if err = os.MkdirAll(filepath.Dir(customConfigPath), 0755); err != nil {
- return err
- }
- // Write the default config content to the file
- return os.WriteFile(customConfigPath, []byte(""), 0644)
-}
-
-func addConfigFileFlag(cmd *dotnet.Cmd, configFilePath string) {
- // Add the config file flag if needed.
- if cmd.GetToolchain() == dotnet.DotnetCore {
- cmd.CommandFlags = append(cmd.CommandFlags, "--configfile", configFilePath)
- } else {
- cmd.CommandFlags = append(cmd.CommandFlags, "-ConfigFile", configFilePath)
- }
-}
-
-// Checks if the user provided input such as -configfile flag or -Source flag.
-// If those flags were provided, NuGet will use the provided configs (default config file or the one with -configfile)
-// If neither provided, we are initializing our own config.
-func (dc *DotnetCommand) prepareConfigFileIfNeeded() (cleanup func() error, err error) {
- dc.solutionPath, err = changeWorkingDir(dc.solutionPath)
- if err != nil {
- return
- }
-
- if dc.isDotnetTestCommand() {
- // The dotnet test command does not support the configfile flag.
- // To avoid resolving from a registry that is not Artifactory, we add the no-restore flag and require the user to run a restore before the test command.
- dc.argAndFlags = append(dc.argAndFlags, noRestoreFlag)
- return
- }
-
- cmdFlag := dc.GetToolchain().GetTypeFlagPrefix() + "configfile"
- currentConfigPath, err := getFlagValueIfExists(cmdFlag, dc.argAndFlags)
- if err != nil {
- return
- }
- if currentConfigPath != "" {
- return
- }
-
- cmdFlag = dc.GetToolchain().GetTypeFlagPrefix() + "source"
- sourceCommandValue, err := getFlagValueIfExists(cmdFlag, dc.argAndFlags)
- if err != nil {
- return
- }
- if sourceCommandValue != "" {
- return
- }
-
- // Use temp dir to save config file, so that config will be removed at the end.
- tempDirPath, err := fileutils.CreateTempDir()
- if err != nil {
- return
- }
- cleanup = func() error {
- return fileutils.RemoveTempDir(tempDirPath)
- }
-
- configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2, dc.allowInsecureConnections)
- if err == nil {
- dc.argAndFlags = append(dc.argAndFlags, dc.GetToolchain().GetTypeFlagPrefix()+"configfile", configFile.Name())
- }
- return
-}
-
-func (dc *DotnetCommand) isDotnetTestCommand() bool {
- return dc.GetToolchain() == dotnet.DotnetCore && dc.subCommand == "test"
-}
-
-// Returns the value of the flag if exists
-func getFlagValueIfExists(cmdFlag string, argAndFlags []string) (string, error) {
- for i := 0; i < len(argAndFlags); i++ {
- if !strings.EqualFold(argAndFlags[i], cmdFlag) {
- continue
- }
- if i+1 == len(argAndFlags) {
- return "", errorutils.CheckErrorf(cmdFlag, " flag was provided without value")
- }
- return argAndFlags[i+1], nil
- }
-
- return "", nil
-}
-
-// InitNewConfig is used when neither of the flags were provided, and we need to init our own config.
-func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, useNugetV2, allowInsecureConnections bool) (configFile *os.File, err error) {
- // Initializing a new NuGet config file that NuGet will use into a temp file
- configFile, err = os.CreateTemp(configDirPath, configFilePattern)
- if errorutils.CheckError(err) != nil {
- return
- }
- log.Debug("Nuget config file created at:", configFile.Name())
- defer func() {
- err = errors.Join(err, errorutils.CheckError(configFile.Close()))
- }()
-
- // We would prefer to write the NuGet configuration using the `nuget add source` command,
- // but the NuGet configuration utility doesn't currently allow setting protocolVersion.
- // Until that is supported, the templated method must be used.
- err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName, allowInsecureConnections)
- return
-}
-
-// Adds a source to the nuget config template
-func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string, allowInsecureConnections bool) error {
- sourceUrl, user, password, err := GetSourceDetails(server, repoName, useNugetV2)
- if err != nil {
- return err
- }
-
- // Specify the protocolVersion
- protoVer := "3"
- if useNugetV2 {
- protoVer = "2"
- }
-
- // Format the templates
- _, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, allowInsecureConnections, user, password)
- return err
-}
-
-func GetSourceDetails(details *config.ServerDetails, repoName string, useNugetV2 bool) (sourceURL, user, password string, err error) {
- var u *url.URL
- u, err = url.Parse(details.ArtifactoryUrl)
- if errorutils.CheckError(err) != nil {
- return
- }
- nugetApi := "api/nuget/v3"
- if useNugetV2 {
- nugetApi = "api/nuget"
- }
- u.Path = path.Join(u.Path, nugetApi, repoName)
- sourceURL = u.String()
-
- user = details.User
- password = details.Password
- // If access-token is defined, extract user from it.
- if details.AccessToken != "" {
- log.Debug("Using access-token details for nuget authentication.")
- if user == "" {
- user = auth.ExtractUsernameFromAccessToken(details.AccessToken)
- }
- password = details.AccessToken
- }
- return
-}
diff --git a/artifactory/commands/dotnet/dotnetcommand_test.go b/artifactory/commands/dotnet/dotnetcommand_test.go
deleted file mode 100644
index 223486e4a..000000000
--- a/artifactory/commands/dotnet/dotnetcommand_test.go
+++ /dev/null
@@ -1,347 +0,0 @@
-package dotnet
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "os"
- "path/filepath"
- "reflect"
- "strings"
- "testing"
- "time"
-
- "github.com/jfrog/build-info-go/build"
- "github.com/jfrog/build-info-go/build/utils/dotnet"
- "github.com/jfrog/gofrog/io"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
- "github.com/stretchr/testify/assert"
-)
-
-func TestGetFlagValueExists(t *testing.T) {
- tests := []struct {
- name string
- currentConfigPath string
- createConfig bool
- expectErr bool
- cmdFlags []string
- expectedCmdFlags []string
- }{
- {"simple", "file.config", true, false,
- []string{"-configFile", "file.config"}, []string{"-configFile", "file.config"}},
-
- {"simple2", "file.config", true, false,
- []string{"-before", "-configFile", "file.config", "after"}, []string{"-before", "-configFile", "file.config", "after"}},
-
- {"err", "file.config", false, true,
- []string{"-before", "-configFile"}, []string{"-before", "-configFile"}},
-
- {"err2", "file.config", false, true,
- []string{"-configFile"}, []string{"-configFile"}},
- }
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- if test.createConfig {
- _, err := io.CreateRandFile(test.currentConfigPath, 0)
- if err != nil {
- t.Error(err)
- }
- defer testsutils.RemoveAndAssert(t, test.currentConfigPath)
- }
- _, err := getFlagValueIfExists("-configfile", test.cmdFlags)
- if err != nil && !test.expectErr {
- t.Error(err)
- }
- if err == nil && test.expectErr {
- t.Errorf("Expecting: error, Got: nil")
- }
- if !reflect.DeepEqual(test.cmdFlags, test.expectedCmdFlags) {
- t.Errorf("Expecting: %s, Got: %s", test.expectedCmdFlags, test.cmdFlags)
- }
- })
- }
-}
-
-func TestInitNewConfig(t *testing.T) {
- tmpDir, err := fileutils.CreateTempDir()
- assert.NoError(t, err)
- defer func() {
- assert.NoError(t, fileutils.RemoveTempDir(tmpDir))
- }()
- repoName := "test-repo"
- server := &config.ServerDetails{
- ArtifactoryUrl: "https://server.com/artifactory",
- User: "user",
- Password: "pass",
- }
- configFile, err := InitNewConfig(tmpDir, repoName, server, false, true)
- assert.NoError(t, err)
- f, err := os.Open(configFile.Name())
- assert.NoError(t, err)
- defer func() {
- assert.NoError(t, f.Close())
- }()
- buf := make([]byte, 1024)
- n, err := f.Read(buf)
- assert.NoError(t, err)
- assert.Equal(t, `
-
-
-
-
-
-
-
-
-
-
-`, string(buf[:n]))
- server.Password = ""
- server.AccessToken = "abc123"
- configFile, err = InitNewConfig(tmpDir, repoName, server, true, true)
- assert.NoError(t, err)
- updatedConfigFile, err := os.Open(configFile.Name())
- assert.NoError(t, err)
- defer func() {
- assert.NoError(t, updatedConfigFile.Close())
- }()
- buf = make([]byte, 1024)
- n, err = updatedConfigFile.Read(buf)
- assert.NoError(t, err)
- assert.Equal(t, `
-
-
-
-
-
-
-
-
-
-
-`, string(buf[:n]))
-}
-
-func TestGetSourceDetails(t *testing.T) {
- server := &config.ServerDetails{
- ArtifactoryUrl: "https://server.com/artifactory",
- User: "user",
- Password: "pass",
- }
- repoName := "repo-name"
- url, user, pass, err := GetSourceDetails(server, repoName, false)
- assert.NoError(t, err)
- assert.Equal(t, "user", user)
- assert.Equal(t, "pass", pass)
- assert.Equal(t, "https://server.com/artifactory/api/nuget/v3/repo-name", url)
- server.Password = ""
- server.AccessToken = "abc123"
- url, user, pass, err = GetSourceDetails(server, repoName, true)
- assert.Equal(t, "user", user)
- assert.Equal(t, "abc123", pass)
- assert.NoError(t, err)
- assert.Equal(t, "https://server.com/artifactory/api/nuget/repo-name", url)
-}
-
-func TestPrepareDotnetBuildInfoModule(t *testing.T) {
- t.Run("generated config file", func(t *testing.T) { testPrepareDotnetBuildInfoModule(t, "restore", []string{}, true) })
- t.Run("existing with configfile flag", func(t *testing.T) {
- testPrepareDotnetBuildInfoModule(t, "restore", []string{"--configfile", "/path/to/config/file"}, false)
- })
- t.Run("existing with source flag", func(t *testing.T) {
- testPrepareDotnetBuildInfoModule(t, "restore", []string{"--source", "/path/to/source"}, false)
- })
- t.Run("dotnet test", func(t *testing.T) {
- testPrepareDotnetBuildInfoModule(t, "test", []string{}, false)
- })
-}
-
-func testPrepareDotnetBuildInfoModule(t *testing.T, subCommand string, flags []string, expectedGeneratedConfigFile bool) {
- tmpDir, err := fileutils.CreateTempDir()
- assert.NoError(t, err)
- defer func() {
- assert.NoError(t, fileutils.RemoveTempDir(tmpDir))
- }()
- module := createNewDotnetModule(t, tmpDir)
- cmd := DotnetCommand{
- toolchainType: dotnet.DotnetCore,
- subCommand: subCommand,
- argAndFlags: flags,
- buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""),
- serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"},
- allowInsecureConnections: true,
- }
- callbackFunc, err := cmd.prepareDotnetBuildInfoModule(module)
- if !assert.NoError(t, err) {
- return
- }
- assert.Equal(t, cmd.toolchainType, module.GetToolchainType())
- assert.Equal(t, cmd.subCommand, module.GetSubcommand())
- assert.Equal(t, cmd.buildConfiguration.GetModule(), module.GetName())
-
- if !expectedGeneratedConfigFile {
- assertConfigFileNotGenerated(t, cmd, module, tmpDir)
- return
- }
- assertConfigFileGenerated(t, module, callbackFunc)
-}
-
-func assertConfigFileNotGenerated(t *testing.T, cmd DotnetCommand, module *build.DotnetModule, tmpDir string) {
- assert.Equal(t, cmd.argAndFlags, module.GetArgAndFlags())
- if cmd.subCommand == "test" {
- assert.True(t, cmd.isDotnetTestCommand())
- assert.Contains(t, cmd.argAndFlags, noRestoreFlag)
- }
- // Temp dir should remain empty if config file was not generated.
- contents, err := os.ReadDir(tmpDir)
- assert.NoError(t, err)
- assert.Empty(t, contents)
-}
-
-func assertConfigFileGenerated(t *testing.T, module *build.DotnetModule, callbackFunc func() error) {
- // Assert config file was generated and added to the flags passed to the module.
- assert.Len(t, module.GetArgAndFlags(), 2)
- configFilePath, err := getFlagValueIfExists("--configfile", module.GetArgAndFlags())
- assert.NoError(t, err)
- assertFileExists(t, configFilePath, true)
- assert.True(t, strings.HasPrefix(filepath.Base(configFilePath), configFilePattern))
-
- // Assert config file is removed when calling the callback function.
- assert.NoError(t, callbackFunc())
- assertFileExists(t, configFilePath, false)
-}
-
-func assertFileExists(t *testing.T, path string, expected bool) {
- exists, err := fileutils.IsFileExists(path, false)
- assert.NoError(t, err)
- assert.Equal(t, expected, exists)
-}
-
-func createNewDotnetModule(t *testing.T, tmpDir string) *build.DotnetModule {
- dotnetBuild := build.NewBuild("", "", time.Now(), "", tmpDir, nil)
- module, err := dotnetBuild.AddDotnetModules("")
- assert.NoError(t, err)
- return module
-}
-
-func TestGetConfigPathFromEnvIfProvided(t *testing.T) {
- testCases := []struct {
- name string
- mockEnv map[string]string
- cmdType dotnet.ToolchainType
- expectedPath string
- }{
- {
- name: "DotnetCore with DOTNET_CLI_HOME",
- mockEnv: map[string]string{
- "DOTNET_CLI_HOME": "/custom/dotnet",
- },
- cmdType: dotnet.DotnetCore,
- expectedPath: "/custom/dotnet/NuGet.Config",
- },
- {
- name: "NuGet with NUGET_CONFIG_FILE",
- mockEnv: map[string]string{
- "NUGET_CONFIG_FILE": "/custom/nuget.config",
- },
- cmdType: dotnet.Nuget,
- expectedPath: "/custom/nuget.config",
- },
- {
- name: "No env variable",
- mockEnv: map[string]string{},
- cmdType: dotnet.Nuget,
- expectedPath: "",
- },
- }
-
- // Test the function with different environment variable settings
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- t.Setenv("DOTNET_CLI_HOME", testCase.mockEnv["DOTNET_CLI_HOME"])
-
- // Set other environment variables if needed
- if testCase.mockEnv["NUGET_CONFIG_FILE"] != "" {
- t.Setenv("NUGET_CONFIG_FILE", testCase.mockEnv["NUGET_CONFIG_FILE"])
- }
- result := GetConfigPathFromEnvIfProvided(testCase.cmdType)
- assert.Equal(t, testCase.expectedPath, ioutils.WinToUnixPathSeparator(result))
- })
- }
-}
-
-func TestCreateConfigFileIfNeeded(t *testing.T) {
- testCases := []struct {
- name string
- configPath string
- fileExists bool
- expectedError error
- }{
- {
- name: "File does not exist, create file with default content",
- configPath: "/custom/path/NuGet.Config",
- fileExists: false,
- },
- {
- name: "File exists, no changes",
- configPath: "/custom/path/NuGet.Config",
- fileExists: true,
- },
- }
-
- // Setup for testing file existence and creation
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- configPath := filepath.Join(t.TempDir(), testCase.configPath)
- if testCase.fileExists {
- assert.NoError(t, os.MkdirAll(filepath.Dir(configPath), 0777))
- assert.NoError(t, os.WriteFile(configPath, []byte{}, 0644))
- }
- err := CreateConfigFileIfNeeded(configPath)
- assert.NoError(t, err)
-
- if !testCase.fileExists {
- // Read the content of the file
- content, err := os.ReadFile(configPath)
- assert.NoError(t, err)
-
- // Assert the content is the default config content
- assert.Equal(t, "", string(content))
- }
- })
- }
-}
-
-func TestAddConfigFileFlag(t *testing.T) {
- testCases := []struct {
- name string
- toolchainType dotnet.ToolchainType
- expectedFlags []string
- }{
- {
- name: "DotnetCore toolchain",
- toolchainType: dotnet.DotnetCore,
- expectedFlags: []string{"--configfile", "/path/to/NuGet.Config"},
- },
- {
- name: "NuGet toolchain",
- toolchainType: dotnet.Nuget,
- expectedFlags: []string{"-ConfigFile", "/path/to/NuGet.Config"},
- },
- }
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- // Create a mock command object
- cmd, err := dotnet.NewToolchainCmd(testCase.toolchainType)
- assert.NoError(t, err)
-
- // Call the function
- addConfigFileFlag(cmd, "/path/to/NuGet.Config")
-
- // Assert that the flags are as expected
- assert.Equal(t, testCase.expectedFlags, cmd.CommandFlags)
- })
- }
-}
diff --git a/artifactory/commands/dotnet/dotnetcorecli.go b/artifactory/commands/dotnet/dotnetcorecli.go
deleted file mode 100644
index b3a857507..000000000
--- a/artifactory/commands/dotnet/dotnetcorecli.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package dotnet
-
-import (
- "github.com/jfrog/build-info-go/build/utils/dotnet"
-)
-
-type DotnetCoreCliCommand struct {
- *DotnetCommand
-}
-
-func NewDotnetCoreCliCommand() *DotnetCoreCliCommand {
- dotnetCoreCliCmd := DotnetCoreCliCommand{&DotnetCommand{}}
- dotnetCoreCliCmd.SetToolchainType(dotnet.DotnetCore)
- return &dotnetCoreCliCmd
-}
-
-func (dccc *DotnetCoreCliCommand) Run() (err error) {
- return dccc.Exec()
-}
diff --git a/artifactory/commands/dotnet/nuget.go b/artifactory/commands/dotnet/nuget.go
deleted file mode 100644
index cf14d5883..000000000
--- a/artifactory/commands/dotnet/nuget.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package dotnet
-
-import (
- "github.com/jfrog/build-info-go/build/utils/dotnet"
- "github.com/jfrog/build-info-go/build/utils/dotnet/solution"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "os"
-)
-
-type NugetCommand struct {
- *DotnetCommand
-}
-
-func NewNugetCommand() *NugetCommand {
- nugetCmd := NugetCommand{&DotnetCommand{}}
- nugetCmd.SetToolchainType(dotnet.Nuget)
- return &nugetCmd
-}
-
-func (nc *NugetCommand) Run() error {
- return nc.Exec()
-}
-
-func DependencyTreeCmd() error {
- workspace, err := os.Getwd()
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- sol, err := solution.Load(workspace, "", "", log.Logger)
- if err != nil {
- return err
- }
-
- // Create the tree for each project
- for _, project := range sol.GetProjects() {
- err = project.CreateDependencyTree(log.Logger)
- if err != nil {
- return err
- }
- }
- // Build the tree.
- content, err := sol.Marshal()
- if err != nil {
- return errorutils.CheckError(err)
- }
- log.Output(clientutils.IndentJson(content))
- return nil
-}
diff --git a/artifactory/commands/generic/copy.go b/artifactory/commands/generic/copy.go
deleted file mode 100644
index 94db67186..000000000
--- a/artifactory/commands/generic/copy.go
+++ /dev/null
@@ -1,93 +0,0 @@
-package generic
-
-import (
- "errors"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type CopyCommand struct {
- GenericCommand
- threads int
-}
-
-func NewCopyCommand() *CopyCommand {
- return &CopyCommand{GenericCommand: *NewGenericCommand()}
-}
-
-func (cc *CopyCommand) Threads() int {
- return cc.threads
-}
-
-func (cc *CopyCommand) SetThreads(threads int) *CopyCommand {
- cc.threads = threads
- return cc
-}
-
-func (cc *CopyCommand) CommandName() string {
- return "rt_copy"
-}
-
-// Copies the artifacts using the specified move pattern.
-func (cc *CopyCommand) Run() error {
- // Create Service Manager:
- servicesManager, err := utils.CreateServiceManagerWithThreads(cc.serverDetails, cc.dryRun, cc.threads, cc.retries, cc.retryWaitTimeMilliSecs)
- if err != nil {
- return err
- }
-
- var errorOccurred = false
- var copyParamsArray []services.MoveCopyParams
- // Create CopyParams for all File-Spec groups.
- for i := 0; i < len(cc.spec.Files); i++ {
- copyParams, err := getCopyParams(cc.spec.Get(i))
- if err != nil {
- errorOccurred = true
- log.Error(err)
- continue
- }
- copyParamsArray = append(copyParamsArray, copyParams)
- }
-
- // Perform copy.
- totalCopied, totalFailed, err := servicesManager.Copy(copyParamsArray...)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- }
- cc.result.SetSuccessCount(totalCopied)
- cc.result.SetFailCount(totalFailed)
-
- if errorOccurred {
- return errors.New("copy finished with errors, please review the logs")
- }
- return err
-}
-
-func getCopyParams(f *spec.File) (copyParams services.MoveCopyParams, err error) {
- copyParams = services.NewMoveCopyParams()
- copyParams.CommonParams, err = f.ToCommonParams()
- if err != nil {
- return
- }
- copyParams.Recursive, err = f.IsRecursive(true)
- if err != nil {
- return
- }
- copyParams.ExcludeArtifacts, err = f.IsExcludeArtifacts(false)
- if err != nil {
- return
- }
- copyParams.IncludeDeps, err = f.IsIncludeDeps(false)
- if err != nil {
- return
- }
- copyParams.Flat, err = f.IsFlat(false)
- if err != nil {
- return
- }
- return
-}
diff --git a/artifactory/commands/generic/createaccesstoken.go b/artifactory/commands/generic/createaccesstoken.go
deleted file mode 100644
index 74e1aad14..000000000
--- a/artifactory/commands/generic/createaccesstoken.go
+++ /dev/null
@@ -1,132 +0,0 @@
-package generic
-
-import (
- "encoding/json"
- "github.com/jfrog/jfrog-client-go/auth"
- "strings"
-
- rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
-)
-
-const (
- GroupsPrefix = "member-of-groups:"
- UserScopedNotation = "*"
- AdminPrivilegesSuffix = ":admin"
-)
-
-type AccessTokenCreateCommand struct {
- serverDetails *config.ServerDetails
- refreshable bool
- expiry int
- userName string
- audience string
- groups string
- grantAdmin bool
- response *auth.CreateTokenResponseData
-}
-
-func NewAccessTokenCreateCommand() *AccessTokenCreateCommand {
- return &AccessTokenCreateCommand{response: new(auth.CreateTokenResponseData)}
-}
-
-func (atcc *AccessTokenCreateCommand) SetServerDetails(serverDetails *config.ServerDetails) *AccessTokenCreateCommand {
- atcc.serverDetails = serverDetails
- return atcc
-}
-
-func (atcc *AccessTokenCreateCommand) SetRefreshable(refreshable bool) *AccessTokenCreateCommand {
- atcc.refreshable = refreshable
- return atcc
-}
-
-func (atcc *AccessTokenCreateCommand) SetExpiry(expiry int) *AccessTokenCreateCommand {
- atcc.expiry = expiry
- return atcc
-}
-
-func (atcc *AccessTokenCreateCommand) SetUserName(userName string) *AccessTokenCreateCommand {
- atcc.userName = userName
- return atcc
-}
-
-func (atcc *AccessTokenCreateCommand) SetAudience(audience string) *AccessTokenCreateCommand {
- atcc.audience = audience
- return atcc
-}
-
-func (atcc *AccessTokenCreateCommand) SetGrantAdmin(grantAdmin bool) *AccessTokenCreateCommand {
- atcc.grantAdmin = grantAdmin
- return atcc
-}
-
-func (atcc *AccessTokenCreateCommand) SetGroups(groups string) *AccessTokenCreateCommand {
- atcc.groups = groups
- return atcc
-}
-
-func (atcc *AccessTokenCreateCommand) Response() ([]byte, error) {
- content, err := json.Marshal(*atcc.response)
- return content, errorutils.CheckError(err)
-}
-
-func (atcc *AccessTokenCreateCommand) ServerDetails() (*config.ServerDetails, error) {
- return atcc.serverDetails, nil
-}
-
-func (atcc *AccessTokenCreateCommand) CommandName() string {
- return "rt_create_access_token"
-}
-
-func (atcc *AccessTokenCreateCommand) Run() error {
- servicesManager, err := rtUtils.CreateServiceManager(atcc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- tokenParams, err := atcc.getTokenParams()
- if err != nil {
- return err
- }
-
- *atcc.response, err = servicesManager.CreateToken(tokenParams)
- return err
-}
-
-func (atcc *AccessTokenCreateCommand) getTokenParams() (tokenParams services.CreateTokenParams, err error) {
- tokenParams = services.NewCreateTokenParams()
- tokenParams.ExpiresIn = atcc.expiry
- tokenParams.Refreshable = atcc.refreshable
- tokenParams.Audience = atcc.audience
- // Artifactory expects the username to be lower-cased. In case it is not,
- // Artifactory will still accept a non-lower-cased user, except for token related actions.
- tokenParams.Username = strings.ToLower(atcc.userName)
- // By default, we will create "user-scoped token", unless specific groups or admin-privilege-instance were specified
- if len(atcc.groups) == 0 && !atcc.grantAdmin {
- atcc.groups = UserScopedNotation
- }
- if len(atcc.groups) > 0 {
- tokenParams.Scope = GroupsPrefix + atcc.groups
- }
- if atcc.grantAdmin {
- instanceId, err := getInstanceId(atcc.serverDetails)
- if err != nil {
- return tokenParams, err
- }
- if len(tokenParams.Scope) > 0 {
- tokenParams.Scope += " "
- }
- tokenParams.Scope += instanceId + AdminPrivilegesSuffix
- }
-
- return
-}
-
-func getInstanceId(serverDetails *config.ServerDetails) (string, error) {
- servicesManager, err := rtUtils.CreateServiceManager(serverDetails, -1, 0, false)
- if err != nil {
- return "", err
- }
- return servicesManager.GetServiceId()
-}
diff --git a/artifactory/commands/generic/delete.go b/artifactory/commands/generic/delete.go
deleted file mode 100644
index 367965dc2..000000000
--- a/artifactory/commands/generic/delete.go
+++ /dev/null
@@ -1,138 +0,0 @@
-package generic
-
-import (
- ioutils "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- clientutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
-)
-
-type DeleteCommand struct {
- GenericCommand
- threads int
-}
-
-func NewDeleteCommand() *DeleteCommand {
- return &DeleteCommand{GenericCommand: *NewGenericCommand()}
-}
-
-func (dc *DeleteCommand) Threads() int {
- return dc.threads
-}
-
-func (dc *DeleteCommand) SetThreads(threads int) *DeleteCommand {
- dc.threads = threads
- return dc
-}
-
-func (dc *DeleteCommand) CommandName() string {
- return "rt_delete"
-}
-
-func (dc *DeleteCommand) Run() (err error) {
- reader, err := dc.GetPathsToDelete()
- if err != nil {
- return
- }
- defer ioutils.Close(reader, &err)
- allowDelete := true
- if !dc.quiet {
- allowDelete, err = utils.ConfirmDelete(reader)
- if err != nil {
- return
- }
- }
- if allowDelete {
- var successCount int
- var failedCount int
- successCount, failedCount, err = dc.DeleteFiles(reader)
- result := dc.Result()
- result.SetFailCount(failedCount)
- result.SetSuccessCount(successCount)
- }
- return
-}
-
-func (dc *DeleteCommand) GetPathsToDelete() (contentReader *content.ContentReader, err error) {
- serverDetails, err := dc.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return
- }
- servicesManager, err := utils.CreateServiceManager(serverDetails, dc.retries, dc.retryWaitTimeMilliSecs, dc.DryRun())
- if err != nil {
- return
- }
- var temp []*content.ContentReader
- defer func() {
- for _, reader := range temp {
- ioutils.Close(reader, &err)
- }
- }()
- for i := 0; i < len(dc.Spec().Files); i++ {
- var deleteParams services.DeleteParams
- deleteParams, err = getDeleteParams(dc.Spec().Get(i))
- if err != nil {
- return
- }
- var reader *content.ContentReader
- reader, err = servicesManager.GetPathsToDelete(deleteParams)
- if err != nil {
- return
- }
- temp = append(temp, reader)
- }
- tempMergedReader, err := content.MergeReaders(temp, content.DefaultKey)
- if err != nil {
- return nil, err
- }
- defer ioutils.Close(tempMergedReader, &err)
- // After merge, remove top chain dirs as we may encounter duplicates and collisions between files and directories to delete.
- // For example:
- // Reader1: {"a"}
- // Reader2: {"a/b","a/c"}
- // After merge, received a Reader: {"a","a/b","a/c"}.
- // If "a" is deleted prior to "a/b" or "a/c", the delete operation returns a failure.
- contentReader, err = clientutils.ReduceTopChainDirResult(clientutils.ResultItem{}, tempMergedReader)
- return
-}
-
-func (dc *DeleteCommand) DeleteFiles(reader *content.ContentReader) (successCount, failedCount int, err error) {
- serverDetails, err := dc.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return 0, 0, err
- }
- servicesManager, err := utils.CreateDeleteServiceManager(serverDetails, dc.Threads(), dc.retries, dc.retryWaitTimeMilliSecs, dc.DryRun())
- if err != nil {
- return 0, 0, err
- }
- deletedCount, err := servicesManager.DeleteFiles(reader)
- if err != nil {
- return 0, 0, err
- }
- length, err := reader.Length()
- if err != nil {
- return 0, 0, err
- }
- return deletedCount, length - deletedCount, err
-}
-
-func getDeleteParams(f *spec.File) (deleteParams services.DeleteParams, err error) {
- deleteParams = services.NewDeleteParams()
- deleteParams.CommonParams, err = f.ToCommonParams()
- if err != nil {
- return
- }
- deleteParams.ExcludeArtifacts, err = f.IsExcludeArtifacts(false)
- if err != nil {
- return
- }
- deleteParams.IncludeDeps, err = f.IsIncludeDeps(false)
- if err != nil {
- return
- }
- deleteParams.Recursive, err = f.IsRecursive(true)
- return
-}
diff --git a/artifactory/commands/generic/deleteprops.go b/artifactory/commands/generic/deleteprops.go
deleted file mode 100644
index 22603615a..000000000
--- a/artifactory/commands/generic/deleteprops.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package generic
-
-import (
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
-)
-
-type DeletePropsCommand struct {
- PropsCommand
-}
-
-func NewDeletePropsCommand() *DeletePropsCommand {
- return &DeletePropsCommand{}
-}
-
-func (dp *DeletePropsCommand) DeletePropsCommand(command PropsCommand) *DeletePropsCommand {
- dp.PropsCommand = command
- return dp
-}
-
-func (dp *DeletePropsCommand) CommandName() string {
- return "rt_delete_properties"
-}
-
-func (dp *DeletePropsCommand) Run() error {
- serverDetails, err := dp.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return err
- }
- servicesManager, err := createPropsServiceManager(dp.threads, dp.retries, dp.retryWaitTimeMilliSecs, serverDetails)
- if err != nil {
- return err
- }
- reader, err := searchItems(dp.Spec(), servicesManager)
- if err != nil {
- return err
- }
- defer reader.Close()
- propsParams := GetPropsParams(reader, dp.props)
- success, err := servicesManager.DeleteProps(propsParams)
- result := dp.Result()
- result.SetSuccessCount(success)
- totalLength, totalLengthErr := reader.Length()
- result.SetFailCount(totalLength - success)
- if totalLengthErr != nil {
- return totalLengthErr
- }
- return err
-}
diff --git a/artifactory/commands/generic/download.go b/artifactory/commands/generic/download.go
deleted file mode 100644
index 3dbf87732..000000000
--- a/artifactory/commands/generic/download.go
+++ /dev/null
@@ -1,341 +0,0 @@
-package generic
-
-import (
- "errors"
- "os"
- "path/filepath"
- "strconv"
- "strings"
-
- buildinfo "github.com/jfrog/build-info-go/entities"
- gofrog "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- serviceutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type DownloadCommand struct {
- buildConfiguration *build.BuildConfiguration
- GenericCommand
- configuration *utils.DownloadConfiguration
- progress ioUtils.ProgressMgr
-}
-
-func NewDownloadCommand() *DownloadCommand {
- return &DownloadCommand{GenericCommand: *NewGenericCommand()}
-}
-
-func (dc *DownloadCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *DownloadCommand {
- dc.buildConfiguration = buildConfiguration
- return dc
-}
-
-func (dc *DownloadCommand) Configuration() *utils.DownloadConfiguration {
- return dc.configuration
-}
-
-func (dc *DownloadCommand) SetConfiguration(configuration *utils.DownloadConfiguration) *DownloadCommand {
- dc.configuration = configuration
- return dc
-}
-
-func (dc *DownloadCommand) SetProgress(progress ioUtils.ProgressMgr) {
- dc.progress = progress
-}
-
-func (dc *DownloadCommand) ShouldPrompt() bool {
- return !dc.DryRun() && dc.SyncDeletesPath() != "" && !dc.Quiet()
-}
-
-func (dc *DownloadCommand) CommandName() string {
- return "rt_download"
-}
-
-func (dc *DownloadCommand) Run() error {
- return dc.download()
-}
-
-func (dc *DownloadCommand) download() (err error) {
- // Init progress bar if needed
- if dc.progress != nil {
- dc.progress.SetHeadlineMsg("")
- dc.progress.InitProgressReaders()
- }
- // Create Service Manager:
- servicesManager, err := utils.CreateDownloadServiceManager(dc.serverDetails, dc.configuration.Threads, dc.retries, dc.retryWaitTimeMilliSecs, dc.DryRun(), dc.progress)
- if err != nil {
- return err
- }
-
- // Build Info Collection:
- toCollect, err := dc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
- if toCollect && !dc.DryRun() {
- var buildName, buildNumber string
- buildName, err = dc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err = dc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- if err = build.SaveBuildGeneralDetails(buildName, buildNumber, dc.buildConfiguration.GetProject()); err != nil {
- return err
- }
- }
-
- var errorOccurred = false
- var downloadParamsArray []services.DownloadParams
- // Create DownloadParams for all File-Spec groups.
- var downParams services.DownloadParams
- for i := 0; i < len(dc.Spec().Files); i++ {
- downParams, err = getDownloadParams(dc.Spec().Get(i), dc.configuration)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- continue
- }
- downloadParamsArray = append(downloadParamsArray, downParams)
- }
- // Perform download.
- // In case of build-info collection/sync-deletes operation/a detailed summary is required, we use the download service which provides results file reader,
- // otherwise we use the download service which provides only general counters.
- var totalDownloaded, totalFailed int
- var summary *serviceutils.OperationSummary
- if toCollect || dc.SyncDeletesPath() != "" || dc.DetailedSummary() {
- summary, err = servicesManager.DownloadFilesWithSummary(downloadParamsArray...)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- }
- if summary != nil {
- defer gofrog.Close(summary.ArtifactsDetailsReader, &err)
- // If 'detailed summary' was requested, then the reader should not be closed here.
- // It will be closed after it will be used to generate the summary.
- if dc.DetailedSummary() {
- dc.result.SetReader(summary.TransferDetailsReader)
- } else {
- defer gofrog.Close(summary.TransferDetailsReader, &err)
- }
- totalDownloaded = summary.TotalSucceeded
- totalFailed = summary.TotalFailed
- }
- } else {
- totalDownloaded, totalFailed, err = servicesManager.DownloadFiles(downloadParamsArray...)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- }
- }
- dc.result.SetSuccessCount(totalDownloaded)
- dc.result.SetFailCount(totalFailed)
- // Check for errors.
- if errorOccurred {
- return errors.New("download finished with errors, please review the logs")
- }
- if dc.DryRun() {
- dc.result.SetSuccessCount(totalDownloaded)
- dc.result.SetFailCount(0)
- return err
- } else if dc.SyncDeletesPath() != "" {
- var absSyncDeletesPath string
- absSyncDeletesPath, err = filepath.Abs(dc.SyncDeletesPath())
- if err != nil {
- return errorutils.CheckError(err)
- }
- if _, err = os.Stat(absSyncDeletesPath); err == nil {
- // Unmarshal the local paths of the downloaded files from the results file reader
- var tmpRoot string
- tmpRoot, err = createDownloadResultEmptyTmpReflection(summary.TransferDetailsReader)
- defer func() {
- err = errors.Join(err, fileutils.RemoveTempDir(tmpRoot))
- }()
- if err != nil {
- return err
- }
- walkFn := createSyncDeletesWalkFunction(tmpRoot)
- err = gofrog.Walk(dc.SyncDeletesPath(), walkFn, false)
- if err != nil {
- return errorutils.CheckError(err)
- }
- } else if os.IsNotExist(err) {
- log.Info("Sync-deletes path", absSyncDeletesPath, "does not exists.")
- }
- }
- log.Debug("Downloaded", strconv.Itoa(totalDownloaded), "artifacts.")
-
- // Build Info
- if toCollect {
- var buildName, buildNumber string
- buildName, err = dc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err = dc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- var buildDependencies []buildinfo.Dependency
- buildDependencies, err = serviceutils.ConvertArtifactsDetailsToBuildInfoDependencies(summary.ArtifactsDetailsReader)
- if err != nil {
- return err
- }
- populateFunc := func(partial *buildinfo.Partial) {
- partial.Dependencies = buildDependencies
- partial.ModuleId = dc.buildConfiguration.GetModule()
- partial.ModuleType = buildinfo.Generic
- }
- return build.SavePartialBuildInfo(buildName, buildNumber, dc.buildConfiguration.GetProject(), populateFunc)
- }
-
- return err
-}
-
-func getDownloadParams(f *spec.File, configuration *utils.DownloadConfiguration) (downParams services.DownloadParams, err error) {
- downParams = services.NewDownloadParams()
- downParams.CommonParams, err = f.ToCommonParams()
- if err != nil {
- return
- }
- downParams.Symlink = configuration.Symlink
- downParams.MinSplitSize = configuration.MinSplitSize
- downParams.SplitCount = configuration.SplitCount
- downParams.SkipChecksum = configuration.SkipChecksum
-
- downParams.Recursive, err = f.IsRecursive(true)
- if err != nil {
- return
- }
-
- downParams.IncludeDirs, err = f.IsIncludeDirs(false)
- if err != nil {
- return
- }
-
- downParams.Flat, err = f.IsFlat(false)
- if err != nil {
- return
- }
-
- downParams.Explode, err = f.IsExplode(false)
- if err != nil {
- return
- }
-
- downParams.BypassArchiveInspection, err = f.IsBypassArchiveInspection(false)
- if err != nil {
- return
- }
-
- downParams.ValidateSymlink, err = f.IsValidateSymlinks(false)
- if err != nil {
- return
- }
-
- downParams.ExcludeArtifacts, err = f.IsExcludeArtifacts(false)
- if err != nil {
- return
- }
-
- downParams.IncludeDeps, err = f.IsIncludeDeps(false)
- if err != nil {
- return
- }
-
- downParams.Transitive, err = f.IsTransitive(false)
- if err != nil {
- return
- }
-
- downParams.PublicGpgKey = f.GetPublicGpgKey()
-
- return
-}
-
-// We will create the same downloaded hierarchies under a temp directory with 0-size files.
-// We will use this "empty reflection" of the download operation to determine whether a file was downloaded or not while walking the real filesystem from sync-deletes root.
-func createDownloadResultEmptyTmpReflection(reader *content.ContentReader) (tmpRoot string, err error) {
- tmpRoot, err = fileutils.CreateTempDir()
- if errorutils.CheckError(err) != nil {
- return
- }
- for path := new(clientutils.FileTransferDetails); reader.NextRecord(path) == nil; path = new(clientutils.FileTransferDetails) {
- var absDownloadPath string
- absDownloadPath, err = filepath.Abs(path.TargetPath)
- if errorutils.CheckError(err) != nil {
- return
- }
- legalPath := createLegalPath(tmpRoot, absDownloadPath)
- tmpFileRoot := filepath.Dir(legalPath)
- err = os.MkdirAll(tmpFileRoot, os.ModePerm)
- if errorutils.CheckError(err) != nil {
- return
- }
- var tmpFile *os.File
- tmpFile, err = os.Create(legalPath)
- if errorutils.CheckError(err) != nil {
- return
- }
- err = tmpFile.Close()
- if errorutils.CheckError(err) != nil {
- return
- }
- }
- return
-}
-
-// Creates absolute path for temp file suitable for all environments
-func createLegalPath(root, path string) string {
- // Avoid concatenating the volume name (e.g "C://") in Windows environment.
- volumeName := filepath.VolumeName(path)
- if volumeName != "" && strings.HasPrefix(path, volumeName) {
- alternativeVolumeName := "VolumeName" + string(volumeName[0])
- path = strings.Replace(path, volumeName, alternativeVolumeName, 1)
- }
- // Join the current path to the temp root provided.
- path = filepath.Join(root, path)
- return path
-}
-
-func createSyncDeletesWalkFunction(tempRoot string) gofrog.WalkFunc {
- return func(path string, info os.FileInfo, err error) error {
- if err != nil {
- return err
- }
- // Convert path to absolute path
- path, err = filepath.Abs(path)
- if errorutils.CheckError(err) != nil {
- return err
- }
- pathToCheck := createLegalPath(tempRoot, path)
-
- // If the path exists under the temp root directory, it means it's been downloaded during the last operations, and cannot be deleted.
- if fileutils.IsPathExists(pathToCheck, false) {
- return nil
- }
- log.Info("Deleting:", path)
- if info.IsDir() {
- // If current path is a dir - remove all content and return ErrSkipDir to stop walking this path
- err = fileutils.RemoveTempDir(path)
- if err == nil {
- return gofrog.ErrSkipDir
- }
- } else {
- // Path is a file
- err = os.Remove(path)
- }
-
- return errorutils.CheckError(err)
- }
-}
diff --git a/artifactory/commands/generic/generic.go b/artifactory/commands/generic/generic.go
deleted file mode 100644
index c6bd5ad75..000000000
--- a/artifactory/commands/generic/generic.go
+++ /dev/null
@@ -1,105 +0,0 @@
-package generic
-
-import (
- commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type GenericCommand struct {
- serverDetails *config.ServerDetails
- spec *spec.SpecFiles
- result *commandsutils.Result
- dryRun bool
- detailedSummary bool
- syncDeletesPath string
- quiet bool
- retries int
- retryWaitTimeMilliSecs int
- aqlInclude []string
-}
-
-func NewGenericCommand() *GenericCommand {
- return &GenericCommand{result: new(commandsutils.Result)}
-}
-
-func (gc *GenericCommand) DryRun() bool {
- return gc.dryRun
-}
-
-func (gc *GenericCommand) SetDryRun(dryRun bool) *GenericCommand {
- gc.dryRun = dryRun
- return gc
-}
-
-func (gc *GenericCommand) SyncDeletesPath() string {
- return gc.syncDeletesPath
-}
-
-func (gc *GenericCommand) SetSyncDeletesPath(syncDeletes string) *GenericCommand {
- gc.syncDeletesPath = syncDeletes
- return gc
-}
-
-func (gc *GenericCommand) Quiet() bool {
- return gc.quiet
-}
-
-func (gc *GenericCommand) SetQuiet(quiet bool) *GenericCommand {
- gc.quiet = quiet
- return gc
-}
-
-func (gc *GenericCommand) Retries() int {
- return gc.retries
-}
-
-func (gc *GenericCommand) SetRetries(retries int) *GenericCommand {
- gc.retries = retries
- return gc
-}
-
-func (gc *GenericCommand) SetRetryWaitMilliSecs(retryWaitMilliSecs int) *GenericCommand {
- gc.retryWaitTimeMilliSecs = retryWaitMilliSecs
- return gc
-}
-
-func (gc *GenericCommand) Result() *commandsutils.Result {
- return gc.result
-}
-
-func (gc *GenericCommand) Spec() *spec.SpecFiles {
- return gc.spec
-}
-
-func (gc *GenericCommand) SetSpec(spec *spec.SpecFiles) *GenericCommand {
- gc.spec = spec
- return gc
-}
-
-func (gc *GenericCommand) ServerDetails() (*config.ServerDetails, error) {
- return gc.serverDetails, nil
-}
-
-func (gc *GenericCommand) SetServerDetails(serverDetails *config.ServerDetails) *GenericCommand {
- gc.serverDetails = serverDetails
- return gc
-}
-
-func (gc *GenericCommand) DetailedSummary() bool {
- return gc.detailedSummary
-}
-
-func (gc *GenericCommand) SetDetailedSummary(detailedSummary bool) *GenericCommand {
- gc.detailedSummary = detailedSummary
- return gc
-}
-
-func (gc *GenericCommand) AqlInclue() []string {
- return gc.aqlInclude
-}
-
-func (gc *GenericCommand) SetAqlInclude(include []string) *GenericCommand {
- gc.aqlInclude = include
- return gc
-}
diff --git a/artifactory/commands/generic/gitlfsclean.go b/artifactory/commands/generic/gitlfsclean.go
deleted file mode 100644
index 04805a81b..000000000
--- a/artifactory/commands/generic/gitlfsclean.go
+++ /dev/null
@@ -1,110 +0,0 @@
-package generic
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- clientutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type GitLfsCommand struct {
- GenericCommand
- configuration *GitLfsCleanConfiguration
-}
-
-func NewGitLfsCommand() *GitLfsCommand {
- return &GitLfsCommand{GenericCommand: *NewGenericCommand()}
-}
-
-func (glc *GitLfsCommand) Configuration() *GitLfsCleanConfiguration {
- return glc.configuration
-}
-
-func (glc *GitLfsCommand) SetConfiguration(configuration *GitLfsCleanConfiguration) *GitLfsCommand {
- glc.configuration = configuration
- return glc
-}
-
-func (glc *GitLfsCommand) Run() error {
- serverDetails, err := glc.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return err
- }
- servicesManager, err := utils.CreateServiceManager(serverDetails, glc.retries, glc.retryWaitTimeMilliSecs, glc.DryRun())
- if err != nil {
- return err
- }
-
- gitLfsCleanParams := getGitLfsCleanParams(glc.configuration)
-
- filesToDeleteReader, err := servicesManager.GetUnreferencedGitLfsFiles(gitLfsCleanParams)
- if err != nil {
- return err
- }
- defer filesToDeleteReader.Close()
- length, err := filesToDeleteReader.Length()
- if err != nil || length < 1 {
- return err
- }
-
- if glc.configuration.Quiet {
- return glc.deleteLfsFilesFromArtifactory(filesToDeleteReader)
- }
- return glc.interactiveDeleteLfsFiles(filesToDeleteReader)
-}
-
-func (glc *GitLfsCommand) CommandName() string {
- return "rt_git_lfs_clean"
-}
-
-func (glc *GitLfsCommand) deleteLfsFilesFromArtifactory(deleteItems *content.ContentReader) error {
- length, err := deleteItems.Length()
- if err != nil {
- return errorutils.CheckError(err)
- }
- log.Info("Deleting", length, "files from", glc.configuration.Repo, "...")
- servicesManager, err := utils.CreateServiceManager(glc.serverDetails, glc.retries, glc.retryWaitTimeMilliSecs, glc.DryRun())
- if err != nil {
- return err
- }
- _, err = servicesManager.DeleteFiles(deleteItems)
- if err != nil {
- return errorutils.CheckError(err)
- }
- return nil
-}
-
-type GitLfsCleanConfiguration struct {
- Quiet bool
- Refs string
- Repo string
- GitPath string
-}
-
-func getGitLfsCleanParams(configuration *GitLfsCleanConfiguration) (gitLfsCleanParams services.GitLfsCleanParams) {
- gitLfsCleanParams = services.NewGitLfsCleanParams()
- gitLfsCleanParams.GitPath = configuration.GitPath
- gitLfsCleanParams.Refs = configuration.Refs
- gitLfsCleanParams.Repo = configuration.Repo
- return
-}
-
-func (glc *GitLfsCommand) interactiveDeleteLfsFiles(filesToDelete *content.ContentReader) error {
- for resultItem := new(clientutils.ResultItem); filesToDelete.NextRecord(resultItem) == nil; resultItem = new(clientutils.ResultItem) {
- log.Output(" " + resultItem.Name)
- }
- if err := filesToDelete.GetError(); err != nil {
- return err
- }
- filesToDelete.Reset()
- confirmed := coreutils.AskYesNo("Are you sure you want to delete the above files?\n"+
- "You can avoid this confirmation message by adding --quiet to the command.", false)
- if confirmed {
- err := glc.deleteLfsFilesFromArtifactory(filesToDelete)
- return err
- }
- return nil
-}
diff --git a/artifactory/commands/generic/move.go b/artifactory/commands/generic/move.go
deleted file mode 100644
index 3ff5326b6..000000000
--- a/artifactory/commands/generic/move.go
+++ /dev/null
@@ -1,93 +0,0 @@
-package generic
-
-import (
- "errors"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type MoveCommand struct {
- GenericCommand
- threads int
-}
-
-func NewMoveCommand() *MoveCommand {
- return &MoveCommand{GenericCommand: *NewGenericCommand()}
-}
-
-func (mc *MoveCommand) Threads() int {
- return mc.threads
-}
-
-func (mc *MoveCommand) SetThreads(threads int) *MoveCommand {
- mc.threads = threads
- return mc
-}
-
-// Moves the artifacts using the specified move pattern.
-func (mc *MoveCommand) Run() error {
- // Create Service Manager:
- servicesManager, err := utils.CreateServiceManagerWithThreads(mc.serverDetails, mc.DryRun(), mc.threads, mc.retries, mc.retryWaitTimeMilliSecs)
- if err != nil {
- return err
- }
-
- var errorOccurred = false
- var moveParamsArray []services.MoveCopyParams
- // Create MoveParams for all File-Spec groups.
- for i := 0; i < len(mc.Spec().Files); i++ {
- moveParams, err := getMoveParams(mc.Spec().Get(i))
- if err != nil {
- errorOccurred = true
- log.Error(err)
- continue
- }
- moveParamsArray = append(moveParamsArray, moveParams)
- }
-
- // Perform move.
- totalMoved, totalFailed, err := servicesManager.Move(moveParamsArray...)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- }
- mc.result.SetSuccessCount(totalMoved)
- mc.result.SetFailCount(totalFailed)
-
- if errorOccurred {
- return errors.New("move finished with errors, please review the logs")
- }
- return err
-}
-
-func (mc *MoveCommand) CommandName() string {
- return "rt_move"
-}
-
-func getMoveParams(f *spec.File) (moveParams services.MoveCopyParams, err error) {
- moveParams = services.NewMoveCopyParams()
- moveParams.CommonParams, err = f.ToCommonParams()
- if err != nil {
- return
- }
- moveParams.Recursive, err = f.IsRecursive(true)
- if err != nil {
- return
- }
- moveParams.ExcludeArtifacts, err = f.IsExcludeArtifacts(false)
- if err != nil {
- return
- }
- moveParams.IncludeDeps, err = f.IsIncludeDeps(false)
- if err != nil {
- return
- }
- moveParams.Flat, err = f.IsFlat(false)
- if err != nil {
- return
- }
- return
-}
diff --git a/artifactory/commands/generic/props.go b/artifactory/commands/generic/props.go
deleted file mode 100644
index 34f9b7f21..000000000
--- a/artifactory/commands/generic/props.go
+++ /dev/null
@@ -1,106 +0,0 @@
-package generic
-
-import (
- "errors"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/artifactory"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- clientConfig "github.com/jfrog/jfrog-client-go/config"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type PropsCommand struct {
- props string
- threads int
- GenericCommand
-}
-
-func NewPropsCommand() *PropsCommand {
- return &PropsCommand{GenericCommand: *NewGenericCommand()}
-}
-
-func (pc *PropsCommand) Threads() int {
- return pc.threads
-}
-
-func (pc *PropsCommand) SetThreads(threads int) *PropsCommand {
- pc.threads = threads
- return pc
-}
-
-func (pc *PropsCommand) Props() string {
- return pc.props
-}
-
-func (pc *PropsCommand) SetProps(props string) *PropsCommand {
- pc.props = props
- return pc
-}
-
-func createPropsServiceManager(threads, httpRetries, retryWaitMilliSecs int, serverDetails *config.ServerDetails) (artifactory.ArtifactoryServicesManager, error) {
- certsPath, err := coreutils.GetJfrogCertsDir()
- if err != nil {
- return nil, err
- }
- artAuth, err := serverDetails.CreateArtAuthConfig()
- if err != nil {
- return nil, err
- }
- serviceConfig, err := clientConfig.NewConfigBuilder().
- SetServiceDetails(artAuth).
- SetCertificatesPath(certsPath).
- SetInsecureTls(serverDetails.InsecureTls).
- SetThreads(threads).
- SetHttpRetries(httpRetries).
- SetHttpRetryWaitMilliSecs(retryWaitMilliSecs).
- Build()
- if err != nil {
- return nil, err
- }
- return artifactory.New(serviceConfig)
-}
-
-func searchItems(spec *spec.SpecFiles, servicesManager artifactory.ArtifactoryServicesManager) (resultReader *content.ContentReader, err error) {
- var errorOccurred = false
- temp := []*content.ContentReader{}
- defer func() {
- for _, reader := range temp {
- err = errors.Join(err, reader.Close())
- }
- }()
- for i := 0; i < len(spec.Files); i++ {
- searchParams, err := utils.GetSearchParams(spec.Get(i))
- if err != nil {
- errorOccurred = true
- log.Error(err)
- continue
- }
- reader, err := servicesManager.SearchFiles(searchParams)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- continue
- }
- temp = append(temp, reader)
- }
- resultReader, err = content.MergeReaders(temp, content.DefaultKey)
- if err != nil {
- return
- }
- if errorOccurred {
- err = errorutils.CheckErrorf("Operation finished with errors, please review the logs.")
- }
- return
-}
-
-func GetPropsParams(reader *content.ContentReader, properties string) (propsParams services.PropsParams) {
- propsParams = services.NewPropsParams()
- propsParams.Reader = reader
- propsParams.Props = properties
- return
-}
diff --git a/artifactory/commands/generic/search.go b/artifactory/commands/generic/search.go
deleted file mode 100644
index b5cf9ff40..000000000
--- a/artifactory/commands/generic/search.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package generic
-
-import (
- "errors"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- clientartutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type SearchCommand struct {
- GenericCommand
-}
-
-func NewSearchCommand() *SearchCommand {
- return &SearchCommand{GenericCommand: *NewGenericCommand()}
-}
-
-func (sc *SearchCommand) CommandName() string {
- return "rt_search"
-}
-
-func (sc *SearchCommand) Run() error {
- reader, err := sc.Search()
- sc.Result().SetReader(reader)
- return err
-}
-
-func (sc *SearchCommand) Search() (*content.ContentReader, error) {
- // Service Manager
- serverDetails, err := sc.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return nil, err
- }
- servicesManager, err := utils.CreateServiceManager(serverDetails, sc.retries, sc.retryWaitTimeMilliSecs, false)
- if err != nil {
- return nil, err
- }
- // Search Loop
- log.Info("Searching artifacts...")
-
- searchResults, callbackFunc, err := utils.SearchFiles(servicesManager, sc.Spec())
- defer func() {
- err = errors.Join(err, callbackFunc())
- }()
- if err != nil {
- return nil, err
- }
-
- reader, err := utils.AqlResultToSearchResult(searchResults)
- if err != nil {
- return nil, err
- }
- length, err := reader.Length()
- clientartutils.LogSearchResults(length)
- return reader, err
-}
diff --git a/artifactory/commands/generic/setprops.go b/artifactory/commands/generic/setprops.go
deleted file mode 100644
index b3bb5a09d..000000000
--- a/artifactory/commands/generic/setprops.go
+++ /dev/null
@@ -1,53 +0,0 @@
-package generic
-
-import (
- "errors"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
-)
-
-type SetPropsCommand struct {
- PropsCommand
-}
-
-func NewSetPropsCommand() *SetPropsCommand {
- return &SetPropsCommand{}
-}
-
-func (setProps *SetPropsCommand) SetPropsCommand(command PropsCommand) *SetPropsCommand {
- setProps.PropsCommand = command
- return setProps
-}
-
-func (setProps *SetPropsCommand) CommandName() string {
- return "rt_set_properties"
-}
-
-func (setProps *SetPropsCommand) Run() (err error) {
- serverDetails, err := setProps.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return err
- }
- servicesManager, err := createPropsServiceManager(setProps.threads, setProps.retries, setProps.retryWaitTimeMilliSecs, serverDetails)
- if err != nil {
- return err
- }
-
- reader, err := searchItems(setProps.Spec(), servicesManager)
- if err != nil {
- return err
- }
- defer func() {
- err = errors.Join(err, reader.Close())
- }()
- propsParams := GetPropsParams(reader, setProps.props)
- success, err := servicesManager.SetProps(propsParams)
-
- result := setProps.Result()
- result.SetSuccessCount(success)
- totalLength, totalLengthErr := reader.Length()
- result.SetFailCount(totalLength - success)
- if totalLengthErr != nil {
- return totalLengthErr
- }
- return err
-}
diff --git a/artifactory/commands/generic/upload.go b/artifactory/commands/generic/upload.go
deleted file mode 100644
index 8b721ffd1..000000000
--- a/artifactory/commands/generic/upload.go
+++ /dev/null
@@ -1,313 +0,0 @@
-package generic
-
-import (
- "errors"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/commandsummary"
- "github.com/jfrog/jfrog-client-go/artifactory"
- "os"
-
- buildInfo "github.com/jfrog/build-info-go/entities"
-
- ioutils "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- rtServicesUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientUtils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "strconv"
- "time"
-)
-
-type UploadCommand struct {
- GenericCommand
- uploadConfiguration *utils.UploadConfiguration
- buildConfiguration *build.BuildConfiguration
- progress ioUtils.ProgressMgr
-}
-
-func NewUploadCommand() *UploadCommand {
- return &UploadCommand{GenericCommand: *NewGenericCommand()}
-}
-
-func (uc *UploadCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *UploadCommand {
- uc.buildConfiguration = buildConfiguration
- return uc
-}
-
-func (uc *UploadCommand) UploadConfiguration() *utils.UploadConfiguration {
- return uc.uploadConfiguration
-}
-
-func (uc *UploadCommand) SetUploadConfiguration(uploadConfiguration *utils.UploadConfiguration) *UploadCommand {
- uc.uploadConfiguration = uploadConfiguration
- return uc
-}
-
-func (uc *UploadCommand) SetProgress(progress ioUtils.ProgressMgr) {
- uc.progress = progress
-}
-
-func (uc *UploadCommand) ShouldPrompt() bool {
- return uc.syncDelete() && !uc.Quiet()
-}
-
-func (uc *UploadCommand) syncDelete() bool {
- return !uc.DryRun() && uc.SyncDeletesPath() != ""
-}
-
-func (uc *UploadCommand) CommandName() string {
- return "rt_upload"
-}
-
-func (uc *UploadCommand) Run() error {
- return uc.upload()
-}
-
-// Uploads the artifacts in the specified local path pattern to the specified target path.
-// Returns the total number of artifacts successfully uploaded.
-func (uc *UploadCommand) upload() (err error) {
- // Init progress bar if needed
- if uc.progress != nil {
- uc.progress.SetHeadlineMsg("Uploading")
- uc.progress.InitProgressReaders()
- }
- // In case of sync-delete get the user to confirm first, and save the operation timestamp.
- syncDeletesProp := ""
- if uc.syncDelete() {
- timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)
- syncDeletesProp = "sync.deletes.timestamp=" + timestamp
- }
-
- // Create Service Manager:
- uc.uploadConfiguration.MinChecksumDeploySize, err = utils.GetMinChecksumDeploySize()
- if err != nil {
- return
- }
- serverDetails, err := uc.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return
- }
- servicesManager, err := utils.CreateUploadServiceManager(serverDetails, uc.uploadConfiguration.Threads, uc.retries, uc.retryWaitTimeMilliSecs, uc.DryRun(), uc.progress)
- if err != nil {
- return
- }
-
- addVcsProps := false
- buildProps := ""
- // Build Info Collection:
- toCollect, err := uc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return
- }
- if toCollect && !uc.DryRun() {
- addVcsProps = true
- buildProps, err = build.CreateBuildPropsFromConfiguration(uc.buildConfiguration)
- if err != nil {
- return err
- }
- }
-
- var errorOccurred = false
- var uploadParamsArray []services.UploadParams
- // Create UploadParams for all File-Spec groups.
- for i := 0; i < len(uc.Spec().Files); i++ {
- file := uc.Spec().Get(i)
- file.TargetProps = clientUtils.AddProps(file.TargetProps, file.Props)
- file.TargetProps = clientUtils.AddProps(file.TargetProps, syncDeletesProp)
- file.Props += syncDeletesProp
- uploadParams, err := getUploadParams(file, uc.uploadConfiguration, buildProps, addVcsProps)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- continue
- }
- uploadParamsArray = append(uploadParamsArray, uploadParams)
- }
-
- // Perform upload.
- // In case of build-info collection or a detailed summary request, we use the upload service which provides results file reader,
- // otherwise we use the upload service which provides only general counters.
- var successCount, failCount int
- var artifactsDetailsReader *content.ContentReader = nil
- if uc.DetailedSummary() || toCollect {
- var summary *rtServicesUtils.OperationSummary
- summary, err = servicesManager.UploadFilesWithSummary(artifactory.UploadServiceOptions{}, uploadParamsArray...)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- }
- if summary != nil {
- artifactsDetailsReader = summary.ArtifactsDetailsReader
- defer ioutils.Close(artifactsDetailsReader, &err)
- // If 'detailed summary' was requested, then the reader should not be closed here.
- // It will be closed after it will be used to generate the summary.
- if uc.DetailedSummary() {
- uc.result.SetReader(summary.TransferDetailsReader)
- } else {
- err = summary.TransferDetailsReader.Close()
- if err != nil {
- errorOccurred = true
- log.Error(err)
- }
- }
- successCount = summary.TotalSucceeded
- failCount = summary.TotalFailed
-
- if err = recordCommandSummary(summary); err != nil {
- return
- }
- }
- } else {
- successCount, failCount, err = servicesManager.UploadFiles(artifactory.UploadServiceOptions{}, uploadParamsArray...)
- if err != nil {
- errorOccurred = true
- log.Error(err)
- }
- }
- uc.result.SetSuccessCount(successCount)
- uc.result.SetFailCount(failCount)
- if errorOccurred {
- err = errors.New("upload finished with errors. Review the logs for more information")
- return
- }
- if failCount > 0 {
- return
- }
-
- // Handle sync-deletes
- if uc.syncDelete() {
- err = uc.handleSyncDeletes(syncDeletesProp)
- if err != nil {
- return
- }
- }
-
- // Build info
- if !uc.DryRun() && toCollect {
- var buildArtifacts []buildInfo.Artifact
- buildArtifacts, err = rtServicesUtils.ConvertArtifactsDetailsToBuildInfoArtifacts(artifactsDetailsReader)
- if err != nil {
- return
- }
- return build.PopulateBuildArtifactsAsPartials(buildArtifacts, uc.buildConfiguration, buildInfo.Generic)
- }
-
- return
-}
-
-func getUploadParams(f *spec.File, configuration *utils.UploadConfiguration, buildProps string, addVcsProps bool) (uploadParams services.UploadParams, err error) {
- uploadParams = services.NewUploadParams()
- uploadParams.CommonParams, err = f.ToCommonParams()
- if err != nil {
- return
- }
- uploadParams.Deb = configuration.Deb
- uploadParams.MinChecksumDeploy = configuration.MinChecksumDeploySize
- uploadParams.MinSplitSize = configuration.MinSplitSizeMB * rtServicesUtils.SizeMiB
- uploadParams.SplitCount = configuration.SplitCount
- uploadParams.ChunkSize = configuration.ChunkSizeMB * rtServicesUtils.SizeMiB
- uploadParams.AddVcsProps = addVcsProps
- uploadParams.BuildProps = buildProps
- uploadParams.Archive = f.Archive
- uploadParams.TargetPathInArchive = f.TargetPathInArchive
-
- uploadParams.Recursive, err = f.IsRecursive(true)
- if err != nil {
- return
- }
-
- uploadParams.Regexp, err = f.IsRegexp(false)
- if err != nil {
- return
- }
-
- uploadParams.Ant, err = f.IsAnt(false)
- if err != nil {
- return
- }
-
- uploadParams.IncludeDirs, err = f.IsIncludeDirs(false)
- if err != nil {
- return
- }
-
- uploadParams.Flat, err = f.IsFlat(true)
- if err != nil {
- return
- }
-
- uploadParams.ExplodeArchive, err = f.IsExplode(false)
- if err != nil {
- return
- }
-
- uploadParams.Symlink, err = f.IsSymlinks(false)
- if err != nil {
- return
- }
-
- return
-}
-
-func (uc *UploadCommand) handleSyncDeletes(syncDeletesProp string) (err error) {
- servicesManager, err := utils.CreateServiceManager(uc.serverDetails, uc.retries, uc.retryWaitTimeMilliSecs, false)
- if err != nil {
- return err
- }
- deleteSpec := createDeleteSpecForSync(uc.SyncDeletesPath(), syncDeletesProp)
- deleteParams, err := getDeleteParams(deleteSpec.Get(0))
- if err != nil {
- return err
- }
- resultItems, err := servicesManager.GetPathsToDelete(deleteParams)
- if err != nil {
- return err
- }
- defer ioutils.Close(resultItems, &err)
- _, err = servicesManager.DeleteFiles(resultItems)
- return err
-}
-
-func createDeleteSpecForSync(deletePattern string, syncDeletesProp string) *spec.SpecFiles {
- return spec.NewBuilder().
- Pattern(deletePattern).
- ExcludeProps(syncDeletesProp).
- Recursive(true).
- BuildSpec()
-}
-
-func recordCommandSummary(summary *rtServicesUtils.OperationSummary) (err error) {
- if !commandsummary.ShouldRecordSummary() {
- return
- }
- uploadSummary, err := commandsummary.NewUploadSummary()
- if err != nil {
- return
- }
- data, err := readDetailsFromReader(summary.TransferDetailsReader)
- if err != nil {
- return
- }
- return uploadSummary.Record(data)
-}
-
-// Reads transfer details from the reader and return the content as bytes for further processing
-func readDetailsFromReader(reader *content.ContentReader) (readContent []byte, err error) {
- if reader == nil {
- return
- }
- for _, file := range reader.GetFilesPaths() {
- // Read source file
- sourceBytes, err := os.ReadFile(file)
- if err != nil {
- return nil, errorutils.CheckError(err)
- }
- readContent = append(readContent, sourceBytes...)
- }
- return
-}
diff --git a/artifactory/commands/golang/archive.go b/artifactory/commands/golang/archive.go
deleted file mode 100644
index b81ef3313..000000000
--- a/artifactory/commands/golang/archive.go
+++ /dev/null
@@ -1,222 +0,0 @@
-package golang
-
-// The code in this file was copied from https://github.com/golang/go
-// which is under this license https://github.com/golang/go/blob/master/LICENSE
-// Copyright (c) 2009 The Go Authors. All rights reserved.
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-import (
- "github.com/jfrog/jfrog-client-go/artifactory/services/fspatterns"
- "github.com/jfrog/jfrog-client-go/utils"
- "golang.org/x/mod/module"
- gozip "golang.org/x/mod/zip"
- "io"
- "os"
- "path/filepath"
- "regexp"
- "strings"
-)
-
-// Package zip provides functions for creating and extracting module zip files.
-//
-// Module zip files have several restrictions listed below. These are necessary
-// to ensure that module zip files can be extracted consistently on supported
-// platforms and file systems.
-//
-// • No two file paths may be equal under Unicode case-folding (see
-// strings.EqualFold).
-//
-// • A go.mod file may or may not appear in the top-level directory. If present,
-// it must be named "go.mod", not any other case. Files named "go.mod"
-// are not allowed in any other directory.
-//
-// • The total size in bytes of a module zip file may be at most MaxZipFile
-// bytes (500 MiB). The total uncompressed size of the files within the
-// zip may also be at most MaxZipFile bytes.
-//
-// • Each file's uncompressed size must match its declared 64-bit uncompressed
-// size in the zip file header.
-//
-// • If the zip contains files named "@/go.mod" or
-// "@/LICENSE", their sizes in bytes may be at most
-// MaxGoMod or MaxLICENSE, respectively (both are 16 MiB).
-//
-// • Empty directories are ignored. File permissions and timestamps are also
-// ignored.
-//
-// • Symbolic links and other irregular files are not allowed.
-//
-// Note that this package does not provide hashing functionality. See
-// golang.org/x/mod/sumdb/dirhash.
-
-// Archive project files according to the go project standard
-func archiveProject(writer io.Writer, dir, mod, version string, excludedPatterns []string) error {
- m := module.Version{Version: version, Path: mod}
- excludedPatterns, err := getAbsolutePaths(excludedPatterns)
- if err != nil {
- return err
- }
- excludePatternsStr := fspatterns.PrepareExcludePathPattern(excludedPatterns, utils.GetPatternType(utils.PatternTypes{RegExp: false, Ant: false}), true)
- var files []gozip.File
- err = filepath.Walk(dir, func(filePath string, info os.FileInfo, err error) error {
- if err != nil {
- return err
- }
- relPath, err := filepath.Rel(dir, filePath)
- if err != nil {
- return err
- }
- slashPath := filepath.ToSlash(relPath)
- if info.IsDir() {
- if filePath == dir {
- // Don't skip the top-level directory.
- return nil
- }
-
- // Skip VCS directories.
- // fossil repos are regular files with arbitrary names, so we don't try
- // to exclude them.
- switch filepath.Base(filePath) {
- case ".bzr", ".git", ".hg", ".svn":
- return filepath.SkipDir
- }
-
- // Skip some subdirectories inside vendor, but maintain bug
- // golang.org/issue/31562, described in isVendoredPackage.
- // We would like Create and CreateFromDir to produce the same result
- // for a set of files, whether expressed as a directory tree or zip.
-
- if isVendoredPackage(slashPath) {
- return filepath.SkipDir
- }
-
- // Skip submodules (directories containing go.mod files).
- if goModInfo, err := os.Lstat(filepath.Join(filePath, "go.mod")); err == nil && !goModInfo.IsDir() {
- return filepath.SkipDir
- }
- }
- if info.Mode().IsRegular() {
- if !isVendoredPackage(slashPath) {
- excluded, err := isPathExcluded(filePath, excludePatternsStr)
- if err != nil {
- return err
- }
- if !excluded {
- files = append(files, dirFile{
- filePath: filePath,
- slashPath: slashPath,
- info: info,
- })
- }
- }
- return nil
- }
- // Not a regular file or a directory. Probably a symbolic link.
- // Irregular files are ignored, so skip it.
- return nil
- })
- if err != nil {
- return err
- }
-
- return gozip.Create(writer, m, files)
-}
-
-func getAbsolutePaths(exclusionPatterns []string) ([]string, error) {
- var absolutedPaths []string
- for _, singleExclusion := range exclusionPatterns {
- singleExclusion, err := filepath.Abs(singleExclusion)
- if err != nil {
- return nil, err
- }
- absolutedPaths = append(absolutedPaths, singleExclusion)
- }
- return absolutedPaths, nil
-}
-
-// This function receives a path and a regexp.
-// It returns trUe is the path received matches the regexp.
-// Before the match, thw path is turned into an absolute.
-func isPathExcluded(path string, excludePatternsRegexp string) (excluded bool, err error) {
- var fullPath string
- if len(excludePatternsRegexp) > 0 {
- fullPath, err = filepath.Abs(path)
- if err != nil {
- return
- }
- excluded, err = regexp.MatchString(excludePatternsRegexp, fullPath)
- }
- return
-}
-
-func isVendoredPackage(name string) bool {
- var i int
- if strings.HasPrefix(name, "vendor/") {
- i += len("vendor/")
- } else if j := strings.Index(name, "/vendor/"); j >= 0 {
- // This offset looks incorrect; this should probably be
- //
- // i = j + len("/vendor/")
- //
- // Unfortunately, we can't fix it without invalidating checksums.
- // Fortunately, the error appears to be strictly conservative: we'll retain
- // vendored packages that we should have pruned, but we won't prune
- // non-vendored packages that we should have retained.
- //
- // Since this defect doesn't seem to break anything, it's not worth fixing
- // for now.
- i += len("/vendor/")
- } else {
- return false
- }
- return strings.Contains(name[i:], "/")
-}
-
-type dirFile struct {
- filePath, slashPath string
- info os.FileInfo
-}
-
-func (f dirFile) Path() string { return f.slashPath }
-func (f dirFile) Lstat() (os.FileInfo, error) { return f.info, nil }
-func (f dirFile) Open() (io.ReadCloser, error) { return os.Open(f.filePath) }
-
-// File provides an abstraction for a file in a directory, zip, or anything
-// else that looks like a file.
-type File interface {
- // Path returns a clean slash-separated relative path from the module root
- // directory to the file.
- Path() string
-
- // Lstat returns information about the file. If the file is a symbolic link,
- // Lstat returns information about the link itself, not the file it points to.
- Lstat() (os.FileInfo, error)
-
- // Open provides access to the data within a regular file. Open may return
- // an error if called on a directory or symbolic link.
- Open() (io.ReadCloser, error)
-}
diff --git a/artifactory/commands/golang/archive_test.go b/artifactory/commands/golang/archive_test.go
deleted file mode 100644
index a455104d2..000000000
--- a/artifactory/commands/golang/archive_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package golang
-
-import (
- "bytes"
- "github.com/jfrog/gofrog/crypto"
- "github.com/stretchr/testify/assert"
- "os"
- "path/filepath"
- "reflect"
- "testing"
-
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/log"
- "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
-)
-
-func TestArchiveProject(t *testing.T) {
- log.SetDefaultLogger()
- if coreutils.IsWindows() {
- t.Skip("Skipping archive test...")
- }
- pwd, err := os.Getwd()
- if err != nil {
- t.Error(err)
- }
- buff := &bytes.Buffer{}
- originalFolder := "test_.git_suffix"
- baseDir, dotGitPath := tests.PrepareDotGitDir(t, originalFolder, "testdata")
- var archiveWithExclusion = []struct {
- buff *bytes.Buffer
- filePath string
- mod string
- version string
- excludedPatterns []string
- expected map[crypto.Algorithm]string
- }{
- {buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", nil, map[crypto.Algorithm]string{crypto.MD5: "5b3603a7bf637622516673b845249205", crypto.SHA1: "7386685c432c39428c9cb8584a2b970139c5e626", crypto.SHA256: "eefd8aa3f9ac89876c8442d5feebbc837666bf40114d201219e3e6d51c208949"}},
- {buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"./testdata/dir1/*"}, map[crypto.Algorithm]string{crypto.MD5: "c2eeb4ef958edee91570690bf4111fc7", crypto.SHA1: "d77e10eaa9bd863a9ff3775d3e452041e6f5aa40", crypto.SHA256: "ecf66c1256263b2b4386efc299fa0c389263608efda9d1d91af8a746e6c5709a"}},
- {buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"./testdata/dir2/*"}, map[crypto.Algorithm]string{crypto.MD5: "bbe78a98ba10c1428f3a364570015e11", crypto.SHA1: "99fd22ea2fe9c2c48124e741881fc3a555458a7e", crypto.SHA256: "e2299f3c4e1f22d36befba191a347783dc2047e8e38cf6b9b96c273090f6e25b"}},
- {buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"./testdata/dir2/*", "testdata/dir3/*"}, map[crypto.Algorithm]string{crypto.MD5: "28617d6e74fce3dd2bab21b1bd65009b", crypto.SHA1: "410814fbf21afdfb9c5b550151a51c2e986447fa", crypto.SHA256: "e877c07315d6d3ad69139035defc08c04b400b36cd069b35ea3c2960424f2dc6"}},
- {buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"./testdata/dir2/*", "./testdata/dir3/dir4/*"}, map[crypto.Algorithm]string{crypto.MD5: "46a3ded48ed7998b1b35c80fbe0ffab5", crypto.SHA1: "a26e73e7d29e49dd5d9c87da8f7c93cf929750df", crypto.SHA256: "cf224b12eca12de4a052ef0f444519d64b6cecaf7b06050a02998be190e88847"}},
- {buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"./testdata/dir3/*"}, map[crypto.Algorithm]string{crypto.MD5: "c2a2dd6a7af84c2d88a48caf0c3aec34", crypto.SHA1: "193d761317a602d18566561678b7bddc4773385c", crypto.SHA256: "3efcd8b0d88081ec64333ff98b43616d283c4d52ed26cd7c8df646d9ea452c31"}},
- {buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"*.txt"}, map[crypto.Algorithm]string{crypto.MD5: "e93953b4be84d7753e0f33589b7dc4ba", crypto.SHA1: "280c7492f57262b6e0af56b06c9db6a128e32ab9", crypto.SHA256: "e7357986c59bf670af1e2f4868edb1406a87d328b7681b15cf038491cdc7e88c"}},
- {buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"./*/dir4/*.txt"}, map[crypto.Algorithm]string{crypto.MD5: "785f0c0c7b20dfd716178856edb79834", crypto.SHA1: "d07204277ece1d7bef6a9f289a56afb91d66125f", crypto.SHA256: "6afa0dd70bfa7c6d3aca1a3dfcd6465c542d64136c6391fa611795e6fa5800ce"}},
- }
- for _, testData := range archiveWithExclusion {
- err = archiveProject(testData.buff, testData.filePath, testData.mod, testData.version, testData.excludedPatterns)
- assert.NoError(t, err)
- actual, err := crypto.CalcChecksums(buff)
- assert.NoError(t, err)
-
- if !reflect.DeepEqual(testData.expected, actual) {
- t.Errorf("Expecting: %v, Got: %v", testData.expected, actual)
- }
- }
- tests.RenamePath(dotGitPath, filepath.Join(baseDir, originalFolder), t)
-}
-
-func TestGetAbsolutePaths(t *testing.T) {
- testData := []string{filepath.Join(".", "dir1", "*"), "*.txt", filepath.Join("*", "dir2", "*")}
- result, err := getAbsolutePaths(testData)
- assert.NoError(t, err)
- wd, err := os.Getwd()
- assert.NoError(t, err)
- expectedResults := []string{filepath.Join(wd, "dir1", "*"), filepath.Join(wd, "*.txt"), filepath.Join(wd, "*", "dir2", "*")}
- assert.ElementsMatch(t, result, expectedResults)
-}
diff --git a/artifactory/commands/golang/go.go b/artifactory/commands/golang/go.go
deleted file mode 100644
index 39ac40ae1..000000000
--- a/artifactory/commands/golang/go.go
+++ /dev/null
@@ -1,423 +0,0 @@
-package golang
-
-import (
- "encoding/json"
- "errors"
- "fmt"
- "github.com/jfrog/build-info-go/build"
- biutils "github.com/jfrog/build-info-go/utils"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/auth"
- "github.com/jfrog/jfrog-client-go/http/httpclient"
- rtutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "net/http"
- "net/url"
- "os"
- "path"
- "path/filepath"
- "strings"
-)
-
-type GoCommand struct {
- goArg []string
- buildConfiguration *buildUtils.BuildConfiguration
- deployerParams *project.RepositoryConfig
- resolverParams *project.RepositoryConfig
- configFilePath string
- noFallback bool
-}
-
-func NewGoCommand() *GoCommand {
- return &GoCommand{}
-}
-
-func (gc *GoCommand) SetConfigFilePath(configFilePath string) *GoCommand {
- gc.configFilePath = configFilePath
- return gc
-}
-
-func (gc *GoCommand) SetResolverParams(resolverParams *project.RepositoryConfig) *GoCommand {
- gc.resolverParams = resolverParams
- return gc
-}
-
-func (gc *GoCommand) SetDeployerParams(deployerParams *project.RepositoryConfig) *GoCommand {
- gc.deployerParams = deployerParams
- return gc
-}
-
-func (gc *GoCommand) SetBuildConfiguration(buildConfiguration *buildUtils.BuildConfiguration) *GoCommand {
- gc.buildConfiguration = buildConfiguration
- return gc
-}
-
-func (gc *GoCommand) SetGoArg(goArg []string) *GoCommand {
- gc.goArg = goArg
- return gc
-}
-
-func (gc *GoCommand) CommandName() string {
- return "rt_go"
-}
-
-func (gc *GoCommand) ServerDetails() (*config.ServerDetails, error) {
- // If deployer Artifactory details exists, returns it.
- if gc.deployerParams != nil && !gc.deployerParams.IsServerDetailsEmpty() {
- return gc.deployerParams.ServerDetails()
- }
-
- // If resolver Artifactory details exists, returns it.
- if gc.resolverParams != nil && !gc.resolverParams.IsServerDetailsEmpty() {
- return gc.resolverParams.ServerDetails()
- }
-
- vConfig, err := project.ReadConfigFile(gc.configFilePath, project.YAML)
- if err != nil {
- return nil, err
- }
- return buildUtils.GetServerDetails(vConfig)
-}
-
-func (gc *GoCommand) Run() error {
- // Read config file.
- log.Debug("Preparing to read the config file", gc.configFilePath)
- vConfig, err := project.ReadConfigFile(gc.configFilePath, project.YAML)
- if err != nil {
- return err
- }
-
- // Extract resolution params.
- gc.resolverParams, err = project.GetRepoConfigByPrefix(gc.configFilePath, project.ProjectConfigResolverPrefix, vConfig)
- if err != nil {
- return err
- }
-
- if vConfig.IsSet(project.ProjectConfigDeployerPrefix) {
- // Extract deployer params.
- gc.deployerParams, err = project.GetRepoConfigByPrefix(gc.configFilePath, project.ProjectConfigDeployerPrefix, vConfig)
- if err != nil {
- return err
- }
- }
-
- // Extract build info information from the args.
- gc.goArg, gc.buildConfiguration, err = buildUtils.ExtractBuildDetailsFromArgs(gc.goArg)
- if err != nil {
- return err
- }
-
- // Extract no-fallback flag from the args.
- gc.goArg, err = gc.extractNoFallbackFromArgs()
- if err != nil {
- return err
- }
- return gc.run()
-}
-
-func (gc *GoCommand) extractNoFallbackFromArgs() (cleanArgs []string, err error) {
- var flagIndex int
- cleanArgs = append([]string(nil), gc.goArg...)
-
- // Extract no-fallback boolean flag from the args.
- flagIndex, gc.noFallback, err = coreutils.FindBooleanFlag("--no-fallback", cleanArgs)
- if err != nil {
- return
- }
-
- coreutils.RemoveFlagFromCommand(&cleanArgs, flagIndex, flagIndex)
- return
-}
-
-func (gc *GoCommand) run() (err error) {
- err = logGoVersion()
- if err != nil {
- return
- }
- goBuildInfo, err := buildUtils.PrepareBuildPrerequisites(gc.buildConfiguration)
- if err != nil {
- return
- }
- defer func() {
- if goBuildInfo != nil && err != nil {
- err = errors.Join(err, goBuildInfo.Clean())
- }
- }()
-
- resolverDetails, err := gc.resolverParams.ServerDetails()
- if err != nil {
- return
- }
- // If noFallback=false, missing packages will be fetched directly from VCS
- repoUrl, err := GetArtifactoryRemoteRepoUrl(resolverDetails, gc.resolverParams.TargetRepo(), GoProxyUrlParams{Direct: !gc.noFallback})
- if err != nil {
- return
- }
-
- err = biutils.RunGo(gc.goArg, repoUrl)
- if errorutils.CheckError(err) != nil {
- err = coreutils.ConvertExitCodeError(err)
- return
- }
-
- if goBuildInfo != nil {
- // Need to collect build info
- tempDirPath := ""
- if isGoGetCommand := len(gc.goArg) > 0 && gc.goArg[0] == "get"; isGoGetCommand {
- if len(gc.goArg) < 2 {
- // Package name was not supplied. Invalid go get commend
- err = errorutils.CheckErrorf("Invalid get command. Package name is missing")
- return
- }
- tempDirPath, err = fileutils.CreateTempDir()
- if err != nil {
- return
- }
- // Cleanup the temp working directory at the end.
- defer func() {
- err = errors.Join(err, fileutils.RemoveTempDir(tempDirPath))
- }()
- var serverDetails auth.ServiceDetails
- serverDetails, err = resolverDetails.CreateArtAuthConfig()
- if err != nil {
- return
- }
- err = copyGoPackageFiles(tempDirPath, gc.goArg[1], gc.resolverParams.TargetRepo(), serverDetails)
- if err != nil {
- return
- }
- }
- var goModule *build.GoModule
- goModule, err = goBuildInfo.AddGoModule(tempDirPath)
- if errorutils.CheckError(err) != nil {
- return
- }
- if gc.buildConfiguration.GetModule() != "" {
- goModule.SetName(gc.buildConfiguration.GetModule())
- }
- err = errorutils.CheckError(goModule.CalcDependencies())
- }
-
- return
-}
-
-// copyGoPackageFiles copies the package files from the go mod cache directory to the given destPath.
-// The path to those cache files is retrieved using the supplied package name and Artifactory details.
-func copyGoPackageFiles(destPath, packageName, rtTargetRepo string, authArtDetails auth.ServiceDetails) error {
- packageFilesPath, err := getPackageFilePathFromArtifactory(packageName, rtTargetRepo, authArtDetails)
- if err != nil {
- return err
- }
- // Copy the entire content of the relevant Go pkg directory to the requested destination path.
- err = biutils.CopyDir(packageFilesPath, destPath, true, nil)
- if err != nil {
- return fmt.Errorf("couldn't find suitable package files: %s", packageFilesPath)
- }
- // Set permission recursively
- return coreutils.SetPermissionsRecursively(destPath, 0755)
-}
-
-// getPackageFilePathFromArtifactory returns a string that represents the package files cache path.
-// In most cases the path to those cache files is retrieved using the supplied package name and Artifactory details.
-// However, if the user asked for a specific version (package@vX.Y.Z) the unnecessary call to Artifactory is avoided.
-func getPackageFilePathFromArtifactory(packageName, rtTargetRepo string, authArtDetails auth.ServiceDetails) (packageFilesPath string, err error) {
- var version string
- packageCachePath, err := biutils.GetGoModCachePath()
- if errorutils.CheckError(err) != nil {
- return
- }
- packageNameSplitted := strings.Split(packageName, "@")
- name := packageNameSplitted[0]
- // The case the user asks for a specific version
- if len(packageNameSplitted) == 2 && strings.HasPrefix(packageNameSplitted[1], "v") {
- version = packageNameSplitted[1]
- } else {
- branchName := ""
- // The case the user asks for a specific branch
- if len(packageNameSplitted) == 2 {
- branchName = packageNameSplitted[1]
- }
- packageVersionRequest := buildPackageVersionRequest(name, branchName)
- // Retrieve the package version using Artifactory
- version, err = getPackageVersion(rtTargetRepo, packageVersionRequest, authArtDetails)
- if err != nil {
- return
- }
- }
- packageFilesPath, err = getFileSystemPackagePath(packageCachePath, name, version)
- return
-
-}
-
-// getPackageVersion returns the matching version for the packageName string using the Artifactory details that are provided.
-// PackageName string should be in the following format: /@V/.info OR latest.info
-// For example the jfrog/jfrog-cli/@v/master.info packageName will return the corresponding canonical version (vX.Y.Z) string for the jfrog-cli master branch.
-func getPackageVersion(repoName, packageName string, details auth.ServiceDetails) (string, error) {
- artifactoryApiUrl, err := rtutils.BuildUrl(details.GetUrl(), "api/go/"+repoName, make(map[string]string))
- if err != nil {
- return "", err
- }
- artHttpDetails := details.CreateHttpClientDetails()
- client, err := httpclient.ClientBuilder().Build()
- if err != nil {
- return "", err
- }
- artifactoryApiUrl = artifactoryApiUrl + "/" + packageName
- resp, body, _, err := client.SendGet(artifactoryApiUrl, true, artHttpDetails, "")
- if err != nil {
- return "", err
- }
- if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil {
- return "", err
- }
- // Extract version from response
- var version PackageVersionResponseContent
- if err = json.Unmarshal(body, &version); err != nil {
- return "", errorutils.CheckError(err)
- }
- return version.Version, nil
-}
-
-type PackageVersionResponseContent struct {
- Version string `json:"Version,omitempty"`
-}
-
-// getFileSystemPackagePath returns a string that represents the package files cache path.
-// In some cases when the path isn't represented by the package name, instead the name represents a specific project's directory's path.
-// In this case we will scan the path until we find the package directory.
-// Example : When running 'go get github.com/golang/mock/mockgen@v1.4.1'
-// - "mockgen" is a directory inside "mock" package ("mockgen" doesn't contain "go.mod").
-// - go download and save the whole "mock" package in local cache under 'github.com/golang/mock@v1.4.1' -- >
-// "go get" downloads and saves the whole "mock" package in the local cache under 'github.com/golang/mock@v1.4.1'
-func getFileSystemPackagePath(packageCachePath, name, version string) (string, error) {
- separator := string(filepath.Separator)
- // For Windows OS
- path := filepath.Clean(name)
- for path != "" {
- packagePath := filepath.Join(packageCachePath, path+"@"+version)
- exists, err := fileutils.IsDirExists(packagePath, false)
- if err != nil {
- return "", err
- }
- if exists {
- return packagePath, nil
- }
- // Remove path's last element and check again
- path, _ = filepath.Split(path)
- path = strings.TrimSuffix(path, separator)
- }
- return "", errors.New("Could not find package: " + name + " in: " + packageCachePath)
-}
-
-// buildPackageVersionRequest returns a string representing the version request to Artifactory.
-// The resulted string is in the following format: "/@V/.info".
-// If a branch name is not given, the branch name will be replaced with the "latest" keyword.
-// ("/@V/latest.info").
-func buildPackageVersionRequest(name, branchName string) string {
- packageVersionRequest := path.Join(name, "@v")
- if branchName != "" {
- // A branch name was given by the user
- return path.Join(packageVersionRequest, branchName+".info")
- }
- // No version was given to "go get" command, so the latest version should be requested
- return path.Join(packageVersionRequest, "latest.info")
-}
-
-func SetArtifactoryAsResolutionServer(serverDetails *config.ServerDetails, depsRepo string, goProxyParams GoProxyUrlParams) (err error) {
- if err = setGoProxy(serverDetails, depsRepo, goProxyParams); err != nil {
- err = fmt.Errorf("failed while setting Artifactory as a dependencies resolution registry: %s", err.Error())
- }
- return
-}
-
-func setGoProxy(server *config.ServerDetails, remoteGoRepo string, goProxyParams GoProxyUrlParams) error {
- repoUrl, err := GetArtifactoryRemoteRepoUrl(server, remoteGoRepo, goProxyParams)
- if err != nil {
- return err
- }
- return os.Setenv("GOPROXY", repoUrl)
-}
-
-func SetGoModCache(cacheFolder string) error {
- return os.Setenv("GOMODCACHE", cacheFolder)
-}
-
-func logGoVersion() error {
- version, err := biutils.GetParsedGoVersion()
- if err != nil {
- return errorutils.CheckError(err)
- }
- log.Info("Using go:", version.GetVersion())
- return nil
-}
-
-type GoProxyUrlParams struct {
- // Fallback to retrieve the modules directly from the source if
- // the module failed to be retrieved from the proxy.
- // add |direct to the end of the url.
- // example: https://gocenter.io|direct
- Direct bool
- // The path from baseUrl to the standard Go repository path
- // URL structure: //api/go/
- EndpointPrefix string
-}
-
-func (gdu *GoProxyUrlParams) BuildUrl(url *url.URL, repoName string) string {
- url.Path = path.Join(url.Path, gdu.EndpointPrefix, "api/go/", repoName)
-
- return gdu.addDirect(url.String())
-}
-
-func (gdu *GoProxyUrlParams) addDirect(url string) string {
- if gdu.Direct && !strings.HasSuffix(url, "|direct") {
- return url + "|direct"
- }
- return url
-}
-
-func GetArtifactoryRemoteRepoUrl(serverDetails *config.ServerDetails, repo string, goProxyParams GoProxyUrlParams) (string, error) {
- authServerDetails, err := serverDetails.CreateArtAuthConfig()
- if err != nil {
- return "", err
- }
- return getArtifactoryApiUrl(repo, authServerDetails, goProxyParams)
-}
-
-// Gets the URL of the specified repository Go API in Artifactory.
-// The URL contains credentials (username and access token or password).
-func getArtifactoryApiUrl(repoName string, details auth.ServiceDetails, goProxyParams GoProxyUrlParams) (string, error) {
- rtUrl, err := url.Parse(details.GetUrl())
- if err != nil {
- return "", errorutils.CheckError(err)
- }
-
- username := details.GetUser()
- password := details.GetPassword()
-
- // Get credentials from access-token if exists.
- if details.GetAccessToken() != "" {
- log.Debug("Using proxy with access-token.")
- if username == "" {
- username = auth.ExtractUsernameFromAccessToken(details.GetAccessToken())
- }
- password = details.GetAccessToken()
- }
- if password != "" {
- rtUrl.User = url.UserPassword(username, password)
- }
-
- return goProxyParams.BuildUrl(rtUrl, repoName), nil
-}
-
-func GetModuleName(projectDir string) (string, error) {
- path, err := biutils.GetModuleNameByDir(projectDir, log.Logger)
- if err != nil {
- return "", errorutils.CheckError(err)
- }
- return path, nil
-}
diff --git a/artifactory/commands/golang/go_test.go b/artifactory/commands/golang/go_test.go
deleted file mode 100644
index 8fc86ad9e..000000000
--- a/artifactory/commands/golang/go_test.go
+++ /dev/null
@@ -1,167 +0,0 @@
-package golang
-
-import (
- "fmt"
- biutils "github.com/jfrog/build-info-go/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/artifactory/auth"
- testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "net/url"
- "os"
- "path/filepath"
- "strings"
- "testing"
-)
-
-func TestBuildPackageVersionRequest(t *testing.T) {
- tests := []struct {
- packageName string
- branchName string
- expectedRequest string
- }{
- {"github.com/jfrog/jfrog-cli", "", "github.com/jfrog/jfrog-cli/@v/latest.info"},
- {"github.com/jfrog/jfrog-cli", "dev", "github.com/jfrog/jfrog-cli/@v/dev.info"},
- {"github.com/jfrog/jfrog-cli", "v1.0.7", "github.com/jfrog/jfrog-cli/@v/v1.0.7.info"},
- }
- for _, test := range tests {
- t.Run(test.expectedRequest, func(t *testing.T) {
- versionRequest := buildPackageVersionRequest(test.packageName, test.branchName)
- if versionRequest != test.expectedRequest {
- t.Error("Failed to build package version request. The version request is", versionRequest, " but it is expected to be", test.expectedRequest)
- }
- })
- }
-}
-
-func TestGetPackageFilesPath(t *testing.T) {
- packageCachePath, err := biutils.GetGoModCachePath()
- assert.NoError(t, err)
- packageName := "github.com/golang/mock/mockgen"
- version := "v1.4.1"
- expectedPackagePath := filepath.Join(packageCachePath, "github.com/golang/mock@"+version)
- err = os.MkdirAll(expectedPackagePath, os.ModePerm)
- assert.NoError(t, err)
- defer testsutils.RemoveAllAndAssert(t, expectedPackagePath)
- actualPackagePath, err := getFileSystemPackagePath(packageCachePath, packageName, version)
- assert.NoError(t, err)
- assert.Equal(t, expectedPackagePath, actualPackagePath)
-}
-
-func TestSetArtifactoryAsResolutionServer(t *testing.T) {
- server := &config.ServerDetails{
- Url: "http://localhost:8080/",
- ArtifactoryUrl: "http://localhost:8080/artifactory/",
- User: "myUser",
- Password: "myPassword",
- ServerId: "myServer",
- }
- repo := "myRepo"
-
- // Setting the GOPROXY value to "" to ensure that the new value set in SetArtifactoryAsResolutionServer is correctly validated.
- cleanup := testsutils.SetEnvWithCallbackAndAssert(t, "GOPROXY", "")
- defer cleanup()
-
- assert.NoError(t, SetArtifactoryAsResolutionServer(server, repo, GoProxyUrlParams{Direct: true}))
-
- serverUrlWithoutHttp := strings.TrimPrefix(server.ArtifactoryUrl, "http://")
- expectedGoProxy := fmt.Sprintf("http://%s:%s@%sapi/go/%s|direct", server.User, server.Password, serverUrlWithoutHttp, repo)
- assert.Equal(t, expectedGoProxy, os.Getenv("GOPROXY"))
-
- // Verify that the EndpointPrefix value is correctly added to the GOPROXY.
- // In this test case, the endpoint prefix is set to api/curation/audit/.
- // This parameter allows downloading dependencies from a custom API instead of the default one.
- assert.NoError(t, SetArtifactoryAsResolutionServer(server, repo, GoProxyUrlParams{Direct: true, EndpointPrefix: coreutils.CurationPassThroughApi}))
-
- serverUrlWithoutHttp = strings.TrimPrefix(server.ArtifactoryUrl, "http://")
- expectedGoProxy = fmt.Sprintf("http://%s:%s@%sapi/curation/audit/api/go/%s|direct", server.User, server.Password, serverUrlWithoutHttp, repo)
- assert.Equal(t, expectedGoProxy, os.Getenv("GOPROXY"))
-}
-
-func TestGetArtifactoryRemoteRepoUrl(t *testing.T) {
- server := &config.ServerDetails{
- ArtifactoryUrl: "https://server.com/artifactory",
- AccessToken: "eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA",
- }
- repoName := "test-repo"
- repoUrl, err := GetArtifactoryRemoteRepoUrl(server, repoName, GoProxyUrlParams{})
- assert.NoError(t, err)
- assert.Equal(t, "https://test:eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA@server.com/artifactory/api/go/test-repo", repoUrl)
-}
-
-func TestGetArtifactoryApiUrl(t *testing.T) {
- details := auth.NewArtifactoryDetails()
- details.SetUrl("https://test.com/artifactory/")
-
- // Test username and password
- details.SetUser("frog")
- details.SetPassword("passfrog")
- url, err := getArtifactoryApiUrl("test-repo", details, GoProxyUrlParams{})
- assert.NoError(t, err)
- assert.Equal(t, "https://frog:passfrog@test.com/artifactory/api/go/test-repo", url)
-
- // Test username and password with EndpointPrefix and direct
- details.SetUser("frog")
- details.SetPassword("passfrog")
- url, err = getArtifactoryApiUrl("test-repo", details, GoProxyUrlParams{EndpointPrefix: "test", Direct: true})
- assert.NoError(t, err)
- assert.Equal(t, "https://frog:passfrog@test.com/artifactory/test/api/go/test-repo|direct", url)
-
- // Test access token
- // Set fake access token with username "test"
- details.SetUser("")
- details.SetAccessToken("eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA")
- url, err = getArtifactoryApiUrl("test-repo", details, GoProxyUrlParams{})
- assert.NoError(t, err)
- assert.Equal(t, "https://test:eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA@test.com/artifactory/api/go/test-repo", url)
-
- // Test access token with username
- // Set fake access token with username "test"
- // Expect username to be "frog"
- details.SetUser("frog")
- details.SetAccessToken("eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA")
- url, err = getArtifactoryApiUrl("test-repo", details, GoProxyUrlParams{})
- assert.NoError(t, err)
- assert.Equal(t, "https://frog:eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA@test.com/artifactory/api/go/test-repo", url)
-}
-
-func TestGoProxyUrlParams_BuildUrl(t *testing.T) {
- testCases := []struct {
- name string
- RepoName string
- Direct bool
- EndpointPrefix string
- ExpectedUrl string
- }{
- {
- name: "Url Without direct or Prefix",
- RepoName: "go",
- ExpectedUrl: "https://test/api/go/go",
- },
- {
- name: "Url With direct",
- RepoName: "go",
- Direct: true,
- ExpectedUrl: "https://test/api/go/go|direct",
- },
- {
- name: "Url With Prefix",
- RepoName: "go",
- EndpointPrefix: "prefix",
- ExpectedUrl: "https://test/prefix/api/go/go",
- },
- }
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- remoteUrl, err := url.Parse("https://test")
- require.NoError(t, err)
- gdu := &GoProxyUrlParams{
- Direct: testCase.Direct,
- EndpointPrefix: testCase.EndpointPrefix,
- }
- assert.Equalf(t, testCase.ExpectedUrl, gdu.BuildUrl(remoteUrl, testCase.RepoName), "BuildUrl(%v, %v)", remoteUrl, testCase.RepoName)
- })
- }
-}
diff --git a/artifactory/commands/golang/gopublish.go b/artifactory/commands/golang/gopublish.go
deleted file mode 100644
index 07160ee98..000000000
--- a/artifactory/commands/golang/gopublish.go
+++ /dev/null
@@ -1,171 +0,0 @@
-package golang
-
-import (
- "os/exec"
-
- "github.com/jfrog/build-info-go/build"
- commandutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
-)
-
-const minSupportedArtifactoryVersion = "6.2.0"
-
-type GoPublishCommandArgs struct {
- buildConfiguration *buildUtils.BuildConfiguration
- version string
- detailedSummary bool
- excludedPatterns []string
- result *commandutils.Result
- project.RepositoryConfig
-}
-
-type GoPublishCommand struct {
- configFilePath string
- internalCommandName string
- *GoPublishCommandArgs
-}
-
-func NewGoPublishCommand() *GoPublishCommand {
- return &GoPublishCommand{GoPublishCommandArgs: &GoPublishCommandArgs{result: new(commandutils.Result)}, internalCommandName: "rt_go_publish"}
-}
-
-func (gpc *GoPublishCommand) CommandName() string {
- return gpc.internalCommandName
-}
-
-func (gpc *GoPublishCommand) SetConfigFilePath(configFilePath string) *GoPublishCommand {
- gpc.configFilePath = configFilePath
- return gpc
-}
-
-func (gpc *GoPublishCommand) GetExcludedPatterns() []string {
- return gpc.excludedPatterns
-}
-
-func (gpc *GoPublishCommandArgs) SetExcludedPatterns(excludedPatterns []string) *GoPublishCommandArgs {
- gpc.excludedPatterns = excludedPatterns
- return gpc
-}
-
-func (gpc *GoPublishCommand) Run() error {
- err := validatePrerequisites()
- if err != nil {
- return err
- }
-
- err = logGoVersion()
- if err != nil {
- return err
- }
- // Read config file.
- vConfig, err := project.ReadConfigFile(gpc.configFilePath, project.YAML)
- if err != nil {
- return err
- }
- repoConfig, err := project.GetRepoConfigByPrefix(gpc.configFilePath, project.ProjectConfigDeployerPrefix, vConfig)
- if err != nil {
- return err
- }
- gpc.RepositoryConfig = *repoConfig
- serverDetails, err := gpc.ServerDetails()
- if errorutils.CheckError(err) != nil {
- return err
- }
- serviceManager, err := utils.CreateServiceManager(serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- artifactoryVersion, err := serviceManager.GetConfig().GetServiceDetails().GetVersion()
- if err != nil {
- return err
- }
- err = clientutils.ValidateMinimumVersion(clientutils.Artifactory, artifactoryVersion, minSupportedArtifactoryVersion)
- if err != nil {
- return err
- }
- var goBuild *build.Build
- var buildName, buildNumber, project string
- collectBuildInfo, err := gpc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
- if collectBuildInfo {
- buildName, err = gpc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err = gpc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- project = gpc.buildConfiguration.GetProject()
- buildInfoService := buildUtils.CreateBuildInfoService()
- goBuild, err = buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, project)
- if err != nil {
- return errorutils.CheckError(err)
- }
- }
-
- // Publish the package to Artifactory.
- summary, artifacts, err := publishPackage(gpc.version, gpc.TargetRepo(), buildName, buildNumber, project, gpc.GetExcludedPatterns(), serviceManager)
- if err != nil {
- return err
- }
- result := gpc.Result()
- result.SetSuccessCount(summary.TotalSucceeded)
- result.SetFailCount(summary.TotalFailed)
- if gpc.detailedSummary {
- result.SetReader(summary.TransferDetailsReader)
- }
- // Publish the build-info to Artifactory
- if collectBuildInfo {
- goModule, err := goBuild.AddGoModule("")
- if err != nil {
- return errorutils.CheckError(err)
- }
- if gpc.buildConfiguration.GetModule() != "" {
- goModule.SetName(gpc.buildConfiguration.GetModule())
- }
- err = goModule.AddArtifacts(artifacts...)
- if err != nil {
- return errorutils.CheckError(err)
- }
- }
-
- return err
-}
-
-func (gpc *GoPublishCommandArgs) Result() *commandutils.Result {
- return gpc.result
-}
-
-func (gpc *GoPublishCommandArgs) SetVersion(version string) *GoPublishCommandArgs {
- gpc.version = version
- return gpc
-}
-
-func (gpc *GoPublishCommandArgs) SetBuildConfiguration(buildConfiguration *buildUtils.BuildConfiguration) *GoPublishCommandArgs {
- gpc.buildConfiguration = buildConfiguration
- return gpc
-}
-
-func (gpc *GoPublishCommandArgs) SetDetailedSummary(detailedSummary bool) *GoPublishCommandArgs {
- gpc.detailedSummary = detailedSummary
- return gpc
-}
-
-func (gpc *GoPublishCommandArgs) IsDetailedSummary() bool {
- return gpc.detailedSummary
-}
-
-func validatePrerequisites() error {
- _, err := exec.LookPath("go")
- if err != nil {
- return errorutils.CheckError(err)
- }
- return nil
-}
diff --git a/artifactory/commands/golang/publish.go b/artifactory/commands/golang/publish.go
deleted file mode 100644
index 30e7d799a..000000000
--- a/artifactory/commands/golang/publish.go
+++ /dev/null
@@ -1,248 +0,0 @@
-package golang
-
-import (
- "archive/zip"
- "bytes"
- "encoding/json"
- "errors"
- "fmt"
- buildinfo "github.com/jfrog/build-info-go/entities"
- "github.com/jfrog/build-info-go/utils"
- "github.com/jfrog/gofrog/crypto"
- "github.com/jfrog/gofrog/version"
- "io"
- "os"
- "path"
- "path/filepath"
- "strings"
- "time"
-
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-client-go/artifactory"
- _go "github.com/jfrog/jfrog-client-go/artifactory/services/go"
- servicesutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-// Publish go project to Artifactory.
-func publishPackage(packageVersion, targetRepo, buildName, buildNumber, projectKey string, excludedPatterns []string, servicesManager artifactory.ArtifactoryServicesManager) (summary *servicesutils.OperationSummary, artifacts []buildinfo.Artifact, err error) {
- projectPath, err := getProjectRoot()
- if err != nil {
- return nil, nil, errorutils.CheckError(err)
- }
-
- // Read module name
- moduleName, err := GetModuleName(projectPath)
- if err != nil {
- return nil, nil, err
- }
-
- log.Info("Publishing", moduleName, "to", targetRepo)
- filePathInRepo := path.Join(moduleName, "@v", packageVersion)
- collectBuildInfo := len(buildName) > 0 && len(buildNumber) > 0
- modContent, modArtifact, err := readModFile(packageVersion, projectPath, targetRepo, filePathInRepo+".mod", collectBuildInfo)
- if err != nil {
- return nil, nil, err
- }
-
- props, err := build.CreateBuildProperties(buildName, buildNumber, projectKey)
- if err != nil {
- return nil, nil, err
- }
-
- // Temp directory for the project archive.
- // The directory will be deleted at the end.
- tempDirPath, err := fileutils.CreateTempDir()
- if err != nil {
- return nil, nil, err
- }
- defer func() {
- err = errors.Join(err, fileutils.RemoveTempDir(tempDirPath))
- }()
-
- var zipArtifact *buildinfo.Artifact
- params := _go.NewGoParams()
- params.Version = packageVersion
- params.Props = props
- params.TargetRepo = targetRepo
- params.ModuleId = moduleName
- params.ModContent = modContent
- params.ModPath = filepath.Join(projectPath, "go.mod")
- params.ZipPath, zipArtifact, err = archive(moduleName, packageVersion, projectPath, targetRepo, tempDirPath, excludedPatterns)
- if err != nil {
- return nil, nil, err
- }
- if collectBuildInfo {
- artifacts = []buildinfo.Artifact{*modArtifact, *zipArtifact}
- }
-
- // Create the info file if Artifactory version is 6.10.0 and above.
- artifactoryVersion, err := servicesManager.GetConfig().GetServiceDetails().GetVersion()
- if err != nil {
- return nil, nil, err
- }
- version := version.NewVersion(artifactoryVersion)
- if version.AtLeast(_go.ArtifactoryMinSupportedVersion) {
- log.Debug("Creating info file", projectPath)
- var pathToInfo string
- pathToInfo, err = createInfoFile(packageVersion)
- if err != nil {
- return nil, nil, err
- }
- defer func() {
- err = errors.Join(err, errorutils.CheckError(os.Remove(pathToInfo)))
- }()
- if collectBuildInfo {
- var infoArtifact *buildinfo.Artifact
- infoArtifact, err = createInfoFileArtifact(pathToInfo, packageVersion, targetRepo, filePathInRepo+".info")
- if err != nil {
- return nil, nil, err
- }
- artifacts = append(artifacts, *infoArtifact)
- }
- params.InfoPath = pathToInfo
- }
-
- summary, err = servicesManager.PublishGoProject(params)
- return summary, artifacts, err
-}
-
-// Creates the info file.
-// Returns the path to that file.
-func createInfoFile(packageVersion string) (path string, err error) {
- currentTime := time.Now().Format("2006-01-02T15:04:05Z")
- goInfoContent := goInfo{Version: packageVersion, Time: currentTime}
- content, err := json.Marshal(&goInfoContent)
- if err != nil {
- return "", errorutils.CheckError(err)
- }
- file, err := os.Create(packageVersion + ".info")
- if err != nil {
- return "", errorutils.CheckError(err)
- }
- defer func() {
- err = errors.Join(err, errorutils.CheckError(file.Close()))
- }()
- _, err = file.Write(content)
- if err != nil {
- return "", errorutils.CheckError(err)
- }
- path, err = filepath.Abs(file.Name())
- if err != nil {
- return "", errorutils.CheckError(err)
- }
- log.Debug("Info file was successfully created:", path)
- return path, nil
-}
-
-// Read go.mod file.
-// Pass createArtifact = true to create an Artifact for build-info.
-func readModFile(version, projectPath, deploymentRepo, relPathInRepo string, createArtifact bool) ([]byte, *buildinfo.Artifact, error) {
- modFilePath := filepath.Join(projectPath, "go.mod")
- modFileExists, _ := fileutils.IsFileExists(modFilePath, true)
- if !modFileExists {
- return nil, nil, errorutils.CheckErrorf("Could not find project's go.mod in " + projectPath)
- }
- modFile, err := os.Open(modFilePath)
- if err != nil {
- return nil, nil, err
- }
- defer func() {
- err = errors.Join(err, errorutils.CheckError(modFile.Close()))
- }()
- content, err := io.ReadAll(modFile)
- if err != nil {
- return nil, nil, errorutils.CheckError(err)
- }
-
- if !createArtifact {
- return content, nil, nil
- }
-
- checksums, err := crypto.CalcChecksums(bytes.NewBuffer(content))
- if err != nil {
- return nil, nil, errorutils.CheckError(err)
- }
-
- // Add mod file as artifact
- artifact := &buildinfo.Artifact{Name: version + ".mod", Type: "mod", OriginalDeploymentRepo: deploymentRepo, Path: relPathInRepo}
- artifact.Checksum = buildinfo.Checksum{Sha1: checksums[crypto.SHA1], Md5: checksums[crypto.MD5]}
- return content, artifact, nil
-}
-
-// Archive the go project.
-// Returns the path of the temp archived project file.
-func archive(moduleName, version, projectPath, deploymentRepo, tempDir string, excludedPatterns []string) (name string, zipArtifact *buildinfo.Artifact, err error) {
- openedFile := false
- tempFile, err := os.CreateTemp(tempDir, "project.zip")
- if err != nil {
- return "", nil, errorutils.CheckError(err)
- }
- openedFile = true
- defer func() {
- if openedFile {
- err = errors.Join(err, errorutils.CheckError(tempFile.Close()))
- }
- }()
- if err = archiveProject(tempFile, projectPath, moduleName, version, excludedPatterns); err != nil {
- return "", nil, errorutils.CheckError(err)
- }
- // Double-check that the paths within the zip file are well-formed.
- fi, err := tempFile.Stat()
- if err != nil {
- return "", nil, err
- }
- z, err := zip.NewReader(tempFile, fi.Size())
- if err != nil {
- return "", nil, err
- }
- prefix := moduleName + "@" + version + "/"
- for _, f := range z.File {
- if !strings.HasPrefix(f.Name, prefix) {
- return "", nil, fmt.Errorf("zip for %s has unexpected file %s", prefix[:len(prefix)-1], f.Name)
- }
- }
- // Sync the file before renaming it
- if err = tempFile.Sync(); err != nil {
- return "", nil, err
- }
- if err = tempFile.Close(); err != nil {
- return "", nil, err
- }
- openedFile = false
- fileDetails, err := fileutils.GetFileDetails(tempFile.Name(), true)
- if err != nil {
- return "", nil, err
- }
-
- zipArtifact = &buildinfo.Artifact{Name: version + ".zip", Type: "zip", OriginalDeploymentRepo: deploymentRepo, Path: path.Join(moduleName, "@v", version+".zip")}
- zipArtifact.Checksum = buildinfo.Checksum{Sha1: fileDetails.Checksum.Sha1, Md5: fileDetails.Checksum.Md5}
- return tempFile.Name(), zipArtifact, nil
-}
-
-// Add the info file also as an artifact to be part of the build info.
-func createInfoFileArtifact(infoFilePath, packageVersion, targetRepo, relPathInRepo string) (*buildinfo.Artifact, error) {
- fileDetails, err := fileutils.GetFileDetails(infoFilePath, true)
- if err != nil {
- return nil, err
- }
-
- artifact := &buildinfo.Artifact{Name: packageVersion + ".info", Type: "info", OriginalDeploymentRepo: targetRepo, Path: relPathInRepo}
- artifact.Checksum = buildinfo.Checksum{Sha1: fileDetails.Checksum.Sha1, Md5: fileDetails.Checksum.Md5}
- return artifact, nil
-}
-
-type goInfo struct {
- Version string `json:"Version"`
- Time string `json:"Time"`
-}
-
-func getProjectRoot() (string, error) {
- path, err := utils.GetProjectRoot()
- if err != nil {
- return "", errorutils.CheckError(err)
- }
- return path, nil
-}
diff --git a/artifactory/commands/golang/testdata/.gitignore b/artifactory/commands/golang/testdata/.gitignore
deleted file mode 100644
index ba7ea82da..000000000
--- a/artifactory/commands/golang/testdata/.gitignore
+++ /dev/null
@@ -1,12 +0,0 @@
-# Binaries for programs and plugins
-*.exe
-*.exe~
-*.dll
-*.so
-*.dylib
-
-# Test binary, build with `go test -c`
-*.test
-
-# Output of the go coverage tool, specifically when used with LiteIDE
-*.out
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/a.txt b/artifactory/commands/golang/testdata/a.txt
deleted file mode 100644
index 8d14cbf98..000000000
--- a/artifactory/commands/golang/testdata/a.txt
+++ /dev/null
@@ -1 +0,0 @@
-a.txt
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/dir1/b.txt b/artifactory/commands/golang/testdata/dir1/b.txt
deleted file mode 100644
index 19acdd81a..000000000
--- a/artifactory/commands/golang/testdata/dir1/b.txt
+++ /dev/null
@@ -1 +0,0 @@
-b.txt
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/dir2/dir2.text b/artifactory/commands/golang/testdata/dir2/dir2.text
deleted file mode 100644
index bf245aeae..000000000
--- a/artifactory/commands/golang/testdata/dir2/dir2.text
+++ /dev/null
@@ -1 +0,0 @@
-dir2.text
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/dir3/c.txt b/artifactory/commands/golang/testdata/dir3/c.txt
deleted file mode 100644
index f632129c1..000000000
--- a/artifactory/commands/golang/testdata/dir3/c.txt
+++ /dev/null
@@ -1 +0,0 @@
-c.txt
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/dir3/dir4/dir4.txt b/artifactory/commands/golang/testdata/dir3/dir4/dir4.txt
deleted file mode 100644
index 1c563de15..000000000
--- a/artifactory/commands/golang/testdata/dir3/dir4/dir4.txt
+++ /dev/null
@@ -1 +0,0 @@
-dir4.txt
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/test-go-publish-git-ignore.dll b/artifactory/commands/golang/testdata/test-go-publish-git-ignore.dll
deleted file mode 100644
index 69c0a0fe4..000000000
--- a/artifactory/commands/golang/testdata/test-go-publish-git-ignore.dll
+++ /dev/null
@@ -1 +0,0 @@
-test-go-publish-git-ignore
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/test_.git_suffix/HEAD b/artifactory/commands/golang/testdata/test_.git_suffix/HEAD
deleted file mode 100644
index 70b2b25d7..000000000
--- a/artifactory/commands/golang/testdata/test_.git_suffix/HEAD
+++ /dev/null
@@ -1 +0,0 @@
-rev-info
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/test_.git_suffix/config b/artifactory/commands/golang/testdata/test_.git_suffix/config
deleted file mode 100644
index 41bf331cf..000000000
--- a/artifactory/commands/golang/testdata/test_.git_suffix/config
+++ /dev/null
@@ -1,2 +0,0 @@
-[remote "origin"]
-url = https://github.com/JFrogDev/jfrog-cli-go.git
\ No newline at end of file
diff --git a/artifactory/commands/golang/testdata/zip/download/rsc/quote/@v/v1.5.3.zip b/artifactory/commands/golang/testdata/zip/download/rsc/quote/@v/v1.5.3.zip
deleted file mode 100644
index b05347bda..000000000
Binary files a/artifactory/commands/golang/testdata/zip/download/rsc/quote/@v/v1.5.3.zip and /dev/null differ
diff --git a/artifactory/commands/golang/testdata/zip/rsc.io/quote/@v/v1.5.2.zip b/artifactory/commands/golang/testdata/zip/rsc.io/quote/@v/v1.5.2.zip
deleted file mode 100644
index 978bceb1e..000000000
Binary files a/artifactory/commands/golang/testdata/zip/rsc.io/quote/@v/v1.5.2.zip and /dev/null differ
diff --git a/artifactory/commands/golang/testdata/zip/v1.2.3.zip b/artifactory/commands/golang/testdata/zip/v1.2.3.zip
deleted file mode 100644
index def5f4eec..000000000
Binary files a/artifactory/commands/golang/testdata/zip/v1.2.3.zip and /dev/null differ
diff --git a/artifactory/commands/gradle/gradle.go b/artifactory/commands/gradle/gradle.go
deleted file mode 100644
index 042214b79..000000000
--- a/artifactory/commands/gradle/gradle.go
+++ /dev/null
@@ -1,301 +0,0 @@
-package gradle
-
-import (
- "fmt"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic"
- commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/format"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/dependencies"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/spf13/viper"
- "path/filepath"
-)
-
-const (
- usePlugin = "useplugin"
- useWrapper = "usewrapper"
-)
-
-type GradleCommand struct {
- tasks []string
- configPath string
- configuration *build.BuildConfiguration
- serverDetails *config.ServerDetails
- threads int
- detailedSummary bool
- xrayScan bool
- scanOutputFormat format.OutputFormat
- result *commandsutils.Result
- deploymentDisabled bool
- // File path for Gradle extractor in which all build's artifacts details will be listed at the end of the build.
- buildArtifactsDetailsFile string
-}
-
-func NewGradleCommand() *GradleCommand {
- return &GradleCommand{}
-}
-
-// Returns the ServerDetails. The information returns from the config file provided.
-func (gc *GradleCommand) ServerDetails() (*config.ServerDetails, error) {
- // Get the serverDetails from the config file.
- var err error
- if gc.serverDetails == nil {
- vConfig, err := project.ReadConfigFile(gc.configPath, project.YAML)
- if err != nil {
- return nil, err
- }
- gc.serverDetails, err = build.GetServerDetails(vConfig)
- if err != nil {
- return nil, err
- }
- }
- return gc.serverDetails, err
-}
-
-func (gc *GradleCommand) SetServerDetails(serverDetails *config.ServerDetails) *GradleCommand {
- gc.serverDetails = serverDetails
- return gc
-}
-
-func (gc *GradleCommand) init() (vConfig *viper.Viper, err error) {
- // Read config
- vConfig, err = project.ReadConfigFile(gc.configPath, project.YAML)
- if err != nil {
- return
- }
- if gc.IsXrayScan() && !vConfig.IsSet("deployer") {
- err = errorutils.CheckErrorf("Conditional upload can only be performed if deployer is set in the config")
- return
- }
- // Gradle extractor is needed to run, in order to get the details of the build's artifacts.
- // Gradle's extractor deploy build artifacts. This should be disabled since there is no intent to deploy anything or deploy upon Xray scan results.
- gc.deploymentDisabled = gc.IsXrayScan() || !vConfig.IsSet("deployer")
- if gc.shouldCreateBuildArtifactsFile() {
- // Created a file that will contain all the details about the build's artifacts
- tempFile, err := fileutils.CreateTempFile()
- if err != nil {
- return nil, err
- }
- // If this is a Windows machine there is a need to modify the path for the build info file to match Java syntax with double \\
- gc.buildArtifactsDetailsFile = ioutils.DoubleWinPathSeparator(tempFile.Name())
- if err = tempFile.Close(); errorutils.CheckError(err) != nil {
- return nil, err
- }
- }
- return
-}
-
-// Gradle extractor generates the details of the build's artifacts.
-// This is required for Xray scan and for the detailed summary.
-// We can either scan or print the generated artifacts.
-func (gc *GradleCommand) shouldCreateBuildArtifactsFile() bool {
- return (gc.IsDetailedSummary() && !gc.deploymentDisabled) || gc.IsXrayScan()
-}
-
-func (gc *GradleCommand) Run() error {
- vConfig, err := gc.init()
- if err != nil {
- return err
- }
- err = runGradle(vConfig, gc.tasks, gc.buildArtifactsDetailsFile, gc.configuration, gc.threads, gc.IsXrayScan())
- if err != nil {
- return err
- }
- if gc.buildArtifactsDetailsFile != "" {
- err = gc.unmarshalDeployableArtifacts(gc.buildArtifactsDetailsFile)
- if err != nil {
- return err
- }
- if gc.IsXrayScan() {
- return gc.conditionalUpload()
- }
- }
- return nil
-}
-
-func (gc *GradleCommand) unmarshalDeployableArtifacts(filesPath string) error {
- result, err := commandsutils.UnmarshalDeployableArtifacts(filesPath, gc.configPath, gc.IsXrayScan())
- if err != nil {
- return err
- }
- gc.setResult(result)
- return nil
-}
-
-// ConditionalUpload will scan the artifact using Xray and will upload them only if the scan passes with no
-// violation.
-func (gc *GradleCommand) conditionalUpload() error {
- // Initialize the server details (from config) if it hasn't been initialized yet.
- _, err := gc.ServerDetails()
- if err != nil {
- return err
- }
- binariesSpecFile, pomSpecFile, err := commandsutils.ScanDeployableArtifacts(gc.result, gc.serverDetails, gc.threads, gc.scanOutputFormat)
- // If the detailed summary wasn't requested, the reader should be closed here.
- // (otherwise it will be closed by the detailed summary print method)
- if !gc.detailedSummary {
- e := gc.result.Reader().Close()
- if e != nil {
- return e
- }
- } else {
- gc.result.Reader().Reset()
- }
- if err != nil {
- return err
- }
- // The case scan failed
- if binariesSpecFile == nil {
- return nil
- }
- // First upload binaries
- if len(binariesSpecFile.Files) > 0 {
- uploadCmd := generic.NewUploadCommand()
- uploadConfiguration := new(utils.UploadConfiguration)
- uploadConfiguration.Threads = gc.threads
- uploadCmd.SetUploadConfiguration(uploadConfiguration).SetBuildConfiguration(gc.configuration).SetSpec(binariesSpecFile).SetServerDetails(gc.serverDetails)
- err = uploadCmd.Run()
- if err != nil {
- return err
- }
- }
- if len(pomSpecFile.Files) > 0 {
- // Then Upload pom.xml's
- uploadCmd := generic.NewUploadCommand()
- uploadCmd.SetBuildConfiguration(gc.configuration).SetSpec(pomSpecFile).SetServerDetails(gc.serverDetails)
- err = uploadCmd.Run()
- }
- return err
-}
-
-func (gc *GradleCommand) CommandName() string {
- return "rt_gradle"
-}
-
-func (gc *GradleCommand) SetConfiguration(configuration *build.BuildConfiguration) *GradleCommand {
- gc.configuration = configuration
- return gc
-}
-
-func (gc *GradleCommand) SetConfigPath(configPath string) *GradleCommand {
- gc.configPath = configPath
- return gc
-}
-
-func (gc *GradleCommand) SetTasks(tasks []string) *GradleCommand {
- gc.tasks = tasks
- return gc
-}
-
-func (gc *GradleCommand) SetThreads(threads int) *GradleCommand {
- gc.threads = threads
- return gc
-}
-
-func (gc *GradleCommand) SetDetailedSummary(detailedSummary bool) *GradleCommand {
- gc.detailedSummary = detailedSummary
- return gc
-}
-
-func (gc *GradleCommand) IsDetailedSummary() bool {
- return gc.detailedSummary
-}
-
-func (gc *GradleCommand) SetXrayScan(xrayScan bool) *GradleCommand {
- gc.xrayScan = xrayScan
- return gc
-}
-
-func (gc *GradleCommand) IsXrayScan() bool {
- return gc.xrayScan
-}
-
-func (gc *GradleCommand) SetScanOutputFormat(format format.OutputFormat) *GradleCommand {
- gc.scanOutputFormat = format
- return gc
-}
-
-func (gc *GradleCommand) Result() *commandsutils.Result {
- return gc.result
-}
-
-func (gc *GradleCommand) setResult(result *commandsutils.Result) *GradleCommand {
- gc.result = result
- return gc
-}
-
-func runGradle(vConfig *viper.Viper, tasks []string, deployableArtifactsFile string, configuration *build.BuildConfiguration, threads int, disableDeploy bool) error {
- buildInfoService := build.CreateBuildInfoService()
- buildName, err := configuration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := configuration.GetBuildNumber()
- if err != nil {
- return err
- }
- gradleBuild, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, configuration.GetProject())
- if err != nil {
- return errorutils.CheckError(err)
- }
- gradleModule, err := gradleBuild.AddGradleModule("")
- if err != nil {
- return errorutils.CheckError(err)
- }
- props, wrapper, plugin, err := createGradleRunConfig(vConfig, deployableArtifactsFile, threads, disableDeploy)
- if err != nil {
- return err
- }
- dependencyLocalPath, err := getGradleDependencyLocalPath()
- if err != nil {
- return err
- }
- gradleModule.SetExtractorDetails(dependencyLocalPath, filepath.Join(coreutils.GetCliPersistentTempDirPath(), build.PropertiesTempPath), tasks, wrapper, plugin, dependencies.DownloadExtractor, props)
- return coreutils.ConvertExitCodeError(gradleModule.CalcDependencies())
-}
-
-func getGradleDependencyLocalPath() (string, error) {
- dependenciesPath, err := config.GetJfrogDependenciesPath()
- if err != nil {
- return "", err
- }
- return filepath.Join(dependenciesPath, "gradle"), nil
-}
-
-func createGradleRunConfig(vConfig *viper.Viper, deployableArtifactsFile string, threads int, disableDeploy bool) (props map[string]string, wrapper, plugin bool, err error) {
- wrapper = vConfig.GetBool(useWrapper)
- if threads > 0 {
- vConfig.Set(build.ForkCount, threads)
- }
-
- if disableDeploy {
- setDeployFalse(vConfig)
- }
- props, err = build.CreateBuildInfoProps(deployableArtifactsFile, vConfig, project.Gradle)
- if err != nil {
- return
- }
- if deployableArtifactsFile != "" {
- // Save the path to a temp file, where buildinfo project will write the deployable artifacts details.
- props[build.DeployableArtifacts] = fmt.Sprint(vConfig.Get(build.DeployableArtifacts))
- }
- plugin = vConfig.GetBool(usePlugin)
- return
-}
-
-func setDeployFalse(vConfig *viper.Viper) {
- vConfig.Set(build.DeployerPrefix+build.DeployArtifacts, "false")
- if vConfig.GetString(build.DeployerPrefix+build.Url) == "" {
- vConfig.Set(build.DeployerPrefix+build.Url, "http://empty_url")
- }
- if vConfig.GetString(build.DeployerPrefix+build.Repo) == "" {
- vConfig.Set(build.DeployerPrefix+build.Repo, "empty_repo")
- }
-}
diff --git a/artifactory/commands/mvn/mvn.go b/artifactory/commands/mvn/mvn.go
deleted file mode 100644
index 62d2ebbe3..000000000
--- a/artifactory/commands/mvn/mvn.go
+++ /dev/null
@@ -1,307 +0,0 @@
-package mvn
-
-import (
- "encoding/json"
- "github.com/jfrog/build-info-go/entities"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/generic"
- commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/format"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/spf13/viper"
- "os"
- "strings"
-)
-
-type MvnCommand struct {
- goals []string
- configPath string
- insecureTls bool
- configuration *build.BuildConfiguration
- serverDetails *config.ServerDetails
- threads int
- detailedSummary bool
- xrayScan bool
- scanOutputFormat format.OutputFormat
- result *commandsutils.Result
- deploymentDisabled bool
- // File path for Maven extractor in which all build's artifacts details will be listed at the end of the build.
- buildArtifactsDetailsFile string
-}
-
-func NewMvnCommand() *MvnCommand {
- return &MvnCommand{}
-}
-
-func (mc *MvnCommand) SetServerDetails(serverDetails *config.ServerDetails) *MvnCommand {
- mc.serverDetails = serverDetails
- return mc
-}
-
-func (mc *MvnCommand) SetConfiguration(configuration *build.BuildConfiguration) *MvnCommand {
- mc.configuration = configuration
- return mc
-}
-
-func (mc *MvnCommand) SetConfigPath(configPath string) *MvnCommand {
- mc.configPath = configPath
- return mc
-}
-
-func (mc *MvnCommand) SetGoals(goals []string) *MvnCommand {
- mc.goals = goals
- return mc
-}
-
-func (mc *MvnCommand) SetThreads(threads int) *MvnCommand {
- mc.threads = threads
- return mc
-}
-
-func (mc *MvnCommand) SetInsecureTls(insecureTls bool) *MvnCommand {
- mc.insecureTls = insecureTls
- return mc
-}
-
-func (mc *MvnCommand) SetDetailedSummary(detailedSummary bool) *MvnCommand {
- mc.detailedSummary = detailedSummary
- return mc
-}
-
-func (mc *MvnCommand) IsDetailedSummary() bool {
- return mc.detailedSummary
-}
-
-func (mc *MvnCommand) SetXrayScan(xrayScan bool) *MvnCommand {
- mc.xrayScan = xrayScan
- return mc
-}
-
-func (mc *MvnCommand) IsXrayScan() bool {
- return mc.xrayScan
-}
-
-func (mc *MvnCommand) SetScanOutputFormat(format format.OutputFormat) *MvnCommand {
- mc.scanOutputFormat = format
- return mc
-}
-
-func (mc *MvnCommand) Result() *commandsutils.Result {
- return mc.result
-}
-
-func (mc *MvnCommand) setResult(result *commandsutils.Result) *MvnCommand {
- mc.result = result
- return mc
-}
-
-func (mc *MvnCommand) init() (vConfig *viper.Viper, err error) {
- // Read config
- vConfig, err = build.ReadMavenConfig(mc.configPath, nil)
- if err != nil {
- return
- }
- if mc.IsXrayScan() && !vConfig.IsSet("deployer") {
- err = errorutils.CheckErrorf("Conditional upload can only be performed if deployer is set in the config")
- return
- }
- // Maven's extractor deploys build artifacts. This should be disabled since there is no intent to deploy anything or deploy upon Xray scan results.
- mc.deploymentDisabled = mc.IsXrayScan() || !vConfig.IsSet("deployer")
- if mc.shouldCreateBuildArtifactsFile() {
- // Created a file that will contain all the details about the build's artifacts
- tempFile, err := fileutils.CreateTempFile()
- if err != nil {
- return nil, err
- }
- // If this is a Windows machine there is a need to modify the path for the build info file to match Java syntax with double \\
- mc.buildArtifactsDetailsFile = ioutils.DoubleWinPathSeparator(tempFile.Name())
- if err = tempFile.Close(); errorutils.CheckError(err) != nil {
- return nil, err
- }
- }
- return
-}
-
-// Maven extractor generates the details of the build's artifacts.
-// This is required for Xray scan and for the detailed summary.
-// We can either scan or print the generated artifacts.
-func (mc *MvnCommand) shouldCreateBuildArtifactsFile() bool {
- return (mc.IsDetailedSummary() && !mc.deploymentDisabled) || mc.IsXrayScan()
-}
-
-func (mc *MvnCommand) Run() error {
- vConfig, err := mc.init()
- if err != nil {
- return err
- }
-
- mvnParams := NewMvnUtils().
- SetConfig(vConfig).
- SetBuildArtifactsDetailsFile(mc.buildArtifactsDetailsFile).
- SetBuildConf(mc.configuration).
- SetGoals(mc.goals).
- SetInsecureTls(mc.insecureTls).
- SetDisableDeploy(mc.deploymentDisabled).
- SetThreads(mc.threads)
- if err = RunMvn(mvnParams); err != nil {
- return err
- }
-
- if mc.configuration != nil {
- isCollectedBuildInfo, err := mc.configuration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
- if isCollectedBuildInfo {
- if err = mc.updateBuildInfoArtifactsWithDeploymentRepo(vConfig, mvnParams.GetBuildInfoFilePath()); err != nil {
- return err
- }
- }
- }
-
- if mc.buildArtifactsDetailsFile == "" {
- return nil
- }
-
- if err = mc.unmarshalDeployableArtifacts(mc.buildArtifactsDetailsFile); err != nil {
- return err
- }
- if mc.IsXrayScan() {
- return mc.conditionalUpload()
- }
- return nil
-}
-
-// Returns the ServerDetails. The information returns from the config file provided.
-func (mc *MvnCommand) ServerDetails() (*config.ServerDetails, error) {
- // Get the serverDetails from the config file.
- if mc.serverDetails == nil {
- vConfig, err := project.ReadConfigFile(mc.configPath, project.YAML)
- if err != nil {
- return nil, err
- }
- mc.serverDetails, err = build.GetServerDetails(vConfig)
- if err != nil {
- return nil, err
- }
- }
- return mc.serverDetails, nil
-}
-
-func (mc *MvnCommand) unmarshalDeployableArtifacts(filesPath string) error {
- result, err := commandsutils.UnmarshalDeployableArtifacts(filesPath, mc.configPath, mc.IsXrayScan())
- if err != nil {
- return err
- }
- mc.setResult(result)
- return nil
-}
-
-func (mc *MvnCommand) CommandName() string {
- return "rt_maven"
-}
-
-// ConditionalUpload will scan the artifact using Xray and will upload them only if the scan passes with no
-// violation.
-func (mc *MvnCommand) conditionalUpload() error {
- // Initialize the server details (from config) if it hasn't been initialized yet.
- _, err := mc.ServerDetails()
- if err != nil {
- return err
- }
- binariesSpecFile, pomSpecFile, err := commandsutils.ScanDeployableArtifacts(mc.result, mc.serverDetails, mc.threads, mc.scanOutputFormat)
- // If the detailed summary wasn't requested, the reader should be closed here.
- // (otherwise it will be closed by the detailed summary print method)
- if !mc.IsDetailedSummary() {
- e := mc.result.Reader().Close()
- if e != nil {
- return e
- }
- } else {
- mc.result.Reader().Reset()
- }
- if err != nil {
- return err
- }
- // The case scan failed
- if binariesSpecFile == nil {
- return nil
- }
- // First upload binaries
- if len(binariesSpecFile.Files) > 0 {
- uploadCmd := generic.NewUploadCommand()
- uploadConfiguration := new(utils.UploadConfiguration)
- uploadConfiguration.Threads = mc.threads
- uploadCmd.SetUploadConfiguration(uploadConfiguration).SetBuildConfiguration(mc.configuration).SetSpec(binariesSpecFile).SetServerDetails(mc.serverDetails)
- err = uploadCmd.Run()
- if err != nil {
- return err
- }
- }
- if len(pomSpecFile.Files) > 0 {
- // Then Upload pom.xml's
- uploadCmd := generic.NewUploadCommand()
- uploadConfiguration := new(utils.UploadConfiguration)
- uploadConfiguration.Threads = mc.threads
- uploadCmd.SetUploadConfiguration(uploadConfiguration).SetBuildConfiguration(mc.configuration).SetSpec(pomSpecFile).SetServerDetails(mc.serverDetails)
- err = uploadCmd.Run()
- }
- return err
-}
-
-// updateBuildInfoArtifactsWithDeploymentRepo updates existing build-info temp file with the target repository for each artifact
-func (mc *MvnCommand) updateBuildInfoArtifactsWithDeploymentRepo(vConfig *viper.Viper, buildInfoFilePath string) error {
- exists, err := fileutils.IsFileExists(buildInfoFilePath, false)
- if err != nil || !exists {
- return err
- }
- content, err := os.ReadFile(buildInfoFilePath)
- if err != nil {
- return errorutils.CheckErrorf("failed to read build info file: %s", err.Error())
- }
- // In some scenarios, the build info details are set but no content is generated.
- // For example, running a `jf mvn ` from the Setup JFrog Cli GitHub Action
- // automatically fills the build info details, but the command itself may not generate any content.
- // Examples include `mvn -v`, `mvn test`, etc.
- if len(content) == 0 {
- return nil
- }
- buildInfo := new(entities.BuildInfo)
- if err = json.Unmarshal(content, &buildInfo); err != nil {
- return errorutils.CheckErrorf("failed to parse build info file: %s", err.Error())
- }
-
- if vConfig.IsSet(project.ProjectConfigDeployerPrefix) {
- snapshotRepository := vConfig.GetString(build.DeployerPrefix + build.SnapshotRepo)
- releaseRepository := vConfig.GetString(build.DeployerPrefix + build.ReleaseRepo)
- for moduleIndex := range buildInfo.Modules {
- currModule := &buildInfo.Modules[moduleIndex]
- for artifactIndex := range currModule.Artifacts {
- updateArtifactRepo(&currModule.Artifacts[artifactIndex], snapshotRepository, releaseRepository)
- }
- for artifactIndex := range currModule.ExcludedArtifacts {
- updateArtifactRepo(&currModule.ExcludedArtifacts[artifactIndex], snapshotRepository, releaseRepository)
- }
- }
- }
-
- newBuildInfo, err := json.Marshal(buildInfo)
- if err != nil {
- return errorutils.CheckErrorf("failed to marshal build info: %s", err.Error())
- }
-
- return os.WriteFile(buildInfoFilePath, newBuildInfo, 0644)
-}
-
-func updateArtifactRepo(artifact *entities.Artifact, snapshotRepo, releaseRepo string) {
- if snapshotRepo != "" && strings.Contains(artifact.Path, "-SNAPSHOT") {
- artifact.OriginalDeploymentRepo = snapshotRepo
- } else {
- artifact.OriginalDeploymentRepo = releaseRepo
- }
-}
diff --git a/artifactory/commands/mvn/mvn_test.go b/artifactory/commands/mvn/mvn_test.go
deleted file mode 100644
index a2edff830..000000000
--- a/artifactory/commands/mvn/mvn_test.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package mvn
-
-import (
- "encoding/json"
- "github.com/jfrog/build-info-go/entities"
- "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "os"
- "path/filepath"
- "testing"
-
- "github.com/spf13/viper"
- "github.com/stretchr/testify/assert"
-)
-
-func TestUpdateBuildInfoArtifactsWithTargetRepo(t *testing.T) {
- vConfig := viper.New()
- vConfig.Set(build.DeployerPrefix+build.SnapshotRepo, "snapshots")
- vConfig.Set(build.DeployerPrefix+build.ReleaseRepo, "releases")
-
- tempDir := t.TempDir()
- assert.NoError(t, io.CopyDir(filepath.Join("testdata", "buildinfo_files"), tempDir, true, nil))
-
- buildName := "buildName"
- buildNumber := "1"
- mc := MvnCommand{
- configuration: build.NewBuildConfiguration(buildName, buildNumber, "", ""),
- }
-
- buildInfoFilePath := filepath.Join(tempDir, "buildinfo1")
-
- err := mc.updateBuildInfoArtifactsWithDeploymentRepo(vConfig, buildInfoFilePath)
- assert.NoError(t, err)
-
- buildInfoContent, err := os.ReadFile(buildInfoFilePath)
- assert.NoError(t, err)
-
- var buildInfo entities.BuildInfo
- assert.NoError(t, json.Unmarshal(buildInfoContent, &buildInfo))
-
- assert.Len(t, buildInfo.Modules, 2)
- modules := buildInfo.Modules
-
- firstModule := modules[0]
- assert.Len(t, firstModule.Artifacts, 0)
- excludedArtifacts := firstModule.ExcludedArtifacts
- assert.Len(t, excludedArtifacts, 2)
- assert.Equal(t, "snapshots", excludedArtifacts[0].OriginalDeploymentRepo)
- assert.Equal(t, "snapshots", excludedArtifacts[1].OriginalDeploymentRepo)
-
- secondModule := modules[1]
- assert.Len(t, secondModule.ExcludedArtifacts, 0)
- artifacts := secondModule.Artifacts
- assert.Len(t, artifacts, 2)
- assert.Equal(t, "releases", artifacts[0].OriginalDeploymentRepo)
- assert.Equal(t, "releases", artifacts[1].OriginalDeploymentRepo)
-}
diff --git a/artifactory/commands/mvn/testdata/buildinfo_files/buildinfo1 b/artifactory/commands/mvn/testdata/buildinfo_files/buildinfo1
deleted file mode 100644
index 910b71012..000000000
--- a/artifactory/commands/mvn/testdata/buildinfo_files/buildinfo1
+++ /dev/null
@@ -1,174 +0,0 @@
-{
- "version" : "1.0.1",
- "name" : "cli-maven-build-1721887447",
- "number" : "123",
- "buildAgent" : {
- "name" : "Maven",
- "version" : "3.9.6"
- },
- "agent" : {
- "name" : "/",
- "version" : "3.9.6"
- },
- "started" : "2024-07-25T09:04:12.957698+03:00",
- "durationMillis" : 157391,
- "vcs" : [ ],
- "modules" : [ {
- "properties" : {
- "maven.compiler.target" : "1.8",
- "maven.compiler.source" : "1.8",
- "project.build.sourceEncoding" : "UTF-8",
- "daversion" : "3.7-SNAPSHOT"
- },
- "type" : "maven",
- "id" : "org.jfrog.test:multi2:3.7-SNAPSHOT",
- "repository" : "snapshots",
- "excludedArtifacts" : [ {
- "type" : "jar",
- "name" : "multi2-3.7-SNAPSHOT.jar",
- "path" : "org/jfrog/test/multi2/3.7-SNAPSHOT"
- }, {
- "type" : "pom",
- "name" : "multi2-3.7-SNAPSHOT.pom",
- "path" : "org/jfrog/test/multi2/3.7-SNAPSHOT"
- } ],
- "dependencies" : [ {
- "type" : "jar",
- "sha1" : "99129f16442844f6a4a11ae22fbbee40b14d774f",
- "sha256" : "b58e459509e190bed737f3592bc1950485322846cf10e78ded1d065153012d70",
- "md5" : "1f40fb782a4f2cf78f161d32670f7a3a",
- "id" : "junit:junit:3.8.1",
- "scopes" : [ "test" ],
- "requestedBy" : [ [ "org.jfrog.test:multi2:3.7-SNAPSHOT" ] ]
- } ]
- }, {
- "properties" : {
- "maven.compiler.target" : "1.8",
- "maven.compiler.source" : "1.8",
- "project.build.sourceEncoding" : "UTF-8"
- },
- "type" : "maven",
- "id" : "org.jfrog.test:multi1:3.7-SNAPSHOT",
- "repository" : "releases",
- "artifacts" : [ {
- "type" : "test-jar",
- "sha1" : "bb4ea0797dd6d3ca0a79872ceb748aa86ad6d21c",
- "sha256" : "028ea2c1a08738e69d5b1900bcbbf47dfd5b3a6b10bb017dec11cf476efbe29e",
- "md5" : "7d8221c0c7a6993f3a71edf7417c3d69",
- "name" : "multi1-3.7-tests.jar",
- "path" : "org/jfrog/test/multi1/3.7/multi1-3.7-tests.jar"
- }, {
- "type" : "pom",
- "sha1" : "bf793dfd54eb7d21332cc0f546572ce1a8c0abdb",
- "sha256" : "c07a3407dddb58a2daa42b2b117814d5545bcfece45c0cfffb21216eea072722",
- "md5" : "40cceb21b38d85a34972835e2ee8e0d6",
- "name" : "multi1-3.7.pom",
- "path" : "org/jfrog/test/multi1/3.7/multi1-3.7.pom"
- } ],
- "dependencies" : [ {
- "type" : "jar",
- "sha1" : "449ea46b27426eb846611a90b2fb8b4dcf271191",
- "sha256" : "d33246bb33527685d04f23536ebf91b06ad7fa8b371fcbeb12f01523eb610104",
- "md5" : "25c0752852205167af8f31a1eb019975",
- "id" : "org.springframework:spring-beans:2.5.6",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.springframework:spring-aop:2.5.6", "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "5043bfebc3db072ed80fbd362e7caf00e885d8ae",
- "sha256" : "ce6f913cad1f0db3aad70186d65c5bc7ffcc9a99e3fe8e0b137312819f7c362f",
- "md5" : "ed448347fc0104034aa14c8189bf37de",
- "id" : "commons-logging:commons-logging:1.1.1",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.springframework:spring-aop:2.5.6", "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "a8762d07e76cfde2395257a5da47ba7c1dbd3dce",
- "sha256" : "a7f713593007813bf07d19bd1df9f81c86c0719e9a0bb2ef1b98b78313fc940d",
- "md5" : "b6a50c8a15ece8753e37cbe5700bf84f",
- "id" : "commons-io:commons-io:1.4",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "0235ba8b489512805ac13a8f9ea77a1ca5ebe3e8",
- "sha256" : "0addec670fedcd3f113c5c8091d783280d23f75e3acb841b61a9cdb079376a08",
- "md5" : "04177054e180d09e3998808efa0401c7",
- "id" : "aopalliance:aopalliance:1.0",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.springframework:spring-aop:2.5.6", "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "63f943103f250ef1f3a4d5e94d145a0f961f5316",
- "sha256" : "545f4e7dc678ffb4cf8bd0fd40b4a4470a409a787c0ea7d0ad2f08d56112987b",
- "md5" : "b8a34113a3a1ce29c8c60d7141f5a704",
- "id" : "javax.servlet.jsp:jsp-api:2.1",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "a05c4de7bf2e0579ac0f21e16f3737ec6fa0ff98",
- "sha256" : "78da962833d83a9df219d07b6c8c60115a0146a7314f8e44df3efdcf15792eaa",
- "md5" : "5d6576b5b572c6d644af2924da9a1952",
- "id" : "org.apache.commons:commons-email:1.1",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jdk15-jar",
- "sha1" : "9b8614979f3d093683d8249f61a9b6a29bc61d3d",
- "sha256" : "13e43a36008719957314bc9bfa2380e7a5881ccd364003687275b782ca4c62a6",
- "md5" : "52537a8a5231ca74518aec08434df7eb",
- "id" : "org.testng:testng:5.9",
- "scopes" : [ "test" ],
- "requestedBy" : [ [ "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "99129f16442844f6a4a11ae22fbbee40b14d774f",
- "sha256" : "b58e459509e190bed737f3592bc1950485322846cf10e78ded1d065153012d70",
- "md5" : "1f40fb782a4f2cf78f161d32670f7a3a",
- "id" : "junit:junit:3.8.1",
- "scopes" : [ "test" ],
- "requestedBy" : [ [ "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "e6cb541461c2834bdea3eb920f1884d1eb508b50",
- "sha256" : "2881c79c9d6ef01c58e62beea13e9d1ac8b8baa16f2fc198ad6e6776defdcdd3",
- "md5" : "8ae38e87cd4f86059c0294a8fe3e0b18",
- "id" : "javax.activation:activation:1.1",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.apache.commons:commons-email:1.1", "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "342d1eb41a2bc7b52fa2e54e9872463fc86e2650",
- "sha256" : "72582f8ba285601fa753ceeda73ff3cbd94c6e78f52ec611621eaa0186165452",
- "md5" : "2a666534a425add50d017d4aa06a6fca",
- "id" : "org.codehaus.plexus:plexus-utils:1.5.1",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "7d04f648dd88a2173ee7ff7bcb337a080ee5bea1",
- "sha256" : "32dff5cc773ebf023e2fcd1e96313360ec92362a93f74e7370d7dfda75bbe004",
- "md5" : "036c65b02a789306fbadd3c330f1e055",
- "id" : "org.springframework:spring-aop:2.5.6",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "1aa1579ae5ecd41920c4f355b0a9ef40b68315dd",
- "sha256" : "96868f82264ebd9b7d41f04d78cbe87ab75d68a7bbf8edfb82416aabe9b54b6c",
- "md5" : "2e64a3805d543bdb86e6e5eeca5529f8",
- "id" : "javax.mail:mail:1.4",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.apache.commons:commons-email:1.1", "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- }, {
- "type" : "jar",
- "sha1" : "c450bc49099430e13d21548d1e3d1a564b7e35e9",
- "sha256" : "cf37656069488043c47f49a5520bb06d6879b63ef6044abb200c51a7ff2d6c49",
- "md5" : "378db2cc1fbdd9ed05dff2dc1023963e",
- "id" : "org.springframework:spring-core:2.5.6",
- "scopes" : [ "compile" ],
- "requestedBy" : [ [ "org.springframework:spring-aop:2.5.6", "org.jfrog.test:multi1:3.7-SNAPSHOT" ] ]
- } ]
- } ]
-}
\ No newline at end of file
diff --git a/artifactory/commands/mvn/utils.go b/artifactory/commands/mvn/utils.go
deleted file mode 100644
index 96749e696..000000000
--- a/artifactory/commands/mvn/utils.go
+++ /dev/null
@@ -1,177 +0,0 @@
-package mvn
-
-import (
- "io"
- "os"
- "path/filepath"
- "strings"
-
- "github.com/jfrog/build-info-go/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
-
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/dependencies"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/spf13/viper"
-)
-
-type MvnUtils struct {
- vConfig *viper.Viper
- buildConf *buildUtils.BuildConfiguration
- buildArtifactsDetailsFile string
- buildInfoFilePath string
- goals []string
- threads int
- insecureTls bool
- disableDeploy bool
- outputWriter io.Writer
-}
-
-func NewMvnUtils() *MvnUtils {
- return &MvnUtils{buildConf: &buildUtils.BuildConfiguration{}}
-}
-
-func (mu *MvnUtils) SetBuildConf(buildConf *buildUtils.BuildConfiguration) *MvnUtils {
- mu.buildConf = buildConf
- return mu
-}
-
-func (mu *MvnUtils) SetBuildArtifactsDetailsFile(buildArtifactsDetailsFile string) *MvnUtils {
- mu.buildArtifactsDetailsFile = buildArtifactsDetailsFile
- return mu
-}
-
-func (mu *MvnUtils) SetGoals(goals []string) *MvnUtils {
- mu.goals = goals
- return mu
-}
-
-func (mu *MvnUtils) SetThreads(threads int) *MvnUtils {
- mu.threads = threads
- return mu
-}
-
-func (mu *MvnUtils) SetInsecureTls(insecureTls bool) *MvnUtils {
- mu.insecureTls = insecureTls
- return mu
-}
-
-func (mu *MvnUtils) SetDisableDeploy(disableDeploy bool) *MvnUtils {
- mu.disableDeploy = disableDeploy
- return mu
-}
-
-func (mu *MvnUtils) SetConfig(vConfig *viper.Viper) *MvnUtils {
- mu.vConfig = vConfig
- return mu
-}
-
-func (mu *MvnUtils) SetOutputWriter(writer io.Writer) *MvnUtils {
- mu.outputWriter = writer
- return mu
-}
-
-func RunMvn(mu *MvnUtils) error {
- buildInfoService := buildUtils.CreateBuildInfoService()
- buildName, err := mu.buildConf.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := mu.buildConf.GetBuildNumber()
- if err != nil {
- return err
- }
- mvnBuild, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, mu.buildConf.GetProject())
- if err != nil {
- return errorutils.CheckError(err)
- }
- mavenModule, err := mvnBuild.AddMavenModule("")
- if err != nil {
- return errorutils.CheckError(err)
- }
- props, useWrapper, err := createMvnRunProps(mu.vConfig, mu.buildArtifactsDetailsFile, mu.threads, mu.insecureTls, mu.disableDeploy)
- if err != nil {
- return err
- }
- var mvnOpts []string
- if v := os.Getenv("MAVEN_OPTS"); v != "" {
- mvnOpts = strings.Fields(v)
- }
- if v, ok := props["buildInfoConfig.artifactoryResolutionEnabled"]; ok {
- mvnOpts = append(mvnOpts, "-DbuildInfoConfig.artifactoryResolutionEnabled="+v)
- }
- projectRoot, exists, err := fileutils.FindUpstream(".mvn", fileutils.Dir)
- if err != nil {
- return errorutils.CheckError(err)
- }
- if !exists {
- projectRoot = ""
- }
- dependencyLocalPath, err := getMavenDependencyLocalPath()
- if err != nil {
- return err
- }
- mavenModule.SetExtractorDetails(dependencyLocalPath,
- filepath.Join(coreutils.GetCliPersistentTempDirPath(), buildUtils.PropertiesTempPath),
- mu.goals,
- dependencies.DownloadExtractor,
- props,
- useWrapper).
- SetOutputWriter(mu.outputWriter)
- mavenModule.SetMavenOpts(mvnOpts...)
- mavenModule.SetRootProjectDir(projectRoot)
- if err = coreutils.ConvertExitCodeError(mavenModule.CalcDependencies()); err != nil {
- return err
- }
- mu.buildInfoFilePath = mavenModule.GetGeneratedBuildInfoPath()
- return nil
-}
-
-// GetBuildInfoFilePath returns the path to the temporary build info file
-// This file stores build-info details and is populated by the Maven extractor after CalcDependencies() is called
-func (mu *MvnUtils) GetBuildInfoFilePath() string {
- return mu.buildInfoFilePath
-}
-
-func getMavenDependencyLocalPath() (string, error) {
- dependenciesPath, err := config.GetJfrogDependenciesPath()
- if err != nil {
- return "", err
- }
- return filepath.Join(dependenciesPath, "maven", build.MavenExtractorDependencyVersion), nil
-}
-
-func createMvnRunProps(vConfig *viper.Viper, buildArtifactsDetailsFile string, threads int, insecureTls, disableDeploy bool) (props map[string]string, useWrapper bool, err error) {
- useWrapper = vConfig.GetBool("useWrapper")
- vConfig.Set(buildUtils.InsecureTls, insecureTls)
- if threads > 0 {
- vConfig.Set(buildUtils.ForkCount, threads)
- }
-
- if disableDeploy {
- setDeployFalse(vConfig)
- }
-
- if vConfig.IsSet("resolver") {
- vConfig.Set("buildInfoConfig.artifactoryResolutionEnabled", "true")
- }
- buildInfoProps, err := buildUtils.CreateBuildInfoProps(buildArtifactsDetailsFile, vConfig, project.Maven)
-
- return buildInfoProps, useWrapper, err
-}
-
-func setDeployFalse(vConfig *viper.Viper) {
- vConfig.Set(buildUtils.DeployerPrefix+buildUtils.DeployArtifacts, "false")
- if vConfig.GetString(buildUtils.DeployerPrefix+buildUtils.Url) == "" {
- vConfig.Set(buildUtils.DeployerPrefix+buildUtils.Url, "http://empty_url")
- }
- if vConfig.GetString(buildUtils.DeployerPrefix+buildUtils.ReleaseRepo) == "" {
- vConfig.Set(buildUtils.DeployerPrefix+buildUtils.ReleaseRepo, "empty_repo")
- }
- if vConfig.GetString(buildUtils.DeployerPrefix+buildUtils.SnapshotRepo) == "" {
- vConfig.Set(buildUtils.DeployerPrefix+buildUtils.SnapshotRepo, "empty_repo")
- }
-}
diff --git a/artifactory/commands/npm/common.go b/artifactory/commands/npm/common.go
deleted file mode 100644
index 1cbc2bc2e..000000000
--- a/artifactory/commands/npm/common.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package npm
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type CommonArgs struct {
- repo string
- buildConfiguration *build.BuildConfiguration
- npmArgs []string
- serverDetails *config.ServerDetails
-}
-
-func (ca *CommonArgs) SetServerDetails(serverDetails *config.ServerDetails) *CommonArgs {
- ca.serverDetails = serverDetails
- return ca
-}
-
-func (ca *CommonArgs) SetNpmArgs(npmArgs []string) *CommonArgs {
- ca.npmArgs = npmArgs
- return ca
-}
-
-func (ca *CommonArgs) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *CommonArgs {
- ca.buildConfiguration = buildConfiguration
- return ca
-}
-
-func (ca *CommonArgs) SetRepo(repo string) *CommonArgs {
- ca.repo = repo
- return ca
-}
diff --git a/artifactory/commands/npm/npmcommand.go b/artifactory/commands/npm/npmcommand.go
deleted file mode 100644
index 079bc1714..000000000
--- a/artifactory/commands/npm/npmcommand.go
+++ /dev/null
@@ -1,433 +0,0 @@
-package npm
-
-import (
- "bufio"
- "errors"
- "fmt"
- "os"
- "path/filepath"
- "strconv"
- "strings"
-
- "github.com/jfrog/build-info-go/build"
- biUtils "github.com/jfrog/build-info-go/build/utils"
- "github.com/jfrog/gofrog/version"
- commandUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/npm"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/auth"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "github.com/spf13/viper"
-)
-
-const (
- npmrcFileName = ".npmrc"
- npmrcBackupFileName = "jfrog.npmrc.backup"
- minSupportedNpmVersion = "5.4.0"
-
- // Scoped authentication env var that sets the _auth or _authToken npm config variables.
- npmConfigAuthEnv = "npm_config_%s:%s"
- npmVersionSupportingScopedAuthEnv = "9.2.0"
- // Legacy un-scoped auth env vars doesn't support access tokens (with _authToken suffix).
- npmLegacyConfigAuthEnv = "npm_config__auth"
-)
-
-type NpmCommand struct {
- CommonArgs
- cmdName string
- jsonOutput bool
- executablePath string
- // Function to be called to restore the user's old npmrc and delete the one we created.
- restoreNpmrcFunc func() error
- workingDirectory string
- // Npm registry as exposed by Artifactory.
- registry string
- // Npm token generated by Artifactory using the user's provided credentials.
- npmAuth string
- authArtDetails auth.ServiceDetails
- npmVersion *version.Version
- internalCommandName string
- configFilePath string
- collectBuildInfo bool
- buildInfoModule *build.NpmModule
-}
-
-func NewNpmCommand(cmdName string, collectBuildInfo bool) *NpmCommand {
- return &NpmCommand{
- cmdName: cmdName,
- collectBuildInfo: collectBuildInfo,
- internalCommandName: "rt_npm_" + cmdName,
- }
-}
-
-func NewNpmInstallCommand() *NpmCommand {
- return &NpmCommand{cmdName: "install", internalCommandName: "rt_npm_install"}
-}
-
-func NewNpmCiCommand() *NpmCommand {
- return &NpmCommand{cmdName: "ci", internalCommandName: "rt_npm_ci"}
-}
-
-func (nc *NpmCommand) CommandName() string {
- return nc.internalCommandName
-}
-
-func (nc *NpmCommand) SetConfigFilePath(configFilePath string) *NpmCommand {
- nc.configFilePath = configFilePath
- return nc
-}
-
-func (nc *NpmCommand) SetArgs(args []string) *NpmCommand {
- nc.npmArgs = args
- return nc
-}
-
-func (nc *NpmCommand) SetRepoConfig(conf *project.RepositoryConfig) *NpmCommand {
- serverDetails, _ := conf.ServerDetails()
- nc.SetRepo(conf.TargetRepo()).SetServerDetails(serverDetails)
- return nc
-}
-
-func (nc *NpmCommand) SetServerDetails(serverDetails *config.ServerDetails) *NpmCommand {
- nc.serverDetails = serverDetails
- return nc
-}
-
-func (nc *NpmCommand) SetRepo(repo string) *NpmCommand {
- nc.repo = repo
- return nc
-}
-
-func (nc *NpmCommand) Init() error {
- // Read config file.
- log.Debug("Preparing to read the config file", nc.configFilePath)
- vConfig, err := project.ReadConfigFile(nc.configFilePath, project.YAML)
- if err != nil {
- return err
- }
-
- repoConfig, err := nc.getRepoConfig(vConfig)
- if err != nil {
- return err
- }
- _, _, _, filteredNpmArgs, buildConfiguration, err := commandUtils.ExtractNpmOptionsFromArgs(nc.npmArgs)
- if err != nil {
- return err
- }
- nc.SetRepoConfig(repoConfig).SetArgs(filteredNpmArgs).SetBuildConfiguration(buildConfiguration)
- return nil
-}
-
-// Get the repository configuration from the config file.
-// Use the resolver prefix for all commands except for 'dist-tag' which use the deployer prefix.
-func (nc *NpmCommand) getRepoConfig(vConfig *viper.Viper) (repoConfig *project.RepositoryConfig, err error) {
- prefix := project.ProjectConfigResolverPrefix
- // Aliases accepted by npm.
- if nc.cmdName == "dist-tag" || nc.cmdName == "dist-tags" {
- prefix = project.ProjectConfigDeployerPrefix
- }
- return project.GetRepoConfigByPrefix(nc.configFilePath, prefix, vConfig)
-}
-
-func (nc *NpmCommand) SetBuildConfiguration(buildConfiguration *buildUtils.BuildConfiguration) *NpmCommand {
- nc.buildConfiguration = buildConfiguration
- return nc
-}
-
-func (nc *NpmCommand) ServerDetails() (*config.ServerDetails, error) {
- return nc.serverDetails, nil
-}
-
-func (nc *NpmCommand) RestoreNpmrcFunc() func() error {
- return nc.restoreNpmrcFunc
-}
-
-func (nc *NpmCommand) PreparePrerequisites(repo string) error {
- log.Debug("Preparing prerequisites...")
- var err error
- nc.npmVersion, nc.executablePath, err = biUtils.GetNpmVersionAndExecPath(log.Logger)
- if err != nil {
- return err
- }
- if nc.npmVersion.Compare(minSupportedNpmVersion) > 0 {
- return errorutils.CheckErrorf(
- "JFrog CLI npm %s command requires npm client version %s or higher. The Current version is: %s", nc.cmdName, minSupportedNpmVersion, nc.npmVersion.GetVersion())
- }
-
- if err = nc.setJsonOutput(); err != nil {
- return err
- }
-
- nc.workingDirectory, err = coreutils.GetWorkingDirectory()
- if err != nil {
- return err
- }
- log.Debug("Working directory set to:", nc.workingDirectory)
- if err = nc.setArtifactoryAuth(); err != nil {
- return err
- }
-
- if err = nc.setNpmAuthRegistry(repo); err != nil {
- return err
- }
-
- return nc.setRestoreNpmrcFunc()
-}
-
-func (nc *NpmCommand) setNpmAuthRegistry(repo string) (err error) {
- nc.npmAuth, nc.registry, err = commandUtils.GetArtifactoryNpmRepoDetails(repo, nc.authArtDetails, !nc.isNpmVersionSupportsScopedAuthEnv())
- return
-}
-
-func (nc *NpmCommand) setRestoreNpmrcFunc() error {
- restoreNpmrcFunc, err := ioutils.BackupFile(filepath.Join(nc.workingDirectory, npmrcFileName), npmrcBackupFileName)
- if err != nil {
- return err
- }
- nc.restoreNpmrcFunc = func() error {
- if unsetEnvErr := os.Unsetenv(npmConfigAuthEnv); unsetEnvErr != nil {
- return unsetEnvErr
- }
- return restoreNpmrcFunc()
- }
- return nil
-}
-
-func (nc *NpmCommand) setArtifactoryAuth() error {
- authArtDetails, err := nc.serverDetails.CreateArtAuthConfig()
- if err != nil {
- return err
- }
- if authArtDetails.GetSshAuthHeaders() != nil {
- return errorutils.CheckErrorf("SSH authentication is not supported in this command")
- }
- nc.authArtDetails = authArtDetails
- return nil
-}
-
-func (nc *NpmCommand) setJsonOutput() error {
- jsonOutput, err := npm.ConfigGet(nc.npmArgs, "json", nc.executablePath)
- if err != nil {
- return err
- }
-
- // In case of --json=, the value of json is set to 'true', but the result from the command is not 'true'
- nc.jsonOutput = jsonOutput != "false"
- return nil
-}
-
-func (nc *NpmCommand) processConfigLine(configLine string) (filteredLine string, err error) {
- splitOption := strings.SplitN(configLine, "=", 2)
- key := strings.TrimSpace(splitOption[0])
- validLine := len(splitOption) == 2 && isValidKey(key)
- if !validLine {
- if strings.HasPrefix(splitOption[0], "@") {
- // Override scoped registries (@scope = xyz)
- return fmt.Sprintf("%s = %s\n", splitOption[0], nc.registry), nil
- }
- return
- }
- value := strings.TrimSpace(splitOption[1])
- if key == commandUtils.NpmConfigAuthKey || key == commandUtils.NpmConfigAuthTokenKey {
- return "", nc.setNpmConfigAuthEnv(value, key)
- }
- if strings.HasPrefix(value, "[") && strings.HasSuffix(value, "]") {
- return addArrayConfigs(key, value), nil
- }
-
- return fmt.Sprintf("%s\n", configLine), err
-}
-
-func (nc *NpmCommand) setNpmConfigAuthEnv(value, authKey string) error {
- // Check if the npm version supports scoped auth env vars.
- if nc.isNpmVersionSupportsScopedAuthEnv() {
- // Get registry name without the protocol name but including the '//'
- registryWithoutProtocolName := nc.registry[strings.Index(nc.registry, "://")+1:]
- // Set "npm_config_//:_auth" environment variable to allow authentication with Artifactory
- scopedRegistryEnv := fmt.Sprintf(npmConfigAuthEnv, registryWithoutProtocolName, authKey)
- return os.Setenv(scopedRegistryEnv, value)
- }
- // Set "npm_config__auth" environment variable to allow authentication with Artifactory when running post-install scripts on subdirectories.
- // For older versions, use un-scoped auth env vars.
- return os.Setenv(npmLegacyConfigAuthEnv, value)
-}
-
-func (nc *NpmCommand) isNpmVersionSupportsScopedAuthEnv() bool {
- return nc.npmVersion.Compare(npmVersionSupportingScopedAuthEnv) <= 0
-}
-
-func (nc *NpmCommand) prepareConfigData(data []byte) ([]byte, error) {
- var filteredConf []string
- configString := string(data) + "\n" + nc.npmAuth
- scanner := bufio.NewScanner(strings.NewReader(configString))
- for scanner.Scan() {
- currOption := scanner.Text()
- if currOption == "" {
- continue
- }
- filteredLine, err := nc.processConfigLine(currOption)
- if err != nil {
- return nil, errorutils.CheckError(err)
- }
- if filteredLine != "" {
- filteredConf = append(filteredConf, filteredLine)
- }
- }
- if err := scanner.Err(); err != nil {
- return nil, errorutils.CheckError(err)
- }
-
- filteredConf = append(filteredConf, "json = ", strconv.FormatBool(nc.jsonOutput), "\n")
- filteredConf = append(filteredConf, "registry = ", nc.registry, "\n")
- return []byte(strings.Join(filteredConf, "")), nil
-}
-
-func (nc *NpmCommand) CreateTempNpmrc() error {
- data, err := npm.GetConfigList(nc.npmArgs, nc.executablePath)
- if err != nil {
- return err
- }
- configData, err := nc.prepareConfigData(data)
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- if err = removeNpmrcIfExists(nc.workingDirectory); err != nil {
- return err
- }
- log.Debug("Creating temporary .npmrc file.")
- return errorutils.CheckError(os.WriteFile(filepath.Join(nc.workingDirectory, npmrcFileName), configData, 0755))
-}
-
-func (nc *NpmCommand) Run() (err error) {
- if err = nc.PreparePrerequisites(nc.repo); err != nil {
- return
- }
- defer func() {
- err = errors.Join(err, nc.restoreNpmrcFunc())
- }()
- if err = nc.CreateTempNpmrc(); err != nil {
- return
- }
-
- if err = nc.prepareBuildInfoModule(); err != nil {
- return
- }
-
- err = nc.collectDependencies()
- return
-}
-
-func (nc *NpmCommand) prepareBuildInfoModule() error {
- var err error
- if nc.collectBuildInfo {
- nc.collectBuildInfo, err = nc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
- }
- // Build-info should not be created when installing a single package (npm install ).
- if nc.collectBuildInfo && len(filterFlags(nc.npmArgs)) > 0 {
- log.Info("Build-info dependencies collection is not supported for installations of single packages. Build-info creation is skipped.")
- nc.collectBuildInfo = false
- }
- buildName, err := nc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := nc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- buildInfoService := buildUtils.CreateBuildInfoService()
- npmBuild, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, nc.buildConfiguration.GetProject())
- if err != nil {
- return errorutils.CheckError(err)
- }
- nc.buildInfoModule, err = npmBuild.AddNpmModule(nc.workingDirectory)
- if err != nil {
- return errorutils.CheckError(err)
- }
- nc.buildInfoModule.SetCollectBuildInfo(nc.collectBuildInfo)
- if nc.buildConfiguration.GetModule() != "" {
- nc.buildInfoModule.SetName(nc.buildConfiguration.GetModule())
- }
- return nil
-}
-
-func (nc *NpmCommand) collectDependencies() error {
- nc.buildInfoModule.SetNpmArgs(append([]string{nc.cmdName}, nc.npmArgs...))
- return errorutils.CheckError(nc.buildInfoModule.Build())
-}
-
-// Gets a config with value which is an array
-func addArrayConfigs(key, arrayValue string) string {
- if arrayValue == "[]" {
- return ""
- }
-
- values := strings.TrimPrefix(strings.TrimSuffix(arrayValue, "]"), "[")
- valuesSlice := strings.Split(values, ",")
- var configArrayValues strings.Builder
- for _, val := range valuesSlice {
- configArrayValues.WriteString(fmt.Sprintf("%s[] = %s\n", key, val))
- }
-
- return configArrayValues.String()
-}
-
-func removeNpmrcIfExists(workingDirectory string) error {
- if _, err := os.Stat(filepath.Join(workingDirectory, npmrcFileName)); err != nil {
- // The file does not exist, nothing to do.
- if os.IsNotExist(err) {
- return nil
- }
- return errorutils.CheckError(err)
- }
-
- log.Debug("Removing existing .npmrc file")
- return errorutils.CheckError(os.Remove(filepath.Join(workingDirectory, npmrcFileName)))
-}
-
-// To avoid writing configurations that are used by us
-func isValidKey(key string) bool {
- return !strings.HasPrefix(key, "//") &&
- !strings.HasPrefix(key, ";") && // Comments
- !strings.HasPrefix(key, "@") && // Scoped configurations
- key != "registry" &&
- key != "metrics-registry" &&
- key != "json" // Handled separately because 'npm c ls' should run with json=false
-}
-
-func filterFlags(splitArgs []string) []string {
- var filteredArgs []string
- for _, arg := range splitArgs {
- if !strings.HasPrefix(arg, "-") {
- filteredArgs = append(filteredArgs, arg)
- }
- }
- return filteredArgs
-}
-
-func (nc *NpmCommand) GetRepo() string {
- return nc.repo
-}
-
-// Creates an .npmrc file in the project's directory in order to configure the provided Artifactory server as a resolution server
-func SetArtifactoryAsResolutionServer(serverDetails *config.ServerDetails, depsRepo string) (clearResolutionServerFunc func() error, err error) {
- npmCmd := NewNpmInstallCommand().SetServerDetails(serverDetails)
- if err = npmCmd.PreparePrerequisites(depsRepo); err != nil {
- return
- }
- if err = npmCmd.CreateTempNpmrc(); err != nil {
- return
- }
- clearResolutionServerFunc = npmCmd.RestoreNpmrcFunc()
- log.Info(fmt.Sprintf("Resolving dependencies from '%s' from repo '%s'", serverDetails.Url, depsRepo))
- return
-}
diff --git a/artifactory/commands/npm/npmcommand_test.go b/artifactory/commands/npm/npmcommand_test.go
deleted file mode 100644
index 70c8f8a32..000000000
--- a/artifactory/commands/npm/npmcommand_test.go
+++ /dev/null
@@ -1,160 +0,0 @@
-package npm
-
-import (
- "fmt"
- biutils "github.com/jfrog/build-info-go/utils"
- "github.com/jfrog/gofrog/version"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- commonTests "github.com/jfrog/jfrog-cli-core/v2/common/tests"
- "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
- testsUtils "github.com/jfrog/jfrog-client-go/utils/tests"
- "github.com/stretchr/testify/assert"
- "net/http"
- "os"
- "path/filepath"
- "strings"
- "testing"
-)
-
-// #nosec G101 - Dummy token for tests.
-const authToken = "YWRtaW46QVBCN1ZkZFMzN3NCakJiaHRGZThVb0JlZzFl"
-
-func TestPrepareConfigData(t *testing.T) {
- configBefore := []byte(
- "json=true\n" +
- "user-agent=npm/5.5.1 node/v8.9.1 darwin x64\n" +
- "metrics-registry=http://somebadregistry\nscope=\n" +
- "//reg=ddddd\n" +
- "@jfrog:registry=http://somebadregistry\n" +
- "registry=http://somebadregistry\n" +
- "email=ddd@dd.dd\n" +
- "allow-same-version=false\n" +
- "cache-lock-retries=10")
-
- expectedConfig :=
- []string{
- "json = true",
- "allow-same-version=false",
- "user-agent=npm/5.5.1 node/v8.9.1 darwin x64",
- "@jfrog:registry = http://goodRegistry",
- "email=ddd@dd.dd",
- "cache-lock-retries=10",
- "registry = http://goodRegistry",
- }
-
- npmi := NpmCommand{registry: "http://goodRegistry", jsonOutput: true, npmAuth: "_auth = " + authToken, npmVersion: version.NewVersion("9.5.0")}
- configAfter, err := npmi.prepareConfigData(configBefore)
- if err != nil {
- t.Error(err)
- }
- actualConfigArray := strings.Split(string(configAfter), "\n")
- for _, eConfig := range expectedConfig {
- found := false
- for _, aConfig := range actualConfigArray {
- if aConfig == eConfig {
- found = true
- break
- }
- }
- if !found {
- t.Errorf("The expected config: %s is missing from the actual configuration list:\n %s", eConfig, actualConfigArray)
- }
- }
-
- // Assert that NPM_CONFIG__AUTH environment variable was set
- assert.Equal(t, authToken, os.Getenv(fmt.Sprintf(npmConfigAuthEnv, "//goodRegistry", utils.NpmConfigAuthKey)))
- testsUtils.UnSetEnvAndAssert(t, fmt.Sprintf(npmConfigAuthEnv, "//goodRegistry", utils.NpmConfigAuthKey))
-}
-
-func TestSetNpmConfigAuthEnv(t *testing.T) {
- testCases := []struct {
- name string
- npmCm *NpmCommand
- authKey string
- value string
- expectedEnv string
- }{
- {
- name: "set scoped registry auth env",
- npmCm: &NpmCommand{
- npmVersion: version.NewVersion("9.3.1"),
- },
- authKey: utils.NpmConfigAuthKey,
- value: "some_auth_token",
- expectedEnv: "npm_config_//registry.example.com:_auth",
- },
- {
- name: "set scoped registry authToken env",
- npmCm: &NpmCommand{
- npmVersion: version.NewVersion("9.3.1"),
- },
- authKey: utils.NpmConfigAuthTokenKey,
- value: "some_auth_token",
- expectedEnv: "npm_config_//registry.example.com:_authToken",
- },
- {
- name: "set legacy auth env",
- npmCm: &NpmCommand{
- npmVersion: version.NewVersion("8.16.3"),
- },
- authKey: utils.NpmConfigAuthKey,
- value: "some_auth_token",
- expectedEnv: "npm_config__auth",
- },
- {
- name: "set legacy auth env even though authToken is passed",
- npmCm: &NpmCommand{
- npmVersion: version.NewVersion("8.16.3"),
- },
- authKey: utils.NpmConfigAuthTokenKey,
- value: "some_auth_token",
- expectedEnv: "npm_config__auth",
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.name, func(t *testing.T) {
- tc.npmCm.registry = "https://registry.example.com"
- err := tc.npmCm.setNpmConfigAuthEnv(tc.value, tc.authKey)
- assert.NoError(t, err)
- envValue := os.Getenv(tc.expectedEnv)
- assert.Equal(t, tc.value, envValue)
- assert.NoError(t, os.Unsetenv(tc.expectedEnv))
- })
- }
-}
-
-func TestSetArtifactoryAsResolutionServer(t *testing.T) {
- tmpDir, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t)
- defer createTempDirCallback()
-
- npmProjectPath := filepath.Join("..", "..", "..", "tests", "testdata", "npm-project")
- err := biutils.CopyDir(npmProjectPath, tmpDir, false, nil)
- assert.NoError(t, err)
-
- cwd, err := os.Getwd()
- assert.NoError(t, err)
- chdirCallback := testsUtils.ChangeDirWithCallback(t, cwd, tmpDir)
- defer chdirCallback()
-
- // Prepare mock server
- testServer, serverDetails, _ := commonTests.CreateRtRestsMockServer(t, func(w http.ResponseWriter, r *http.Request) {
- if r.RequestURI == "/api/system/version" {
- w.WriteHeader(http.StatusOK)
- _, err = w.Write([]byte("{\"version\" : \"7.75.4\"}"))
- assert.NoError(t, err)
- }
- })
- defer testServer.Close()
-
- depsRepo := "my-rt-resolution-repo"
-
- clearResolutionServerFunc, err := SetArtifactoryAsResolutionServer(serverDetails, depsRepo)
- assert.NoError(t, err)
- assert.NotNil(t, clearResolutionServerFunc)
- defer func() {
- assert.NoError(t, clearResolutionServerFunc())
- }()
-
- assert.FileExists(t, filepath.Join(tmpDir, ".npmrc"))
-}
diff --git a/artifactory/commands/npm/publish.go b/artifactory/commands/npm/publish.go
deleted file mode 100644
index 8da35cbd5..000000000
--- a/artifactory/commands/npm/publish.go
+++ /dev/null
@@ -1,497 +0,0 @@
-package npm
-
-import (
- "archive/tar"
- "compress/gzip"
- "errors"
- "fmt"
- "github.com/jfrog/build-info-go/build"
- biutils "github.com/jfrog/build-info-go/build/utils"
- ioutils "github.com/jfrog/gofrog/io"
- "github.com/jfrog/gofrog/version"
- commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/npm"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/format"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/artifactory"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- specutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/content"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "io"
- "os"
- "path/filepath"
- "strings"
-)
-
-const (
- DistTagPropKey = "npm.disttag"
- // The --pack-destination argument of npm pack was introduced in npm version 7.18.0.
- packDestinationNpmMinVersion = "7.18.0"
-)
-
-type NpmPublishCommandArgs struct {
- CommonArgs
- executablePath string
- workingDirectory string
- collectBuildInfo bool
- packedFilePaths []string
- packageInfo *biutils.PackageInfo
- publishPath string
- tarballProvided bool
- artifactsDetailsReader *content.ContentReader
- xrayScan bool
- scanOutputFormat format.OutputFormat
- distTag string
-}
-
-type NpmPublishCommand struct {
- configFilePath string
- commandName string
- result *commandsutils.Result
- detailedSummary bool
- npmVersion *version.Version
- *NpmPublishCommandArgs
-}
-
-func NewNpmPublishCommand() *NpmPublishCommand {
- return &NpmPublishCommand{NpmPublishCommandArgs: NewNpmPublishCommandArgs(), commandName: "rt_npm_publish", result: new(commandsutils.Result)}
-}
-
-func NewNpmPublishCommandArgs() *NpmPublishCommandArgs {
- return &NpmPublishCommandArgs{}
-}
-
-func (npc *NpmPublishCommand) ServerDetails() (*config.ServerDetails, error) {
- return npc.serverDetails, nil
-}
-
-func (npc *NpmPublishCommand) SetConfigFilePath(configFilePath string) *NpmPublishCommand {
- npc.configFilePath = configFilePath
- return npc
-}
-
-func (npc *NpmPublishCommand) SetArgs(args []string) *NpmPublishCommand {
- npc.NpmPublishCommandArgs.npmArgs = args
- return npc
-}
-
-func (npc *NpmPublishCommand) SetDetailedSummary(detailedSummary bool) *NpmPublishCommand {
- npc.detailedSummary = detailedSummary
- return npc
-}
-
-func (npc *NpmPublishCommand) SetXrayScan(xrayScan bool) *NpmPublishCommand {
- npc.xrayScan = xrayScan
- return npc
-}
-
-func (npc *NpmPublishCommand) GetXrayScan() bool {
- return npc.xrayScan
-}
-
-func (npc *NpmPublishCommand) SetScanOutputFormat(format format.OutputFormat) *NpmPublishCommand {
- npc.scanOutputFormat = format
- return npc
-}
-
-func (npc *NpmPublishCommand) SetDistTag(tag string) *NpmPublishCommand {
- npc.distTag = tag
- return npc
-}
-
-func (npc *NpmPublishCommand) Result() *commandsutils.Result {
- return npc.result
-}
-
-func (npc *NpmPublishCommand) IsDetailedSummary() bool {
- return npc.detailedSummary
-}
-
-func (npc *NpmPublishCommand) Init() error {
- var err error
- npc.npmVersion, npc.executablePath, err = biutils.GetNpmVersionAndExecPath(log.Logger)
- if err != nil {
- return err
- }
- detailedSummary, xrayScan, scanOutputFormat, filteredNpmArgs, buildConfiguration, err := commandsutils.ExtractNpmOptionsFromArgs(npc.NpmPublishCommandArgs.npmArgs)
- if err != nil {
- return err
- }
- filteredNpmArgs, tag, err := coreutils.ExtractTagFromArgs(filteredNpmArgs)
- if err != nil {
- return err
- }
- if npc.configFilePath != "" {
- // Read config file.
- log.Debug("Preparing to read the config file", npc.configFilePath)
- vConfig, err := project.ReadConfigFile(npc.configFilePath, project.YAML)
- if err != nil {
- return err
- }
- deployerParams, err := project.GetRepoConfigByPrefix(npc.configFilePath, project.ProjectConfigDeployerPrefix, vConfig)
- if err != nil {
- return err
- }
- rtDetails, err := deployerParams.ServerDetails()
- if err != nil {
- return errorutils.CheckError(err)
- }
- npc.SetBuildConfiguration(buildConfiguration).SetRepo(deployerParams.TargetRepo()).SetNpmArgs(filteredNpmArgs).SetServerDetails(rtDetails)
- }
- npc.SetDetailedSummary(detailedSummary).SetXrayScan(xrayScan).SetScanOutputFormat(scanOutputFormat).SetDistTag(tag)
- return nil
-}
-
-func (npc *NpmPublishCommand) Run() (err error) {
- log.Info("Running npm Publish")
- err = npc.preparePrerequisites()
- if err != nil {
- return err
- }
-
- var npmBuild *build.Build
- var buildName, buildNumber, projectKey string
- if npc.collectBuildInfo {
- buildName, err = npc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err = npc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- projectKey = npc.buildConfiguration.GetProject()
- buildInfoService := buildUtils.CreateBuildInfoService()
- npmBuild, err = buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, projectKey)
- if err != nil {
- return errorutils.CheckError(err)
- }
- }
-
- if !npc.tarballProvided {
- if err = npc.pack(); err != nil {
- return err
- }
- }
-
- if err = npc.publish(); err != nil {
- if npc.tarballProvided {
- return err
- }
- // We should delete the tarball we created
- return errors.Join(err, deleteCreatedTarball(npc.packedFilePaths))
- }
-
- if !npc.tarballProvided {
- if err = deleteCreatedTarball(npc.packedFilePaths); err != nil {
- return err
- }
- }
-
- if !npc.collectBuildInfo {
- log.Info("npm publish finished successfully.")
- return nil
- }
-
- npmModule, err := npmBuild.AddNpmModule("")
- if err != nil {
- return errorutils.CheckError(err)
- }
- if npc.buildConfiguration.GetModule() != "" {
- npmModule.SetName(npc.buildConfiguration.GetModule())
- }
- buildArtifacts, err := specutils.ConvertArtifactsDetailsToBuildInfoArtifacts(npc.artifactsDetailsReader)
- if err != nil {
- return err
- }
- defer ioutils.Close(npc.artifactsDetailsReader, &err)
- err = npmModule.AddArtifacts(buildArtifacts...)
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- log.Info("npm publish finished successfully.")
- return nil
-}
-
-func (npc *NpmPublishCommand) CommandName() string {
- return npc.commandName
-}
-
-func (npc *NpmPublishCommand) preparePrerequisites() error {
- npc.packedFilePaths = make([]string, 0)
- currentDir, err := os.Getwd()
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- currentDir, err = filepath.Abs(currentDir)
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- npc.workingDirectory = currentDir
- log.Debug("Working directory set to:", npc.workingDirectory)
- npc.collectBuildInfo, err = npc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
- if err = npc.setPublishPath(); err != nil {
- return err
- }
-
- artDetails, err := npc.serverDetails.CreateArtAuthConfig()
- if err != nil {
- return err
- }
-
- if err = utils.ValidateRepoExists(npc.repo, artDetails); err != nil {
- return err
- }
-
- return npc.setPackageInfo()
-}
-
-func (npc *NpmPublishCommand) pack() error {
- log.Debug("Creating npm package.")
- packedFileNames, err := npm.Pack(npc.npmArgs, npc.executablePath)
- if err != nil {
- return err
- }
-
- tarballDir, err := npc.getTarballDir()
- if err != nil {
- return err
- }
-
- for _, packageFileName := range packedFileNames {
- npc.packedFilePaths = append(npc.packedFilePaths, filepath.Join(tarballDir, packageFileName))
- }
-
- return nil
-}
-
-func (npc *NpmPublishCommand) getTarballDir() (string, error) {
- if npc.npmVersion == nil || npc.npmVersion.Compare(packDestinationNpmMinVersion) > 0 {
- return npc.workingDirectory, nil
- }
-
- // Extract pack destination argument from the args.
- flagIndex, _, dest, err := coreutils.FindFlag("--pack-destination", npc.NpmPublishCommandArgs.npmArgs)
- if err != nil || flagIndex == -1 {
- return npc.workingDirectory, err
- }
- return dest, nil
-}
-
-func (npc *NpmPublishCommand) publish() (err error) {
- for _, packedFilePath := range npc.packedFilePaths {
- log.Debug("Deploying npm package.")
- if err = npc.readPackageInfoFromTarball(packedFilePath); err != nil {
- return
- }
- target := fmt.Sprintf("%s/%s", npc.repo, npc.packageInfo.GetDeployPath())
-
- // If requested, perform a Xray binary scan before deployment. If a FailBuildError is returned, skip the deployment.
- if npc.xrayScan {
- fileSpec := spec.NewBuilder().
- Pattern(packedFilePath).
- Target(npc.repo + "/").
- BuildSpec()
- if err = commandsutils.ConditionalUploadScanFunc(npc.serverDetails, fileSpec, 1, npc.scanOutputFormat); err != nil {
- return
- }
- }
- err = errors.Join(err, npc.doDeploy(target, npc.serverDetails, packedFilePath))
- }
- return
-}
-
-func (npc *NpmPublishCommand) doDeploy(target string, artDetails *config.ServerDetails, packedFilePath string) error {
- servicesManager, err := utils.CreateServiceManager(artDetails, -1, 0, false)
- if err != nil {
- return err
- }
- up := services.NewUploadParams()
- up.CommonParams = &specutils.CommonParams{Pattern: packedFilePath, Target: target}
- if err = npc.addDistTagIfSet(up.CommonParams); err != nil {
- return err
- }
- var totalFailed int
- if npc.collectBuildInfo || npc.detailedSummary {
- if npc.collectBuildInfo {
- buildName, err := npc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := npc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- err = buildUtils.SaveBuildGeneralDetails(buildName, buildNumber, npc.buildConfiguration.GetProject())
- if err != nil {
- return err
- }
- up.BuildProps, err = buildUtils.CreateBuildProperties(buildName, buildNumber, npc.buildConfiguration.GetProject())
- if err != nil {
- return err
- }
- }
- summary, err := servicesManager.UploadFilesWithSummary(artifactory.UploadServiceOptions{}, up)
- if err != nil {
- return err
- }
- totalFailed = summary.TotalFailed
- if npc.collectBuildInfo {
- npc.artifactsDetailsReader = summary.ArtifactsDetailsReader
- } else {
- err = summary.ArtifactsDetailsReader.Close()
- if err != nil {
- return err
- }
- }
- if npc.detailedSummary {
- if err = npc.setDetailedSummary(summary); err != nil {
- return err
- }
- } else {
- if err = summary.TransferDetailsReader.Close(); err != nil {
- return err
- }
- }
- } else {
- _, totalFailed, err = servicesManager.UploadFiles(artifactory.UploadServiceOptions{}, up)
- if err != nil {
- return err
- }
- }
-
- // We are deploying only one Artifact which have to be deployed, in case of failure we should fail
- if totalFailed > 0 {
- return errorutils.CheckErrorf("Failed to upload the npm package to Artifactory. See Artifactory logs for more details.")
- }
- return nil
-}
-
-// Set the dist tag property to the package if required by the --tag option.
-func (npc *NpmPublishCommand) addDistTagIfSet(params *specutils.CommonParams) error {
- if npc.distTag == "" {
- return nil
- }
- props, err := specutils.ParseProperties(DistTagPropKey + "=" + npc.distTag)
- if err != nil {
- return err
- }
- params.TargetProps = props
- return nil
-}
-
-func (npc *NpmPublishCommand) setDetailedSummary(summary *specutils.OperationSummary) (err error) {
- npc.result.SetFailCount(npc.result.FailCount() + summary.TotalFailed)
- npc.result.SetSuccessCount(npc.result.SuccessCount() + summary.TotalSucceeded)
- if npc.result.Reader() == nil {
- npc.result.SetReader(summary.TransferDetailsReader)
- } else {
- if err = npc.appendReader(summary); err != nil {
- return
- }
- }
- return
-}
-
-func (npc *NpmPublishCommand) appendReader(summary *specutils.OperationSummary) error {
- readersSlice := []*content.ContentReader{npc.result.Reader(), summary.TransferDetailsReader}
- reader, err := content.MergeReaders(readersSlice, content.DefaultKey)
- if err != nil {
- return err
- }
- npc.result.SetReader(reader)
- return nil
-}
-
-func (npc *NpmPublishCommand) setPublishPath() error {
- log.Debug("Reading Package Json.")
-
- npc.publishPath = npc.workingDirectory
- if len(npc.npmArgs) > 0 && !strings.HasPrefix(strings.TrimSpace(npc.npmArgs[0]), "-") {
- path := strings.TrimSpace(npc.npmArgs[0])
- path = clientutils.ReplaceTildeWithUserHome(path)
-
- if filepath.IsAbs(path) {
- npc.publishPath = path
- } else {
- npc.publishPath = filepath.Join(npc.workingDirectory, path)
- }
- }
- return nil
-}
-
-func (npc *NpmPublishCommand) setPackageInfo() error {
- log.Debug("Setting Package Info.")
- fileInfo, err := os.Stat(npc.publishPath)
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- if fileInfo.IsDir() {
- npc.packageInfo, err = biutils.ReadPackageInfoFromPackageJsonIfExists(npc.publishPath, npc.npmVersion)
- return err
- }
- log.Debug("The provided path is not a directory, we assume this is a compressed npm package")
- npc.tarballProvided = true
- // Sets the location of the provided tarball
- npc.packedFilePaths = []string{npc.publishPath}
- return npc.readPackageInfoFromTarball(npc.publishPath)
-}
-
-func (npc *NpmPublishCommand) readPackageInfoFromTarball(packedFilePath string) (err error) {
- log.Debug("Extracting info from npm package:", packedFilePath)
- tarball, err := os.Open(packedFilePath)
- if err != nil {
- return errorutils.CheckError(err)
- }
- defer func() {
- err = errors.Join(err, errorutils.CheckError(tarball.Close()))
- }()
- gZipReader, err := gzip.NewReader(tarball)
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- tarReader := tar.NewReader(gZipReader)
- for {
- hdr, err := tarReader.Next()
- if err != nil {
- if err == io.EOF {
- return errorutils.CheckErrorf("Could not find 'package.json' in the compressed npm package: " + packedFilePath)
- }
- return errorutils.CheckError(err)
- }
- if hdr.Name == "package/package.json" {
- packageJson, err := io.ReadAll(tarReader)
- if err != nil {
- return errorutils.CheckError(err)
- }
- npc.packageInfo, err = biutils.ReadPackageInfo(packageJson, npc.npmVersion)
- return err
- }
- }
-}
-
-func deleteCreatedTarball(packedFilesPath []string) error {
- for _, packedFilePath := range packedFilesPath {
- if err := os.Remove(packedFilePath); err != nil {
- return errorutils.CheckError(err)
- }
- log.Debug("Successfully deleted the created npm package:", packedFilePath)
- }
- return nil
-}
diff --git a/artifactory/commands/npm/publish_test.go b/artifactory/commands/npm/publish_test.go
deleted file mode 100644
index d49d3cf36..000000000
--- a/artifactory/commands/npm/publish_test.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package npm
-
-import (
- "path/filepath"
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestReadPackageInfoFromTarball(t *testing.T) {
- npmPublish := NewNpmPublishCommand()
-
- var testCases = []struct {
- filePath string
- packageName string
- packageVersion string
- }{
- {
- filePath: filepath.Join("..", "testdata", "npm", "npm-example-0.0.3.tgz"),
- packageName: "npm-example",
- packageVersion: "0.0.3",
- }, {
- filePath: filepath.Join("..", "testdata", "npm", "npm-example-0.0.4.tgz"),
- packageName: "npm-example",
- packageVersion: "0.0.4",
- },
- }
- for _, test := range testCases {
- err := npmPublish.readPackageInfoFromTarball(test.filePath)
- assert.NoError(t, err)
- assert.Equal(t, test.packageName, npmPublish.packageInfo.Name)
- assert.Equal(t, test.packageVersion, npmPublish.packageInfo.Version)
- }
-}
diff --git a/artifactory/commands/oc/startbuild.go b/artifactory/commands/oc/startbuild.go
deleted file mode 100644
index b08ef383b..000000000
--- a/artifactory/commands/oc/startbuild.go
+++ /dev/null
@@ -1,261 +0,0 @@
-package oc
-
-import (
- "bufio"
- "encoding/json"
- "errors"
- "github.com/jfrog/gofrog/version"
- "io"
- "os"
- "os/exec"
- "strings"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-const minSupportedOcVersion = "3.0.0"
-
-type OcStartBuildCommand struct {
- executablePath string
- serverId string
- repo string
- ocArgs []string
- serverDetails *config.ServerDetails
- buildConfiguration *build.BuildConfiguration
-}
-
-func NewOcStartBuildCommand() *OcStartBuildCommand {
- return &OcStartBuildCommand{}
-}
-
-func (osb *OcStartBuildCommand) Run() error {
- log.Info("Running oc start-build...")
- var err error
- if err = osb.validateAllowedOptions(); err != nil {
- return err
- }
-
- osb.serverDetails, err = config.GetSpecificConfig(osb.serverId, true, true)
- if err != nil {
- return err
- }
-
- if err = osb.setOcExecutable(); err != nil {
- return err
- }
- if err = osb.validateOcVersion(); err != nil {
- return err
- }
-
- // Run the build on OpenShift
- ocBuildName, err := startBuild(osb.executablePath, osb.ocArgs)
- if err != nil {
- return err
- }
- log.Info("Build", ocBuildName, "finished successfully.")
- buildName, err := osb.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := osb.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
- project := osb.buildConfiguration.GetProject()
- if buildName == "" {
- return nil
- }
-
- log.Info("Collecting build info...")
- // Get the new image details from OpenShift
- imageTag, manifestSha256, err := getImageDetails(osb.executablePath, ocBuildName)
- if err != nil {
- return err
- }
-
- if err := build.SaveBuildGeneralDetails(buildName, buildNumber, project); err != nil {
- return err
- }
- serviceManager, err := utils.CreateServiceManager(osb.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- image := container.NewImage(imageTag)
- builder, err := container.NewRemoteAgentBuildInfoBuilder(image, osb.repo, buildName, buildNumber, project, serviceManager, manifestSha256)
- if err != nil {
- return err
- }
- buildInfo, err := builder.Build(osb.buildConfiguration.GetModule())
- if err != nil {
- return err
- }
-
- log.Info("oc start-build finished successfully.")
- return build.SaveBuildInfo(buildName, buildNumber, project, buildInfo)
-}
-
-func (osb *OcStartBuildCommand) ServerDetails() (*config.ServerDetails, error) {
- return osb.serverDetails, nil
-}
-
-func (osb *OcStartBuildCommand) CommandName() string {
- return "rt_oc_start_build"
-}
-
-func (osb *OcStartBuildCommand) setOcExecutable() error {
- ocExecPath, err := exec.LookPath("oc")
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- osb.executablePath = ocExecPath
- log.Debug("Found OpenShift CLI executable at:", osb.executablePath)
- return nil
-}
-
-func (osb *OcStartBuildCommand) SetOcArgs(args []string) *OcStartBuildCommand {
- osb.ocArgs = args
- return osb
-}
-
-func (osb *OcStartBuildCommand) SetRepo(repo string) *OcStartBuildCommand {
- osb.repo = repo
- return osb
-}
-
-func (osb *OcStartBuildCommand) SetServerId(serverId string) *OcStartBuildCommand {
- osb.serverId = serverId
- return osb
-}
-
-func (osb *OcStartBuildCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *OcStartBuildCommand {
- osb.buildConfiguration = buildConfiguration
- return osb
-}
-
-func (osb *OcStartBuildCommand) validateAllowedOptions() error {
- notAllowedOcOptions := []string{"-w", "--wait", "--template", "-o", "--output"}
- for _, arg := range osb.ocArgs {
- for _, optionName := range notAllowedOcOptions {
- if arg == optionName || strings.HasPrefix(arg, optionName+"=") {
- return errorutils.CheckErrorf("the %s option is not allowed", optionName)
- }
- }
- }
- return nil
-}
-
-func (osb *OcStartBuildCommand) validateOcVersion() error {
- ocVersionStr, err := getOcVersion(osb.executablePath)
- if err != nil {
- return err
- }
- trimmedVersion := strings.TrimPrefix(ocVersionStr, "v")
- ocVersion := version.NewVersion(trimmedVersion)
- if ocVersion.Compare(minSupportedOcVersion) > 0 {
- return errorutils.CheckErrorf(
- "JFrog CLI oc start-build command requires OpenShift CLI version " + minSupportedOcVersion + " or higher")
- }
- return nil
-}
-
-func startBuild(executablePath string, ocFlags []string) (ocBuildName string, err error) {
- cmdArgs := []string{"start-build", "-w", "--template={{.metadata.name}}{{\"\\n\"}}"}
- cmdArgs = append(cmdArgs, ocFlags...)
-
- log.Debug("Running command: oc", strings.Join(cmdArgs, " "))
- cmd := exec.Command(executablePath, cmdArgs...)
- outputPr, outputPw, err := os.Pipe()
- if err != nil {
- return "", errorutils.CheckError(err)
- }
- outputWriter := io.MultiWriter(os.Stderr, outputPw)
- cmd.Stdout = outputWriter
- cmd.Stderr = os.Stderr
- err = cmd.Start()
- if err != nil {
- return "", errorutils.CheckError(err)
- }
-
- // The build name is in the first line of the output
- scanner := bufio.NewScanner(outputPr)
- scanner.Scan()
- ocBuildName = scanner.Text()
-
- err = errorutils.CheckError(convertExitError(cmd.Wait()))
- return
-}
-
-func getImageDetails(executablePath, ocBuildName string) (imageTag, manifestSha256 string, err error) {
- cmdArgs := []string{"get", "build", ocBuildName, "--template={{.status.outputDockerImageReference}}@{{.status.output.to.imageDigest}}"}
- log.Debug("Running command: oc", strings.Join(cmdArgs, " "))
- outputBytes, err := exec.Command(executablePath, cmdArgs...).Output()
- if err != nil {
- return "", "", errorutils.CheckError(convertExitError(err))
- }
- output := string(outputBytes)
- splitOutput := strings.Split(strings.TrimSpace(output), "@")
- if len(splitOutput) != 2 {
- return "", "", errorutils.CheckErrorf("Unable to parse image tag and digest of build %s. Output from OpenShift CLI: %s", ocBuildName, output)
- }
-
- return splitOutput[0], splitOutput[1], nil
-}
-
-func getOcVersion(executablePath string) (string, error) {
- cmdArgs := []string{"version", "-o=json"}
- outputBytes, err := exec.Command(executablePath, cmdArgs...).Output()
- if err != nil {
- // If an error occurred, maybe it's because the '-o' flag is not supported in OpenShift CLI v3 and below.
- // Try executing this command without this flag.
- return getOldOcVersion(executablePath)
- }
- var versionRes ocVersionResponse
- err = json.Unmarshal(outputBytes, &versionRes)
- if err != nil {
- return "", errorutils.CheckError(err)
- }
-
- return versionRes.ClientVersion.GitVersion, nil
-}
-
-// Running 'oc version' without the '-o=json' flag that is not supported in OpenShift CLI v3 and below.
-func getOldOcVersion(executablePath string) (string, error) {
- outputBytes, err := exec.Command(executablePath, "version").Output()
- if err != nil {
- return "", errorutils.CheckError(convertExitError(err))
- }
- // In OpenShift CLI v3 the output of 'oc version' looks like this:
- // oc v3.0.0
- // kubernetes v1.11.0
- // [...]
- // Get the first line of the output
- scanner := bufio.NewScanner(strings.NewReader(string(outputBytes)))
- scanner.Scan()
- firstLine := scanner.Text()
- if !strings.HasPrefix(firstLine, "oc v") {
- return "", errorutils.CheckErrorf("Could not parse OpenShift CLI version. JFrog CLI oc start-build command requires OpenShift CLI version " + minSupportedOcVersion + " or higher.")
- }
- return strings.TrimPrefix(firstLine, "oc "), nil
-}
-
-func convertExitError(err error) error {
- if exitError, ok := err.(*exec.ExitError); ok {
- return errors.New(string(exitError.Stderr))
- }
- return err
-}
-
-type ocVersionResponse struct {
- ClientVersion clientVersion `json:"clientVersion,omitempty"`
-}
-
-type clientVersion struct {
- GitVersion string `json:"gitVersion,omitempty"`
-}
diff --git a/artifactory/commands/oc/startbuild_test.go b/artifactory/commands/oc/startbuild_test.go
deleted file mode 100644
index 1cdf6f49b..000000000
--- a/artifactory/commands/oc/startbuild_test.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package oc
-
-import (
- "github.com/stretchr/testify/assert"
- "testing"
-)
-
-func TestValidateAllowedOptions(t *testing.T) {
- ocStartBuildCmd := NewOcStartBuildCommand()
-
- testCases := []struct {
- args []string
- valid bool
- }{
- {[]string{}, true},
- {[]string{"-F"}, true},
- {[]string{"-w"}, false},
- {[]string{"--wait", "false"}, false},
- {[]string{"-F", "--template={{.name}}", "-o='json'"}, false},
- {[]string{"repo", "-o='json'"}, false},
- {[]string{"--output=json", "-F"}, false},
- }
-
- for _, testCase := range testCases {
- ocStartBuildCmd = ocStartBuildCmd.SetOcArgs(testCase.args)
- err := ocStartBuildCmd.validateAllowedOptions()
- assert.Equal(t, testCase.valid, err == nil, "Test args:", testCase.args)
- }
-}
diff --git a/artifactory/commands/permissiontarget/create.go b/artifactory/commands/permissiontarget/create.go
deleted file mode 100644
index f34fd843b..000000000
--- a/artifactory/commands/permissiontarget/create.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package permissiontarget
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type PermissionTargetCreateCommand struct {
- PermissionTargetCommand
-}
-
-func NewPermissionTargetCreateCommand() *PermissionTargetCreateCommand {
- return &PermissionTargetCreateCommand{}
-}
-
-func (ptcc *PermissionTargetCreateCommand) SetTemplatePath(path string) *PermissionTargetCreateCommand {
- ptcc.templatePath = path
- return ptcc
-}
-
-func (ptcc *PermissionTargetCreateCommand) SetVars(vars string) *PermissionTargetCreateCommand {
- ptcc.vars = vars
- return ptcc
-}
-
-func (ptcc *PermissionTargetCreateCommand) SetServerDetails(serverDetails *config.ServerDetails) *PermissionTargetCreateCommand {
- ptcc.serverDetails = serverDetails
- return ptcc
-}
-
-func (ptcc *PermissionTargetCreateCommand) ServerDetails() (*config.ServerDetails, error) {
- return ptcc.serverDetails, nil
-}
-
-func (ptcc *PermissionTargetCreateCommand) CommandName() string {
- return "rt_permission_target_create"
-}
-
-func (ptcc *PermissionTargetCreateCommand) Run() (err error) {
- return ptcc.PerformPermissionTargetCmd(false)
-}
diff --git a/artifactory/commands/permissiontarget/delete.go b/artifactory/commands/permissiontarget/delete.go
deleted file mode 100644
index fb9bdfc9a..000000000
--- a/artifactory/commands/permissiontarget/delete.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package permissiontarget
-
-import (
- rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
-)
-
-type PermissionTargetDeleteCommand struct {
- rtDetails *config.ServerDetails
- permissionTargetName string
- quiet bool
-}
-
-func NewPermissionTargetDeleteCommand() *PermissionTargetDeleteCommand {
- return &PermissionTargetDeleteCommand{}
-}
-
-func (ptdc *PermissionTargetDeleteCommand) SetPermissionTargetName(permissionTargetName string) *PermissionTargetDeleteCommand {
- ptdc.permissionTargetName = permissionTargetName
- return ptdc
-}
-
-func (ptdc *PermissionTargetDeleteCommand) SetQuiet(quiet bool) *PermissionTargetDeleteCommand {
- ptdc.quiet = quiet
- return ptdc
-}
-
-func (ptdc *PermissionTargetDeleteCommand) SetServerDetails(serverDetails *config.ServerDetails) *PermissionTargetDeleteCommand {
- ptdc.rtDetails = serverDetails
- return ptdc
-}
-
-func (ptdc *PermissionTargetDeleteCommand) ServerDetails() (*config.ServerDetails, error) {
- return ptdc.rtDetails, nil
-}
-
-func (ptdc *PermissionTargetDeleteCommand) CommandName() string {
- return "rt_permission_target_delete"
-}
-
-func (ptdc *PermissionTargetDeleteCommand) Run() (err error) {
- if !ptdc.quiet && !coreutils.AskYesNo("Are you sure you want to permanently delete the permission target "+ptdc.permissionTargetName+"?", false) {
- return nil
- }
- servicesManager, err := rtUtils.CreateServiceManager(ptdc.rtDetails, -1, 0, false)
- if err != nil {
- return err
- }
- return servicesManager.DeletePermissionTarget(ptdc.permissionTargetName)
-}
diff --git a/artifactory/commands/permissiontarget/permissiontarget.go b/artifactory/commands/permissiontarget/permissiontarget.go
deleted file mode 100644
index 3683c3907..000000000
--- a/artifactory/commands/permissiontarget/permissiontarget.go
+++ /dev/null
@@ -1,122 +0,0 @@
-package permissiontarget
-
-import (
- "encoding/json"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "strings"
-)
-
-const DefaultBuildRepositoriesValue = "artifactory-build-info"
-
-type PermissionTargetCommand struct {
- serverDetails *config.ServerDetails
- templatePath string
- vars string
-}
-
-func (ptc *PermissionTargetCommand) Vars() string {
- return ptc.vars
-}
-
-func (ptc *PermissionTargetCommand) TemplatePath() string {
- return ptc.templatePath
-}
-
-func (ptc *PermissionTargetCommand) PerformPermissionTargetCmd(isUpdate bool) (err error) {
- permissionTargetConfigMap, err := utils.ConvertTemplateToMap(ptc)
- if err != nil {
- return err
- }
- // Go over the confMap and write the values with the correct types
- for key, value := range permissionTargetConfigMap {
- isBuildSection := false
- switch key {
- case Name:
- if _, ok := value.(string); !ok {
- return errorutils.CheckErrorf("template syntax error: the value for the key: \"Name\" is not a string type.")
- }
- case Build:
- isBuildSection = true
- fallthrough
- case Repo:
- fallthrough
- case ReleaseBundle:
- permissionSection, err := covertPermissionSection(value, isBuildSection)
- if err != nil {
- return err
- }
- permissionTargetConfigMap[key] = permissionSection
- default:
- return errorutils.CheckErrorf("template syntax error: unknown key: \"" + key + "\".")
- }
- }
- // Convert the new JSON with the correct types to params struct
- content, err := json.Marshal(permissionTargetConfigMap)
- if errorutils.CheckError(err) != nil {
- return err
- }
- params := services.NewPermissionTargetParams()
- err = json.Unmarshal(content, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- servicesManager, err := rtUtils.CreateServiceManager(ptc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdatePermissionTarget(params)
- }
- return servicesManager.CreatePermissionTarget(params)
-}
-
-// Each section is a map of string->interface{}. We need to convert each value to its correct type
-func covertPermissionSection(value interface{}, isBuildSection bool) (*services.PermissionTargetSection, error) {
- content, err := json.Marshal(value)
- if errorutils.CheckError(err) != nil {
- return nil, err
- }
- var answer PermissionSectionAnswer
- err = json.Unmarshal(content, &answer)
- if errorutils.CheckError(err) != nil {
- return nil, err
- }
- var pts services.PermissionTargetSection
- if len(answer.IncludePatterns) > 0 {
- pts.IncludePatterns = strings.Split(answer.IncludePatterns, ",")
- }
- if len(answer.ExcludePatterns) > 0 {
- pts.ExcludePatterns = strings.Split(answer.ExcludePatterns, ",")
- }
- // 'build' permission target must include repositories with a default value that cannot be changed.
- if isBuildSection {
- answer.Repositories = DefaultBuildRepositoriesValue
- }
- if len(answer.Repositories) > 0 {
- pts.Repositories = strings.Split(answer.Repositories, ",")
- }
-
- if answer.ActionsUsers != nil || answer.ActionsGroups != nil {
- pts.Actions = &services.Actions{}
- }
- if answer.ActionsUsers != nil {
- convertActionMap(answer.ActionsUsers, &pts.Actions.Users)
- }
- if answer.ActionsGroups != nil {
- convertActionMap(answer.ActionsGroups, &pts.Actions.Groups)
- }
- return &pts, nil
-}
-
-// actionMap is map of string->string. We need to convert each value to []string
-func convertActionMap(srcMap map[string]string, tgtMap *map[string][]string) {
- *tgtMap = make(map[string][]string)
- for key, permissionsStr := range srcMap {
- (*tgtMap)[key] = strings.Split(permissionsStr, ",")
- }
-
-}
diff --git a/artifactory/commands/permissiontarget/template.go b/artifactory/commands/permissiontarget/template.go
deleted file mode 100644
index 1d19f1090..000000000
--- a/artifactory/commands/permissiontarget/template.go
+++ /dev/null
@@ -1,238 +0,0 @@
-package permissiontarget
-
-import (
- "encoding/json"
- "fmt"
- "os"
- "sort"
- "strings"
-
- "github.com/c-bata/go-prompt"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type PermissionTargetTemplateCommand struct {
- path string
-}
-
-const (
- // Strings for prompt questions
- SelectPermissionTargetSectionMsg = "Select the permission target section to configure" + ioutils.PressTabMsg
- LeaveEmptyForDefault = "(press enter for default)"
-
- // Yes,No answers
- Yes = "yes"
- No = "no"
-
- // Main permission target configuration JSON keys
- Name = "name"
- Repo = "repo"
- Build = "build"
- ReleaseBundle = "releaseBundle"
-
- IncludePatternsDefault = "**"
- ExcludePatternsDefault = ""
-
- // Possible permissions
- read = "read"
- write = "write"
- annotate = "annotate"
- delete = "delete"
- manage = "manage"
- managedXrayMeta = "managedXrayMeta"
- distribute = "distribute"
-
- permissionSelectEnd = ioutils.DummyDefaultAnswer
-)
-
-func NewPermissionTargetTemplateCommand() *PermissionTargetTemplateCommand {
- return &PermissionTargetTemplateCommand{}
-}
-
-func (pttc *PermissionTargetTemplateCommand) SetTemplatePath(path string) *PermissionTargetTemplateCommand {
- pttc.path = path
- return pttc
-}
-
-func (pttc *PermissionTargetTemplateCommand) ServerDetails() (*config.ServerDetails, error) {
- // Since it's a local command, usage won't be reported.
- return nil, nil
-}
-
-func (pttc *PermissionTargetTemplateCommand) Run() (err error) {
- err = utils.ValidateTemplatePath(pttc.path)
- if err != nil {
- return
- }
- permissionTargetTemplateQuestionnaire := &ioutils.InteractiveQuestionnaire{
- MandatoryQuestionsKeys: []string{Name},
- QuestionsMap: questionMap,
- OptionalKeysSuggests: optionalSuggestsMap,
- }
- err = permissionTargetTemplateQuestionnaire.Perform()
- if err != nil {
- return err
- }
- resBytes, err := json.Marshal(permissionTargetTemplateQuestionnaire.AnswersMap)
- if err != nil {
- return errorutils.CheckError(err)
- }
- if err = os.WriteFile(pttc.path, resBytes, 0644); err != nil {
- return errorutils.CheckError(err)
- }
- log.Info(fmt.Sprintf("Permission target configuration template successfully created at %s.", pttc.path))
-
- return nil
-}
-
-func (pttc *PermissionTargetTemplateCommand) CommandName() string {
- return "rt_permission_target_template"
-}
-
-var optionalSuggestsMap = []prompt.Suggest{
- {Text: ioutils.SaveAndExit},
- {Text: Repo},
- {Text: Build},
- {Text: ReleaseBundle},
-}
-
-// Each permission target section (repo/build/releaseBundle) can have the following keys:
-// - repos - Mandatory for repo and releaseBundle. Has a const default value for build.
-// - include/exclude-patterns - Optional, has a default value.
-// - actions - Optional,includes two maps (users and groups): user/group name -> permissions array.
-func permissionSectionCallBack(iq *ioutils.InteractiveQuestionnaire, section string) (value string, err error) {
- if section == ioutils.SaveAndExit {
- return
- }
- var sectionAnswer PermissionSectionAnswer
- if section != Build {
- sectionAnswer.Repositories = ioutils.AskString(reposQuestionInfo.Msg, reposQuestionInfo.PromptPrefix, false, reposQuestionInfo.AllowVars)
- }
- sectionAnswer.IncludePatterns = ioutils.AskStringWithDefault(includePatternsQuestionInfo.Msg, includePatternsQuestionInfo.PromptPrefix, IncludePatternsDefault)
- sectionAnswer.ExcludePatterns = ioutils.AskString(excludePatternsQuestionInfo.Msg, excludePatternsQuestionInfo.PromptPrefix, true, excludePatternsQuestionInfo.AllowVars)
- configureActions := ioutils.AskFromList("", configureActionsQuestionInfo.PromptPrefix+"users?"+ioutils.PressTabMsg, false, configureActionsQuestionInfo.Options, Yes)
- if configureActions == Yes {
- sectionAnswer.ActionsUsers = make(map[string]string)
- readActionsMap("user", sectionAnswer.ActionsUsers)
- }
- configureActions = ioutils.AskFromList("", configureActionsQuestionInfo.PromptPrefix+"groups?", false, configureActionsQuestionInfo.Options, Yes)
- if configureActions == Yes {
- sectionAnswer.ActionsGroups = make(map[string]string)
- readActionsMap("group", sectionAnswer.ActionsGroups)
- }
- iq.AnswersMap[section] = sectionAnswer
- return
-}
-
-// We will read (user/group name, permissions) pairs until empty name is read.
-func readActionsMap(actionsType string, actionsMap map[string]string) {
- customKeyPrompt := "Insert " + actionsType + " name (press enter to finish) >"
- for {
- key := ioutils.AskString("", customKeyPrompt, true, false)
- if key == "" {
- return
- }
- value := strings.Join(readPermissionList(key), ",")
- actionsMap[key] = value
- }
-}
-
-func readPermissionList(permissionsOwner string) (permissions []string) {
- var permissionsMap = map[string]bool{
- read: false,
- write: false,
- annotate: false,
- delete: false,
- manage: false,
- managedXrayMeta: false,
- distribute: false,
- }
- for {
- answer := ioutils.AskFromList("", "Select permission value for "+permissionsOwner+" (press tab for options or enter to finish) >", true, buildPermissionSuggestArray(permissionsMap), permissionSelectEnd)
- if answer == permissionSelectEnd {
- break
- }
- // If the answer is a valid key, we will mark it with true to remove it from the suggestion list
- if _, ok := permissionsMap[answer]; ok {
- permissionsMap[answer] = true
- } else {
- // answer is a var, we will add it to the final permissions slice result
- permissions = append(permissions, answer)
- }
- }
- for key, value := range permissionsMap {
- if value {
- permissions = append(permissions, key)
- }
- }
- return
-}
-
-func buildPermissionSuggestArray(permissionMap map[string]bool) (permissions []prompt.Suggest) {
- for key, value := range permissionMap {
- if !value {
- permissions = append(permissions, prompt.Suggest{Text: key})
- }
- }
- sort.Slice(permissions, func(i, j int) bool {
- return permissions[i].Text < permissions[j].Text
- })
- return
-}
-
-var questionMap = map[string]ioutils.QuestionInfo{
- Name: {
- Msg: "",
- PromptPrefix: "Insert the permission target name >",
- AllowVars: false,
- Writer: ioutils.WriteStringAnswer,
- MapKey: Name,
- Callback: nil,
- },
- ioutils.OptionalKey: {
- Msg: "",
- PromptPrefix: SelectPermissionTargetSectionMsg,
- AllowVars: false,
- Writer: nil,
- MapKey: "",
- Callback: permissionSectionCallBack,
- },
- Repo: ioutils.FreeStringQuestionInfo,
- Build: ioutils.FreeStringQuestionInfo,
- ReleaseBundle: ioutils.FreeStringQuestionInfo,
-}
-
-var reposQuestionInfo = ioutils.QuestionInfo{
- Msg: "Insert the section's repositories value.\nYou can specify the name \"ANY\" to apply to all repositories, \"ANY REMOTE\" for all remote repositories or \"ANY LOCAL\" for all local repositories",
- PromptPrefix: ioutils.CommaSeparatedListMsg + " >",
-}
-
-var includePatternsQuestionInfo = ioutils.QuestionInfo{
- Msg: "Insert a value for include-patterns",
- PromptPrefix: ioutils.CommaSeparatedListMsg + " " + LeaveEmptyForDefault,
-}
-
-var excludePatternsQuestionInfo = ioutils.QuestionInfo{
- Msg: "Insert value for exclude-patterns",
- PromptPrefix: ioutils.CommaSeparatedListMsg + " " + LeaveEmptyForDefault + " []:",
-}
-
-var configureActionsQuestionInfo = ioutils.QuestionInfo{
- PromptPrefix: "Configure actions for ",
- Options: []prompt.Suggest{
- {Text: Yes},
- {Text: No},
- },
-}
-
-type PermissionSectionAnswer struct {
- Repositories string `json:"repositories,omitempty"`
- IncludePatterns string `json:"include-patterns,omitempty"`
- ExcludePatterns string `json:"exclude-patterns,omitempty"`
- ActionsUsers map[string]string `json:"actions-users,omitempty"`
- ActionsGroups map[string]string `json:"actions-groups,omitempty"`
-}
diff --git a/artifactory/commands/permissiontarget/update.go b/artifactory/commands/permissiontarget/update.go
deleted file mode 100644
index 79ece5097..000000000
--- a/artifactory/commands/permissiontarget/update.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package permissiontarget
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type PermissionTargetUpdateCommand struct {
- PermissionTargetCommand
-}
-
-func NewPermissionTargetUpdateCommand() *PermissionTargetUpdateCommand {
- return &PermissionTargetUpdateCommand{}
-}
-
-func (ptuc *PermissionTargetUpdateCommand) SetTemplatePath(path string) *PermissionTargetUpdateCommand {
- ptuc.templatePath = path
- return ptuc
-}
-
-func (ptuc *PermissionTargetUpdateCommand) SetVars(vars string) *PermissionTargetUpdateCommand {
- ptuc.vars = vars
- return ptuc
-}
-
-func (ptuc *PermissionTargetUpdateCommand) SetServerDetails(serverDetails *config.ServerDetails) *PermissionTargetUpdateCommand {
- ptuc.serverDetails = serverDetails
- return ptuc
-}
-
-func (ptuc *PermissionTargetUpdateCommand) ServerDetails() (*config.ServerDetails, error) {
- return ptuc.serverDetails, nil
-}
-
-func (ptuc *PermissionTargetUpdateCommand) CommandName() string {
- return "rt_permission_target_update"
-}
-
-func (ptuc *PermissionTargetUpdateCommand) Run() (err error) {
- return ptuc.PerformPermissionTargetCmd(true)
-}
diff --git a/artifactory/commands/python/dependencies/cache.go b/artifactory/commands/python/dependencies/cache.go
deleted file mode 100644
index 71b5dd215..000000000
--- a/artifactory/commands/python/dependencies/cache.go
+++ /dev/null
@@ -1,91 +0,0 @@
-package dependencies
-
-import (
- "encoding/json"
- buildinfo "github.com/jfrog/build-info-go/entities"
- ioutils "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "io"
- "os"
- "path/filepath"
-)
-
-const cacheLatestVersion = 1
-
-type DependenciesCache struct {
- Version int `json:"version,omitempty"`
- DepsMap map[string]buildinfo.Dependency `json:"dependencies,omitempty"`
-}
-
-// Reads the json cache file of recent used project's dependencies, and converts it into a map of
-// Key: dependency_name Value: dependency's struct with all relevant information.
-// If cache file does not exist -> return nil, nil.
-// If error occurred, return error.
-func GetProjectDependenciesCache(cacheDir string) (cache *DependenciesCache, err error) {
- cache = new(DependenciesCache)
- cacheFilePath, exists, err := getCacheFilePath(cacheDir)
- if errorutils.CheckError(err) != nil || !exists {
- return nil, err
- }
- jsonFile, err := os.Open(cacheFilePath)
- if errorutils.CheckError(err) != nil {
- return nil, err
- }
- defer ioutils.Close(jsonFile, &err)
- byteValue, err := io.ReadAll(jsonFile)
- if errorutils.CheckError(err) != nil {
- return nil, err
- }
- err = json.Unmarshal(byteValue, cache)
- if errorutils.CheckError(err) != nil {
- return nil, err
- }
- return
-}
-
-// Receives map of all current project's dependencies information.
-// The map contains the dependencies retrieved from Artifactory as well as those read from cache.
-// Writes the updated project's dependencies cache with all current dependencies.
-func UpdateDependenciesCache(updatedMap map[string]buildinfo.Dependency, cacheDir string) (err error) {
- updatedCache := DependenciesCache{Version: cacheLatestVersion, DepsMap: updatedMap}
- content, err := json.Marshal(&updatedCache)
- if err != nil {
- return errorutils.CheckError(err)
- }
- cacheFilePath, _, err := getCacheFilePath(cacheDir)
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- cacheFile, err := os.Create(cacheFilePath)
- if err != nil {
- return errorutils.CheckError(err)
- }
- defer ioutils.Close(cacheFile, &err)
- _, err = cacheFile.Write(content)
- if err != nil {
- return errorutils.CheckError(err)
- }
- return
-}
-
-// Return required dependency from cache.
-// If dependency does not exist, return nil.
-// dependencyName - Name of dependency (lowercase package name).
-func (cache DependenciesCache) GetDependency(dependencyName string) (dependency buildinfo.Dependency) {
- dependency = cache.DepsMap[dependencyName]
- return
-}
-
-// Cache file will be located in the ./.jfrog/projects/deps.cache.json
-func getCacheFilePath(cacheDir string) (cacheFilePath string, exists bool, err error) {
- projectsDirPath := filepath.Join(cacheDir, ".jfrog", "projects")
- err = fileutils.CreateDirIfNotExist(projectsDirPath)
- if err != nil {
- return
- }
- cacheFilePath = filepath.Join(projectsDirPath, "deps.cache.json")
- exists, err = fileutils.IsFileExists(cacheFilePath, false)
- return
-}
diff --git a/artifactory/commands/python/dependencies/cache_test.go b/artifactory/commands/python/dependencies/cache_test.go
deleted file mode 100644
index 0d13e066d..000000000
--- a/artifactory/commands/python/dependencies/cache_test.go
+++ /dev/null
@@ -1,101 +0,0 @@
-package dependencies
-
-import (
- "errors"
- buildinfo "github.com/jfrog/build-info-go/entities"
- testsutils "github.com/jfrog/jfrog-client-go/utils/tests"
- "github.com/stretchr/testify/assert"
- "os"
- "path/filepath"
- "reflect"
- "testing"
-)
-
-func TestDependenciesCache(t *testing.T) {
- // Change test's work directory, rollback after function returns.
-
- tmpTestPath := filepath.Join(os.TempDir(), "cacheTest")
- err := os.MkdirAll(tmpTestPath, os.ModePerm)
- if err != nil {
- t.Error("Failed mkDirAll: " + err.Error())
- }
- wd, err := os.Getwd()
- assert.NoError(t, err, "Failed to get current dir")
- chdirCallback := testsutils.ChangeDirWithCallback(t, wd, tmpTestPath)
- defer func() {
- chdirCallback()
- testsutils.RemoveAllAndAssert(t, tmpTestPath)
- }()
-
- cacheMap := make(map[string]buildinfo.Dependency)
- csA := buildinfo.Checksum{Sha1: "sha1A", Md5: "md5A"}
- depenA := buildinfo.Dependency{
- Id: "depenA-1.0-A.zip",
- Checksum: csA,
- }
- cacheMap["A"] = depenA
- csC := buildinfo.Checksum{Sha1: "sha1C", Md5: "md5C"}
- depenC := buildinfo.Dependency{
- Id: "depenC-3.4-C.gzip",
- Checksum: csC,
- }
- cacheMap["C"] = depenC
- err = UpdateDependenciesCache(cacheMap, tmpTestPath)
- if err != nil {
- t.Error("Failed creating dependencies cache: " + err.Error())
- }
- cache, err := readCacheAndCheckError(tmpTestPath)
- if err != nil {
- t.Error("Failed reading dependencies cache: " + err.Error())
- }
-
- if !reflect.DeepEqual(cache.GetDependency("A"), depenA) {
- t.Error("Failed retrieving dependency A!!!")
- }
- if cache.GetDependency("B").Id != "" {
- t.Error("Retrieving non-existing dependency B should return nil.")
- }
- if !reflect.DeepEqual(cache.GetDependency("C"), depenC) {
- t.Error("Failed retrieving dependency C!!!")
- }
- if cache.GetDependency("T").Id != "" {
- t.Error("Retrieving non-existing dependency T should return nil checksum.")
- }
-
- delete(cacheMap, "A")
- csT := buildinfo.Checksum{Sha1: "sha1T", Md5: "md5T"}
- depenT := buildinfo.Dependency{
- Id: "depenT-6.0.68-T.zip",
- Checksum: csT,
- }
- cacheMap["T"] = depenT
- err = UpdateDependenciesCache(cacheMap, tmpTestPath)
- if err != nil {
- t.Error("Failed creating dependencies cache: " + err.Error())
- }
-
- cache, err = readCacheAndCheckError(tmpTestPath)
- if err != nil {
- t.Error("Failed reading dependencies cache: " + err.Error())
- }
- if cache.GetDependency("A").Id != "" {
- t.Error("Retrieving non-existing dependency T should return nil checksum.")
- }
- if !reflect.DeepEqual(cache.GetDependency("T"), depenT) {
- t.Error("Failed retrieving dependency T.")
- }
- if !reflect.DeepEqual(cache.GetDependency("C"), depenC) {
- t.Error("Failed retrieving dependency C.")
- }
-}
-
-func readCacheAndCheckError(cacheDir string) (cache *DependenciesCache, err error) {
- cache, err = GetProjectDependenciesCache(cacheDir)
- if err != nil {
- return
- }
- if cache == nil {
- err = errors.New("Cache file does not exist.")
- }
- return
-}
diff --git a/artifactory/commands/python/dependencies/dependencies.go b/artifactory/commands/python/dependencies/dependencies.go
deleted file mode 100644
index 142855d7c..000000000
--- a/artifactory/commands/python/dependencies/dependencies.go
+++ /dev/null
@@ -1,142 +0,0 @@
-package dependencies
-
-import (
- "encoding/json"
- "fmt"
- ioutils "github.com/jfrog/gofrog/io"
- "io"
- "strings"
-
- buildinfo "github.com/jfrog/build-info-go/entities"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-client-go/artifactory"
- serviceutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-// Populate project's dependencies with checksums and file names.
-// If the dependency was downloaded in this pip-install execution, checksum will be fetched from Artifactory.
-// Otherwise, check if exists in cache.
-// Return dependency-names of all dependencies which its information could not be obtained.
-func UpdateDepsChecksumInfo(dependenciesMap map[string]buildinfo.Dependency, srcPath string, servicesManager artifactory.ArtifactoryServicesManager, repository string) error {
- dependenciesCache, err := GetProjectDependenciesCache(srcPath)
- if err != nil {
- return err
- }
-
- var missingDeps []string
- // Iterate dependencies map to update info.
- for depName, depInfo := range dependenciesMap {
- // Get dependency info.
- depFileName, depChecksum, err := getDependencyInfo(depName, repository, dependenciesCache, depInfo.Id, servicesManager)
- if err != nil {
- return err
- }
-
- // Check if info not found.
- if depFileName == "" || depChecksum.IsEmpty() {
- // Dependency either wasn't downloaded in this run nor stored in cache.
- missingDeps = append(missingDeps, depName)
- // dependenciesMap should contain only dependencies with checksums.
- delete(dependenciesMap, depName)
-
- continue
- }
- depInfo.Checksum = depChecksum
- dependenciesMap[depName] = depInfo
- }
-
- promptMissingDependencies(missingDeps)
-
- err = UpdateDependenciesCache(dependenciesMap, srcPath)
- if err != nil {
- return err
- }
- return nil
-}
-
-// Get dependency information.
-// If dependency was downloaded in this pip-install execution, fetch info from Artifactory.
-// Otherwise, fetch info from cache.
-func getDependencyInfo(depName, repository string, dependenciesCache *DependenciesCache, depFileName string, servicesManager artifactory.ArtifactoryServicesManager) (string, buildinfo.Checksum, error) {
- // Check if this dependency was updated during this pip-install execution, and we have its file-name.
- // If updated - fetch checksum from Artifactory, regardless of what was previously stored in cache.
-
- if dependenciesCache != nil {
- depFromCache := dependenciesCache.GetDependency(depName)
- if depFromCache.Id != "" {
- // Cached dependencies are used in the following cases:
- // 1. When file name is empty and therefore the dependency is cached
- // 2. When file name is identical to the cached file name
- if depFileName == "" || depFileName == depFromCache.Id {
- // The checksum was found in cache - the info is returned.
- return depFromCache.Id, depFromCache.Checksum, nil
- }
- }
- }
-
- if depFileName != "" {
- checksum, err := getDependencyChecksumFromArtifactory(servicesManager, repository, depFileName)
- return depFileName, checksum, err
- }
-
- return "", buildinfo.Checksum{}, nil
-}
-
-// Fetch checksum for file from Artifactory.
-// If the file isn't found, or md5 or sha1 are missing, return nil.
-func getDependencyChecksumFromArtifactory(servicesManager artifactory.ArtifactoryServicesManager, repository, dependencyFile string) (checksum buildinfo.Checksum, err error) {
- log.Debug(fmt.Sprintf("Fetching checksums for: %s", dependencyFile))
- repository, err = utils.GetRepoNameForDependenciesSearch(repository, servicesManager)
- if err != nil {
- return
- }
- stream, err := servicesManager.Aql(serviceutils.CreateAqlQueryForPypi(repository, dependencyFile))
- if err != nil {
- return
- }
- defer ioutils.Close(stream, &err)
- result, err := io.ReadAll(stream)
- if err != nil {
- return
- }
- parsedResult := new(aqlResult)
- err = json.Unmarshal(result, parsedResult)
- if err = errorutils.CheckError(err); err != nil {
- return
- }
- if len(parsedResult.Results) == 0 {
- log.Debug(fmt.Sprintf("File: %s could not be found in repository: %s", dependencyFile, repository))
- return
- }
-
- // Verify checksum exist.
- sha256 := parsedResult.Results[0].Sha256
- sha1 := parsedResult.Results[0].Actual_Sha1
- md5 := parsedResult.Results[0].Actual_Md5
- if sha1 == "" || md5 == "" {
- // Missing checksum.
- log.Debug(fmt.Sprintf("Missing checksums for file: %s, sha256: '%s', sha1: '%s', md5: '%s'", dependencyFile, sha256, sha1, md5))
- return
- }
-
- // Update checksum.
- checksum = buildinfo.Checksum{Sha256: sha256, Sha1: sha1, Md5: md5}
- log.Debug(fmt.Sprintf("Found checksums for file: %s, sha256: '%s', sha1: '%s', md5: '%s'", dependencyFile, sha256, sha1, md5))
-
- return
-}
-
-func promptMissingDependencies(missingDeps []string) {
- if len(missingDeps) > 0 {
- log.Warn(strings.Join(missingDeps, "\n"))
- log.Warn("The pypi packages above could not be found in Artifactory or were not downloaded in this execution, therefore they are not included in the build-info.\n" +
- "Reinstalling in clean environment or using '--no-cache-dir' and '--force-reinstall' flags (in one execution only), will force downloading and populating Artifactory with these packages, and therefore resolve the issue.")
- }
-}
-
-type aqlResult struct {
- Results []*serviceutils.ResultItem `json:"results,omitempty"`
-}
diff --git a/artifactory/commands/python/pip.go b/artifactory/commands/python/pip.go
deleted file mode 100644
index ca6ac8dee..000000000
--- a/artifactory/commands/python/pip.go
+++ /dev/null
@@ -1,92 +0,0 @@
-package python
-
-import (
- "fmt"
- "io"
- "os"
- "os/exec"
- "path/filepath"
-
- "github.com/jfrog/build-info-go/entities"
- "github.com/jfrog/build-info-go/utils/pythonutils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/python/dependencies"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type PipCommand struct {
- PythonCommand
-}
-
-func NewPipCommand() *PipCommand {
- return &PipCommand{PythonCommand: *NewPythonCommand(pythonutils.Pip)}
-}
-
-func (pc *PipCommand) Run() (err error) {
- return pc.PythonCommand.Run()
-}
-
-func (pc *PipCommand) UpdateDepsChecksumInfoFunc(dependenciesMap map[string]entities.Dependency, srcPath string) error {
- servicesManager, err := utils.CreateServiceManager(pc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- return dependencies.UpdateDepsChecksumInfo(dependenciesMap, srcPath, servicesManager, pc.repository)
-}
-
-func (pc *PipCommand) SetRepo(repo string) *PipCommand {
- pc.PythonCommand.SetRepo(repo)
- return pc
-}
-
-func (pc *PipCommand) SetArgs(arguments []string) *PipCommand {
- pc.PythonCommand.SetArgs(arguments)
- return pc
-}
-
-func (pc *PipCommand) SetCommandName(commandName string) *PipCommand {
- pc.PythonCommand.SetCommandName(commandName)
- return pc
-}
-
-func CreatePipConfigManually(customPipConfigPath, repoWithCredsUrl string) error {
- if err := os.MkdirAll(filepath.Dir(customPipConfigPath), os.ModePerm); err != nil {
- return err
- }
- // Write the configuration to pip.conf.
- configContent := fmt.Sprintf("[global]\nindex-url = %s\n", repoWithCredsUrl)
- return os.WriteFile(customPipConfigPath, []byte(configContent), 0644)
-}
-
-func (pc *PipCommand) CommandName() string {
- return "rt_python_pip"
-}
-
-func (pc *PipCommand) SetServerDetails(serverDetails *config.ServerDetails) *PipCommand {
- pc.PythonCommand.SetServerDetails(serverDetails)
- return pc
-}
-
-func (pc *PipCommand) ServerDetails() (*config.ServerDetails, error) {
- return pc.serverDetails, nil
-}
-
-func (pc *PipCommand) GetCmd() *exec.Cmd {
- var cmd []string
- cmd = append(cmd, string(pc.pythonTool))
- cmd = append(cmd, pc.commandName)
- cmd = append(cmd, pc.args...)
- return exec.Command(cmd[0], cmd[1:]...)
-}
-
-func (pc *PipCommand) GetEnv() map[string]string {
- return map[string]string{}
-}
-
-func (pc *PipCommand) GetStdWriter() io.WriteCloser {
- return nil
-}
-
-func (pc *PipCommand) GetErrWriter() io.WriteCloser {
- return nil
-}
diff --git a/artifactory/commands/python/pip_test.go b/artifactory/commands/python/pip_test.go
deleted file mode 100644
index 92079ada6..000000000
--- a/artifactory/commands/python/pip_test.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package python
-
-import (
- "github.com/stretchr/testify/assert"
- "os"
- "path/filepath"
- "testing"
-)
-
-func TestCreatePipConfigManually(t *testing.T) {
- // Define the test parameters
- customConfigPath := filepath.Join(t.TempDir(), "/tmp/test/pip.conf")
- // #nosec G101 -- False positive - no hardcoded credentials.
- repoWithCredsUrl := "https://example.com/simple/"
- expectedContent := "[global]\nindex-url = https://example.com/simple/\n"
-
- // Call the function under test
- err := CreatePipConfigManually(customConfigPath, repoWithCredsUrl)
-
- // Assert no error occurred
- assert.NoError(t, err)
-
- // Verify the file exists and has the correct content
- fileContent, err := os.ReadFile(customConfigPath)
- assert.NoError(t, err)
- assert.Equal(t, expectedContent, string(fileContent))
-}
diff --git a/artifactory/commands/python/pipenv.go b/artifactory/commands/python/pipenv.go
deleted file mode 100644
index 54fd9d116..000000000
--- a/artifactory/commands/python/pipenv.go
+++ /dev/null
@@ -1,80 +0,0 @@
-package python
-
-import (
- "io"
- "os/exec"
-
- "github.com/jfrog/build-info-go/entities"
- "github.com/jfrog/build-info-go/utils/pythonutils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/python/dependencies"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type PipenvCommand struct {
- PythonCommand
-}
-
-func NewPipenvCommand() *PipenvCommand {
- return &PipenvCommand{PythonCommand: PythonCommand{pythonTool: pythonutils.Pipenv}}
-}
-
-func (pc *PipenvCommand) Run() (err error) {
- return pc.PythonCommand.Run()
-}
-
-func (pc *PipenvCommand) UpdateDepsChecksumInfoFunc(dependenciesMap map[string]entities.Dependency, srcPath string) error {
- servicesManager, err := utils.CreateServiceManager(pc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- return dependencies.UpdateDepsChecksumInfo(dependenciesMap, srcPath, servicesManager, pc.repository)
-}
-
-func (pc *PipenvCommand) SetRepo(repo string) *PipenvCommand {
- pc.PythonCommand.SetRepo(repo)
- return pc
-}
-
-func (pc *PipenvCommand) SetArgs(arguments []string) *PipenvCommand {
- pc.PythonCommand.SetArgs(arguments)
- return pc
-}
-
-func (pc *PipenvCommand) SetCommandName(commandName string) *PipenvCommand {
- pc.PythonCommand.SetCommandName(commandName)
- return pc
-}
-
-func (pc *PipenvCommand) CommandName() string {
- return "rt_python_pipenv"
-}
-
-func (pc *PipenvCommand) SetServerDetails(serverDetails *config.ServerDetails) *PipenvCommand {
- pc.PythonCommand.SetServerDetails(serverDetails)
- return pc
-}
-
-func (pc *PipenvCommand) ServerDetails() (*config.ServerDetails, error) {
- return pc.serverDetails, nil
-}
-
-func (pc *PipenvCommand) GetCmd() *exec.Cmd {
- var cmd []string
- cmd = append(cmd, string(pc.pythonTool))
- cmd = append(cmd, pc.commandName)
- cmd = append(cmd, pc.args...)
- return exec.Command(cmd[0], cmd[1:]...)
-}
-
-func (pc *PipenvCommand) GetEnv() map[string]string {
- return map[string]string{}
-}
-
-func (pc *PipenvCommand) GetStdWriter() io.WriteCloser {
- return nil
-}
-
-func (pc *PipenvCommand) GetErrWriter() io.WriteCloser {
- return nil
-}
diff --git a/artifactory/commands/python/poetry.go b/artifactory/commands/python/poetry.go
deleted file mode 100644
index ec362653e..000000000
--- a/artifactory/commands/python/poetry.go
+++ /dev/null
@@ -1,233 +0,0 @@
-package python
-
-import (
- "errors"
- "fmt"
- "github.com/jfrog/build-info-go/build"
- "github.com/jfrog/build-info-go/entities"
- "github.com/jfrog/build-info-go/utils/pythonutils"
- gofrogcmd "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/python/dependencies"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "github.com/spf13/viper"
- "golang.org/x/exp/slices"
- "io"
- "os"
- "os/exec"
- "path/filepath"
-)
-
-const (
- poetryConfigAuthPrefix = "http-basic."
- poetryConfigRepoPrefix = "repositories."
- pyproject = "pyproject.toml"
-)
-
-type PoetryCommand struct {
- PythonCommand
-}
-
-func NewPoetryCommand() *PoetryCommand {
- return &PoetryCommand{
- PythonCommand: *NewPythonCommand(pythonutils.Poetry),
- }
-}
-
-func (pc *PoetryCommand) Run() (err error) {
- log.Info(fmt.Sprintf("Running Poetry %s.", pc.commandName))
- var buildConfiguration *buildUtils.BuildConfiguration
- pc.args, buildConfiguration, err = buildUtils.ExtractBuildDetailsFromArgs(pc.args)
- if err != nil {
- return err
- }
- pythonBuildInfo, err := buildUtils.PrepareBuildPrerequisites(buildConfiguration)
- if err != nil {
- return
- }
- defer func() {
- if pythonBuildInfo != nil && err != nil {
- err = errors.Join(err, pythonBuildInfo.Clean())
- }
- }()
- err = pc.SetPypiRepoUrlWithCredentials()
- if err != nil {
- return err
- }
- if pythonBuildInfo != nil {
- switch pc.commandName {
- case "install":
- return pc.install(buildConfiguration, pythonBuildInfo)
- case "publish":
- return pc.publish(buildConfiguration, pythonBuildInfo)
- default:
- // poetry native command
- return gofrogcmd.RunCmd(pc)
-
- }
- }
- return gofrogcmd.RunCmd(pc)
-}
-
-func (pc *PoetryCommand) install(buildConfiguration *buildUtils.BuildConfiguration, pythonBuildInfo *build.Build) (err error) {
- var pythonModule *build.PythonModule
- pythonModule, err = pythonBuildInfo.AddPythonModule("", pc.pythonTool)
- if err != nil {
- return
- }
- if buildConfiguration.GetModule() != "" {
- pythonModule.SetName(buildConfiguration.GetModule())
- }
- var localDependenciesPath string
- localDependenciesPath, err = config.GetJfrogDependenciesPath()
- if err != nil {
- return
- }
- pythonModule.SetLocalDependenciesPath(localDependenciesPath)
- pythonModule.SetUpdateDepsChecksumInfoFunc(pc.UpdateDepsChecksumInfoFunc)
-
- return errorutils.CheckError(pythonModule.RunInstallAndCollectDependencies(pc.args))
-}
-
-func (pc *PoetryCommand) publish(buildConfiguration *buildUtils.BuildConfiguration, pythonBuildInfo *build.Build) error {
- publishCmdArgs := append(slices.Clone(pc.args), "-r "+pc.repository)
- // Collect build info by running the jf poetry install cmd
- pc.args = []string{}
- err := pc.install(buildConfiguration, pythonBuildInfo)
- if err != nil {
- return err
- }
- // Run the publish cmd
- pc.args = publishCmdArgs
- return gofrogcmd.RunCmd(pc)
-}
-
-func (pc *PoetryCommand) UpdateDepsChecksumInfoFunc(dependenciesMap map[string]entities.Dependency, srcPath string) error {
- servicesManager, err := utils.CreateServiceManager(pc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- return dependencies.UpdateDepsChecksumInfo(dependenciesMap, srcPath, servicesManager, pc.repository)
-}
-
-func (pc *PoetryCommand) SetRepo(repo string) *PoetryCommand {
- pc.repository = repo
- return pc
-}
-
-func (pc *PoetryCommand) SetArgs(arguments []string) *PoetryCommand {
- pc.args = arguments
- return pc
-}
-
-func (pc *PoetryCommand) SetCommandName(commandName string) *PoetryCommand {
- pc.commandName = commandName
- return pc
-}
-
-func (pc *PoetryCommand) SetPypiRepoUrlWithCredentials() error {
- rtUrl, username, password, err := GetPypiRepoUrlWithCredentials(pc.serverDetails, pc.repository, false)
- if err != nil {
- return err
- }
- if password != "" {
- return ConfigPoetryRepo(
- rtUrl.Scheme+"://"+rtUrl.Host+rtUrl.Path,
- username,
- password,
- pc.repository)
- }
- return nil
-}
-
-func ConfigPoetryRepo(url, username, password, configRepoName string) error {
- err := RunPoetryConfig(url, username, password, configRepoName)
- if err != nil {
- return err
- }
-
- // Add the repository config to the pyproject.toml
- currentDir, err := os.Getwd()
- if err != nil {
- return errorutils.CheckError(err)
- }
- if err = addRepoToPyprojectFile(filepath.Join(currentDir, pyproject), configRepoName, url); err != nil {
- return err
- }
- return poetryUpdate()
-}
-
-func RunPoetryConfig(url, username, password, configRepoName string) error {
- // Add the poetry repository config
- // poetry config repositories. https:///artifactory/api/pypi//simple
- err := RunConfigCommand(project.Poetry, []string{poetryConfigRepoPrefix + configRepoName, url})
- if err != nil {
- return err
- }
-
- // Set the poetry repository credentials
- // poetry config http-basic.
- return RunConfigCommand(project.Poetry, []string{poetryConfigAuthPrefix + configRepoName, username, password})
-}
-
-func poetryUpdate() (err error) {
- log.Info("Running Poetry update")
- cmd := gofrogcmd.NewCommand("poetry", "update", []string{})
- err = gofrogcmd.RunCmd(cmd)
- if err != nil {
- return errorutils.CheckErrorf("Poetry config command failed with: %s", err.Error())
- }
- return
-}
-
-func addRepoToPyprojectFile(filepath, poetryRepoName, repoUrl string) error {
- viper.SetConfigType("toml")
- viper.SetConfigFile(filepath)
- if err := viper.ReadInConfig(); err != nil {
- return errorutils.CheckErrorf("Failed to read pyproject.toml: %s", err.Error())
- }
- viper.Set("tool.poetry.source", []map[string]string{{"name": poetryRepoName, "url": repoUrl}})
- if err := viper.WriteConfig(); err != nil {
- return errorutils.CheckErrorf("Failed to add tool.poetry.source to pyproject.toml: %s", err.Error())
-
- }
- log.Info(fmt.Sprintf("Added tool.poetry.source name:%q url:%q", poetryRepoName, repoUrl))
- return nil
-}
-
-func (pc *PoetryCommand) CommandName() string {
- return "rt_python_poetry"
-}
-
-func (pc *PoetryCommand) SetServerDetails(serverDetails *config.ServerDetails) *PoetryCommand {
- pc.serverDetails = serverDetails
- return pc
-}
-
-func (pc *PoetryCommand) ServerDetails() (*config.ServerDetails, error) {
- return pc.serverDetails, nil
-}
-
-func (pc *PoetryCommand) GetCmd() *exec.Cmd {
- var cmd []string
- cmd = append(cmd, string(pc.pythonTool))
- cmd = append(cmd, pc.commandName)
- cmd = append(cmd, pc.args...)
- return exec.Command(cmd[0], cmd[1:]...)
-}
-
-func (pc *PoetryCommand) GetEnv() map[string]string {
- return map[string]string{}
-}
-
-func (pc *PoetryCommand) GetStdWriter() io.WriteCloser {
- return nil
-}
-
-func (pc *PoetryCommand) GetErrWriter() io.WriteCloser {
- return nil
-}
diff --git a/artifactory/commands/python/poetry_test.go b/artifactory/commands/python/poetry_test.go
deleted file mode 100644
index 48cd16cd8..000000000
--- a/artifactory/commands/python/poetry_test.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package python
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
- "github.com/stretchr/testify/assert"
- "path/filepath"
- "testing"
-)
-
-func TestAddRepoToPyprojectFile(t *testing.T) {
- poetryProjectPath, cleanUp := initPoetryTest(t)
- defer cleanUp()
- pyProjectPath := filepath.Join(poetryProjectPath, "pyproject.toml")
- dummyRepoName := "test-repo-name"
- dummyRepoURL := "https://ecosysjfrog.jfrog.io/"
-
- err := addRepoToPyprojectFile(pyProjectPath, dummyRepoName, dummyRepoURL)
- assert.NoError(t, err)
- // Validate pyproject.toml file content
- content, err := fileutils.ReadFile(pyProjectPath)
- assert.NoError(t, err)
- assert.Contains(t, string(content), dummyRepoURL)
-}
-
-func initPoetryTest(t *testing.T) (string, func()) {
- // Create and change directory to test workspace
- testAbs, err := filepath.Abs(filepath.Join("..", "..", "..", "tests", "testdata", "poetry-project"))
- assert.NoError(t, err)
- poetryProjectPath, cleanUp := tests.CreateTestWorkspace(t, testAbs)
- return poetryProjectPath, cleanUp
-}
diff --git a/artifactory/commands/python/python.go b/artifactory/commands/python/python.go
deleted file mode 100644
index 3a2a94709..000000000
--- a/artifactory/commands/python/python.go
+++ /dev/null
@@ -1,217 +0,0 @@
-package python
-
-import (
- "bytes"
- "errors"
- "github.com/jfrog/build-info-go/build"
- "github.com/jfrog/build-info-go/entities"
- buildInfoUtils "github.com/jfrog/build-info-go/utils"
- "github.com/jfrog/build-info-go/utils/pythonutils"
- gofrogcmd "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/python/dependencies"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/auth"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "io"
- "net/url"
- "os"
- "os/exec"
-)
-
-const (
- pipenvRemoteRegistryFlag = "--pypi-mirror"
- pipRemoteRegistryFlag = "-i"
-)
-
-type PythonCommand struct {
- serverDetails *config.ServerDetails
- pythonTool pythonutils.PythonTool
- commandName string
- args []string
- repository string
-}
-
-func NewPythonCommand(pythonTool pythonutils.PythonTool) *PythonCommand {
- return &PythonCommand{pythonTool: pythonTool}
-}
-
-func (pc *PythonCommand) Run() (err error) {
- log.Info("Running", string(pc.pythonTool), pc.commandName)
- var buildConfiguration *buildUtils.BuildConfiguration
- pc.args, buildConfiguration, err = buildUtils.ExtractBuildDetailsFromArgs(pc.args)
- if err != nil {
- return
- }
- pythonBuildInfo, err := buildUtils.PrepareBuildPrerequisites(buildConfiguration)
- if err != nil {
- return
- }
- defer func() {
- if pythonBuildInfo != nil && err != nil {
- err = errors.Join(err, pythonBuildInfo.Clean())
- }
- }()
- err = pc.SetPypiRepoUrlWithCredentials()
- if err != nil {
- return
- }
-
- if pythonBuildInfo != nil && pc.commandName == "install" {
- // Need to collect build info
- var pythonModule *build.PythonModule
- pythonModule, err = pythonBuildInfo.AddPythonModule("", pc.pythonTool)
- if err != nil {
- return
- }
- if buildConfiguration.GetModule() != "" {
- pythonModule.SetName(buildConfiguration.GetModule())
- }
- var localDependenciesPath string
- localDependenciesPath, err = config.GetJfrogDependenciesPath()
- if err != nil {
- return
- }
- pythonModule.SetLocalDependenciesPath(localDependenciesPath)
- pythonModule.SetUpdateDepsChecksumInfoFunc(pc.UpdateDepsChecksumInfoFunc)
- err = errorutils.CheckError(pythonModule.RunInstallAndCollectDependencies(pc.args))
- } else {
- // Python native command
- for k, v := range pc.GetEnv() {
- if err := os.Setenv(k, v); err != nil {
- return err
- }
- }
-
- cmd := pc.GetCmd()
- errBuffer := bytes.NewBuffer([]byte{})
- multiWriter := io.MultiWriter(os.Stderr, errBuffer)
- cmd.Stderr = multiWriter
- cmd.Stdout = os.Stdout
-
- err = cmd.Run()
- if err != nil {
- if buildInfoUtils.IsForbiddenOutput(buildInfoUtils.Pip, errBuffer.String()) {
- err = errors.Join(err, buildInfoUtils.NewForbiddenError())
- }
- }
- }
- return
-}
-
-func (pc *PythonCommand) UpdateDepsChecksumInfoFunc(dependenciesMap map[string]entities.Dependency, srcPath string) error {
- servicesManager, err := utils.CreateServiceManager(pc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- return dependencies.UpdateDepsChecksumInfo(dependenciesMap, srcPath, servicesManager, pc.repository)
-}
-
-func (pc *PythonCommand) SetRepo(repo string) *PythonCommand {
- pc.repository = repo
- return pc
-}
-
-func (pc *PythonCommand) SetArgs(arguments []string) *PythonCommand {
- pc.args = arguments
- return pc
-}
-
-func (pc *PythonCommand) SetCommandName(commandName string) *PythonCommand {
- pc.commandName = commandName
- return pc
-}
-
-func (pc *PythonCommand) SetPypiRepoUrlWithCredentials() error {
- rtUrl, err := GetPypiRepoUrl(pc.serverDetails, pc.repository, false)
- if err != nil {
- return err
- }
- pc.args = append(pc.args, GetPypiRemoteRegistryFlag(pc.pythonTool), rtUrl)
- return nil
-}
-
-// Get the pypi repository url and the credentials.
-func GetPypiRepoUrlWithCredentials(serverDetails *config.ServerDetails, repository string, isCurationCmd bool) (*url.URL, string, string, error) {
- rtUrl, err := url.Parse(serverDetails.GetArtifactoryUrl())
- if err != nil {
- return nil, "", "", errorutils.CheckError(err)
- }
-
- username := serverDetails.GetUser()
- password := serverDetails.GetPassword()
-
- // Get credentials from access-token if exists.
- if serverDetails.GetAccessToken() != "" {
- if username == "" {
- username = auth.ExtractUsernameFromAccessToken(serverDetails.GetAccessToken())
- }
- password = serverDetails.GetAccessToken()
- }
- if isCurationCmd {
- rtUrl = rtUrl.JoinPath(coreutils.CurationPassThroughApi)
- }
- rtUrl = rtUrl.JoinPath("api/pypi", repository, "simple")
- return rtUrl, username, password, err
-}
-
-func GetPypiRemoteRegistryFlag(tool pythonutils.PythonTool) string {
- if tool == pythonutils.Pip {
- return pipRemoteRegistryFlag
- }
- return pipenvRemoteRegistryFlag
-}
-
-// Get the pypi repository embedded credentials URL (https://:@/artifactory/api/pypi//simple)
-func GetPypiRepoUrl(serverDetails *config.ServerDetails, repository string, isCurationCmd bool) (string, error) {
- rtUrl, username, password, err := GetPypiRepoUrlWithCredentials(serverDetails, repository, isCurationCmd)
- if err != nil {
- return "", err
- }
- if password != "" {
- rtUrl.User = url.UserPassword(username, password)
- }
- return rtUrl.String(), err
-}
-
-func RunConfigCommand(buildTool project.ProjectType, args []string) error {
- log.Debug("Running", buildTool.String(), "config command...")
- configCmd := gofrogcmd.NewCommand(buildTool.String(), "config", args)
- if err := gofrogcmd.RunCmd(configCmd); err != nil {
- return errorutils.CheckErrorf("%s config command failed with: %q", buildTool.String(), err)
- }
- return nil
-}
-
-func (pc *PythonCommand) SetServerDetails(serverDetails *config.ServerDetails) *PythonCommand {
- pc.serverDetails = serverDetails
- return pc
-}
-
-func (pc *PythonCommand) ServerDetails() (*config.ServerDetails, error) {
- return pc.serverDetails, nil
-}
-
-func (pc *PythonCommand) GetCmd() *exec.Cmd {
- var cmd []string
- cmd = append(cmd, string(pc.pythonTool))
- cmd = append(cmd, pc.commandName)
- cmd = append(cmd, pc.args...)
- return exec.Command(cmd[0], cmd[1:]...)
-}
-
-func (pc *PythonCommand) GetEnv() map[string]string {
- return map[string]string{}
-}
-
-func (pc *PythonCommand) GetStdWriter() io.WriteCloser {
- return nil
-}
-
-func (pc *PythonCommand) GetErrWriter() io.WriteCloser {
- return nil
-}
diff --git a/artifactory/commands/python/python_test.go b/artifactory/commands/python/python_test.go
deleted file mode 100644
index 18666ce45..000000000
--- a/artifactory/commands/python/python_test.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package python
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "strings"
- "testing"
-)
-
-func TestGetPypiRepoUrlWithCredentials(t *testing.T) {
- testCases := []struct {
- name string
- curationCmd bool
- }{
- {
- name: "test curation command true",
- curationCmd: true,
- },
- {
- name: "test curation command false",
- curationCmd: false,
- },
- }
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- url, _, _, err := GetPypiRepoUrlWithCredentials(&config.ServerDetails{}, "test", testCase.curationCmd)
- require.NoError(t, err)
- assert.Equal(t, testCase.curationCmd, strings.Contains(url.Path, coreutils.CurationPassThroughApi))
- })
- }
-}
diff --git a/artifactory/commands/python/twine.go b/artifactory/commands/python/twine.go
deleted file mode 100644
index 6cb70469b..000000000
--- a/artifactory/commands/python/twine.go
+++ /dev/null
@@ -1,195 +0,0 @@
-package python
-
-import (
- "errors"
- "fmt"
- "github.com/jfrog/build-info-go/build"
- "github.com/jfrog/build-info-go/utils/pythonutils"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/auth"
- "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "os"
- "os/exec"
- "strings"
-)
-
-const (
- _configFileOptionKey = "--config-file"
- _repositoryUrlOptionKey = "--repository-url"
- _usernameOptionKey = "--username"
- _passwordOptionKey = "--password"
- _usernamePrefixOptionKey = "-u"
- _passwordPrefixOptionKey = "-p"
- _repositoryUrlEnvKey = "TWINE_REPOSITORY_URL"
- _usernameEnvKey = "TWINE_USERNAME"
- _passwordEnvKey = "TWINE_PASSWORD"
- // Artifactory endpoint for pypi deployment.
- _apiPypi = "api/pypi/"
- _twineExecName = "twine"
- _uploadCmdName = "upload"
-)
-
-var twineRepoConfigFlags = []string{_configFileOptionKey, _repositoryUrlOptionKey, _usernameOptionKey, _passwordOptionKey, _usernamePrefixOptionKey, _passwordPrefixOptionKey}
-
-type TwineCommand struct {
- serverDetails *config.ServerDetails
- commandName string
- args []string
- targetRepo string
- buildConfiguration *buildUtils.BuildConfiguration
-}
-
-func NewTwineCommand(commandName string) *TwineCommand {
- return &TwineCommand{
- commandName: commandName,
- }
-}
-
-func (tc *TwineCommand) CommandName() string {
- return "twine_" + tc.commandName
-}
-
-func (tc *TwineCommand) ServerDetails() (*config.ServerDetails, error) {
- return tc.serverDetails, nil
-}
-
-func (tc *TwineCommand) SetServerDetails(serverDetails *config.ServerDetails) *TwineCommand {
- tc.serverDetails = serverDetails
- return tc
-}
-
-func (tc *TwineCommand) SetTargetRepo(targetRepo string) *TwineCommand {
- tc.targetRepo = targetRepo
- return tc
-}
-
-func (tc *TwineCommand) SetArgs(args []string) *TwineCommand {
- tc.args = args
- return tc
-}
-
-func (tc *TwineCommand) Run() (err error) {
- // Assert no forbidden flags were provided.
- if tc.isRepoConfigFlagProvided() {
- return errorutils.CheckErrorf(tc.getRepoConfigFlagProvidedErr())
- }
- if err = tc.extractAndFilterArgs(tc.args); err != nil {
- return err
- }
- callbackFunc, err := tc.setAuthEnvVars()
- defer func() {
- err = errors.Join(err, callbackFunc())
- }()
-
- collectBuild, err := tc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
- // If build info is not collected, or this is not an upload command, run the twine command directly.
- if !collectBuild || tc.commandName != _uploadCmdName {
- return tc.runPlainTwineCommand()
- }
- return tc.uploadAndCollectBuildInfo()
-}
-
-func (tc *TwineCommand) extractAndFilterArgs(args []string) (err error) {
- cleanArgs := append([]string(nil), args...)
- cleanArgs, tc.buildConfiguration, err = buildUtils.ExtractBuildDetailsFromArgs(cleanArgs)
- if err != nil {
- return
- }
- tc.args = cleanArgs
- return
-}
-
-func (tc *TwineCommand) setAuthEnvVars() (callbackFunc func() error, err error) {
- oldRepoUrl := os.Getenv(_repositoryUrlEnvKey)
- oldUsername := os.Getenv(_usernameEnvKey)
- oldPassword := os.Getenv(_passwordEnvKey)
- callbackFunc = func() error {
- return errors.Join(os.Setenv(_repositoryUrlOptionKey, oldRepoUrl), os.Setenv(_usernameEnvKey, oldUsername), os.Setenv(_passwordEnvKey, oldPassword))
- }
-
- if err = os.Setenv(_repositoryUrlEnvKey, utils.AddTrailingSlashIfNeeded(tc.serverDetails.ArtifactoryUrl)+_apiPypi+tc.targetRepo); err != nil {
- return
- }
-
- username := tc.serverDetails.User
- password := tc.serverDetails.Password
- // Get credentials from access-token if exists.
- if tc.serverDetails.GetAccessToken() != "" {
- if username == "" {
- username = auth.ExtractUsernameFromAccessToken(tc.serverDetails.GetAccessToken())
- }
- password = tc.serverDetails.GetAccessToken()
- }
-
- if err = os.Setenv(_usernameEnvKey, username); err != nil {
- return
- }
- err = os.Setenv(_passwordEnvKey, password)
- return
-}
-
-func (tc *TwineCommand) runPlainTwineCommand() error {
- log.Debug("Running twine command:", tc.commandName, strings.Join(tc.args, " "))
- args := append([]string{tc.commandName}, tc.args...)
- cmd := exec.Command(_twineExecName, args...)
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- return cmd.Run()
-}
-
-func (tc *TwineCommand) uploadAndCollectBuildInfo() error {
- buildInfo, err := buildUtils.PrepareBuildPrerequisites(tc.buildConfiguration)
- if err != nil {
- return err
- }
-
- defer func() {
- if buildInfo != nil && err != nil {
- err = errors.Join(err, buildInfo.Clean())
- }
- }()
-
- var pythonModule *build.PythonModule
- pythonModule, err = buildInfo.AddPythonModule("", pythonutils.Twine)
- if err != nil {
- return err
- }
- if tc.buildConfiguration.GetModule() != "" {
- pythonModule.SetName(tc.buildConfiguration.GetModule())
- }
-
- artifacts, err := pythonModule.TwineUploadWithLogParsing(tc.args)
- if err != nil {
- return err
- }
- for i := range artifacts {
- artifacts[i].OriginalDeploymentRepo = tc.targetRepo
- }
- if err = pythonModule.AddArtifacts(artifacts); err != nil {
- return err
- }
- log.Debug(fmt.Sprintf("Command finished successfully. %d artifacs were added to build info.", len(artifacts)))
- return nil
-}
-
-func (tc *TwineCommand) isRepoConfigFlagProvided() bool {
- for _, arg := range tc.args {
- for _, flag := range twineRepoConfigFlags {
- if strings.HasPrefix(arg, flag) {
- return true
- }
- }
- }
- return false
-}
-
-func (tc *TwineCommand) getRepoConfigFlagProvidedErr() string {
- return "twine command must not be executed with the following flags: " + coreutils.ListToText(twineRepoConfigFlags)
-}
diff --git a/artifactory/commands/replication/create.go b/artifactory/commands/replication/create.go
deleted file mode 100644
index 71c35f399..000000000
--- a/artifactory/commands/replication/create.go
+++ /dev/null
@@ -1,166 +0,0 @@
-package replication
-
-import (
- "encoding/json"
- "fmt"
- "strings"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
-)
-
-type ReplicationCreateCommand struct {
- serverDetails *config.ServerDetails
- templatePath string
- vars string
-}
-
-func NewReplicationCreateCommand() *ReplicationCreateCommand {
- return &ReplicationCreateCommand{}
-}
-
-func (rcc *ReplicationCreateCommand) SetTemplatePath(path string) *ReplicationCreateCommand {
- rcc.templatePath = path
- return rcc
-}
-
-func (rcc *ReplicationCreateCommand) SetVars(vars string) *ReplicationCreateCommand {
- rcc.vars = vars
- return rcc
-}
-
-func (rcc *ReplicationCreateCommand) SetServerDetails(serverDetails *config.ServerDetails) *ReplicationCreateCommand {
- rcc.serverDetails = serverDetails
- return rcc
-}
-
-func (rcc *ReplicationCreateCommand) ServerDetails() (*config.ServerDetails, error) {
- return rcc.serverDetails, nil
-}
-
-func (rcc *ReplicationCreateCommand) CommandName() string {
- return "rt_replication_create"
-}
-
-func (rcc *ReplicationCreateCommand) Run() (err error) {
- content, err := fileutils.ReadFile(rcc.templatePath)
- if errorutils.CheckError(err) != nil {
- return
- }
- // Replace vars string-by-string if needed
- if len(rcc.vars) > 0 {
- templateVars := coreutils.SpecVarsStringToMap(rcc.vars)
- content = coreutils.ReplaceVars(content, templateVars)
- }
- // Unmarshal template to a map
- var replicationConfigMap map[string]interface{}
- err = json.Unmarshal(content, &replicationConfigMap)
- if errorutils.CheckError(err) != nil {
- return
- }
- // All the values in the template are strings
- // Go over the confMap and write the values with the correct type using the writersMap
- serverId := ""
- for key, value := range replicationConfigMap {
- if err = utils.ValidateMapEntry(key, value, writersMap); err != nil {
- return
- }
- if key == "serverId" {
- serverId = fmt.Sprint(value)
- } else {
- err := writersMap[key](&replicationConfigMap, key, fmt.Sprint(value))
- if err != nil {
- return err
- }
- }
- }
- err = fillMissingDefaultValue(replicationConfigMap)
- if err != nil {
- return err
- }
- // Write a JSON with the correct values
- content, err = json.Marshal(replicationConfigMap)
- if errorutils.CheckError(err) != nil {
- return
- }
- var params services.CreateReplicationParams
- err = json.Unmarshal(content, ¶ms)
- if errorutils.CheckError(err) != nil {
- return
- }
-
- setPathPrefixBackwardCompatibility(¶ms)
- servicesManager, err := rtUtils.CreateServiceManager(rcc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- // In case 'serverId' is not found, pull replication will be assumed.
- if serverId != "" {
- if targetRepo, ok := replicationConfigMap["targetRepoKey"]; ok {
- if err = updateArtifactoryInfo(¶ms, serverId, fmt.Sprint(targetRepo)); err != nil {
- return err
- }
- } else {
- return errorutils.CheckErrorf("expected 'targetRepoKey' field in the json template file.")
- }
- }
- return servicesManager.CreateReplication(params)
-}
-
-func fillMissingDefaultValue(replicationConfigMap map[string]interface{}) error {
- if _, ok := replicationConfigMap["socketTimeoutMillis"]; !ok {
- err := writersMap["socketTimeoutMillis"](&replicationConfigMap, "socketTimeoutMillis", "15000")
- if err != nil {
- return err
- }
- }
- if _, ok := replicationConfigMap["syncProperties"]; !ok {
- err := writersMap["syncProperties"](&replicationConfigMap, "syncProperties", "true")
- if err != nil {
- return err
- }
- }
- return nil
-}
-
-// Make the pathPrefix parameter equals to the includePathPrefixPattern to support Artifactory < 7.27.4
-func setPathPrefixBackwardCompatibility(params *services.CreateReplicationParams) {
- if params.IncludePathPrefixPattern == "" {
- params.IncludePathPrefixPattern = params.PathPrefix
- return
- }
- if params.PathPrefix == "" {
- params.PathPrefix = params.IncludePathPrefixPattern
- }
-}
-
-func updateArtifactoryInfo(param *services.CreateReplicationParams, serverId, targetRepo string) error {
- singleConfig, err := config.GetSpecificConfig(serverId, true, false)
- if err != nil {
- return err
- }
- param.Url, param.Password, param.Username = strings.TrimSuffix(singleConfig.GetArtifactoryUrl(), "/")+"/"+targetRepo, singleConfig.GetPassword(), singleConfig.GetUser()
- return nil
-}
-
-var writersMap = map[string]ioutils.AnswerWriter{
- ServerId: ioutils.WriteStringAnswer,
- RepoKey: ioutils.WriteStringAnswer,
- TargetRepoKey: ioutils.WriteStringAnswer,
- CronExp: ioutils.WriteStringAnswer,
- EnableEventReplication: ioutils.WriteBoolAnswer,
- Enabled: ioutils.WriteBoolAnswer,
- SyncDeletes: ioutils.WriteBoolAnswer,
- SyncProperties: ioutils.WriteBoolAnswer,
- SyncStatistics: ioutils.WriteBoolAnswer,
- PathPrefix: ioutils.WriteStringAnswer,
- IncludePathPrefixPattern: ioutils.WriteStringAnswer,
- SocketTimeoutMillis: ioutils.WriteIntAnswer,
- DisableProxy: ioutils.WriteBoolAnswer,
-}
diff --git a/artifactory/commands/replication/create_test.go b/artifactory/commands/replication/create_test.go
deleted file mode 100644
index 007f34394..000000000
--- a/artifactory/commands/replication/create_test.go
+++ /dev/null
@@ -1,77 +0,0 @@
-package replication
-
-import (
- "encoding/json"
- "io"
- "net/http"
- "net/http/httptest"
- "path/filepath"
- "testing"
-
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- "github.com/stretchr/testify/assert"
-)
-
-var (
- templatesPath = filepath.Join("..", "testdata", "replication")
- expected = utils.CreateUpdateReplicationBody(
- utils.ReplicationParams{
- CronExp: "repl-cronExp",
- RepoKey: "repl-RepoKey",
- EnableEventReplication: true,
- SocketTimeoutMillis: 123,
- Enabled: true,
- SyncDeletes: true,
- SyncProperties: true,
- SyncStatistics: true,
- PathPrefix: "repl-pathprefix",
- IncludePathPrefixPattern: "repl-pathprefix",
- },
- )
-)
-
-func TestCreateReplicationPathPrefix(t *testing.T) {
- // Create replication command
- replicationCmd := NewReplicationCreateCommand()
- testServer := createMockServer(t, replicationCmd)
- defer testServer.Close()
-
- // Test create replication with template containing "pathPrefix"
- replicationCmd.SetTemplatePath(filepath.Join(templatesPath, "template-pathPrefix.json"))
- assert.NoError(t, replicationCmd.Run())
-}
-
-func TestReplicationIncludePathPrefix(t *testing.T) {
- // Create replication command
- replicationCmd := NewReplicationCreateCommand()
- testServer := createMockServer(t, replicationCmd)
- defer testServer.Close()
-
- // Test create replication with template containing "includePathPrefixPattern"
- replicationCmd.SetTemplatePath(filepath.Join(templatesPath, "template-includePathPrefixPattern.json"))
- assert.NoError(t, replicationCmd.Run())
-}
-
-// Create mock server to test replication body
-// t - The testing object
-// replicationCmd - The replication-create command to populate with the server URL
-func createMockServer(t *testing.T, replicationCmd *ReplicationCreateCommand) *httptest.Server {
- testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(http.StatusOK)
-
- // Read body
- content, err := io.ReadAll(r.Body)
- assert.NoError(t, err)
-
- // Unmarshal body
- var actual utils.UpdateReplicationBody
- assert.NoError(t, json.Unmarshal(content, &actual))
-
- // Make sure the sent replication body equals to the expected
- assert.Equal(t, *expected, actual)
- }))
- serverDetails := &config.ServerDetails{ArtifactoryUrl: testServer.URL + "/"}
- replicationCmd.SetServerDetails(serverDetails)
- return testServer
-}
diff --git a/artifactory/commands/replication/delete.go b/artifactory/commands/replication/delete.go
deleted file mode 100644
index 61fdc54c2..000000000
--- a/artifactory/commands/replication/delete.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package replication
-
-import (
- rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
-)
-
-type ReplicationDeleteCommand struct {
- serverDetails *config.ServerDetails
- repoKey string
- quiet bool
-}
-
-func NewReplicationDeleteCommand() *ReplicationDeleteCommand {
- return &ReplicationDeleteCommand{}
-}
-
-func (rdc *ReplicationDeleteCommand) SetRepoKey(repoKey string) *ReplicationDeleteCommand {
- rdc.repoKey = repoKey
- return rdc
-}
-
-func (rdc *ReplicationDeleteCommand) SetQuiet(quiet bool) *ReplicationDeleteCommand {
- rdc.quiet = quiet
- return rdc
-}
-
-func (rdc *ReplicationDeleteCommand) SetServerDetails(serverDetails *config.ServerDetails) *ReplicationDeleteCommand {
- rdc.serverDetails = serverDetails
- return rdc
-}
-
-func (rdc *ReplicationDeleteCommand) ServerDetails() (*config.ServerDetails, error) {
- return rdc.serverDetails, nil
-}
-
-func (rdc *ReplicationDeleteCommand) CommandName() string {
- return "rt_replication_delete"
-}
-
-func (rdc *ReplicationDeleteCommand) Run() (err error) {
- if !rdc.quiet && !coreutils.AskYesNo("Are you sure you want to delete the replication for "+rdc.repoKey+" ?", false) {
- return nil
- }
- servicesManager, err := rtUtils.CreateServiceManager(rdc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- return servicesManager.DeleteReplication(rdc.repoKey)
-}
diff --git a/artifactory/commands/replication/template.go b/artifactory/commands/replication/template.go
deleted file mode 100644
index bf782f60b..000000000
--- a/artifactory/commands/replication/template.go
+++ /dev/null
@@ -1,223 +0,0 @@
-package replication
-
-import (
- "encoding/json"
- "fmt"
- "os"
-
- "github.com/c-bata/go-prompt"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-const (
- // Strings for prompt questions
- SelectConfigKeyMsg = "Select the next configuration key" + ioutils.PressTabMsg
-
- // Template types
- TemplateType = "templateType"
- JobType = "jobType"
- Create = "create"
- Pull = "pull"
- Push = "push"
-
- // Common replication configuration JSON keys
- ServerId = "serverId"
- CronExp = "cronExp"
- RepoKey = "repoKey"
- TargetRepoKey = "targetRepoKey"
- EnableEventReplication = "enableEventReplication"
- Enabled = "enabled"
- SyncDeletes = "syncDeletes"
- SyncProperties = "syncProperties"
- SyncStatistics = "syncStatistics"
- // Deprecated
- PathPrefix = "pathPrefix"
- IncludePathPrefixPattern = "includePathPrefixPattern"
- SocketTimeoutMillis = "socketTimeoutMillis"
- DisableProxy = "disableProxy"
-)
-
-type ReplicationTemplateCommand struct {
- path string
-}
-
-func NewReplicationTemplateCommand() *ReplicationTemplateCommand {
- return &ReplicationTemplateCommand{}
-}
-
-func (rtc *ReplicationTemplateCommand) SetTemplatePath(path string) *ReplicationTemplateCommand {
- rtc.path = path
- return rtc
-}
-
-func (rtc *ReplicationTemplateCommand) CommandName() string {
- return "rt_replication_template"
-}
-
-func (rtc *ReplicationTemplateCommand) ServerDetails() (*config.ServerDetails, error) {
- // Since it's a local command, usage won't be reported.
- return nil, nil
-}
-
-func getArtifactoryServerIds() []prompt.Suggest {
- suggest := make([]prompt.Suggest, 0)
- if configurations, _ := config.GetAllServersConfigs(); configurations != nil {
- for _, conf := range configurations {
- suggest = append(suggest, prompt.Suggest{Text: conf.ServerId})
- }
- }
- return suggest
-}
-
-func (rtc *ReplicationTemplateCommand) Run() (err error) {
- replicationTemplateQuestionnaire := &ioutils.InteractiveQuestionnaire{
- MandatoryQuestionsKeys: []string{JobType, RepoKey},
- QuestionsMap: questionMap,
- }
- err = replicationTemplateQuestionnaire.Perform()
- if err != nil {
- return err
- }
- resBytes, err := json.Marshal(replicationTemplateQuestionnaire.AnswersMap)
- if err != nil {
- return errorutils.CheckError(err)
- }
- if err = os.WriteFile(rtc.path, resBytes, 0644); err != nil {
- return errorutils.CheckError(err)
- }
- log.Info(fmt.Sprintf("Replication creation config template successfully created at %s.", rtc.path))
- return nil
-}
-
-var questionMap = map[string]ioutils.QuestionInfo{
- ioutils.OptionalKey: {
- Msg: "",
- PromptPrefix: "Select the next property >",
- AllowVars: false,
- Writer: nil,
- MapKey: "",
- Callback: ioutils.OptionalKeyCallback,
- },
- TemplateType: {
- Options: []prompt.Suggest{
- {Text: Create, Description: "Template for creating a new replication"},
- },
- Msg: "",
- PromptPrefix: "Select the template type >",
- AllowVars: false,
- Writer: nil,
- MapKey: "",
- Callback: nil,
- },
- JobType: {
- Options: []prompt.Suggest{
- {Text: Pull, Description: "Pull replication"},
- {Text: Push, Description: "Push replication"},
- },
- Msg: "",
- PromptPrefix: "Select replication job type" + ioutils.PressTabMsg,
- AllowVars: false,
- Writer: nil,
- MapKey: "",
- Callback: jobTypeCallback,
- },
- RepoKey: {
- Msg: "",
- PromptPrefix: "Enter source repo key >",
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- MapKey: RepoKey,
- Callback: nil,
- },
- TargetRepoKey: {
- Msg: "",
- PromptPrefix: "Enter target repo key >",
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- MapKey: TargetRepoKey,
- Callback: nil,
- },
- ServerId: {
- Options: getArtifactoryServerIds(),
- Msg: "",
- PromptPrefix: "Enter target server id" + ioutils.PressTabMsg,
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- MapKey: ServerId,
- Callback: nil,
- },
- CronExp: {
- Msg: "",
- PromptPrefix: "Enter cron expression for frequency (for example, 0 0 12 * * ? will replicate daily) >",
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- MapKey: CronExp,
- Callback: nil,
- },
- EnableEventReplication: BoolToStringQuestionInfo,
- Enabled: BoolToStringQuestionInfo,
- SyncDeletes: BoolToStringQuestionInfo,
- SyncProperties: BoolToStringQuestionInfo,
- SyncStatistics: BoolToStringQuestionInfo,
- IncludePathPrefixPattern: {
- Msg: "",
- PromptPrefix: "Enter include path prefix pattern >",
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- MapKey: IncludePathPrefixPattern,
- Callback: nil,
- },
- SocketTimeoutMillis: {
- Msg: "",
- PromptPrefix: "Enter socket timeout millis >",
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- MapKey: SocketTimeoutMillis,
- Callback: nil,
- },
-}
-
-func jobTypeCallback(iq *ioutils.InteractiveQuestionnaire, jobType string) (string, error) {
- if jobType == Pull {
- iq.MandatoryQuestionsKeys = append(iq.MandatoryQuestionsKeys, CronExp)
- } else {
- iq.MandatoryQuestionsKeys = append(iq.MandatoryQuestionsKeys, TargetRepoKey, ServerId, CronExp)
- }
- iq.OptionalKeysSuggests = getAllPossibleOptionalRepoConfKeys()
- return "", nil
-}
-
-func getAllPossibleOptionalRepoConfKeys(values ...string) []prompt.Suggest {
- optionalKeys := []string{ioutils.SaveAndExit, Enabled, SyncDeletes, SyncProperties, SyncStatistics, PathPrefix, IncludePathPrefixPattern, EnableEventReplication, SocketTimeoutMillis}
- if len(values) > 0 {
- optionalKeys = append(optionalKeys, values...)
- }
- return ioutils.GetSuggestsFromKeys(optionalKeys, suggestionMap)
-}
-
-// Specific writers for repo templates, since all the values in the templates should be written as string.
-var BoolToStringQuestionInfo = ioutils.QuestionInfo{
- Options: ioutils.GetBoolSuggests(),
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
-}
-
-var suggestionMap = map[string]prompt.Suggest{
- ioutils.SaveAndExit: {Text: ioutils.SaveAndExit},
- ServerId: {Text: ServerId},
- RepoKey: {Text: RepoKey},
- TargetRepoKey: {Text: TargetRepoKey},
- CronExp: {Text: CronExp},
- EnableEventReplication: {Text: EnableEventReplication},
- Enabled: {Text: Enabled},
- SyncDeletes: {Text: SyncDeletes},
- SyncProperties: {Text: SyncProperties},
- SyncStatistics: {Text: SyncStatistics},
- PathPrefix: {Text: PathPrefix},
- IncludePathPrefixPattern: {Text: IncludePathPrefixPattern},
- SocketTimeoutMillis: {Text: SocketTimeoutMillis},
- DisableProxy: {Text: DisableProxy},
-}
diff --git a/artifactory/commands/repository/create.go b/artifactory/commands/repository/create.go
deleted file mode 100644
index c5647bd88..000000000
--- a/artifactory/commands/repository/create.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package repository
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type RepoCreateCommand struct {
- RepoCommand
-}
-
-func NewRepoCreateCommand() *RepoCreateCommand {
- return &RepoCreateCommand{}
-}
-
-func (rcc *RepoCreateCommand) SetTemplatePath(path string) *RepoCreateCommand {
- rcc.templatePath = path
- return rcc
-}
-
-func (rcc *RepoCreateCommand) SetVars(vars string) *RepoCreateCommand {
- rcc.vars = vars
- return rcc
-}
-
-func (rcc *RepoCreateCommand) SetServerDetails(serverDetails *config.ServerDetails) *RepoCreateCommand {
- rcc.serverDetails = serverDetails
- return rcc
-}
-
-func (rcc *RepoCreateCommand) ServerDetails() (*config.ServerDetails, error) {
- return rcc.serverDetails, nil
-}
-
-func (rcc *RepoCreateCommand) CommandName() string {
- return "rt_repo_create"
-}
-
-func (rcc *RepoCreateCommand) Run() (err error) {
- return rcc.PerformRepoCmd(false)
-}
diff --git a/artifactory/commands/repository/delete.go b/artifactory/commands/repository/delete.go
deleted file mode 100644
index 6e3c528bd..000000000
--- a/artifactory/commands/repository/delete.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package repository
-
-import (
- "path/filepath"
- "strings"
-
- rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/artifactory"
-)
-
-type RepoDeleteCommand struct {
- serverDetails *config.ServerDetails
- repoPattern string
- quiet bool
-}
-
-func NewRepoDeleteCommand() *RepoDeleteCommand {
- return &RepoDeleteCommand{}
-}
-
-func (rdc *RepoDeleteCommand) SetRepoPattern(repoPattern string) *RepoDeleteCommand {
- rdc.repoPattern = repoPattern
- return rdc
-}
-
-func (rdc *RepoDeleteCommand) SetQuiet(quiet bool) *RepoDeleteCommand {
- rdc.quiet = quiet
- return rdc
-}
-
-func (rdc *RepoDeleteCommand) SetServerDetails(serverDetails *config.ServerDetails) *RepoDeleteCommand {
- rdc.serverDetails = serverDetails
- return rdc
-}
-
-func (rdc *RepoDeleteCommand) ServerDetails() (*config.ServerDetails, error) {
- return rdc.serverDetails, nil
-}
-
-func (rdc *RepoDeleteCommand) CommandName() string {
- return "rt_repo_delete"
-}
-
-func (rdc *RepoDeleteCommand) Run() (err error) {
- servicesManager, err := rtUtils.CreateServiceManager(rdc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
-
- // A single repo to be deleted
- if !strings.Contains(rdc.repoPattern, "*") {
- return rdc.deleteRepo(&servicesManager, rdc.repoPattern)
- }
-
- // A pattern for the repo name was received
- repos, err := servicesManager.GetAllRepositories()
- if err != nil {
- return err
- }
- for _, repo := range *repos {
- matched, err := filepath.Match(rdc.repoPattern, repo.Key)
- if err != nil {
- return err
- }
- if matched {
- if err := rdc.deleteRepo(&servicesManager, repo.Key); err != nil {
- return err
- }
- }
- }
- return nil
-}
-
-func (rdc *RepoDeleteCommand) deleteRepo(servicesManager *artifactory.ArtifactoryServicesManager, repoKey string) error {
- if !rdc.quiet && !coreutils.AskYesNo("Are you sure you want to permanently delete the repository "+repoKey+" including all of its content?", false) {
- return nil
- }
- return (*servicesManager).DeleteRepository(repoKey)
-}
diff --git a/artifactory/commands/repository/repository.go b/artifactory/commands/repository/repository.go
deleted file mode 100644
index bd5ad71af..000000000
--- a/artifactory/commands/repository/repository.go
+++ /dev/null
@@ -1,1926 +0,0 @@
-package repository
-
-import (
- "encoding/json"
- "errors"
- "fmt"
- "strconv"
- "strings"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/artifactory"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
-)
-
-const (
- // The actual field in the repository configuration is an array (plural) but in practice only one environment is allowed.
- // This is why the question differs from the repository configuration.
- environmentsKey = "environments"
-)
-
-type RepoCommand struct {
- serverDetails *config.ServerDetails
- templatePath string
- vars string
-}
-
-func (rc *RepoCommand) Vars() string {
- return rc.vars
-}
-
-func (rc *RepoCommand) TemplatePath() string {
- return rc.templatePath
-}
-
-func (rc *RepoCommand) PerformRepoCmd(isUpdate bool) (err error) {
- repoConfigMap, err := utils.ConvertTemplateToMap(rc)
- if err != nil {
- return err
- }
- // All the values in the template are strings
- // Go over the confMap and write the values with the correct type using the writersMap
- for key, value := range repoConfigMap {
- if err = utils.ValidateMapEntry(key, value, writersMap); err != nil {
- return
- }
- if err = writersMap[key](&repoConfigMap, key, fmt.Sprint(value)); err != nil {
- return
- }
- }
- // Write a JSON with the correct values
- content, err := json.Marshal(repoConfigMap)
- if err != nil {
- return err
- }
-
- servicesManager, err := rtUtils.CreateServiceManager(rc.serverDetails, -1, 0, false)
- if err != nil {
- return err
- }
- // Rclass and packageType are mandatory keys in our templates
- // Using their values we'll pick the suitable handler from one of the handler maps to create/update a repository
- var handlerFunc func(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error
- packageType := fmt.Sprint(repoConfigMap[PackageType])
- switch repoConfigMap[Rclass] {
- case Local:
- handlerFunc = localRepoHandlers[packageType]
- case Remote:
- handlerFunc = remoteRepoHandlers[packageType]
- case Virtual:
- handlerFunc = virtualRepoHandlers[packageType]
- case Federated:
- handlerFunc = federatedRepoHandlers[packageType]
- default:
- return errorutils.CheckErrorf("unsupported rclass: %s", repoConfigMap[Rclass])
- }
- if handlerFunc == nil {
- return errors.New("unsupported package type: " + packageType)
- }
- return handlerFunc(servicesManager, content, isUpdate)
-}
-
-var writersMap = map[string]ioutils.AnswerWriter{
- Key: ioutils.WriteStringAnswer,
- Rclass: ioutils.WriteStringAnswer,
- PackageType: ioutils.WriteStringAnswer,
- MandatoryUrl: ioutils.WriteStringAnswer,
- Url: ioutils.WriteStringAnswer,
- Description: ioutils.WriteStringAnswer,
- Notes: ioutils.WriteStringAnswer,
- IncludePatterns: ioutils.WriteStringAnswer,
- ExcludePatterns: ioutils.WriteStringAnswer,
- RepoLayoutRef: ioutils.WriteStringAnswer,
- ProjectKey: ioutils.WriteStringAnswer,
- environmentsKey: ioutils.WriteStringArrayAnswer,
- HandleReleases: ioutils.WriteBoolAnswer,
- HandleSnapshots: ioutils.WriteBoolAnswer,
- MaxUniqueSnapshots: ioutils.WriteIntAnswer,
- SuppressPomConsistencyChecks: ioutils.WriteBoolAnswer,
- BlackedOut: ioutils.WriteBoolAnswer,
- DownloadRedirect: ioutils.WriteBoolAnswer,
- PriorityResolution: ioutils.WriteBoolAnswer,
- CdnRedirect: ioutils.WriteBoolAnswer,
- BlockPushingSchema1: ioutils.WriteBoolAnswer,
- DebianTrivialLayout: ioutils.WriteBoolAnswer,
- ExternalDependenciesEnabled: ioutils.WriteBoolAnswer,
- ExternalDependenciesPatterns: ioutils.WriteStringArrayAnswer,
- ChecksumPolicyType: ioutils.WriteStringAnswer,
- MaxUniqueTags: ioutils.WriteIntAnswer,
- SnapshotVersionBehavior: ioutils.WriteStringAnswer,
- XrayIndex: ioutils.WriteBoolAnswer,
- PropertySets: ioutils.WriteStringArrayAnswer,
- ArchiveBrowsingEnabled: ioutils.WriteBoolAnswer,
- CalculateYumMetadata: ioutils.WriteBoolAnswer,
- YumRootDepth: ioutils.WriteIntAnswer,
- DockerApiVersion: ioutils.WriteStringAnswer,
- EnableFileListsIndexing: ioutils.WriteBoolAnswer,
- OptionalIndexCompressionFormats: ioutils.WriteStringArrayAnswer,
- Username: ioutils.WriteStringAnswer,
- Password: ioutils.WriteStringAnswer,
- Proxy: ioutils.WriteStringAnswer,
- RemoteRepoChecksumPolicyType: ioutils.WriteStringAnswer,
- HardFail: ioutils.WriteBoolAnswer,
- Offline: ioutils.WriteBoolAnswer,
- StoreArtifactsLocally: ioutils.WriteBoolAnswer,
- SocketTimeoutMillis: ioutils.WriteIntAnswer,
- LocalAddress: ioutils.WriteStringAnswer,
- RetrievalCachePeriodSecs: ioutils.WriteIntAnswer,
- FailedRetrievalCachePeriodSecs: ioutils.WriteIntAnswer,
- MissedRetrievalCachePeriodSecs: ioutils.WriteIntAnswer,
- UnusedArtifactsCleanupEnabled: ioutils.WriteBoolAnswer,
- UnusedArtifactsCleanupPeriodHours: ioutils.WriteIntAnswer,
- AssumedOfflinePeriodSecs: ioutils.WriteIntAnswer,
- FetchJarsEagerly: ioutils.WriteBoolAnswer,
- FetchSourcesEagerly: ioutils.WriteBoolAnswer,
- ShareConfiguration: ioutils.WriteBoolAnswer,
- SynchronizeProperties: ioutils.WriteBoolAnswer,
- BlockMismatchingMimeTypes: ioutils.WriteBoolAnswer,
- AllowAnyHostAuth: ioutils.WriteBoolAnswer,
- EnableCookieManagement: ioutils.WriteBoolAnswer,
- BowerRegistryUrl: ioutils.WriteStringAnswer,
- ComposerRegistryUrl: ioutils.WriteStringAnswer,
- PyPIRegistryUrl: ioutils.WriteStringAnswer,
- VcsType: ioutils.WriteStringAnswer,
- VcsGitProvider: ioutils.WriteStringAnswer,
- VcsGitDownloadUrl: ioutils.WriteStringAnswer,
- BypassHeadRequests: ioutils.WriteBoolAnswer,
- ClientTlsCertificate: ioutils.WriteStringAnswer,
- FeedContextPath: ioutils.WriteStringAnswer,
- DownloadContextPath: ioutils.WriteStringAnswer,
- V3FeedUrl: ioutils.WriteStringAnswer,
- ContentSynchronisation: writeContentSynchronisation,
- ListRemoteFolderItems: ioutils.WriteBoolAnswer,
- RejectInvalidJars: ioutils.WriteBoolAnswer,
- PodsSpecsRepoUrl: ioutils.WriteStringAnswer,
- EnableTokenAuthentication: ioutils.WriteBoolAnswer,
- Repositories: ioutils.WriteStringArrayAnswer,
- ArtifactoryRequestsCanRetrieveRemoteArtifacts: ioutils.WriteBoolAnswer,
- KeyPair: ioutils.WriteStringAnswer,
- PomRepositoryReferencesCleanupPolicy: ioutils.WriteStringAnswer,
- DefaultDeploymentRepo: ioutils.WriteStringAnswer,
- ForceMavenAuthentication: ioutils.WriteBoolAnswer,
- ForceNugetAuthentication: ioutils.WriteBoolAnswer,
- ExternalDependenciesRemoteRepo: ioutils.WriteStringAnswer,
-}
-
-func writeContentSynchronisation(resultMap *map[string]interface{}, key, value string) error {
- answerArray := strings.Split(value, ",")
- if len(answerArray) != 4 {
- return errors.New("invalid value for Content Synchronisation")
- }
- var cs services.ContentSynchronisation
-
- enabled, err := strconv.ParseBool(answerArray[0])
- if errorutils.CheckError(err) != nil {
- return err
- }
- cs.Enabled = &enabled
-
- enabled, err = strconv.ParseBool(answerArray[1])
- if errorutils.CheckError(err) != nil {
- return err
- }
- cs.Statistics = &services.ContentSynchronisationStatistics{
- Enabled: &enabled,
- }
-
- enabled, err = strconv.ParseBool(answerArray[2])
- if errorutils.CheckError(err) != nil {
- return err
- }
- cs.Properties = &services.ContentSynchronisationProperties{
- Enabled: &enabled,
- }
-
- enabled, err = strconv.ParseBool(answerArray[3])
- if errorutils.CheckError(err) != nil {
- return err
- }
- cs.Source = &services.ContentSynchronisationSource{
- OriginAbsenceDetection: &enabled,
- }
-
- (*resultMap)[key] = cs
- return nil
-}
-
-// repoHandler is a function that gets serviceManager, JSON configuration content and a flag indicates is the operation in an update operation
-// Each handler unmarshal the JSOn content into the jfrog-client's unique rclass-pkgType param struct, and run the operation service
-type repoHandler func(artifactory.ArtifactoryServicesManager, []byte, bool) error
-
-var localRepoHandlers = map[string]repoHandler{
- Maven: localMavenHandler,
- Gradle: localGradleHandler,
- Ivy: localIvyHandles,
- Sbt: localSbtHandler,
- Helm: localHelmHandler,
- Cocoapods: localCocoapodsHandler,
- Opkg: localOpkgHandler,
- Rpm: localRpmHandler,
- Nuget: localNugetHandler,
- Cran: localCranHandler,
- Gems: localGemsHandler,
- Npm: localNpmHandler,
- Bower: localBowerHandler,
- Debian: localDebianHandler,
- Composer: localComposerHandler,
- Pypi: localPypiHandler,
- Docker: localDockerHandler,
- Vagrant: localVagrantHandler,
- Gitlfs: localGitLfsHandler,
- Go: localGoHandler,
- Yum: localYumHandler,
- Conan: localConanHandler,
- Conda: localCondaHandler,
- Chef: localChefHandler,
- Puppet: localPuppetHandler,
- Alpine: localAlpineHandler,
- Generic: localGenericHandler,
- Swift: localSwiftHandler,
- Terraform: localTerraformHandler,
- Cargo: localCargoHandler,
-}
-
-func localMavenHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewMavenLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Maven(params)
- } else {
- err = servicesManager.CreateLocalRepository().Maven(params)
- }
- return err
-}
-
-func localGradleHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGradleLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Gradle(params)
- } else {
- err = servicesManager.CreateLocalRepository().Gradle(params)
- }
- return err
-}
-
-func localIvyHandles(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewIvyLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Ivy(params)
- } else {
- err = servicesManager.CreateLocalRepository().Ivy(params)
- }
- return err
-}
-
-func localSbtHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewSbtLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Sbt(params)
- } else {
- err = servicesManager.CreateLocalRepository().Sbt(params)
- }
- return err
-}
-
-func localHelmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewHelmLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Helm(params)
- } else {
- err = servicesManager.CreateLocalRepository().Helm(params)
- }
- return err
-}
-
-func localCocoapodsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCocoapodsLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Cocoapods(params)
- } else {
- err = servicesManager.CreateLocalRepository().Cocoapods(params)
- }
- return err
-}
-
-func localOpkgHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewOpkgLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Opkg(params)
- } else {
- err = servicesManager.CreateLocalRepository().Opkg(params)
- }
- return err
-}
-
-func localRpmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewRpmLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Rpm(params)
- } else {
- err = servicesManager.CreateLocalRepository().Rpm(params)
- }
- return err
-}
-
-func localNugetHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewNugetLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Nuget(params)
- } else {
- err = servicesManager.CreateLocalRepository().Nuget(params)
- }
- return err
-}
-
-func localCranHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCranLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Cran(params)
- } else {
- err = servicesManager.CreateLocalRepository().Cran(params)
- }
- return err
-}
-
-func localGemsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGemsLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Gems(params)
- } else {
- err = servicesManager.CreateLocalRepository().Gems(params)
- }
- return err
-}
-
-func localNpmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewNpmLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Npm(params)
- } else {
- err = servicesManager.CreateLocalRepository().Npm(params)
- }
- return err
-}
-
-func localBowerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewBowerLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Bower(params)
- } else {
- err = servicesManager.CreateLocalRepository().Bower(params)
- }
- return err
-}
-
-func localDebianHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewDebianLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Debian(params)
- } else {
- err = servicesManager.CreateLocalRepository().Debian(params)
- }
- return err
-}
-
-func localComposerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewComposerLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Composer(params)
- } else {
- err = servicesManager.CreateLocalRepository().Composer(params)
- }
- return err
-}
-
-func localPypiHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewPypiLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Pypi(params)
- } else {
- err = servicesManager.CreateLocalRepository().Pypi(params)
- }
- return err
-}
-
-func localDockerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewDockerLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Docker(params)
- } else {
- err = servicesManager.CreateLocalRepository().Docker(params)
- }
- return err
-}
-
-func localVagrantHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewVagrantLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Vagrant(params)
- } else {
- err = servicesManager.CreateLocalRepository().Vagrant(params)
- }
- return err
-}
-
-func localGitLfsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGitlfsLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Gitlfs(params)
- } else {
- err = servicesManager.CreateLocalRepository().Gitlfs(params)
- }
- return err
-}
-
-func localGoHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGoLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Go(params)
- } else {
- err = servicesManager.CreateLocalRepository().Go(params)
- }
- return err
-}
-
-func localYumHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewYumLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Yum(params)
- } else {
- err = servicesManager.CreateLocalRepository().Yum(params)
- }
- return err
-}
-
-func localConanHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewConanLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Conan(params)
- } else {
- err = servicesManager.CreateLocalRepository().Conan(params)
- }
- return err
-}
-
-func localChefHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewChefLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Chef(params)
- } else {
- err = servicesManager.CreateLocalRepository().Chef(params)
- }
- return err
-}
-
-func localPuppetHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewPuppetLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Puppet(params)
- } else {
- err = servicesManager.CreateLocalRepository().Puppet(params)
- }
- return err
-}
-
-func localAlpineHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewAlpineLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Alpine(params)
- } else {
- err = servicesManager.CreateLocalRepository().Alpine(params)
- }
- return err
-}
-
-func localCondaHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCondaLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Conda(params)
- } else {
- err = servicesManager.CreateLocalRepository().Conda(params)
- }
- return err
-}
-
-func localSwiftHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewSwiftLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
-
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Swift(params)
- } else {
- err = servicesManager.CreateLocalRepository().Swift(params)
- }
- return err
-}
-
-func localTerraformHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewTerraformLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
-
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Terraform(params)
- } else {
- err = servicesManager.CreateLocalRepository().Terraform(params)
- }
- return err
-}
-
-func localCargoHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCargoLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
-
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Cargo(params)
- } else {
- err = servicesManager.CreateLocalRepository().Cargo(params)
- }
- return err
-}
-
-func localGenericHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGenericLocalRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
-
- if isUpdate {
- err = servicesManager.UpdateLocalRepository().Generic(params)
- } else {
- err = servicesManager.CreateLocalRepository().Generic(params)
- }
- return err
-}
-
-var remoteRepoHandlers = map[string]repoHandler{
- Maven: remoteMavenHandler,
- Gradle: remoteGradleHandler,
- Ivy: remoteIvyHandler,
- Sbt: remoteSbtHandler,
- Helm: remoteHelmHandler,
- Cocoapods: remoteCocoapodsHandler,
- Opkg: remoteOpkgHandler,
- Rpm: remoteRpmHandler,
- Nuget: remoteNugetHandler,
- Cran: remoteCranHandler,
- Gems: remoteGemsHandler,
- Npm: remoteNpmHandler,
- Bower: remoteBowerHandler,
- Debian: remoteDebianHandler,
- Composer: remoteComposerHandler,
- Pypi: remotePypiHandler,
- Docker: remoteDockerHandler,
- Gitlfs: remoteGitLfsHandler,
- Go: remoteGoHandler,
- Yum: remoteYumHandler,
- Conan: remoteConanHandler,
- Conda: remoteCondaHandler,
- Chef: remoteChefHandler,
- Puppet: remotePuppetHandler,
- P2: remoteP2Handler,
- Vcs: remoteVcsHandler,
- Alpine: remoteAlpineHandler,
- Generic: remoteGenericHandler,
- Swift: remoteSwiftHandler,
- Terraform: remoteTerraformHandler,
- Cargo: remoteCargoHandler,
-}
-
-func remoteMavenHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewMavenRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Maven(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Maven(params)
- }
- return err
-}
-
-func remoteGradleHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGradleRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Gradle(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Gradle(params)
- }
- return err
-}
-
-func remoteIvyHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewIvyRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Ivy(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Ivy(params)
- }
- return err
-}
-
-func remoteSbtHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewSbtRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Sbt(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Sbt(params)
- }
- return err
-}
-
-func remoteHelmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewHelmRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Helm(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Helm(params)
- }
- return err
-}
-
-func remoteCocoapodsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCocoapodsRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Cocoapods(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Cocoapods(params)
- }
- return err
-}
-
-func remoteOpkgHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewOpkgRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Opkg(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Opkg(params)
- }
- return err
-}
-
-func remoteRpmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewRpmRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Rpm(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Rpm(params)
- }
- return err
-}
-
-func remoteNugetHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewNugetRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Nuget(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Nuget(params)
- }
- return err
-}
-
-func remoteCranHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCranRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Cran(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Cran(params)
- }
- return err
-}
-
-func remoteGemsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGemsRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Gems(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Gems(params)
- }
- return err
-}
-
-func remoteNpmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewNpmRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Npm(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Npm(params)
- }
- return err
-}
-
-func remoteBowerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewBowerRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Bower(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Bower(params)
- }
- return err
-}
-
-func remoteDebianHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewDebianRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Debian(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Debian(params)
- }
- return err
-}
-
-func remoteComposerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewComposerRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Composer(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Composer(params)
- }
- return err
-}
-
-func remotePypiHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewPypiRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Pypi(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Pypi(params)
- }
- return err
-}
-
-func remoteDockerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewDockerRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Docker(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Docker(params)
- }
- return err
-}
-
-func remoteGitLfsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGitlfsRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Gitlfs(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Gitlfs(params)
- }
- return err
-}
-
-func remoteGoHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGoRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Go(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Go(params)
- }
- return err
-}
-
-func remoteConanHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewConanRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Conan(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Conan(params)
- }
- return err
-}
-
-func remoteChefHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewChefRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Chef(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Chef(params)
- }
- return err
-}
-
-func remotePuppetHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewPuppetRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Puppet(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Puppet(params)
- }
- return err
-}
-
-func remoteVcsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewVcsRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Vcs(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Vcs(params)
- }
- return err
-}
-
-func remoteAlpineHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewAlpineRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Alpine(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Alpine(params)
- }
- return err
-}
-
-func remoteP2Handler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewP2RemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().P2(params)
- } else {
- err = servicesManager.CreateRemoteRepository().P2(params)
- }
- return err
-}
-
-func remoteCondaHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCondaRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Conda(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Conda(params)
- }
- return err
-}
-
-func remoteYumHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewYumRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Yum(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Yum(params)
- }
- return err
-}
-
-func remoteSwiftHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewSwiftRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Swift(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Swift(params)
- }
- return err
-}
-
-func remoteCargoHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCargoRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Cargo(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Cargo(params)
- }
- return err
-}
-
-func remoteTerraformHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewTerraformRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Terraform(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Terraform(params)
- }
- return err
-}
-
-func remoteGenericHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGenericRemoteRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateRemoteRepository().Generic(params)
- } else {
- err = servicesManager.CreateRemoteRepository().Generic(params)
- }
- return err
-}
-
-var federatedRepoHandlers = map[string]repoHandler{
- Maven: federatedMavenHandler,
- Gradle: federatedGradleHandler,
- Ivy: federatedIvyHandles,
- Sbt: federatedSbtHandler,
- Helm: federatedHelmHandler,
- Cocoapods: federatedCocoapodsHandler,
- Opkg: federatedOpkgHandler,
- Rpm: federatedRpmHandler,
- Nuget: federatedNugetHandler,
- Cran: federatedCranHandler,
- Gems: federatedGemsHandler,
- Npm: federatedNpmHandler,
- Bower: federatedBowerHandler,
- Debian: federatedDebianHandler,
- Composer: federatedComposerHandler,
- Pypi: federatedPypiHandler,
- Docker: federatedDockerHandler,
- Vagrant: federatedVagrantHandler,
- Gitlfs: federatedGitLfsHandler,
- Go: federatedGoHandler,
- Conan: federatedConanHandler,
- Conda: federatedCondaHandler,
- Chef: federatedChefHandler,
- Puppet: federatedPuppetHandler,
- Alpine: federatedAlpineHandler,
- Generic: federatedGenericHandler,
- Yum: federatedYumHandler,
- Swift: federatedSwiftHandler,
- Terraform: federatedTerraformHandler,
- Cargo: federatedCargoHandler,
-}
-
-func federatedMavenHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewMavenFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Maven(params)
- }
- return servicesManager.CreateFederatedRepository().Maven(params)
-}
-
-func federatedGradleHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGradleFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Gradle(params)
- }
- return servicesManager.CreateFederatedRepository().Gradle(params)
-}
-
-func federatedIvyHandles(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewIvyFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Ivy(params)
- }
- return servicesManager.CreateFederatedRepository().Ivy(params)
-}
-
-func federatedSbtHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewSbtFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Sbt(params)
- }
- return servicesManager.CreateFederatedRepository().Sbt(params)
-}
-
-func federatedHelmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewHelmFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Helm(params)
- }
- return servicesManager.CreateFederatedRepository().Helm(params)
-
-}
-
-func federatedCocoapodsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCocoapodsFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Cocoapods(params)
- }
- return servicesManager.CreateFederatedRepository().Cocoapods(params)
-}
-
-func federatedOpkgHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewOpkgFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Opkg(params)
- }
- return servicesManager.CreateFederatedRepository().Opkg(params)
-}
-
-func federatedRpmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewRpmFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Rpm(params)
- }
- return servicesManager.CreateFederatedRepository().Rpm(params)
-}
-
-func federatedNugetHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewNugetFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Nuget(params)
- }
- return servicesManager.CreateFederatedRepository().Nuget(params)
-}
-
-func federatedCranHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCranFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Cran(params)
- }
- return servicesManager.CreateFederatedRepository().Cran(params)
-}
-
-func federatedGemsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGemsFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Gems(params)
- }
- return servicesManager.CreateFederatedRepository().Gems(params)
-}
-
-func federatedNpmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewNpmFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Npm(params)
- }
- return servicesManager.CreateFederatedRepository().Npm(params)
-}
-
-func federatedBowerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewBowerFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Bower(params)
- }
- return servicesManager.CreateFederatedRepository().Bower(params)
-}
-
-func federatedDebianHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewDebianFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Debian(params)
- }
- return servicesManager.CreateFederatedRepository().Debian(params)
-}
-
-func federatedComposerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewComposerFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Composer(params)
- }
- return servicesManager.CreateFederatedRepository().Composer(params)
-}
-
-func federatedPypiHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewPypiFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Pypi(params)
- }
- return servicesManager.CreateFederatedRepository().Pypi(params)
-}
-
-func federatedDockerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewDockerFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Docker(params)
- }
- return servicesManager.CreateFederatedRepository().Docker(params)
-}
-
-func federatedVagrantHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewVagrantFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Vagrant(params)
- }
- return servicesManager.CreateFederatedRepository().Vagrant(params)
-}
-
-func federatedGitLfsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGitlfsFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Gitlfs(params)
- }
- return servicesManager.CreateFederatedRepository().Gitlfs(params)
-}
-
-func federatedGoHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGoFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Go(params)
- }
- return servicesManager.CreateFederatedRepository().Go(params)
-}
-
-func federatedConanHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewConanFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Conan(params)
- }
- return servicesManager.CreateFederatedRepository().Conan(params)
-}
-
-func federatedCondaHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCondaFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Conda(params)
- }
- return servicesManager.CreateFederatedRepository().Conda(params)
-}
-
-func federatedChefHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewChefFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Chef(params)
- }
- return servicesManager.CreateFederatedRepository().Chef(params)
-}
-
-func federatedPuppetHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewPuppetFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Puppet(params)
- }
- return servicesManager.CreateFederatedRepository().Puppet(params)
-}
-
-func federatedAlpineHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewAlpineFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Alpine(params)
- }
- return servicesManager.CreateFederatedRepository().Alpine(params)
-}
-
-func federatedGenericHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGenericFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
-
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Generic(params)
- }
- return servicesManager.CreateFederatedRepository().Generic(params)
-}
-
-func federatedSwiftHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewSwiftFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Swift(params)
- }
- return servicesManager.CreateFederatedRepository().Swift(params)
-}
-
-func federatedTerraformHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewTerraformFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Terraform(params)
- }
- return servicesManager.CreateFederatedRepository().Terraform(params)
-}
-
-func federatedCargoHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCargoFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Cargo(params)
- }
- return servicesManager.CreateFederatedRepository().Cargo(params)
-}
-
-func federatedYumHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewYumFederatedRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- return servicesManager.UpdateFederatedRepository().Yum(params)
- }
- return servicesManager.CreateFederatedRepository().Yum(params)
-}
-
-var virtualRepoHandlers = map[string]repoHandler{
- Maven: virtualMavenHandler,
- Gradle: virtualGradleHandler,
- Ivy: virtualIvyHandler,
- Sbt: virtualSbtHandler,
- Helm: virtualHelmHandler,
- Rpm: virtualRpmHandler,
- Nuget: virtualNugetHandler,
- Cran: virtualCranHandler,
- Gems: virtualGemsHandler,
- Npm: virtualNpmHandler,
- Bower: virtualBowerHandler,
- Debian: virtualDebianHandler,
- Pypi: virtualPypiHandler,
- Docker: virtualDockerHandler,
- Gitlfs: virtualGitLfsHandler,
- Go: virtualGoHandler,
- Yum: virtualYumHandler,
- Conan: virtualConanHandler,
- Chef: virtualChefHandler,
- Puppet: virtualPuppetHandler,
- Conda: virtualCondaHandler,
- P2: virtualP2Handler,
- Alpine: virtualAlpineHandler,
- Generic: virtualGenericHandler,
- Swift: virtualSwiftHandler,
- Terraform: virtualTerraformHandler,
-}
-
-func virtualMavenHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewMavenVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Maven(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Maven(params)
- }
- return err
-}
-
-func virtualGradleHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGradleVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Gradle(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Gradle(params)
- }
- return err
-}
-
-func virtualIvyHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewIvyVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Ivy(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Ivy(params)
- }
- return err
-}
-
-func virtualSbtHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewSbtVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Sbt(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Sbt(params)
- }
- return err
-}
-
-func virtualHelmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewHelmVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Helm(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Helm(params)
- }
- return err
-}
-
-func virtualRpmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewRpmVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Rpm(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Rpm(params)
- }
- return err
-}
-
-func virtualNugetHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewNugetVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Nuget(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Nuget(params)
- }
- return err
-}
-
-func virtualCranHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCranVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Cran(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Cran(params)
- }
- return err
-}
-
-func virtualGemsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGemsVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Gems(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Gems(params)
- }
- return err
-}
-
-func virtualNpmHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewNpmVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Npm(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Npm(params)
- }
- return err
-}
-
-func virtualBowerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewBowerVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Bower(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Bower(params)
- }
- return err
-}
-
-func virtualDebianHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewDebianVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Debian(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Debian(params)
- }
- return err
-}
-
-func virtualPypiHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewPypiVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Pypi(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Pypi(params)
- }
- return err
-}
-
-func virtualDockerHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewDockerVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Docker(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Docker(params)
- }
- return err
-}
-
-func virtualGitLfsHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGitlfsVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Gitlfs(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Gitlfs(params)
- }
- return err
-}
-
-func virtualGoHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGoVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Go(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Go(params)
- }
- return err
-}
-
-func virtualConanHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewConanVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Conan(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Conan(params)
- }
- return err
-}
-
-func virtualChefHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewChefVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Chef(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Chef(params)
- }
- return err
-}
-
-func virtualPuppetHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewPuppetVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Puppet(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Puppet(params)
- }
- return err
-}
-
-func virtualYumHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewYumVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Yum(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Yum(params)
- }
- return err
-}
-
-func virtualP2Handler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewP2VirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().P2(params)
- } else {
- err = servicesManager.CreateVirtualRepository().P2(params)
- }
- return err
-}
-
-func virtualAlpineHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewAlpineVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Alpine(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Alpine(params)
- }
- return err
-}
-
-func virtualCondaHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewCondaVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Conda(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Conda(params)
- }
- return err
-}
-
-func virtualSwiftHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewSwiftVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Swift(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Swift(params)
- }
- return err
-}
-
-func virtualTerraformHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewTerraformVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Terraform(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Terraform(params)
- }
- return err
-}
-
-func virtualGenericHandler(servicesManager artifactory.ArtifactoryServicesManager, jsonConfig []byte, isUpdate bool) error {
- params := services.NewGenericVirtualRepositoryParams()
- err := json.Unmarshal(jsonConfig, ¶ms)
- if errorutils.CheckError(err) != nil {
- return err
- }
- if isUpdate {
- err = servicesManager.UpdateVirtualRepository().Generic(params)
- } else {
- err = servicesManager.CreateVirtualRepository().Generic(params)
- }
- return err
-}
diff --git a/artifactory/commands/repository/template.go b/artifactory/commands/repository/template.go
deleted file mode 100644
index e9e7ed774..000000000
--- a/artifactory/commands/repository/template.go
+++ /dev/null
@@ -1,952 +0,0 @@
-package repository
-
-import (
- "encoding/json"
- "errors"
- "fmt"
- "os"
- "strings"
-
- "github.com/c-bata/go-prompt"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type RepoTemplateCommand struct {
- path string
-}
-
-const (
- // Strings for prompt questions
- SelectConfigKeyMsg = "Select the next configuration key" + ioutils.PressTabMsg
-
- TemplateType = "templateType"
- Create = "create"
- Update = "update"
-
- MandatoryUrl = "mandatoryUrl"
-
- // Common repository configuration JSON keys
- Key = "key"
- Rclass = "rclass"
- PackageType = "packageType"
- Description = "description"
- Notes = "notes"
- IncludePatterns = "includesPattern"
- ExcludePatterns = "excludesPattern"
- RepoLayoutRef = "repoLayoutRef"
- ProjectKey = "projectKey"
- Environment = "environment"
-
- // Mutual local and remote repository configuration JSON keys
- HandleReleases = "handleReleases"
- HandleSnapshots = "handleSnapshots"
- MaxUniqueSnapshots = "maxUniqueSnapshots"
- SuppressPomConsistencyChecks = "suppressPomConsistencyChecks"
- BlackedOut = "blackedOut"
- XrayIndex = "xrayIndex"
- PropertySets = "propertySets"
- DownloadRedirect = "downloadRedirect"
- PriorityResolution = "priorityResolution"
- CdnRedirect = "cdnRedirect"
- BlockPushingSchema1 = "blockPushingSchema1"
-
- // Mutual local and virtual repository configuration JSON keys
- DebianTrivialLayout = "debianTrivialLayout"
- OptionalIndexCompressionFormats = "optionalIndexCompressionFormats"
- PrimaryKeyPairRef = "primaryKeyPairRef"
-
- // Mutual remote and virtual repository configuration JSON keys
- ExternalDependenciesEnabled = "externalDependenciesEnabled"
- ExternalDependenciesPatterns = "externalDependenciesPatterns"
-
- // Unique local repository configuration JSON keys
- ChecksumPolicyType = "checksumPolicyType"
- MaxUniqueTags = "maxUniqueTags"
- SnapshotVersionBehavior = "snapshotVersionBehavior"
- ArchiveBrowsingEnabled = "archiveBrowsingEnabled"
- CalculateYumMetadata = "calculateYumMetadata"
- YumRootDepth = "yumRootDepth"
- DockerApiVersion = "dockerApiVersion"
- EnableFileListsIndexing = "enableFileListsIndexing"
- ForceNugetAuthentication = "forceNugetAuthentication"
-
- // Unique remote repository configuration JSON keys
- Url = "url"
- Username = "username"
- Password = "password"
- Proxy = "proxy"
- RemoteRepoChecksumPolicyType = "remoteRepoChecksumPolicyType"
- HardFail = "hardFail"
- Offline = "offline"
- StoreArtifactsLocally = "storeArtifactsLocally"
- SocketTimeoutMillis = "socketTimeoutMillis"
- LocalAddress = "localAddress"
- RetrievalCachePeriodSecs = "retrievalCachePeriodSecs"
- FailedRetrievalCachePeriodSecs = "failedRetrievalCachePeriodSecs"
- MissedRetrievalCachePeriodSecs = "missedRetrievalCachePeriodSecs"
- UnusedArtifactsCleanupEnabled = "unusedArtifactsCleanupEnabled"
- UnusedArtifactsCleanupPeriodHours = "unusedArtifactsCleanupPeriodHours"
- AssumedOfflinePeriodSecs = "assumedOfflinePeriodSecs"
- FetchJarsEagerly = "fetchJarsEagerly"
- FetchSourcesEagerly = "fetchSourcesEagerly"
- RejectInvalidJars = "rejectInvalidJars"
- ShareConfiguration = "shareConfiguration"
- SynchronizeProperties = "synchronizeProperties"
- BlockMismatchingMimeTypes = "blockMismatchingMimeTypes"
- AllowAnyHostAuth = "allowAnyHostAuth"
- EnableCookieManagement = "enableCookieManagement"
- BowerRegistryUrl = "bowerRegistryUrl"
- ComposerRegistryUrl = "composerRegistryUrl"
- PyPIRegistryUrl = "pyPIRegistryUrl"
- VcsType = "vcsType"
- VcsGitProvider = "vcsGitProvider"
- VcsGitDownloadUrl = "vcsGitDownloadUrl"
- BypassHeadRequests = "bypassHeadRequests"
- ClientTlsCertificate = "clientTlsCertificate"
- FeedContextPath = "feedContextPath"
- DownloadContextPath = "downloadContextPath"
- V3FeedUrl = "v3FeedUrl"
- ContentSynchronisation = "contentSynchronisation"
- ListRemoteFolderItems = "listRemoteFolderItems"
- EnableTokenAuthentication = "enableTokenAuthentication"
- PodsSpecsRepoUrl = "podsSpecsRepoUrl"
-
- // Unique virtual repository configuration JSON keys
- Repositories = "repositories"
- ArtifactoryRequestsCanRetrieveRemoteArtifacts = "artifactoryRequestsCanRetrieveRemoteArtifacts"
- KeyPair = "keyPair"
- PomRepositoryReferencesCleanupPolicy = "pomRepositoryReferencesCleanupPolicy"
- DefaultDeploymentRepo = "defaultDeploymentRepo"
- ForceMavenAuthentication = "forceMavenAuthentication"
- ExternalDependenciesRemoteRepo = "externalDependenciesRemoteRepo"
-
- // rclasses
- Local = "local"
- Remote = "remote"
- Virtual = "virtual"
- Federated = "federated"
-
- // PackageTypes
- Generic = "generic"
- Maven = "maven"
- Gradle = "gradle"
- Ivy = "ivy"
- Sbt = "sbt"
- Helm = "helm"
- Cocoapods = "cocoapods"
- Opkg = "opkg"
- Rpm = "rpm"
- Nuget = "nuget"
- Cran = "cran"
- Gems = "gems"
- Npm = "npm"
- Bower = "bower"
- Debian = "debian"
- Composer = "composer"
- Pypi = "pypi"
- Docker = "docker"
- Vagrant = "vagrant"
- Gitlfs = "gitlfs"
- Go = "go"
- Yum = "yum"
- Conan = "conan"
- Chef = "chef"
- Puppet = "puppet"
- Vcs = "vcs"
- Alpine = "alpine"
- Conda = "conda"
- P2 = "p2"
- Swift = "swift"
- Terraform = "terraform"
- Cargo = "cargo"
-
- // Repo layout Refs
- BowerDefaultRepoLayout = "bower-default"
- buildDefaultRepoLayout = "build-default"
- ComposerDefaultRepoLayout = "composer-default"
- ConanDefaultRepoLayout = "conan-default"
- GoDefaultRepoLayout = "go-default"
- GradleDefaultRepoLayout = "maven-2-default"
- IvyDefaultRepoLayout = "ivy-default"
- Maven1DefaultRepoLayout = "maven-1-default"
- Maven2DefaultRepoLayout = "maven-2-default"
- NpmDefaultRepoLayout = "npm-default"
- NugetDefaultRepoLayout = "nuget-default"
- puppetDefaultRepoLayout = "puppet-default"
- SbtDefaultRepoLayout = "sbt-default"
- SimpleDefaultRepoLayout = "simple-default"
- VcsDefaultRepoLayout = "vcs-default"
-
- // Checksum Policies
- ClientChecksumPolicy = "client-checksums"
- ServerGeneratedChecksumsPolicy = "server-generated-checksums"
-
- // Snapshot version behaviors
- UniqueBehavior = "unique"
- NonUniqueBehavior = "non-unique"
- DeployerBehavior = "deployer"
-
- // Optional index compression formats
- Bz2Compression = "bz2"
- LzmaCompression = "lzma"
- XzCompression = "xz"
-
- // Docker api versions
- DockerApiV1 = "V1"
- DockerApiV2 = "V2"
-
- // Remote repo checksum policies
- GenerateIfAbsentPolicy = "generate-if-absent"
- FailPolicy = "fail"
- IgnoreAndGeneratePolicy = "ignore-and-generate"
- PassThruPolicy = "pass-thru"
-
- // Vcs Types
- Git = "GIT"
-
- // Vcs git provider
- GithubVcsProvider = "GITHUB"
- BitbucketVcsProvider = "BITBUCKET"
- OldstashVcsProvider = "OLDSTASH"
- StashVcsProvider = "STASH"
- ArtifactoryVcsProvider = "ARTIFACTORY"
- CustomVcsProvider = "CUSTOM"
-
- // POM repository references cleanup policies
- DiscardActiveRefrencePolicy = "discard_active_reference"
- DiscardAnyReferencePolicy = "discard_any_reference"
- NothingPolicy = "nothing"
-)
-
-var optionalSuggestsMap = map[string]prompt.Suggest{
- ioutils.SaveAndExit: {Text: ioutils.SaveAndExit},
- Description: {Text: Description},
- Notes: {Text: Notes},
- IncludePatterns: {Text: IncludePatterns},
- ExcludePatterns: {Text: ExcludePatterns},
- RepoLayoutRef: {Text: RepoLayoutRef},
- ProjectKey: {Text: ProjectKey},
- Environment: {Text: Environment},
- HandleReleases: {Text: HandleReleases},
- HandleSnapshots: {Text: HandleSnapshots},
- MaxUniqueSnapshots: {Text: MaxUniqueSnapshots},
- SuppressPomConsistencyChecks: {Text: SuppressPomConsistencyChecks},
- BlackedOut: {Text: BlackedOut},
- DownloadRedirect: {Text: DownloadRedirect},
- PriorityResolution: {Text: PriorityResolution},
- CdnRedirect: {Text: CdnRedirect},
- BlockPushingSchema1: {Text: BlockPushingSchema1},
- DebianTrivialLayout: {Text: DebianTrivialLayout},
- ExternalDependenciesEnabled: {Text: ExternalDependenciesEnabled},
- ExternalDependenciesPatterns: {Text: ExternalDependenciesPatterns},
- ChecksumPolicyType: {Text: ChecksumPolicyType},
- MaxUniqueTags: {Text: MaxUniqueTags},
- SnapshotVersionBehavior: {Text: SnapshotVersionBehavior},
- XrayIndex: {Text: XrayIndex},
- PropertySets: {Text: PropertySets},
- ArchiveBrowsingEnabled: {Text: ArchiveBrowsingEnabled},
- CalculateYumMetadata: {Text: CalculateYumMetadata},
- YumRootDepth: {Text: YumRootDepth},
- DockerApiVersion: {Text: DockerApiVersion},
- EnableFileListsIndexing: {Text: EnableFileListsIndexing},
- OptionalIndexCompressionFormats: {Text: OptionalIndexCompressionFormats},
- Url: {Text: Url},
- Username: {Text: Username},
- Password: {Text: Password},
- Proxy: {Text: Proxy},
- PrimaryKeyPairRef: {Text: PrimaryKeyPairRef},
- RemoteRepoChecksumPolicyType: {Text: RemoteRepoChecksumPolicyType},
- HardFail: {Text: HardFail},
- Offline: {Text: Offline},
- StoreArtifactsLocally: {Text: StoreArtifactsLocally},
- SocketTimeoutMillis: {Text: SocketTimeoutMillis},
- LocalAddress: {Text: LocalAddress},
- RetrievalCachePeriodSecs: {Text: RetrievalCachePeriodSecs},
- FailedRetrievalCachePeriodSecs: {Text: FailedRetrievalCachePeriodSecs},
- MissedRetrievalCachePeriodSecs: {Text: MissedRetrievalCachePeriodSecs},
- UnusedArtifactsCleanupEnabled: {Text: UnusedArtifactsCleanupEnabled},
- UnusedArtifactsCleanupPeriodHours: {Text: UnusedArtifactsCleanupPeriodHours},
- AssumedOfflinePeriodSecs: {Text: AssumedOfflinePeriodSecs},
- FetchJarsEagerly: {Text: FetchJarsEagerly},
- FetchSourcesEagerly: {Text: FetchSourcesEagerly},
- RejectInvalidJars: {Text: RejectInvalidJars},
- ShareConfiguration: {Text: ShareConfiguration},
- SynchronizeProperties: {Text: SynchronizeProperties},
- BlockMismatchingMimeTypes: {Text: BlockMismatchingMimeTypes},
- AllowAnyHostAuth: {Text: AllowAnyHostAuth},
- EnableCookieManagement: {Text: EnableCookieManagement},
- BowerRegistryUrl: {Text: BowerRegistryUrl},
- ComposerRegistryUrl: {Text: ComposerRegistryUrl},
- PyPIRegistryUrl: {Text: PyPIRegistryUrl},
- VcsType: {Text: VcsType},
- VcsGitProvider: {Text: VcsGitProvider},
- VcsGitDownloadUrl: {Text: VcsGitDownloadUrl},
- BypassHeadRequests: {Text: BypassHeadRequests},
- ClientTlsCertificate: {Text: ClientTlsCertificate},
- FeedContextPath: {Text: FeedContextPath},
- DownloadContextPath: {Text: DownloadContextPath},
- V3FeedUrl: {Text: V3FeedUrl},
- ContentSynchronisation: {Text: ContentSynchronisation},
- ListRemoteFolderItems: {Text: ListRemoteFolderItems},
- PodsSpecsRepoUrl: {Text: PodsSpecsRepoUrl},
- EnableTokenAuthentication: {Text: EnableTokenAuthentication},
- Repositories: {Text: Repositories},
- ArtifactoryRequestsCanRetrieveRemoteArtifacts: {Text: ArtifactoryRequestsCanRetrieveRemoteArtifacts},
- KeyPair: {Text: KeyPair},
- PomRepositoryReferencesCleanupPolicy: {Text: PomRepositoryReferencesCleanupPolicy},
- DefaultDeploymentRepo: {Text: DefaultDeploymentRepo},
- ForceMavenAuthentication: {Text: ForceMavenAuthentication},
- ForceNugetAuthentication: {Text: ForceNugetAuthentication},
- ExternalDependenciesRemoteRepo: {Text: ExternalDependenciesRemoteRepo},
-}
-
-var baseLocalRepoConfKeys = []string{
- Description, Notes, IncludePatterns, ExcludePatterns, RepoLayoutRef, ProjectKey, Environment, BlackedOut, XrayIndex,
- PropertySets, ArchiveBrowsingEnabled, OptionalIndexCompressionFormats, DownloadRedirect, PriorityResolution, CdnRedirect, BlockPushingSchema1,
-}
-
-var mavenGradleLocalRepoConfKeys = []string{
- MaxUniqueSnapshots, HandleReleases, HandleSnapshots, SuppressPomConsistencyChecks, SnapshotVersionBehavior, ChecksumPolicyType,
-}
-
-var rpmLocalRepoConfKeys = []string{
- YumRootDepth, CalculateYumMetadata, EnableFileListsIndexing, PrimaryKeyPairRef,
-}
-
-var nugetLocalRepoConfKeys = []string{
- MaxUniqueSnapshots, ForceNugetAuthentication,
-}
-
-var debianLocalRepoConfKeys = []string{
- DebianTrivialLayout, PrimaryKeyPairRef,
-}
-
-var dockerLocalRepoConfKeys = []string{
- DockerApiVersion, MaxUniqueTags,
-}
-
-var baseRemoteRepoConfKeys = []string{
- Username, Password, Proxy, Description, Notes, IncludePatterns, ExcludePatterns, RepoLayoutRef, ProjectKey, Environment, HardFail, Offline,
- BlackedOut, XrayIndex, StoreArtifactsLocally, SocketTimeoutMillis, LocalAddress, RetrievalCachePeriodSecs, FailedRetrievalCachePeriodSecs,
- MissedRetrievalCachePeriodSecs, UnusedArtifactsCleanupEnabled, UnusedArtifactsCleanupPeriodHours, AssumedOfflinePeriodSecs,
- ShareConfiguration, SynchronizeProperties, BlockMismatchingMimeTypes, PropertySets, AllowAnyHostAuth, EnableCookieManagement,
- BypassHeadRequests, ClientTlsCertificate, DownloadRedirect, PriorityResolution, CdnRedirect, BlockPushingSchema1, ContentSynchronisation,
-}
-
-var mavenGradleRemoteRepoConfKeys = []string{
- FetchJarsEagerly, FetchSourcesEagerly, RemoteRepoChecksumPolicyType, HandleReleases, HandleSnapshots,
- SuppressPomConsistencyChecks, RejectInvalidJars,
-}
-
-var cocoapodsRemoteRepoConfKeys = []string{
- PodsSpecsRepoUrl,
-}
-
-var opkgRemoteRepoConfKeys = []string{
- ListRemoteFolderItems,
-}
-
-var rpmRemoteRepoConfKeys = []string{
- ListRemoteFolderItems,
-}
-
-var nugetRemoteRepoConfKeys = []string{
- FeedContextPath, DownloadContextPath, V3FeedUrl, ForceNugetAuthentication,
-}
-
-var gemsRemoteRepoConfKeys = []string{
- ListRemoteFolderItems,
-}
-
-var npmRemoteRepoConfKeys = []string{
- ListRemoteFolderItems,
-}
-
-var bowerRemoteRepoConfKeys = []string{
- BowerRegistryUrl,
-}
-
-var debianRemoteRepoConfKeys = []string{
- ListRemoteFolderItems,
-}
-
-var composerRemoteRepoConfKeys = []string{
- ComposerRegistryUrl,
-}
-
-var pypiRemoteRepoConfKeys = []string{
- PyPIRegistryUrl, ListRemoteFolderItems,
-}
-
-var dockerRemoteRepoConfKeys = []string{
- ExternalDependenciesEnabled, ExternalDependenciesPatterns, EnableTokenAuthentication,
-}
-
-var gitlfsRemoteRepoConfKeys = []string{
- ListRemoteFolderItems,
-}
-
-var vcsRemoteRepoConfKeys = []string{
- VcsGitProvider, VcsType, MaxUniqueSnapshots, VcsGitDownloadUrl, ListRemoteFolderItems,
-}
-
-var baseVirtualRepoConfKeys = []string{
- Repositories, Description, Notes, IncludePatterns, ExcludePatterns, RepoLayoutRef, ProjectKey, Environment, ArtifactoryRequestsCanRetrieveRemoteArtifacts,
- DefaultDeploymentRepo, OptionalIndexCompressionFormats, PrimaryKeyPairRef,
-}
-
-var mavenGradleVirtualRepoConfKeys = []string{
- ForceMavenAuthentication, PomRepositoryReferencesCleanupPolicy, KeyPair,
-}
-
-var nugetVirtualRepoConfKeys = []string{
- ForceNugetAuthentication,
-}
-
-var npmVirtualRepoConfKeys = []string{
- ExternalDependenciesEnabled, ExternalDependenciesPatterns, ExternalDependenciesRemoteRepo,
-}
-
-var bowerVirtualRepoConfKeys = []string{
- ExternalDependenciesEnabled, ExternalDependenciesPatterns, ExternalDependenciesRemoteRepo,
-}
-
-var debianVirtualRepoConfKeys = []string{
- DebianTrivialLayout,
-}
-
-var goVirtualRepoConfKeys = []string{
- ExternalDependenciesEnabled, ExternalDependenciesPatterns,
-}
-
-var commonPkgTypes = []string{
- Maven, Gradle, Ivy, Sbt, Helm, Rpm, Nuget, Cran, Gems, Npm, Bower, Debian, Pypi, Docker, Gitlfs, Go, Conan,
- Chef, Puppet, Alpine, Generic,
-}
-
-var localRepoAdditionalPkgTypes = []string{
- Cocoapods, Opkg, Composer, Vagrant, Yum,
-}
-
-var remoteRepoAdditionalPkgTypes = []string{
- Cocoapods, Opkg, Composer, Conda, P2, Vcs, Yum,
-}
-
-var virtualRepoAdditionalPkgTypes = []string{
- Conda, P2, Yum,
-}
-
-var federatedRepoAdditionalPkgTypes = []string{
- Vagrant, Opkg, Conda, Composer, Cocoapods,
-}
-
-var pkgTypeSuggestsMap = map[string]prompt.Suggest{
- Generic: {Text: Generic},
- Maven: {Text: Maven},
- Gradle: {Text: Gradle},
- Ivy: {Text: Ivy},
- Sbt: {Text: Sbt},
- Helm: {Text: Helm},
- Cocoapods: {Text: Cocoapods},
- Opkg: {Text: Opkg},
- Rpm: {Text: Rpm},
- Nuget: {Text: Nuget},
- Cran: {Text: Cran},
- Gems: {Text: Gems},
- Npm: {Text: Npm},
- Bower: {Text: Bower},
- Debian: {Text: Debian},
- Composer: {Text: Composer},
- Pypi: {Text: Pypi},
- Docker: {Text: Docker},
- Vagrant: {Text: Vagrant},
- Gitlfs: {Text: Gitlfs},
- Go: {Text: Go},
- Yum: {Text: Yum},
- Conan: {Text: Conan},
- Chef: {Text: Chef},
- Puppet: {Text: Puppet},
- Vcs: {Text: Vcs},
- Conda: {Text: Conda},
- P2: {Text: P2},
- Alpine: {Text: Alpine},
-}
-
-func NewRepoTemplateCommand() *RepoTemplateCommand {
- return &RepoTemplateCommand{}
-}
-
-func (rtc *RepoTemplateCommand) SetTemplatePath(path string) *RepoTemplateCommand {
- rtc.path = path
- return rtc
-}
-
-func (rtc *RepoTemplateCommand) ServerDetails() (*config.ServerDetails, error) {
- // Since it's a local command, usage won't be reported.
- return nil, nil
-}
-
-func (rtc *RepoTemplateCommand) Run() (err error) {
- err = utils.ValidateTemplatePath(rtc.path)
- if err != nil {
- return
- }
- repoTemplateQuestionnaire := &ioutils.InteractiveQuestionnaire{
- MandatoryQuestionsKeys: []string{TemplateType, Key, Rclass},
- QuestionsMap: questionMap,
- }
- err = repoTemplateQuestionnaire.Perform()
- if err != nil {
- return err
- }
- resBytes, err := json.Marshal(repoTemplateQuestionnaire.AnswersMap)
- if err != nil {
- return errorutils.CheckError(err)
- }
- if err = os.WriteFile(rtc.path, resBytes, 0644); err != nil {
- return errorutils.CheckError(err)
- }
- log.Info(fmt.Sprintf("Repository configuration template successfully created at %s.", rtc.path))
-
- return nil
-}
-
-func (rtc *RepoTemplateCommand) CommandName() string {
- return "rt_repo_template"
-}
-
-func rclassCallback(iq *ioutils.InteractiveQuestionnaire, rclass string) (string, error) {
- var pkgTypes = commonPkgTypes
- switch rclass {
- case Remote:
- // For create template url is mandatory, for update we will allow url as an optional key
- if _, ok := iq.AnswersMap[TemplateType]; !ok {
- return "", errors.New("package type is missing in configuration map")
- }
- if iq.AnswersMap[TemplateType] == Create {
- _, err := iq.AskQuestion(iq.QuestionsMap[MandatoryUrl])
- if err != nil {
- return "", err
- }
- }
- pkgTypes = append(pkgTypes, remoteRepoAdditionalPkgTypes...)
- case Local:
- pkgTypes = append(pkgTypes, localRepoAdditionalPkgTypes...)
- case Virtual:
- pkgTypes = append(pkgTypes, virtualRepoAdditionalPkgTypes...)
- case Federated:
- pkgTypes = append(pkgTypes, federatedRepoAdditionalPkgTypes...)
- default:
- return "", errors.New("unsupported rclass")
- }
- // PackageType is also mandatory. Since the possible types depend on which rcalss was chosen, we ask the question here.
- var pkgTypeQuestion = ioutils.QuestionInfo{
- Options: ioutils.GetSuggestsFromKeys(pkgTypes, pkgTypeSuggestsMap),
- Msg: "",
- PromptPrefix: "Select the repository's package type" + ioutils.PressTabMsg,
- AllowVars: false,
- Writer: ioutils.WriteStringAnswer,
- MapKey: PackageType,
- Callback: pkgTypeCallback,
- }
- return iq.AskQuestion(pkgTypeQuestion)
-}
-
-func pkgTypeCallback(iq *ioutils.InteractiveQuestionnaire, pkgType string) (string, error) {
- // Each combination of (rclass,packageType) has its own optional configuration keys.
- // We set the questionnaire's optionalKeys suggests according to the selected combination.
- if _, ok := iq.AnswersMap[Rclass]; !ok {
- return "", errors.New("rclass is missing in configuration map")
- }
- switch iq.AnswersMap[Rclass] {
- case Local:
- iq.OptionalKeysSuggests = getLocalRepoConfKeys(pkgType)
- case Remote:
- // For update template we need to allow url as an optional key
- if _, ok := iq.AnswersMap[TemplateType]; !ok {
- return "", errors.New("package type is missing in configuration map")
- }
- iq.OptionalKeysSuggests = getRemoteRepoConfKeys(pkgType, fmt.Sprint(iq.AnswersMap[TemplateType]))
- case Virtual:
- iq.OptionalKeysSuggests = getVirtualRepoConfKeys(pkgType)
- case Federated:
- iq.OptionalKeysSuggests = getLocalRepoConfKeys(pkgType)
- default:
- return "", errors.New("unsupported rclass was configured")
- }
- // We don't need the templateType value in the final configuration
- delete(iq.AnswersMap, TemplateType)
- return "", nil
-}
-
-// Repo key must have a prefix of "-". This callback adds the prefix to the repo key if it is missing.
-func projectKeyCallback(iq *ioutils.InteractiveQuestionnaire, projectKey string) (string, error) {
- if _, ok := iq.AnswersMap[Key]; !ok {
- return "", errorutils.CheckErrorf("repository key is missing in configuration map")
- }
- requiredProjectPrefix := projectKey + "-"
- currentRepoKey, ok := iq.AnswersMap[Key].(string)
- if !ok {
- return "", errorutils.CheckErrorf("template syntax error: the value for the repository key is not a string type")
- }
-
- if !strings.HasPrefix(currentRepoKey, requiredProjectPrefix) {
- newRepoKey := requiredProjectPrefix + currentRepoKey
- log.Info("Repository key should start with the projectKey followed by a dash. Modifying repo key to: '" + newRepoKey + "'.")
- iq.AnswersMap[Key] = newRepoKey
- }
- return "", nil
-}
-
-func getLocalRepoConfKeys(pkgType string) []prompt.Suggest {
- optionalKeys := []string{ioutils.SaveAndExit}
- optionalKeys = append(optionalKeys, baseLocalRepoConfKeys...)
- switch pkgType {
- case Maven, Gradle:
- optionalKeys = append(optionalKeys, mavenGradleLocalRepoConfKeys...)
- case Rpm:
- optionalKeys = append(optionalKeys, rpmLocalRepoConfKeys...)
- case Nuget:
- optionalKeys = append(optionalKeys, nugetLocalRepoConfKeys...)
- case Debian:
- optionalKeys = append(optionalKeys, debianLocalRepoConfKeys...)
- case Docker:
- optionalKeys = append(optionalKeys, dockerLocalRepoConfKeys...)
- }
- return ioutils.GetSuggestsFromKeys(optionalKeys, optionalSuggestsMap)
-}
-
-func getRemoteRepoConfKeys(pkgType, templateType string) []prompt.Suggest {
- optionalKeys := []string{ioutils.SaveAndExit}
- if templateType == Update {
- optionalKeys = append(optionalKeys, Url)
- }
- optionalKeys = append(optionalKeys, baseRemoteRepoConfKeys...)
- switch pkgType {
- case Maven, Gradle:
- optionalKeys = append(optionalKeys, mavenGradleRemoteRepoConfKeys...)
- case Cocoapods:
- optionalKeys = append(optionalKeys, cocoapodsRemoteRepoConfKeys...)
- case Opkg:
- optionalKeys = append(optionalKeys, opkgRemoteRepoConfKeys...)
- case Rpm:
- optionalKeys = append(optionalKeys, rpmRemoteRepoConfKeys...)
- case Nuget:
- optionalKeys = append(optionalKeys, nugetRemoteRepoConfKeys...)
- case Gems:
- optionalKeys = append(optionalKeys, gemsRemoteRepoConfKeys...)
- case Npm:
- optionalKeys = append(optionalKeys, npmRemoteRepoConfKeys...)
- case Bower:
- optionalKeys = append(optionalKeys, bowerRemoteRepoConfKeys...)
- case Debian:
- optionalKeys = append(optionalKeys, debianRemoteRepoConfKeys...)
- case Composer:
- optionalKeys = append(optionalKeys, composerRemoteRepoConfKeys...)
- case Pypi:
- optionalKeys = append(optionalKeys, pypiRemoteRepoConfKeys...)
- case Docker:
- optionalKeys = append(optionalKeys, dockerRemoteRepoConfKeys...)
- case Gitlfs:
- optionalKeys = append(optionalKeys, gitlfsRemoteRepoConfKeys...)
- case Vcs:
- optionalKeys = append(optionalKeys, vcsRemoteRepoConfKeys...)
- }
- return ioutils.GetSuggestsFromKeys(optionalKeys, optionalSuggestsMap)
-}
-
-func getVirtualRepoConfKeys(pkgType string) []prompt.Suggest {
- optionalKeys := []string{ioutils.SaveAndExit}
- optionalKeys = append(optionalKeys, baseVirtualRepoConfKeys...)
- switch pkgType {
- case Maven, Gradle:
- optionalKeys = append(optionalKeys, mavenGradleVirtualRepoConfKeys...)
- case Nuget:
- optionalKeys = append(optionalKeys, nugetVirtualRepoConfKeys...)
- case Npm:
- optionalKeys = append(optionalKeys, npmVirtualRepoConfKeys...)
- case Bower:
- optionalKeys = append(optionalKeys, bowerVirtualRepoConfKeys...)
- case Debian:
- optionalKeys = append(optionalKeys, debianVirtualRepoConfKeys...)
- case Go:
- optionalKeys = append(optionalKeys, goVirtualRepoConfKeys...)
- }
- return ioutils.GetSuggestsFromKeys(optionalKeys, optionalSuggestsMap)
-}
-
-func contentSynchronisationCallBack(iq *ioutils.InteractiveQuestionnaire, answer string) (value string, err error) {
- // contentSynchronisation has an object value with 4 bool fields.
- // We ask for the rest of the values and writes the values in comma separated list.
- if err != nil {
- return "", nil
- }
- answer += "," + ioutils.AskFromList("", "Insert the value for statistic.enable >", false, ioutils.GetBoolSuggests(), "")
- // cs.Statistics.Enabled, err = strconv.ParseBool(enabled)
- if err != nil {
- return "", nil
- }
- answer += "," + ioutils.AskFromList("", "Insert the value for properties.enable >", false, ioutils.GetBoolSuggests(), "")
- // cs.Properties.Enabled, err = strconv.ParseBool(enabled)
- if err != nil {
- return "", nil
- }
- answer += "," + ioutils.AskFromList("", "Insert the value for source.originAbsenceDetection >", false, ioutils.GetBoolSuggests(), "")
- // cs.Source.OriginAbsenceDetection, err = strconv.ParseBool(enabled)
- if err != nil {
- return "", nil
- }
- iq.AnswersMap[ContentSynchronisation] = answer
- return "", nil
-}
-
-// Specific writers for repo templates, since all the values in the templates should be written as string
-var BoolToStringQuestionInfo = ioutils.QuestionInfo{
- Options: ioutils.GetBoolSuggests(),
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
-}
-
-var IntToStringQuestionInfo = ioutils.QuestionInfo{
- Options: nil,
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
-}
-
-var StringListToStringQuestionInfo = ioutils.QuestionInfo{
- Msg: ioutils.CommaSeparatedListMsg,
- Options: nil,
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
-}
-
-var questionMap = map[string]ioutils.QuestionInfo{
- TemplateType: {
- Options: []prompt.Suggest{
- {Text: Create, Description: "Template for creating a new repository"},
- {Text: Update, Description: "Template for updating an existing repository"},
- },
- Msg: "",
- PromptPrefix: "Select the template type" + ioutils.PressTabMsg,
- AllowVars: false,
- Writer: ioutils.WriteStringAnswer,
- MapKey: TemplateType,
- Callback: nil,
- },
- ioutils.OptionalKey: {
- Msg: "",
- PromptPrefix: SelectConfigKeyMsg,
- AllowVars: false,
- Writer: nil,
- MapKey: "",
- Callback: ioutils.OptionalKeyCallback,
- },
- Key: {
- Msg: "",
- PromptPrefix: "Insert the repository key >",
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- MapKey: Key,
- Callback: nil,
- },
- Rclass: {
- Options: []prompt.Suggest{
- {Text: Local, Description: "A physical, locally-managed repository into which you can deploy artifacts"},
- {Text: Remote, Description: "A caching proxy for a repository managed at a remote URL"},
- {Text: Virtual, Description: "An Aggregation of several repositories with the same package type under a common URL."},
- {Text: Federated, Description: "A Federation is a collection of repositories of Federated type in different JPDs that are automatically configured for full bi-directional mirroring."},
- },
- Msg: "",
- PromptPrefix: "Select the repository class" + ioutils.PressTabMsg,
- AllowVars: false,
- Writer: ioutils.WriteStringAnswer,
- MapKey: Rclass,
- Callback: rclassCallback,
- },
- MandatoryUrl: {
- Msg: "",
- PromptPrefix: "Insert the remote repository URL >",
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- MapKey: Url,
- Callback: nil,
- },
- Url: ioutils.FreeStringQuestionInfo,
- Description: ioutils.FreeStringQuestionInfo,
- Notes: ioutils.FreeStringQuestionInfo,
- IncludePatterns: StringListToStringQuestionInfo,
- ExcludePatterns: StringListToStringQuestionInfo,
- RepoLayoutRef: {
- Options: []prompt.Suggest{
- {Text: BowerDefaultRepoLayout},
- {Text: buildDefaultRepoLayout},
- {Text: ComposerDefaultRepoLayout},
- {Text: ConanDefaultRepoLayout},
- {Text: GoDefaultRepoLayout},
- {Text: GradleDefaultRepoLayout},
- {Text: IvyDefaultRepoLayout},
- {Text: Maven1DefaultRepoLayout},
- {Text: Maven2DefaultRepoLayout},
- {Text: NpmDefaultRepoLayout},
- {Text: NugetDefaultRepoLayout},
- {Text: puppetDefaultRepoLayout},
- {Text: SbtDefaultRepoLayout},
- {Text: SimpleDefaultRepoLayout},
- {Text: VcsDefaultRepoLayout},
- },
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- ProjectKey: {
- Options: nil,
- AllowVars: false,
- Writer: ioutils.WriteStringAnswer,
- Callback: projectKeyCallback,
- },
- Environment: {
- PromptPrefix: "Insert the name of the environment to assign to >",
- AllowVars: true,
- MapKey: environmentsKey,
- Writer: ioutils.WriteStringAnswer,
- },
- HandleReleases: BoolToStringQuestionInfo,
- HandleSnapshots: BoolToStringQuestionInfo,
- MaxUniqueSnapshots: IntToStringQuestionInfo,
- SuppressPomConsistencyChecks: BoolToStringQuestionInfo,
- BlackedOut: BoolToStringQuestionInfo,
- DownloadRedirect: BoolToStringQuestionInfo,
- PriorityResolution: BoolToStringQuestionInfo,
- CdnRedirect: BoolToStringQuestionInfo,
- BlockPushingSchema1: BoolToStringQuestionInfo,
- DebianTrivialLayout: BoolToStringQuestionInfo,
- ExternalDependenciesEnabled: BoolToStringQuestionInfo,
- ExternalDependenciesPatterns: StringListToStringQuestionInfo,
- ChecksumPolicyType: {
- Options: []prompt.Suggest{
- {Text: ClientChecksumPolicy},
- {Text: ServerGeneratedChecksumsPolicy},
- },
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- MaxUniqueTags: IntToStringQuestionInfo,
- SnapshotVersionBehavior: {
- Options: []prompt.Suggest{
- {Text: UniqueBehavior},
- {Text: NonUniqueBehavior},
- {Text: DeployerBehavior},
- },
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- XrayIndex: BoolToStringQuestionInfo,
- PropertySets: StringListToStringQuestionInfo,
- ArchiveBrowsingEnabled: BoolToStringQuestionInfo,
- CalculateYumMetadata: BoolToStringQuestionInfo,
- YumRootDepth: IntToStringQuestionInfo,
- DockerApiVersion: {
- Options: []prompt.Suggest{
- {Text: DockerApiV1},
- {Text: DockerApiV2},
- },
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- EnableFileListsIndexing: BoolToStringQuestionInfo,
- OptionalIndexCompressionFormats: {
- Msg: "Enter a comma separated list of values from " + strings.Join([]string{Bz2Compression, LzmaCompression, XzCompression}, ","),
- Options: nil,
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- PrimaryKeyPairRef: ioutils.FreeStringQuestionInfo,
- Username: ioutils.FreeStringQuestionInfo,
- Password: ioutils.FreeStringQuestionInfo,
- Proxy: ioutils.FreeStringQuestionInfo,
- RemoteRepoChecksumPolicyType: {
- Options: []prompt.Suggest{
- {Text: GenerateIfAbsentPolicy},
- {Text: FailPolicy},
- {Text: IgnoreAndGeneratePolicy},
- {Text: PassThruPolicy},
- },
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- HardFail: BoolToStringQuestionInfo,
- Offline: BoolToStringQuestionInfo,
- StoreArtifactsLocally: BoolToStringQuestionInfo,
- SocketTimeoutMillis: IntToStringQuestionInfo,
- LocalAddress: ioutils.FreeStringQuestionInfo,
- RetrievalCachePeriodSecs: IntToStringQuestionInfo,
- FailedRetrievalCachePeriodSecs: IntToStringQuestionInfo,
- MissedRetrievalCachePeriodSecs: IntToStringQuestionInfo,
- UnusedArtifactsCleanupEnabled: BoolToStringQuestionInfo,
- UnusedArtifactsCleanupPeriodHours: IntToStringQuestionInfo,
- AssumedOfflinePeriodSecs: IntToStringQuestionInfo,
- FetchJarsEagerly: BoolToStringQuestionInfo,
- FetchSourcesEagerly: BoolToStringQuestionInfo,
- RejectInvalidJars: BoolToStringQuestionInfo,
- ShareConfiguration: BoolToStringQuestionInfo,
- SynchronizeProperties: BoolToStringQuestionInfo,
- BlockMismatchingMimeTypes: BoolToStringQuestionInfo,
- AllowAnyHostAuth: BoolToStringQuestionInfo,
- EnableCookieManagement: BoolToStringQuestionInfo,
- BowerRegistryUrl: ioutils.FreeStringQuestionInfo,
- ComposerRegistryUrl: ioutils.FreeStringQuestionInfo,
- PyPIRegistryUrl: ioutils.FreeStringQuestionInfo,
- VcsType: {
- Options: []prompt.Suggest{
- {Text: Git},
- },
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- VcsGitProvider: {
- Options: []prompt.Suggest{
- {Text: GithubVcsProvider},
- {Text: BitbucketVcsProvider},
- {Text: OldstashVcsProvider},
- {Text: StashVcsProvider},
- {Text: ArtifactoryVcsProvider},
- {Text: CustomVcsProvider},
- },
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- VcsGitDownloadUrl: ioutils.FreeStringQuestionInfo,
- BypassHeadRequests: BoolToStringQuestionInfo,
- ClientTlsCertificate: ioutils.FreeStringQuestionInfo,
- FeedContextPath: ioutils.FreeStringQuestionInfo,
- DownloadContextPath: ioutils.FreeStringQuestionInfo,
- V3FeedUrl: ioutils.FreeStringQuestionInfo,
- ListRemoteFolderItems: BoolToStringQuestionInfo,
- EnableTokenAuthentication: BoolToStringQuestionInfo,
- PodsSpecsRepoUrl: ioutils.FreeStringQuestionInfo,
- ContentSynchronisation: {
- Options: ioutils.GetBoolSuggests(),
- AllowVars: true,
- Writer: nil,
- Callback: contentSynchronisationCallBack,
- },
- Repositories: StringListToStringQuestionInfo,
- ArtifactoryRequestsCanRetrieveRemoteArtifacts: BoolToStringQuestionInfo,
- KeyPair: ioutils.FreeStringQuestionInfo,
- PomRepositoryReferencesCleanupPolicy: {
- Options: []prompt.Suggest{
- {Text: DiscardActiveRefrencePolicy},
- {Text: DiscardAnyReferencePolicy},
- {Text: NothingPolicy},
- },
- AllowVars: true,
- Writer: ioutils.WriteStringAnswer,
- },
- DefaultDeploymentRepo: ioutils.FreeStringQuestionInfo,
- ForceMavenAuthentication: BoolToStringQuestionInfo,
- ForceNugetAuthentication: BoolToStringQuestionInfo,
- ExternalDependenciesRemoteRepo: ioutils.FreeStringQuestionInfo,
-}
diff --git a/artifactory/commands/repository/update.go b/artifactory/commands/repository/update.go
deleted file mode 100644
index 13aba85a7..000000000
--- a/artifactory/commands/repository/update.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package repository
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
-)
-
-type RepoUpdateCommand struct {
- RepoCommand
-}
-
-func NewRepoUpdateCommand() *RepoUpdateCommand {
- return &RepoUpdateCommand{}
-}
-
-func (ruc *RepoUpdateCommand) SetTemplatePath(path string) *RepoUpdateCommand {
- ruc.templatePath = path
- return ruc
-}
-
-func (ruc *RepoUpdateCommand) SetVars(vars string) *RepoUpdateCommand {
- ruc.vars = vars
- return ruc
-}
-
-func (ruc *RepoUpdateCommand) SetServerDetails(serverDetails *config.ServerDetails) *RepoUpdateCommand {
- ruc.serverDetails = serverDetails
- return ruc
-}
-
-func (ruc *RepoUpdateCommand) ServerDetails() (*config.ServerDetails, error) {
- return ruc.serverDetails, nil
-}
-
-func (ruc *RepoUpdateCommand) CommandName() string {
- return "rt_repo_update"
-}
-
-func (ruc *RepoUpdateCommand) Run() (err error) {
- return ruc.PerformRepoCmd(true)
-}
diff --git a/artifactory/commands/setup/setup.go b/artifactory/commands/setup/setup.go
deleted file mode 100644
index 213d8f62f..000000000
--- a/artifactory/commands/setup/setup.go
+++ /dev/null
@@ -1,351 +0,0 @@
-package setup
-
-import (
- "fmt"
- bidotnet "github.com/jfrog/build-info-go/build/utils/dotnet"
- biutils "github.com/jfrog/build-info-go/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/dotnet"
- gocommands "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/golang"
- pythoncommands "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/python"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/repository"
- commandsutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/container"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/npm"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/yarn"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "golang.org/x/exp/maps"
- "net/url"
- "os"
- "slices"
-)
-
-// packageManagerToRepositoryPackageType maps project types to corresponding Artifactory repository package types.
-var packageManagerToRepositoryPackageType = map[project.ProjectType]string{
- // Npm package managers
- project.Npm: repository.Npm,
- project.Pnpm: repository.Npm,
- project.Yarn: repository.Npm,
-
- // Python (pypi) package managers
- project.Pip: repository.Pypi,
- project.Pipenv: repository.Pypi,
- project.Poetry: repository.Pypi,
-
- // Nuget package managers
- project.Nuget: repository.Nuget,
- project.Dotnet: repository.Nuget,
-
- // Docker package managers
- project.Docker: repository.Docker,
- project.Podman: repository.Docker,
-
- project.Go: repository.Go,
-}
-
-// SetupCommand configures registries and authentication for various package manager (npm, Yarn, Pip, Pipenv, Poetry, Go)
-type SetupCommand struct {
- // packageManager represents the type of package manager (e.g., NPM, Yarn).
- packageManager project.ProjectType
- // repoName is the name of the repository used for configuration.
- repoName string
- // projectKey is the JFrog Project key in JFrog Platform.
- projectKey string
- // serverDetails contains Artifactory server configuration.
- serverDetails *config.ServerDetails
- // commandName specifies the command for this instance.
- commandName string
-}
-
-// NewSetupCommand initializes a new SetupCommand for the specified package manager
-func NewSetupCommand(packageManager project.ProjectType) *SetupCommand {
- return &SetupCommand{
- packageManager: packageManager,
- commandName: "setup_" + packageManager.String(),
- }
-}
-
-// GetSupportedPackageManagersList returns a sorted list of supported package manager names as strings.
-func GetSupportedPackageManagersList() []string {
- allSupportedPackageManagers := maps.Keys(packageManagerToRepositoryPackageType)
- // Sort keys based on their natural enum order
- slices.SortFunc(allSupportedPackageManagers, func(a, b project.ProjectType) int {
- return int(a) - int(b)
- })
- // Convert enums to their string representation
- result := make([]string, len(allSupportedPackageManagers))
- for i, manager := range allSupportedPackageManagers {
- result[i] = manager.String()
- }
- return result
-}
-
-func IsSupportedPackageManager(packageManager project.ProjectType) bool {
- _, exists := packageManagerToRepositoryPackageType[packageManager]
- return exists
-}
-
-// CommandName returns the name of the login command.
-func (sc *SetupCommand) CommandName() string {
- return sc.commandName
-}
-
-// SetServerDetails assigns the server configuration details to the command.
-func (sc *SetupCommand) SetServerDetails(serverDetails *config.ServerDetails) *SetupCommand {
- sc.serverDetails = serverDetails
- return sc
-}
-
-// ServerDetails returns the stored server configuration details.
-func (sc *SetupCommand) ServerDetails() (*config.ServerDetails, error) {
- return sc.serverDetails, nil
-}
-
-// SetRepoName assigns the repository name to the command.
-func (sc *SetupCommand) SetRepoName(repoName string) *SetupCommand {
- sc.repoName = repoName
- return sc
-}
-
-// SetProjectKey assigns the project key to the command.
-func (sc *SetupCommand) SetProjectKey(projectKey string) *SetupCommand {
- sc.projectKey = projectKey
- return sc
-}
-
-// Run executes the configuration method corresponding to the package manager specified for the command.
-func (sc *SetupCommand) Run() (err error) {
- if !IsSupportedPackageManager(sc.packageManager) {
- return errorutils.CheckErrorf("unsupported package manager: %s", sc.packageManager)
- }
-
- if sc.repoName == "" {
- // Prompt the user to select a virtual repository that matches the package manager.
- if err = sc.promptUserToSelectRepository(); err != nil {
- return err
- }
- }
-
- // Configure the appropriate package manager based on the package manager.
- switch sc.packageManager {
- case project.Npm, project.Pnpm:
- err = sc.configureNpmPnpm()
- case project.Yarn:
- err = sc.configureYarn()
- case project.Pip, project.Pipenv:
- err = sc.configurePip()
- case project.Poetry:
- err = sc.configurePoetry()
- case project.Go:
- err = sc.configureGo()
- case project.Nuget, project.Dotnet:
- err = sc.configureDotnetNuget()
- case project.Docker, project.Podman:
- err = sc.configureContainer()
- default:
- err = errorutils.CheckErrorf("unsupported package manager: %s", sc.packageManager)
- }
- if err != nil {
- return fmt.Errorf("failed to configure %s: %w", sc.packageManager.String(), err)
- }
-
- log.Output(fmt.Sprintf("Successfully configured %s to use JFrog Artifactory repository '%s'.", coreutils.PrintBoldTitle(sc.packageManager.String()), coreutils.PrintBoldTitle(sc.repoName)))
- return nil
-}
-
-// promptUserToSelectRepository prompts the user to select a compatible virtual repository.
-func (sc *SetupCommand) promptUserToSelectRepository() (err error) {
- repoFilterParams := services.RepositoriesFilterParams{
- RepoType: utils.Virtual.String(),
- PackageType: packageManagerToRepositoryPackageType[sc.packageManager],
- ProjectKey: sc.projectKey,
- }
-
- // Prompt for repository selection based on filter parameters.
- sc.repoName, err = utils.SelectRepositoryInteractively(
- sc.serverDetails,
- repoFilterParams,
- fmt.Sprintf("To configure %s, we need you to select a %s repository in Artifactory", repoFilterParams.PackageType, repoFilterParams.RepoType))
-
- return err
-}
-
-// configurePip sets the global index-url for pip and pipenv to use the Artifactory PyPI repository.
-// Runs the following command:
-//
-// pip config set global.index-url https://:@/artifactory/api/pypi//simple
-//
-// Note: Custom configuration file can be set by setting the PIP_CONFIG_FILE environment variable.
-func (sc *SetupCommand) configurePip() error {
- repoWithCredsUrl, err := pythoncommands.GetPypiRepoUrl(sc.serverDetails, sc.repoName, false)
- if err != nil {
- return err
- }
- // If PIP_CONFIG_FILE is set, write the configuration to the custom config file manually.
- // Using 'pip config set' native command is not supported together with PIP_CONFIG_FILE.
- if customPipConfigPath := os.Getenv("PIP_CONFIG_FILE"); customPipConfigPath != "" {
- return pythoncommands.CreatePipConfigManually(customPipConfigPath, repoWithCredsUrl)
- }
- return pythoncommands.RunConfigCommand(project.Pip, []string{"set", "global.index-url", repoWithCredsUrl})
-}
-
-// configurePoetry configures Poetry to use the specified repository and authentication credentials.
-// Runs the following commands:
-//
-// poetry config repositories. https:///artifactory/api/pypi//simple
-// poetry config http-basic.
-//
-// Note: Custom configuration file can be set by setting the POETRY_CONFIG_DIR environment variable.
-func (sc *SetupCommand) configurePoetry() error {
- repoUrl, username, password, err := pythoncommands.GetPypiRepoUrlWithCredentials(sc.serverDetails, sc.repoName, false)
- if err != nil {
- return err
- }
- return pythoncommands.RunPoetryConfig(repoUrl.String(), username, password, sc.repoName)
-}
-
-// configureNpmPnpm configures npm to use the Artifactory repository URL and sets authentication. Pnpm supports the same commands.
-// Runs the following commands:
-//
-// npm/pnpm config set registry https:///artifactory/api/npm/
-//
-// For token-based auth:
-//
-// npm/pnpm config set //your-artifactory-url/artifactory/api/npm//:_authToken ""
-//
-// For basic auth:
-//
-// npm/pnpm config set //your-artifactory-url/artifactory/api/npm//:_auth ""
-//
-// Note: Custom configuration file can be set by setting the NPM_CONFIG_USERCONFIG environment variable.
-func (sc *SetupCommand) configureNpmPnpm() error {
- repoUrl := commandsutils.GetNpmRepositoryUrl(sc.repoName, sc.serverDetails.ArtifactoryUrl)
- if err := npm.ConfigSet(commandsutils.NpmConfigRegistryKey, repoUrl, sc.packageManager.String()); err != nil {
- return err
- }
-
- authKey, authValue := commandsutils.GetNpmAuthKeyValue(sc.serverDetails, repoUrl)
- if authKey != "" && authValue != "" {
- return npm.ConfigSet(authKey, authValue, sc.packageManager.String())
- }
- return nil
-}
-
-// configureYarn configures Yarn to use the specified Artifactory repository and sets authentication.
-// Runs the following commands:
-//
-// yarn config set registry https:///artifactory/api/npm/
-//
-// For token-based auth:
-//
-// yarn config set //your-artifactory-url/artifactory/api/npm//:_authToken ""
-//
-// For basic auth:
-//
-// yarn config set //your-artifactory-url/artifactory/api/npm//:_auth ""
-//
-// Note: Custom configuration file can be set by setting the YARN_RC_FILENAME environment variable.
-func (sc *SetupCommand) configureYarn() (err error) {
- repoUrl := commandsutils.GetNpmRepositoryUrl(sc.repoName, sc.serverDetails.ArtifactoryUrl)
- if err = yarn.ConfigSet(commandsutils.NpmConfigRegistryKey, repoUrl, "yarn", false); err != nil {
- return err
- }
-
- authKey, authValue := commandsutils.GetNpmAuthKeyValue(sc.serverDetails, repoUrl)
- if authKey != "" && authValue != "" {
- return yarn.ConfigSet(authKey, authValue, "yarn", false)
- }
- return nil
-}
-
-// configureGo configures Go to use the Artifactory repository for GOPROXY.
-// Runs the following command:
-//
-// go env -w GOPROXY=https://:@/artifactory/go/,direct
-func (sc *SetupCommand) configureGo() error {
- repoWithCredsUrl, err := gocommands.GetArtifactoryRemoteRepoUrl(sc.serverDetails, sc.repoName, gocommands.GoProxyUrlParams{Direct: true})
- if err != nil {
- return err
- }
- return biutils.RunGo([]string{"env", "-w", "GOPROXY=" + repoWithCredsUrl}, "")
-}
-
-// configureDotnetNuget configures NuGet or .NET Core to use the specified Artifactory repository with credentials.
-// Adds the repository source to the NuGet configuration file, using appropriate credentials for authentication.
-// The following command is run for dotnet:
-//
-// dotnet nuget add source --name "https://acme.jfrog.io/artifactory/api/nuget/{repository-name}" --username --password
-//
-// For NuGet:
-//
-// nuget sources add -Name -Source "https://acme.jfrog.io/artifactory/api/nuget/{repository-name}" -Username -Password
-//
-// Note: Custom dotnet/nuget configuration file can be set by setting the DOTNET_CLI_HOME/NUGET_CONFIG_FILE environment variable.
-func (sc *SetupCommand) configureDotnetNuget() error {
- // Retrieve repository URL and credentials for NuGet or .NET Core.
- sourceUrl, user, password, err := dotnet.GetSourceDetails(sc.serverDetails, sc.repoName, false)
- if err != nil {
- return err
- }
-
- // Determine toolchain type based on the package manager
- toolchainType := bidotnet.DotnetCore
- if sc.packageManager == project.Nuget {
- toolchainType = bidotnet.Nuget
- }
-
- // Get config path from the environment if provided
- customConfigPath := dotnet.GetConfigPathFromEnvIfProvided(toolchainType)
- if customConfigPath != "" {
- // Ensure the config file exists
- if err = dotnet.CreateConfigFileIfNeeded(customConfigPath); err != nil {
- return err
- }
- }
-
- // Remove existing source if it exists
- if err = dotnet.RemoveSourceFromNugetConfigIfExists(toolchainType, customConfigPath); err != nil {
- return err
- }
-
- // Add the repository as a source in the NuGet configuration with credentials for authentication
- return dotnet.AddSourceToNugetConfig(toolchainType, sourceUrl, user, password, customConfigPath)
-}
-
-// configureContainer configures container managers like Docker or Podman to authenticate with JFrog Artifactory.
-// It performs a login using the container manager's CLI command.
-//
-// For Docker:
-//
-// echo | docker login -u --password-stdin
-//
-// For Podman:
-//
-// echo | podman login -u --password-stdin
-func (sc *SetupCommand) configureContainer() error {
- var containerManagerType container.ContainerManagerType
- switch sc.packageManager {
- case project.Docker:
- containerManagerType = container.DockerClient
- case project.Podman:
- containerManagerType = container.Podman
- default:
- return errorutils.CheckErrorf("unsupported container manager: %s", sc.packageManager)
- }
- // Parse the URL to remove the scheme (https:// or http://)
- parsedPlatformURL, err := url.Parse(sc.serverDetails.GetUrl())
- if err != nil {
- return err
- }
- urlWithoutScheme := parsedPlatformURL.Host + parsedPlatformURL.Path
- return container.ContainerManagerLogin(
- urlWithoutScheme,
- &container.ContainerManagerLoginConfig{ServerDetails: sc.serverDetails},
- containerManagerType,
- )
-}
diff --git a/artifactory/commands/setup/setup_test.go b/artifactory/commands/setup/setup_test.go
deleted file mode 100644
index 7fffd7724..000000000
--- a/artifactory/commands/setup/setup_test.go
+++ /dev/null
@@ -1,391 +0,0 @@
-package setup
-
-import (
- "fmt"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/dotnet"
- cmdutils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/auth"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "golang.org/x/exp/slices"
- "os"
- "os/exec"
- "path/filepath"
- "strings"
- "testing"
-)
-
-// #nosec G101 -- Dummy token for tests
-var dummyToken = "eyJ2ZXIiOiIyIiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYiLCJraWQiOiJIcnU2VHctZk1yOTV3dy12TDNjV3ZBVjJ3Qm9FSHpHdGlwUEFwOE1JdDljIn0.eyJzdWIiOiJqZnJ0QDAxYzNnZmZoZzJlOHc2MTQ5ZTNhMnEwdzk3XC91c2Vyc1wvYWRtaW4iLCJzY3AiOiJtZW1iZXItb2YtZ3JvdXBzOnJlYWRlcnMgYXBpOioiLCJhdWQiOiJqZnJ0QDAxYzNnZmZoZzJlOHc2MTQ5ZTNhMnEwdzk3IiwiaXNzIjoiamZydEAwMWMzZ2ZmaGcyZTh3NjE0OWUzYTJxMHc5NyIsImV4cCI6MTU1NjAzNzc2NSwiaWF0IjoxNTU2MDM0MTY1LCJqdGkiOiI1M2FlMzgyMy05NGM3LTQ0OGItOGExOC1iZGVhNDBiZjFlMjAifQ.Bp3sdvppvRxysMlLgqT48nRIHXISj9sJUCXrm7pp8evJGZW1S9hFuK1olPmcSybk2HNzdzoMcwhUmdUzAssiQkQvqd_HanRcfFbrHeg5l1fUQ397ECES-r5xK18SYtG1VR7LNTVzhJqkmRd3jzqfmIK2hKWpEgPfm8DRz3j4GGtDRxhb3oaVsT2tSSi_VfT3Ry74tzmO0GcCvmBE2oh58kUZ4QfEsalgZ8IpYHTxovsgDx_M7ujOSZx_hzpz-iy268-OkrU22PQPCfBmlbEKeEUStUO9n0pj4l1ODL31AGARyJRy46w4yzhw7Fk5P336WmDMXYs5LAX2XxPFNLvNzA"
-
-var testCases = []struct {
- name string
- user string
- password string
- accessToken string
-}{
- {
- name: "Token Authentication",
- accessToken: dummyToken,
- },
- {
- name: "Basic Authentication",
- user: "myUser",
- password: "myPassword",
- },
- {
- name: "Anonymous Access",
- },
-}
-
-func createTestSetupCommand(packageManager project.ProjectType) *SetupCommand {
- cmd := NewSetupCommand(packageManager)
- cmd.repoName = "test-repo"
- dummyUrl := "https://acme.jfrog.io"
- cmd.serverDetails = &config.ServerDetails{Url: dummyUrl, ArtifactoryUrl: dummyUrl + "/artifactory"}
-
- return cmd
-}
-
-func TestSetupCommand_NotSupported(t *testing.T) {
- notSupportedLoginCmd := createTestSetupCommand(project.Cocoapods)
- err := notSupportedLoginCmd.Run()
- assert.Error(t, err)
- assert.ErrorContains(t, err, "unsupported package manager")
-}
-
-func TestSetupCommand_Npm(t *testing.T) {
- testSetupCommandNpmPnpm(t, project.Npm)
-}
-
-func TestSetupCommand_Pnpm(t *testing.T) {
- testSetupCommandNpmPnpm(t, project.Pnpm)
-}
-
-func testSetupCommandNpmPnpm(t *testing.T, packageManager project.ProjectType) {
- // Create a temporary directory to act as the environment's npmrc file location.
- tempDir := t.TempDir()
- npmrcFilePath := filepath.Join(tempDir, ".npmrc")
-
- // Set NPM_CONFIG_USERCONFIG to point to the temporary npmrc file path.
- t.Setenv("NPM_CONFIG_USERCONFIG", npmrcFilePath)
-
- loginCmd := createTestSetupCommand(packageManager)
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- // Set up server details for the current test case's authentication type.
- loginCmd.serverDetails.SetUser(testCase.user)
- loginCmd.serverDetails.SetPassword(testCase.password)
- loginCmd.serverDetails.SetAccessToken(testCase.accessToken)
-
- // Run the login command and ensure no errors occur.
- require.NoError(t, loginCmd.Run())
-
- // Read the contents of the temporary npmrc file.
- npmrcContentBytes, err := os.ReadFile(npmrcFilePath)
- assert.NoError(t, err)
- npmrcContent := string(npmrcContentBytes)
-
- // Validate that the registry URL was set correctly in .npmrc.
- assert.Contains(t, npmrcContent, fmt.Sprintf("%s=%s", cmdutils.NpmConfigRegistryKey, "https://acme.jfrog.io/artifactory/api/npm/test-repo"))
-
- // Validate token-based authentication.
- if testCase.accessToken != "" {
- assert.Contains(t, npmrcContent, fmt.Sprintf("//acme.jfrog.io/artifactory/api/npm/test-repo:%s=%s", cmdutils.NpmConfigAuthTokenKey, dummyToken))
- } else if testCase.user != "" && testCase.password != "" {
- // Validate basic authentication with encoded credentials.
- // Base64 encoding of "myUser:myPassword"
- expectedBasicAuth := fmt.Sprintf("//acme.jfrog.io/artifactory/api/npm/test-repo:%s=\"bXlVc2VyOm15UGFzc3dvcmQ=\"", cmdutils.NpmConfigAuthKey)
- assert.Contains(t, npmrcContent, expectedBasicAuth)
- }
-
- // Clean up the temporary npmrc file.
- assert.NoError(t, os.Remove(npmrcFilePath))
- })
- }
-}
-
-func TestSetupCommand_Yarn(t *testing.T) {
- // Retrieve the home directory and construct the .yarnrc file path.
- homeDir, err := os.UserHomeDir()
- assert.NoError(t, err)
- yarnrcFilePath := filepath.Join(homeDir, ".yarnrc")
-
- // Back up the existing .yarnrc file and ensure restoration after the test.
- restoreYarnrcFunc, err := ioutils.BackupFile(yarnrcFilePath, ".yarnrc.backup")
- assert.NoError(t, err)
- defer func() {
- assert.NoError(t, restoreYarnrcFunc())
- }()
-
- yarnLoginCmd := createTestSetupCommand(project.Yarn)
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- // Set up server details for the current test case's authentication type.
- yarnLoginCmd.serverDetails.SetUser(testCase.user)
- yarnLoginCmd.serverDetails.SetPassword(testCase.password)
- yarnLoginCmd.serverDetails.SetAccessToken(testCase.accessToken)
-
- // Run the login command and ensure no errors occur.
- require.NoError(t, yarnLoginCmd.Run())
-
- // Read the contents of the temporary npmrc file.
- yarnrcContentBytes, err := os.ReadFile(yarnrcFilePath)
- assert.NoError(t, err)
- yarnrcContent := string(yarnrcContentBytes)
-
- // Check that the registry URL is correctly set in .yarnrc.
- assert.Contains(t, yarnrcContent, fmt.Sprintf("%s \"%s\"", cmdutils.NpmConfigRegistryKey, "https://acme.jfrog.io/artifactory/api/npm/test-repo"))
-
- // Validate token-based authentication.
- if testCase.accessToken != "" {
- assert.Contains(t, yarnrcContent, fmt.Sprintf("\"//acme.jfrog.io/artifactory/api/npm/test-repo:%s\" %s", cmdutils.NpmConfigAuthTokenKey, dummyToken))
-
- } else if testCase.user != "" && testCase.password != "" {
- // Validate basic authentication with encoded credentials.
- // Base64 encoding of "myUser:myPassword"
- assert.Contains(t, yarnrcContent, fmt.Sprintf("\"//acme.jfrog.io/artifactory/api/npm/test-repo:%s\" bXlVc2VyOm15UGFzc3dvcmQ=", cmdutils.NpmConfigAuthKey))
- }
-
- // Clean up the temporary npmrc file.
- assert.NoError(t, os.Remove(yarnrcFilePath))
- })
- }
-}
-
-func TestSetupCommand_Pip(t *testing.T) {
- // Test with global configuration file.
- testSetupCommandPip(t, project.Pip, false)
- // Test with custom configuration file.
- testSetupCommandPip(t, project.Pip, true)
-}
-
-func testSetupCommandPip(t *testing.T, packageManager project.ProjectType, customConfig bool) {
- var pipConfFilePath string
- if customConfig {
- // For custom configuration file, set the PIP_CONFIG_FILE environment variable to point to the temporary pip.conf file.
- pipConfFilePath = filepath.Join(t.TempDir(), "pip.conf")
- t.Setenv("PIP_CONFIG_FILE", pipConfFilePath)
- } else {
- // For global configuration file, back up the existing pip.conf file and ensure restoration after the test.
- var restoreFunc func()
- pipConfFilePath, restoreFunc = globalGlobalPipConfigPath(t)
- defer restoreFunc()
- }
-
- pipLoginCmd := createTestSetupCommand(packageManager)
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- // Set up server details for the current test case's authentication type.
- pipLoginCmd.serverDetails.SetUser(testCase.user)
- pipLoginCmd.serverDetails.SetPassword(testCase.password)
- pipLoginCmd.serverDetails.SetAccessToken(testCase.accessToken)
-
- // Run the login command and ensure no errors occur.
- require.NoError(t, pipLoginCmd.Run())
-
- // Read the contents of the temporary pip config file.
- pipConfigContentBytes, err := os.ReadFile(pipConfFilePath)
- assert.NoError(t, err)
- pipConfigContent := string(pipConfigContentBytes)
-
- switch {
- case testCase.accessToken != "":
- // Validate token-based authentication.
- assert.Contains(t, pipConfigContent, fmt.Sprintf("index-url = https://%s:%s@acme.jfrog.io/artifactory/api/pypi/test-repo/simple", auth.ExtractUsernameFromAccessToken(testCase.accessToken), testCase.accessToken))
- case testCase.user != "" && testCase.password != "":
- // Validate basic authentication with user and password.
- assert.Contains(t, pipConfigContent, fmt.Sprintf("index-url = https://%s:%s@acme.jfrog.io/artifactory/api/pypi/test-repo/simple", "myUser", "myPassword"))
- default:
- // Validate anonymous access.
- assert.Contains(t, pipConfigContent, "index-url = https://acme.jfrog.io/artifactory/api/pypi/test-repo/simple")
- }
-
- // Clean up the temporary pip config file.
- assert.NoError(t, os.Remove(pipConfFilePath))
- })
- }
-}
-
-// globalGlobalPipConfigPath returns the path to the global pip.conf file and a backup function to restore the original file.
-func globalGlobalPipConfigPath(t *testing.T) (string, func()) {
- var pipConfFilePath string
- if coreutils.IsWindows() {
- pipConfFilePath = filepath.Join(os.Getenv("APPDATA"), "pip", "pip.ini")
- } else {
- // Retrieve the home directory and construct the pip.conf file path.
- homeDir, err := os.UserHomeDir()
- assert.NoError(t, err)
- pipConfFilePath = filepath.Join(homeDir, ".config", "pip", "pip.conf")
- }
- // Back up the existing .pip.conf file and ensure restoration after the test.
- restorePipConfFunc, err := ioutils.BackupFile(pipConfFilePath, ".pipconf.backup")
- assert.NoError(t, err)
- return pipConfFilePath, func() {
- assert.NoError(t, restorePipConfFunc())
- }
-}
-
-func TestSetupCommand_configurePoetry(t *testing.T) {
- configDir := t.TempDir()
- poetryConfigFilePath := filepath.Join(configDir, "config.toml")
- poetryAuthFilePath := filepath.Join(configDir, "auth.toml")
- t.Setenv("POETRY_CONFIG_DIR", configDir)
- poetryLoginCmd := createTestSetupCommand(project.Poetry)
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- // Set up server details for the current test case's authentication type.
- poetryLoginCmd.serverDetails.SetUser(testCase.user)
- poetryLoginCmd.serverDetails.SetPassword(testCase.password)
- poetryLoginCmd.serverDetails.SetAccessToken(testCase.accessToken)
-
- // Run the login command and ensure no errors occur.
- require.NoError(t, poetryLoginCmd.Run())
-
- // Validate that the repository URL was set correctly in config.toml.
- // Read the contents of the temporary Poetry config file.
- poetryConfigContentBytes, err := os.ReadFile(poetryConfigFilePath)
- assert.NoError(t, err)
- poetryConfigContent := string(poetryConfigContentBytes)
- // Normalize line endings for comparison.(For Windows)
- poetryConfigContent = strings.ReplaceAll(poetryConfigContent, "\r\n", "\n")
-
- assert.Contains(t, poetryConfigContent, "[repositories.test-repo]\nurl = \"https://acme.jfrog.io/artifactory/api/pypi/test-repo/simple\"")
-
- // Validate that the auth details were set correctly in auth.toml.
- // Read the contents of the temporary Poetry config file.
- poetryAuthContentBytes, err := os.ReadFile(poetryAuthFilePath)
- assert.NoError(t, err)
- poetryAuthContent := string(poetryAuthContentBytes)
- // Normalize line endings for comparison.(For Windows)
- poetryAuthContent = strings.ReplaceAll(poetryAuthContent, "\r\n", "\n")
-
- if testCase.accessToken != "" {
- // Validate token-based authentication (The token is stored in the keyring so we can't test it)
- assert.Contains(t, poetryAuthContent, fmt.Sprintf("[http-basic.test-repo]\nusername = \"%s\"", auth.ExtractUsernameFromAccessToken(testCase.accessToken)))
- } else if testCase.user != "" && testCase.password != "" {
- // Validate basic authentication with user and password. (The password is stored in the keyring so we can't test it)
- assert.Contains(t, poetryAuthContent, fmt.Sprintf("[http-basic.test-repo]\nusername = \"%s\"", "myUser"))
- }
-
- // Clean up the temporary Poetry config files.
- assert.NoError(t, os.Remove(poetryConfigFilePath))
- assert.NoError(t, os.Remove(poetryAuthFilePath))
- })
- }
-}
-
-func TestSetupCommand_Go(t *testing.T) {
- goProxyEnv := "GOPROXY"
- // Restore the original value of the GOPROXY environment variable after the test.
- t.Setenv(goProxyEnv, "")
-
- // Assuming createTestSetupCommand initializes your Go login command
- goLoginCmd := createTestSetupCommand(project.Go)
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- // Set up server details for the current test case's authentication type.
- goLoginCmd.serverDetails.SetUser(testCase.user)
- goLoginCmd.serverDetails.SetPassword(testCase.password)
- goLoginCmd.serverDetails.SetAccessToken(testCase.accessToken)
-
- // Run the login command and ensure no errors occur.
- require.NoError(t, goLoginCmd.Run())
-
- // Get the value of the GOPROXY environment variable.
- outputBytes, err := exec.Command("go", "env", goProxyEnv).Output()
- assert.NoError(t, err)
- goProxy := string(outputBytes)
-
- switch {
- case testCase.accessToken != "":
- // Validate token-based authentication.
- assert.Contains(t, goProxy, fmt.Sprintf("https://%s:%s@acme.jfrog.io/artifactory/api/go/test-repo", auth.ExtractUsernameFromAccessToken(testCase.accessToken), testCase.accessToken))
- case testCase.user != "" && testCase.password != "":
- // Validate basic authentication with user and password.
- assert.Contains(t, goProxy, fmt.Sprintf("https://%s:%s@acme.jfrog.io/artifactory/api/go/test-repo", "myUser", "myPassword"))
- default:
- // Validate anonymous access.
- assert.Contains(t, goProxy, "https://acme.jfrog.io/artifactory/api/go/test-repo")
- }
- })
- }
-}
-
-func TestBuildToolLoginCommand_configureNuget(t *testing.T) {
- testBuildToolLoginCommandConfigureDotnetNuget(t, project.Nuget)
-}
-
-func TestBuildToolLoginCommand_configureDotnet(t *testing.T) {
- testBuildToolLoginCommandConfigureDotnetNuget(t, project.Dotnet)
-}
-
-func testBuildToolLoginCommandConfigureDotnetNuget(t *testing.T, packageManager project.ProjectType) {
- var nugetConfigFilePath string
-
- // Set the NuGet.config file path to a custom location.
- if packageManager == project.Dotnet {
- nugetConfigFilePath = filepath.Join(t.TempDir(), "NuGet.Config")
- t.Setenv("DOTNET_CLI_HOME", filepath.Dir(nugetConfigFilePath))
- } else {
- nugetConfigFilePath = filepath.Join(t.TempDir(), "nuget.config")
- t.Setenv("NUGET_CONFIG_FILE", nugetConfigFilePath)
- }
-
- nugetLoginCmd := createTestSetupCommand(packageManager)
-
- for _, testCase := range testCases {
- t.Run(testCase.name, func(t *testing.T) {
- // Set up server details for the current test case's authentication type.
- nugetLoginCmd.serverDetails.SetUser(testCase.user)
- nugetLoginCmd.serverDetails.SetPassword(testCase.password)
- nugetLoginCmd.serverDetails.SetAccessToken(testCase.accessToken)
-
- // Run the login command and ensure no errors occur.
- require.NoError(t, nugetLoginCmd.Run())
-
- // Validate that the repository URL was set correctly in Nuget.config.
- // Read the contents of the temporary Poetry config file.
- nugetConfigContentBytes, err := os.ReadFile(nugetConfigFilePath)
- require.NoError(t, err)
-
- nugetConfigContent := string(nugetConfigContentBytes)
-
- assert.Contains(t, nugetConfigContent, fmt.Sprintf("add key=\"%s\" value=\"https://acme.jfrog.io/artifactory/api/nuget/v3/test-repo\"", dotnet.SourceName))
-
- if testCase.accessToken != "" {
- // Validate token-based authentication (The token is encoded so we can't test it)
- assert.Contains(t, nugetConfigContent, fmt.Sprintf("", auth.ExtractUsernameFromAccessToken(testCase.accessToken)))
- } else if testCase.user != "" && testCase.password != "" {
- // Validate basic nugetConfigContent with user and password. (The password is encoded so we can't test it)
- assert.Contains(t, nugetConfigContent, fmt.Sprintf("", testCase.user))
- }
- })
- }
-}
-
-func TestGetSupportedPackageManagersList(t *testing.T) {
- packageManagersList := GetSupportedPackageManagersList()
- // Check that "Go" is before "Pip", and "Pip" is before "Npm"
- assert.Less(t, slices.Index(packageManagersList, project.Go.String()), slices.Index(packageManagersList, project.Pip.String()), "Go should come before Pip")
- assert.Less(t, slices.Index(packageManagersList, project.Pip.String()), slices.Index(packageManagersList, project.Npm.String()), "Pip should come before Npm")
-}
-
-func TestIsSupportedPackageManager(t *testing.T) {
- // Test valid package managers
- for pm := range packageManagerToRepositoryPackageType {
- assert.True(t, IsSupportedPackageManager(pm), "Package manager %s should be supported", pm)
- }
-
- // Test unsupported package manager
- assert.False(t, IsSupportedPackageManager(project.Cocoapods), "Package manager Cocoapods should not be supported")
-}
diff --git a/artifactory/commands/terraform/terraformpublish.go b/artifactory/commands/terraform/terraformpublish.go
deleted file mode 100644
index 853683d82..000000000
--- a/artifactory/commands/terraform/terraformpublish.go
+++ /dev/null
@@ -1,376 +0,0 @@
-package terraform
-
-import (
- "errors"
- buildInfo "github.com/jfrog/build-info-go/entities"
- ioutils "github.com/jfrog/gofrog/io"
- "github.com/jfrog/gofrog/parallel"
- commandsUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/build"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/artifactory"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- servicesUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientUtils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
- "golang.org/x/exp/slices"
- "io"
- "io/fs"
- "os"
- "path"
- "path/filepath"
- "strings"
-)
-
-const threads = 3
-
-type TerraformPublishCommandArgs struct {
- namespace string
- provider string
- tag string
- exclusions []string
- buildConfiguration *build.BuildConfiguration
- collectBuildInfo bool
- buildProps string
-}
-
-type TerraformPublishCommand struct {
- *TerraformPublishCommandArgs
- args []string
- repo string
- configFilePath string
- serverDetails *config.ServerDetails
- result *commandsUtils.Result
-}
-
-func NewTerraformPublishCommand() *TerraformPublishCommand {
- return &TerraformPublishCommand{TerraformPublishCommandArgs: NewTerraformPublishCommandArgs(), result: new(commandsUtils.Result)}
-}
-
-func NewTerraformPublishCommandArgs() *TerraformPublishCommandArgs {
- return &TerraformPublishCommandArgs{}
-}
-
-func (tpc *TerraformPublishCommand) SetArgs(terraformArg []string) *TerraformPublishCommand {
- tpc.args = terraformArg
- return tpc
-}
-
-func (tpc *TerraformPublishCommand) setServerDetails(serverDetails *config.ServerDetails) {
- tpc.serverDetails = serverDetails
-}
-
-func (tpc *TerraformPublishCommand) setRepoConfig(conf *project.RepositoryConfig) *TerraformPublishCommand {
- serverDetails, _ := conf.ServerDetails()
- tpc.setRepo(conf.TargetRepo()).setServerDetails(serverDetails)
- return tpc
-}
-
-func (tpc *TerraformPublishCommand) setRepo(repo string) *TerraformPublishCommand {
- tpc.repo = repo
- return tpc
-}
-
-func (tpc *TerraformPublishCommand) ServerDetails() (*config.ServerDetails, error) {
- return tpc.serverDetails, nil
-}
-
-func (tpc *TerraformPublishCommand) CommandName() string {
- return "rt_terraform_publish"
-}
-
-func (tpc *TerraformPublishCommand) SetConfigFilePath(configFilePath string) *TerraformPublishCommand {
- tpc.configFilePath = configFilePath
- return tpc
-}
-
-func (tpc *TerraformPublishCommand) Result() *commandsUtils.Result {
- return tpc.result
-}
-
-func (tpc *TerraformPublishCommand) Run() error {
- log.Info("Running Terraform publish")
- err := tpc.publish()
- if err != nil {
- return err
- }
- log.Info("Terraform publish finished successfully.")
- return nil
-}
-
-func (tpc *TerraformPublishCommand) Init() error {
- err := tpc.extractTerraformPublishOptionsFromArgs(tpc.args)
- if err != nil {
- return err
- }
- if tpc.namespace == "" || tpc.provider == "" || tpc.tag == "" {
- return errorutils.CheckErrorf("the --namespace, --provider and --tag options are mandatory")
- }
- if err = tpc.setRepoFromConfiguration(); err != nil {
- return err
- }
- artDetails, err := tpc.serverDetails.CreateArtAuthConfig()
- if err != nil {
- return err
- }
- if err = utils.ValidateRepoExists(tpc.repo, artDetails); err != nil {
- return err
- }
- tpc.collectBuildInfo, err = tpc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
- if tpc.collectBuildInfo {
- tpc.buildProps, err = build.CreateBuildPropsFromConfiguration(tpc.buildConfiguration)
- }
- return err
-}
-
-func (tpc *TerraformPublishCommand) publish() error {
- log.Debug("Deploying terraform module...")
- success, failed, err := tpc.terraformPublish()
- if err != nil {
- return err
- }
- tpc.result.SetSuccessCount(success)
- tpc.result.SetFailCount(failed)
- return nil
-}
-
-func (tpa *TerraformPublishCommandArgs) extractTerraformPublishOptionsFromArgs(args []string) (err error) {
- // Extract namespace information from the args.
- var flagIndex, valueIndex int
- flagIndex, valueIndex, tpa.namespace, err = coreutils.FindFlag("--namespace", args)
- if err != nil {
- return
- }
- coreutils.RemoveFlagFromCommand(&args, flagIndex, valueIndex)
- // Extract provider information from the args.
- flagIndex, valueIndex, tpa.provider, err = coreutils.FindFlag("--provider", args)
- if err != nil {
- return
- }
- coreutils.RemoveFlagFromCommand(&args, flagIndex, valueIndex)
- // Extract tag information from the args.
- flagIndex, valueIndex, tpa.tag, err = coreutils.FindFlag("--tag", args)
- if err != nil {
- return
- }
- coreutils.RemoveFlagFromCommand(&args, flagIndex, valueIndex)
- // Extract exclusions information from the args.
- flagIndex, valueIndex, exclusionsString, err := coreutils.FindFlag("--exclusions", args)
- if err != nil {
- return
- }
- tpa.exclusions = append(tpa.exclusions, strings.Split(exclusionsString, ";")...)
- coreutils.RemoveFlagFromCommand(&args, flagIndex, valueIndex)
- args, tpa.buildConfiguration, err = build.ExtractBuildDetailsFromArgs(args)
- if err != nil {
- return err
- }
- if len(args) != 0 {
- err = errorutils.CheckErrorf("Unknown flag:" + strings.Split(args[0], "=")[0] + ". for a terraform publish command please provide --namespace, --provider, --tag and optionally --exclusions.")
- }
- return
-}
-
-func (tpc *TerraformPublishCommand) terraformPublish() (int, int, error) {
- uploadSummary := getNewUploadSummaryMultiArray()
- producerConsumer := parallel.NewRunner(3, 20000, false)
- errorsQueue := clientUtils.NewErrorsQueue(threads)
-
- tpc.prepareTerraformPublishTasks(producerConsumer, errorsQueue, uploadSummary)
- tpc.performTerraformPublishTasks(producerConsumer)
- e := errorsQueue.GetError()
- if e != nil {
- return 0, 0, e
- }
- return tpc.aggregateSummaryResults(uploadSummary)
-}
-
-func (tpc *TerraformPublishCommand) prepareTerraformPublishTasks(producer parallel.Runner, errorsQueue *clientUtils.ErrorsQueue, uploadSummary *[][]*servicesUtils.OperationSummary) {
- go func() {
- defer producer.Done()
- pwd, err := os.Getwd()
- if err != nil {
- log.Error(err)
- errorsQueue.AddError(err)
- }
- // Walk and upload directories which contain '.tf' files.
- err = tpc.walkDirAndUploadTerraformModules(pwd, producer, errorsQueue, uploadSummary, addTaskWithError)
- if err != nil && err != io.EOF {
- log.Error(err)
- errorsQueue.AddError(err)
- }
- }()
-}
-
-// ProduceTaskFunc is provided as an argument to 'walkDirAndUploadTerraformModules' function for testing purposes.
-type ProduceTaskFunc func(producer parallel.Runner, serverDetails *config.ServerDetails, uploadSummary *[][]*servicesUtils.OperationSummary, uploadParams *services.UploadParams, errorsQueue *clientUtils.ErrorsQueue) (int, error)
-
-func addTaskWithError(producer parallel.Runner, serverDetails *config.ServerDetails, uploadSummary *[][]*servicesUtils.OperationSummary, uploadParams *services.UploadParams, errorsQueue *clientUtils.ErrorsQueue) (int, error) {
- return producer.AddTaskWithError(uploadModuleTask(serverDetails, uploadSummary, uploadParams), errorsQueue.AddError)
-}
-
-func uploadModuleTask(serverDetails *config.ServerDetails, uploadSummary *[][]*servicesUtils.OperationSummary, uploadParams *services.UploadParams) parallel.TaskFunc {
- return func(threadId int) (err error) {
- summary, err := createServiceManagerAndUpload(serverDetails, uploadParams, false)
- if err != nil {
- return err
- }
- // Add summary to the thread's summary array.
- (*uploadSummary)[threadId] = append((*uploadSummary)[threadId], summary)
- return nil
- }
-}
-
-func createServiceManagerAndUpload(serverDetails *config.ServerDetails, uploadParams *services.UploadParams, dryRun bool) (operationSummary *servicesUtils.OperationSummary, err error) {
- serviceManager, err := utils.CreateServiceManagerWithThreads(serverDetails, dryRun, 1, -1, 0)
- if err != nil {
- return nil, err
- }
- return serviceManager.UploadFilesWithSummary(artifactory.UploadServiceOptions{}, *uploadParams)
-}
-
-func (tpc *TerraformPublishCommand) walkDirAndUploadTerraformModules(pwd string, producer parallel.Runner, errorsQueue *clientUtils.ErrorsQueue, uploadSummary *[][]*servicesUtils.OperationSummary, produceTaskFunc ProduceTaskFunc) error {
- return filepath.WalkDir(pwd, func(path string, info fs.DirEntry, err error) error {
- if err != nil {
- return err
- }
- pathInfo, e := os.Lstat(path)
- if e != nil {
- return errorutils.CheckError(e)
- }
- // Skip files and check only directories.
- if !pathInfo.IsDir() {
- return nil
- }
- isTerraformModule, e := checkIfTerraformModule(path)
- if e != nil {
- return e
- }
- if isTerraformModule {
- uploadParams := tpc.uploadParamsForTerraformPublish(pathInfo.Name(), strings.TrimPrefix(path, pwd+string(filepath.Separator)))
- _, e = produceTaskFunc(producer, tpc.serverDetails, uploadSummary, uploadParams, errorsQueue)
- if e != nil {
- log.Error(e)
- errorsQueue.AddError(e)
- }
-
- // SkipDir will not stop the walk, but it will make us jump to the next directory.
- return filepath.SkipDir
- }
- return nil
- })
-}
-
-func (tpc *TerraformPublishCommand) performTerraformPublishTasks(consumer parallel.Runner) {
- // Blocking until consuming is finished.
- consumer.Run()
-}
-
-// Aggregate the operation summaries from all threads, to get the number of successful and failed uploads.
-// If collecting build info, also aggregate the artifacts uploaded.
-func (tpc *TerraformPublishCommand) aggregateSummaryResults(uploadSummary *[][]*servicesUtils.OperationSummary) (totalUploaded, totalFailed int, err error) {
- var artifacts []buildInfo.Artifact
- for i := 0; i < threads; i++ {
- threadSummary := (*uploadSummary)[i]
- for j := range threadSummary {
- // Operation summary should always be returned.
- if threadSummary[j] == nil {
- return 0, 0, errorutils.CheckErrorf("unexpected nil operation summary")
- }
- totalUploaded += threadSummary[j].TotalSucceeded
- totalFailed += threadSummary[j].TotalFailed
-
- if tpc.collectBuildInfo {
- buildArtifacts, err := readArtifactsFromSummary(threadSummary[j])
- if err != nil {
- return 0, 0, err
- }
- artifacts = append(artifacts, buildArtifacts...)
- }
- }
- }
- if tpc.collectBuildInfo {
- err = build.PopulateBuildArtifactsAsPartials(artifacts, tpc.buildConfiguration, buildInfo.Terraform)
- }
- return
-}
-
-func readArtifactsFromSummary(summary *servicesUtils.OperationSummary) (artifacts []buildInfo.Artifact, err error) {
- artifactsDetailsReader := summary.ArtifactsDetailsReader
- if artifactsDetailsReader == nil {
- return []buildInfo.Artifact{}, nil
- }
- defer ioutils.Close(artifactsDetailsReader, &err)
- return servicesUtils.ConvertArtifactsDetailsToBuildInfoArtifacts(artifactsDetailsReader)
-}
-
-func (tpc *TerraformPublishCommand) uploadParamsForTerraformPublish(moduleName, dirPath string) *services.UploadParams {
- uploadParams := services.NewUploadParams()
- uploadParams.Target = tpc.getPublishTarget(moduleName)
- uploadParams.Pattern = dirPath + "/(*)"
- uploadParams.TargetPathInArchive = "{1}"
- uploadParams.Archive = "zip"
- uploadParams.Recursive = true
- uploadParams.CommonParams.TargetProps = servicesUtils.NewProperties()
- uploadParams.CommonParams.Exclusions = append(slices.Clone(tpc.exclusions), "*.git", "*.DS_Store")
- uploadParams.BuildProps = tpc.buildProps
- return &uploadParams
-}
-
-// Module's path in terraform repository : namespace/moduleName/provider/tag.zip
-func (tpc *TerraformPublishCommand) getPublishTarget(moduleName string) string {
- return path.Join(tpc.repo, tpc.namespace, moduleName, tpc.provider, tpc.tag+".zip")
-}
-
-// We identify a Terraform module by having at least one file with a ".tf" extension inside the module directory.
-func checkIfTerraformModule(path string) (isModule bool, err error) {
- dirname := path + string(filepath.Separator)
- d, err := os.Open(dirname)
- if err != nil {
- return false, errorutils.CheckError(err)
- }
- defer func() {
- err = errors.Join(err, d.Close())
- }()
-
- files, err := d.Readdir(-1)
- if err != nil {
- return false, errorutils.CheckError(err)
- }
- for _, file := range files {
- if file.Mode().IsRegular() {
- if filepath.Ext(file.Name()) == ".tf" {
- return true, nil
- }
- }
- }
- return false, nil
-}
-
-func (tpc *TerraformPublishCommand) setRepoFromConfiguration() error {
- // Read config file.
- log.Debug("Preparing to read the config file", tpc.configFilePath)
- vConfig, err := project.ReadConfigFile(tpc.configFilePath, project.YAML)
- if err != nil {
- return err
- }
- deployerParams, err := project.GetRepoConfigByPrefix(tpc.configFilePath, project.ProjectConfigDeployerPrefix, vConfig)
- if err != nil {
- return err
- }
- tpc.setRepoConfig(deployerParams)
- return nil
-}
-
-// Each thread will save the summary of all its operations, in an array at its corresponding index.
-func getNewUploadSummaryMultiArray() *[][]*servicesUtils.OperationSummary {
- uploadSummary := make([][]*servicesUtils.OperationSummary, threads)
- return &uploadSummary
-}
diff --git a/artifactory/commands/terraform/terraformpublish_test.go b/artifactory/commands/terraform/terraformpublish_test.go
deleted file mode 100644
index d89df81b0..000000000
--- a/artifactory/commands/terraform/terraformpublish_test.go
+++ /dev/null
@@ -1,105 +0,0 @@
-package terraform
-
-import (
- "errors"
- "github.com/jfrog/gofrog/parallel"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- clientServicesUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- clientUtils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/stretchr/testify/assert"
- "path/filepath"
- "testing"
-)
-
-func TestPreparePrerequisites(t *testing.T) {
- terraformPublishArgs := NewTerraformPublishCommandArgs()
- terraformArgs := []string{"--namespace=name", "--provider=aws", "--tag=v0.1.2", "--exclusions=*test*;*ignore*"}
- assert.NoError(t, terraformPublishArgs.extractTerraformPublishOptionsFromArgs(terraformArgs))
- assert.Equal(t, "name", terraformPublishArgs.namespace)
- assert.Equal(t, "aws", terraformPublishArgs.provider)
- assert.Equal(t, "v0.1.2", terraformPublishArgs.tag)
- assert.Equal(t, []string{"*test*", "*ignore*"}, terraformPublishArgs.exclusions)
- // Add unknown flag
- terraformArgs = []string{"--namespace=name", "--provider=aws", "--tag=v0.1.2", "--exclusions=*test*;*ignore*", "--unknown-flag=value"}
- assert.EqualError(t, terraformPublishArgs.extractTerraformPublishOptionsFromArgs(terraformArgs), "Unknown flag:--unknown-flag. for a terraform publish command please provide --namespace, --provider, --tag and optionally --exclusions.")
-}
-
-func TestCheckIfTerraformModule(t *testing.T) {
- dirPath := filepath.Join("..", "testdata", "terraform", "terraform_project")
- // Check terraform module directory which contain files with a ".tf" extension.
- isModule, err := checkIfTerraformModule(dirPath)
- assert.NoError(t, err)
- assert.True(t, isModule)
- // Check npm directory which doesn't contain files with a ".tf" extension.
- dirPath = filepath.Join("..", "testdata", "npm")
- isModule, err = checkIfTerraformModule(dirPath)
- assert.NoError(t, err)
- assert.False(t, isModule)
-}
-
-func TestWalkDirAndUploadTerraformModules(t *testing.T) {
- t.Run("testEmptyModule", func(t *testing.T) { runTerraformTest(t, "empty", mockEmptyModule) })
- t.Run("mockProduceTaskFunc", func(t *testing.T) {
- runTerraformTest(t, "terraform_project", getTaskMock(t, []string{"a.tf", "test_dir/b.tf", "test_dir/submodules/test_submodule/c.tf"}))
- })
- t.Run("testSpecialChar", func(t *testing.T) {
- runTerraformTest(t, "terra$+~&^a#", getTaskMock(t, []string{"a.tf", "$+~&^a#@.tf"}))
- })
- t.Run("testExcludeTestDirectory", func(t *testing.T) {
- runTerraformTestWithExclusions(t, "terraform_project", getTaskMock(t, []string{"a.tf"}), []string{"*test_dir*", "*@*"})
- })
- t.Run("testExcludeTestSubmoduleModule", func(t *testing.T) {
- runTerraformTestWithExclusions(t, filepath.Join("terraform_project", "test_dir"), getTaskMock(t, []string{"b.tf"}), []string{"*test_sub*", "*@*"})
- })
- t.Run("testExcludeSpecialChar", func(t *testing.T) {
- runTerraformTestWithExclusions(t, "terra$+~&^a#", getTaskMock(t, []string{"a.tf"}), []string{"*test_dir*", "*@*"})
- })
-}
-
-func getTerraformTestDir(path string) string {
- return filepath.Join("..", "testdata", "terraform", path)
-}
-
-func runTerraformTest(t *testing.T, subDir string, testFunc ProduceTaskFunc) {
- runTerraformTestWithExclusions(t, subDir, testFunc, []string{})
-}
-
-func runTerraformTestWithExclusions(t *testing.T, subDir string, testFunc ProduceTaskFunc, exclusions []string) {
- terraformPublish := NewTerraformPublishCommand()
- terraformPublish.setServerDetails(&config.ServerDetails{})
- terraformPublish.exclusions = exclusions
- uploadSummary := getNewUploadSummaryMultiArray()
- producerConsumer := parallel.NewRunner(threads, 20000, false)
- errorsQueue := clientUtils.NewErrorsQueue(1)
- assert.NoError(t, terraformPublish.walkDirAndUploadTerraformModules(getTerraformTestDir(subDir), producerConsumer, errorsQueue, uploadSummary, testFunc))
- assert.NoError(t, errorsQueue.GetError())
-}
-
-// In order to verify the walk function has visited the correct dirs, and that the correct files were collected/excluded, we run a dry run upload on the files without an archive.
-func getTaskMock(t *testing.T, expectedPaths []string) func(parallel.Runner, *config.ServerDetails, *[][]*clientServicesUtils.OperationSummary, *services.UploadParams, *clientUtils.ErrorsQueue) (int, error) {
- return func(_ parallel.Runner, serverDetails *config.ServerDetails, _ *[][]*clientServicesUtils.OperationSummary, uploadParams *services.UploadParams, _ *clientUtils.ErrorsQueue) (int, error) {
- uploadParams.Target = uploadParams.TargetPathInArchive
- uploadParams.TargetPathInArchive = ""
- uploadParams.Archive = ""
- uploadParams.Target = "dummy-repo/{1}"
-
- summary, err := createServiceManagerAndUpload(serverDetails, uploadParams, true)
- assert.NoError(t, err)
- if !assert.NotNil(t, summary) {
- return 0, nil
- }
- artifacts, err := readArtifactsFromSummary(summary)
- assert.NoError(t, err)
- var actualPaths []string
- for _, artifact := range artifacts {
- actualPaths = append(actualPaths, artifact.Path)
- }
- assert.ElementsMatch(t, actualPaths, expectedPaths)
- return 0, nil
- }
-}
-
-func mockEmptyModule(_ parallel.Runner, _ *config.ServerDetails, _ *[][]*clientServicesUtils.OperationSummary, _ *services.UploadParams, _ *clientUtils.ErrorsQueue) (int, error) {
- return 0, errors.New("failed: testing empty directory. this function shouldn't be called. ")
-}
diff --git a/artifactory/commands/yarn/yarn.go b/artifactory/commands/yarn/yarn.go
deleted file mode 100644
index 1a369d90e..000000000
--- a/artifactory/commands/yarn/yarn.go
+++ /dev/null
@@ -1,496 +0,0 @@
-package yarn
-
-import (
- "bufio"
- "encoding/json"
- "errors"
- "github.com/jfrog/build-info-go/entities"
- gofrogio "github.com/jfrog/gofrog/io"
- "github.com/jfrog/jfrog-cli-core/v2/common/format"
- "github.com/jfrog/jfrog-client-go/artifactory"
- "github.com/jfrog/jfrog-client-go/artifactory/services"
- servicesUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
- "io"
- "os"
- "os/exec"
- "path/filepath"
- "strconv"
- "strings"
-
- "github.com/jfrog/build-info-go/build"
- buildUtils "github.com/jfrog/jfrog-cli-core/v2/common/build"
-
- commandUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils/yarn"
- "github.com/jfrog/jfrog-cli-core/v2/common/project"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
- "github.com/jfrog/jfrog-client-go/auth"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-const (
- YarnrcFileName = ".yarnrc.yml"
- YarnrcBackupFileName = "jfrog.yarnrc.backup"
- NpmScopesConfigName = "npmScopes"
- YarnLockFileName = "yarn.lock"
- //#nosec G101
- yarnNpmRegistryServerEnv = "YARN_NPM_REGISTRY_SERVER"
- yarnNpmAuthIndent = "YARN_NPM_AUTH_IDENT"
- // #nosec G101
- yarnNpmAuthToken = "YARN_NPM_AUTH_TOKEN"
- yarnNpmAlwaysAuth = "YARN_NPM_ALWAYS_AUTH"
-)
-
-type YarnCommand struct {
- executablePath string
- workingDirectory string
- registry string
- npmAuthIdent string
- npmAuthToken string
- repo string
- collectBuildInfo bool
- configFilePath string
- yarnArgs []string
- threads int
- serverDetails *config.ServerDetails
- buildConfiguration *buildUtils.BuildConfiguration
- buildInfoModule *build.YarnModule
-}
-
-func NewYarnCommand() *YarnCommand {
- return &YarnCommand{}
-}
-
-func (yc *YarnCommand) SetConfigFilePath(configFilePath string) *YarnCommand {
- yc.configFilePath = configFilePath
- return yc
-}
-
-func (yc *YarnCommand) SetArgs(args []string) *YarnCommand {
- yc.yarnArgs = args
- return yc
-}
-
-func (yc *YarnCommand) Run() (err error) {
- log.Info("Running Yarn...")
- if err = yc.validateSupportedCommand(); err != nil {
- return
- }
-
- if err = yc.readConfigFile(); err != nil {
- return
- }
-
- var filteredYarnArgs []string
- yc.threads, _, _, _, filteredYarnArgs, yc.buildConfiguration, err = extractYarnOptionsFromArgs(yc.yarnArgs)
- if err != nil {
- return
- }
-
- if err = yc.preparePrerequisites(); err != nil {
- return
- }
-
- var missingDepsChan chan string
- var missingDependencies []string
- if yc.collectBuildInfo {
- missingDepsChan, err = yc.prepareBuildInfo()
- if err != nil {
- return
- }
- go func() {
- for depId := range missingDepsChan {
- missingDependencies = append(missingDependencies, depId)
- }
- }()
- }
-
- restoreYarnrcFunc, err := ioutils.BackupFile(filepath.Join(yc.workingDirectory, YarnrcFileName), YarnrcBackupFileName)
- if err != nil {
- return errors.Join(err, restoreYarnrcFunc())
- }
- backupEnvMap, err := ModifyYarnConfigurations(yc.executablePath, yc.registry, yc.npmAuthIdent, yc.npmAuthToken)
- if err != nil {
- return errors.Join(err, restoreYarnrcFunc())
- }
-
- yc.buildInfoModule.SetArgs(filteredYarnArgs)
- if err = yc.buildInfoModule.Build(); err != nil {
- return errors.Join(err, restoreYarnrcFunc())
- }
-
- if yc.collectBuildInfo {
- close(missingDepsChan)
- printMissingDependencies(missingDependencies)
- }
-
- if err = RestoreConfigurationsFromBackup(backupEnvMap, restoreYarnrcFunc); err != nil {
- return
- }
-
- log.Info("Yarn finished successfully.")
- return
-}
-
-func (yc *YarnCommand) ServerDetails() (*config.ServerDetails, error) {
- return yc.serverDetails, nil
-}
-
-func (yc *YarnCommand) CommandName() string {
- return "rt_yarn"
-}
-
-func (yc *YarnCommand) validateSupportedCommand() error {
- for index, arg := range yc.yarnArgs {
- if arg == "npm" && len(yc.yarnArgs) > index {
- npmCommand := yc.yarnArgs[index+1]
- // The command 'yarn npm publish' is not supported
- if npmCommand == "publish" {
- return errorutils.CheckErrorf("The command 'jfrog rt yarn npm publish' is not supported. Use 'jfrog rt upload' instead.")
- }
- // 'yarn npm *' commands other than 'info' and 'whoami' are not supported
- if npmCommand != "info" && npmCommand != "whoami" {
- return errorutils.CheckErrorf("The command 'jfrog rt yarn npm %s' is not supported.", npmCommand)
- }
- }
- }
- return nil
-}
-
-func (yc *YarnCommand) readConfigFile() error {
- log.Debug("Preparing to read the config file", yc.configFilePath)
- vConfig, err := project.ReadConfigFile(yc.configFilePath, project.YAML)
- if err != nil {
- return err
- }
-
- // Extract resolution params
- resolverParams, err := project.GetRepoConfigByPrefix(yc.configFilePath, project.ProjectConfigResolverPrefix, vConfig)
- if err != nil {
- return err
- }
- yc.repo = resolverParams.TargetRepo()
- yc.serverDetails, err = resolverParams.ServerDetails()
- return err
-}
-
-func (yc *YarnCommand) preparePrerequisites() error {
- log.Debug("Preparing prerequisites.")
- var err error
- if err = yc.setYarnExecutable(); err != nil {
- return err
- }
-
- yc.workingDirectory, err = coreutils.GetWorkingDirectory()
- if err != nil {
- return err
- }
- log.Debug("Working directory set to:", yc.workingDirectory)
-
- yc.collectBuildInfo, err = yc.buildConfiguration.IsCollectBuildInfo()
- if err != nil {
- return err
- }
-
- buildName, err := yc.buildConfiguration.GetBuildName()
- if err != nil {
- return err
- }
- buildNumber, err := yc.buildConfiguration.GetBuildNumber()
- if err != nil {
- return err
- }
-
- buildInfoService := buildUtils.CreateBuildInfoService()
- npmBuild, err := buildInfoService.GetOrCreateBuildWithProject(buildName, buildNumber, yc.buildConfiguration.GetProject())
- if err != nil {
- return errorutils.CheckError(err)
- }
- yc.buildInfoModule, err = npmBuild.AddYarnModule(yc.workingDirectory)
- if err != nil {
- return errorutils.CheckError(err)
- }
- if yc.buildConfiguration.GetModule() != "" {
- yc.buildInfoModule.SetName(yc.buildConfiguration.GetModule())
- }
-
- yc.registry, yc.npmAuthIdent, yc.npmAuthToken, err = GetYarnAuthDetails(yc.serverDetails, yc.repo)
- return err
-}
-
-func (yc *YarnCommand) prepareBuildInfo() (missingDepsChan chan string, err error) {
- log.Info("Preparing for dependencies information collection... For the first run of the build, the dependencies collection may take a few minutes. Subsequent runs should be faster.")
- servicesManager, err := utils.CreateServiceManager(yc.serverDetails, -1, 0, false)
- if err != nil {
- return
- }
-
- // Collect checksums from last build to decrease requests to Artifactory
- buildName, err := yc.buildConfiguration.GetBuildName()
- if err != nil {
- return
- }
- previousBuildDependencies, err := getDependenciesFromLatestBuild(servicesManager, buildName)
- if err != nil {
- return
- }
- missingDepsChan = make(chan string)
- collectChecksumsFunc := createCollectChecksumsFunc(previousBuildDependencies, servicesManager, missingDepsChan)
- yc.buildInfoModule.SetTraverseDependenciesFunc(collectChecksumsFunc)
- yc.buildInfoModule.SetThreads(yc.threads)
- return
-}
-
-func (yc *YarnCommand) setYarnExecutable() error {
- yarnExecPath, err := exec.LookPath("yarn")
- if err != nil {
- return errorutils.CheckError(err)
- }
-
- yc.executablePath = yarnExecPath
- log.Debug("Found Yarn executable at:", yc.executablePath)
- return nil
-}
-
-func GetYarnAuthDetails(server *config.ServerDetails, repo string) (registry, npmAuthIdent, npmAuthToken string, err error) {
- authRtDetails, err := setArtifactoryAuth(server)
- if err != nil {
- return
- }
- var npmAuthOutput string
- npmAuthOutput, registry, err = commandUtils.GetArtifactoryNpmRepoDetails(repo, authRtDetails, false)
- if err != nil {
- return
- }
- npmAuthIdent, npmAuthToken, err = extractAuthValFromNpmAuth(npmAuthOutput)
- return
-}
-
-func setArtifactoryAuth(server *config.ServerDetails) (auth.ServiceDetails, error) {
- authArtDetails, err := server.CreateArtAuthConfig()
- if err != nil {
- return nil, err
- }
- if authArtDetails.GetSshAuthHeaders() != nil {
- return nil, errorutils.CheckErrorf("SSH authentication is not supported in this command")
- }
- return authArtDetails, nil
-}
-
-func RestoreConfigurationsFromBackup(envVarsBackup map[string]*string, restoreYarnrcFunc func() error) error {
- if err := restoreEnvironmentVariables(envVarsBackup); err != nil {
- return err
- }
- return restoreYarnrcFunc()
-}
-
-func restoreEnvironmentVariables(envVarsBackup map[string]*string) error {
- for key, value := range envVarsBackup {
- if value == nil || *value == "" {
- if err := os.Unsetenv(key); err != nil {
- return err
- }
- continue
- }
-
- if err := os.Setenv(key, *value); err != nil {
- return err
- }
- }
- return nil
-}
-
-func ModifyYarnConfigurations(execPath, registry, npmAuthIdent, npmAuthToken string) (map[string]*string, error) {
- envVarsUpdated := map[string]string{
- yarnNpmRegistryServerEnv: registry,
- yarnNpmAuthIndent: npmAuthIdent,
- yarnNpmAuthToken: npmAuthToken,
- yarnNpmAlwaysAuth: "true",
- }
- envVarsBackup := make(map[string]*string)
- for key, value := range envVarsUpdated {
- oldVal, err := backupAndSetEnvironmentVariable(key, value)
- if err != nil {
- return nil, err
- }
- envVarsBackup[key] = &oldVal
- }
- // Update scoped registries (these cannot be set in environment variables)
- return envVarsBackup, errorutils.CheckError(updateScopeRegistries(execPath, registry, npmAuthIdent, npmAuthToken))
-}
-
-func updateScopeRegistries(execPath, registry, npmAuthIdent, npmAuthToken string) error {
- npmScopesStr, err := yarn.ConfigGet(NpmScopesConfigName, execPath, true)
- if err != nil {
- return err
- }
- npmScopesMap := make(map[string]yarnNpmScope)
- err = json.Unmarshal([]byte(npmScopesStr), &npmScopesMap)
- if err != nil {
- return errorutils.CheckError(err)
- }
- artifactoryScope := yarnNpmScope{NpmAlwaysAuth: true, NpmAuthIdent: npmAuthIdent, NpmAuthToken: npmAuthToken, NpmRegistryServer: registry}
- for scopeName := range npmScopesMap {
- npmScopesMap[scopeName] = artifactoryScope
- }
- updatedNpmScopesStr, err := json.Marshal(npmScopesMap)
- if err != nil {
- return errorutils.CheckError(err)
- }
- return yarn.ConfigSet(NpmScopesConfigName, string(updatedNpmScopesStr), execPath, true)
-}
-
-type yarnNpmScope struct {
- NpmAlwaysAuth bool `json:"npmAlwaysAuth,omitempty"`
- NpmAuthIdent string `json:"npmAuthIdent,omitempty"`
- NpmAuthToken string `json:"npmAuthToken,omitempty"`
- NpmRegistryServer string `json:"npmRegistryServer,omitempty"`
-}
-
-func backupAndSetEnvironmentVariable(key, value string) (string, error) {
- oldVal, _ := os.LookupEnv(key)
- return oldVal, errorutils.CheckError(os.Setenv(key, value))
-}
-
-// npmAuth includes several fields, but we need only the field '_auth' or '_authToken'
-func extractAuthValFromNpmAuth(npmAuth string) (authIndent, authToken string, err error) {
- scanner := bufio.NewScanner(strings.NewReader(npmAuth))
-
- for scanner.Scan() {
- currLine := scanner.Text()
- if !strings.HasPrefix(currLine, commandUtils.NpmConfigAuthKey) {
- continue
- }
-
- lineParts := strings.SplitN(currLine, "=", 2)
- if len(lineParts) < 2 {
- return "", "", errorutils.CheckErrorf("failed while retrieving npm auth details from Artifactory")
- }
- authVal := strings.TrimSpace(lineParts[1])
-
- switch strings.TrimSpace(lineParts[0]) {
- case commandUtils.NpmConfigAuthKey:
- return authVal, "", nil
- case commandUtils.NpmConfigAuthTokenKey:
- return "", authVal, nil
- default:
- return "", "", errorutils.CheckErrorf("unexpected auth key found in npm auth")
- }
- }
-
- return "", "", errorutils.CheckErrorf("failed while retrieving npm auth details from Artifactory")
-}
-
-type aqlResult struct {
- Results []*servicesUtils.ResultItem `json:"results,omitempty"`
-}
-
-func getDependenciesFromLatestBuild(servicesManager artifactory.ArtifactoryServicesManager, buildName string) (map[string]*entities.Dependency, error) {
- buildDependencies := make(map[string]*entities.Dependency)
- previousBuild, found, err := servicesManager.GetBuildInfo(services.BuildInfoParams{BuildName: buildName, BuildNumber: servicesUtils.LatestBuildNumberKey})
- if err != nil || !found {
- return buildDependencies, err
- }
- for _, module := range previousBuild.BuildInfo.Modules {
- for _, dependency := range module.Dependencies {
- buildDependencies[dependency.Id] = &entities.Dependency{Id: dependency.Id, Type: dependency.Type,
- Checksum: entities.Checksum{Md5: dependency.Md5, Sha1: dependency.Sha1}}
- }
- }
- return buildDependencies, nil
-}
-
-// Get dependency's checksum and type.
-func getDependencyInfo(name, ver string, previousBuildDependencies map[string]*entities.Dependency,
- servicesManager artifactory.ArtifactoryServicesManager) (checksum entities.Checksum, fileType string, err error) {
- id := name + ":" + ver
- if dep, ok := previousBuildDependencies[id]; ok {
- // Get checksum from previous build.
- checksum = dep.Checksum
- fileType = dep.Type
- return
- }
-
- // Get info from Artifactory.
- log.Debug("Fetching checksums for", id)
- var stream io.ReadCloser
- stream, err = servicesManager.Aql(servicesUtils.CreateAqlQueryForYarn(name, ver))
- if err != nil {
- return
- }
- defer gofrogio.Close(stream, &err)
- var result []byte
- result, err = io.ReadAll(stream)
- if err != nil {
- return
- }
- parsedResult := new(aqlResult)
- if err = json.Unmarshal(result, parsedResult); err != nil {
- return entities.Checksum{}, "", errorutils.CheckError(err)
- }
- if len(parsedResult.Results) == 0 {
- log.Debug(id, "could not be found in Artifactory.")
- return
- }
- if i := strings.LastIndex(parsedResult.Results[0].Name, "."); i != -1 {
- fileType = parsedResult.Results[0].Name[i+1:]
- }
- log.Debug(id, "was found in Artifactory. Name:", parsedResult.Results[0].Name,
- "SHA-1:", parsedResult.Results[0].Actual_Sha1,
- "MD5:", parsedResult.Results[0].Actual_Md5)
-
- checksum = entities.Checksum{Sha1: parsedResult.Results[0].Actual_Sha1, Md5: parsedResult.Results[0].Actual_Md5, Sha256: parsedResult.Results[0].Sha256}
- return
-}
-
-func extractYarnOptionsFromArgs(args []string) (threads int, detailedSummary, xrayScan bool, scanOutputFormat format.OutputFormat, cleanArgs []string, buildConfig *buildUtils.BuildConfiguration, err error) {
- threads = 3
- // Extract threads information from the args.
- flagIndex, valueIndex, numOfThreads, err := coreutils.FindFlag("--threads", args)
- if err != nil {
- return
- }
- coreutils.RemoveFlagFromCommand(&args, flagIndex, valueIndex)
- if numOfThreads != "" {
- threads, err = strconv.Atoi(numOfThreads)
- if err != nil {
- err = errorutils.CheckError(err)
- return
- }
- }
- detailedSummary, xrayScan, scanOutputFormat, cleanArgs, buildConfig, err = commandUtils.ExtractNpmOptionsFromArgs(args)
- return
-}
-
-func printMissingDependencies(missingDependencies []string) {
- if len(missingDependencies) == 0 {
- return
- }
-
- log.Warn(strings.Join(missingDependencies, "\n"), "\nThe npm dependencies above could not be found in Artifactory and therefore are not included in the build-info.\n"+
- "Deleting the local cache will force populating Artifactory with these dependencies.")
-}
-
-func createCollectChecksumsFunc(previousBuildDependencies map[string]*entities.Dependency, servicesManager artifactory.ArtifactoryServicesManager, missingDepsChan chan string) func(dependency *entities.Dependency) (bool, error) {
- return func(dependency *entities.Dependency) (bool, error) {
- splitDepId := strings.SplitN(dependency.Id, ":", 2)
- name := splitDepId[0]
- ver := splitDepId[1]
-
- // Get dependency info.
- checksum, fileType, err := getDependencyInfo(name, ver, previousBuildDependencies, servicesManager)
- if err != nil || checksum.IsEmpty() {
- missingDepsChan <- dependency.Id
- return false, err
- }
-
- // Update dependency.
- dependency.Type = fileType
- dependency.Checksum = checksum
- return true, nil
- }
-}
diff --git a/artifactory/commands/yarn/yarn_test.go b/artifactory/commands/yarn/yarn_test.go
deleted file mode 100644
index 271793d36..000000000
--- a/artifactory/commands/yarn/yarn_test.go
+++ /dev/null
@@ -1,75 +0,0 @@
-package yarn
-
-import (
- "os"
- "testing"
-
- "github.com/jfrog/jfrog-client-go/utils/tests"
- "github.com/stretchr/testify/assert"
-)
-
-func TestValidateSupportedCommand(t *testing.T) {
- yarnCmd := NewYarnCommand()
-
- testCases := []struct {
- args []string
- valid bool
- }{
- {[]string{}, true},
- {[]string{"--json"}, true},
- {[]string{"npm", "publish", "--json"}, false},
- {[]string{"npm", "--json", "publish"}, false},
- {[]string{"npm", "tag", "list"}, false},
- {[]string{"npm", "info", "package-name"}, true},
- {[]string{"npm", "whoami"}, true},
- }
-
- for _, testCase := range testCases {
- yarnCmd.yarnArgs = testCase.args
- err := yarnCmd.validateSupportedCommand()
- assert.Equal(t, testCase.valid, err == nil, "Test args:", testCase.args)
- }
-}
-
-func TestSetAndRestoreEnvironmentVariables(t *testing.T) {
- const jfrogCliTestingEnvVar = "JFROG_CLI_ENV_VAR_FOR_TESTING"
- // Check backup and restore of an existing variable
- setEnvCallback := tests.SetEnvWithCallbackAndAssert(t, jfrogCliTestingEnvVar, "abc")
- backupEnvsMap := make(map[string]*string)
- oldVal, err := backupAndSetEnvironmentVariable(jfrogCliTestingEnvVar, "new-value")
- assert.NoError(t, err)
- assert.Equal(t, "new-value", os.Getenv(jfrogCliTestingEnvVar))
- backupEnvsMap[jfrogCliTestingEnvVar] = &oldVal
- assert.NoError(t, restoreEnvironmentVariables(backupEnvsMap))
- assert.Equal(t, "abc", os.Getenv(jfrogCliTestingEnvVar))
-
- // Check backup and restore of a variable that doesn't exist
- setEnvCallback()
- oldVal, err = backupAndSetEnvironmentVariable(jfrogCliTestingEnvVar, "another-value")
- assert.NoError(t, err)
- assert.Equal(t, "another-value", os.Getenv(jfrogCliTestingEnvVar))
- backupEnvsMap[jfrogCliTestingEnvVar] = &oldVal
- err = restoreEnvironmentVariables(backupEnvsMap)
- assert.NoError(t, err)
- _, exist := os.LookupEnv(jfrogCliTestingEnvVar)
- assert.False(t, exist)
-}
-
-func TestExtractAuthValuesFromNpmAuth(t *testing.T) {
- testCases := []struct {
- responseFromArtifactory string
- expectedExtractedAuthIndent string
- expectedExtractedAuthToken string
- }{
- {"_auth = Z290Y2hhISB5b3UgcmVhbGx5IHRoaW5rIGkgd291bGQgcHV0IHJlYWwgY3JlZGVudGlhbHMgaGVyZT8=\nalways-auth = true\nemail = notexist@mail.com\n", "Z290Y2hhISB5b3UgcmVhbGx5IHRoaW5rIGkgd291bGQgcHV0IHJlYWwgY3JlZGVudGlhbHMgaGVyZT8=", ""},
- {"always-auth=true\nemail=notexist@mail.com\n_auth=TGVhcCBhbmQgdGhlIHJlc3Qgd2lsbCBmb2xsb3c=\n", "TGVhcCBhbmQgdGhlIHJlc3Qgd2lsbCBmb2xsb3c=", ""},
- {"_authToken = ThisIsNotARealToken\nalways-auth = true\nemail = notexist@mail.com\n", "", "ThisIsNotARealToken"},
- }
-
- for _, testCase := range testCases {
- actualExtractedAuthIndent, actualExtractedAuthToken, err := extractAuthValFromNpmAuth(testCase.responseFromArtifactory)
- assert.NoError(t, err)
- assert.Equal(t, testCase.expectedExtractedAuthIndent, actualExtractedAuthIndent)
- assert.Equal(t, testCase.expectedExtractedAuthToken, actualExtractedAuthToken)
- }
-}
diff --git a/artifactory/formats/buildpublishapi.go b/artifactory/formats/buildpublishapi.go
deleted file mode 100644
index 205c3c89a..000000000
--- a/artifactory/formats/buildpublishapi.go
+++ /dev/null
@@ -1,22 +0,0 @@
-package formats
-
-import (
- "bytes"
- "encoding/json"
-)
-
-// Structs in this file should NOT be changed!
-// The structs are used as an API for the build-publish command, thus changing their structure or the 'json' annotation will break the API.
-
-type BuildPublishOutput struct {
- BuildInfoUiUrl string `json:"buildInfoUiUrl,omitempty"`
-}
-
-// This function is similar to json.Marshal with EscapeHTML false.
-func (bpo *BuildPublishOutput) JSON() ([]byte, error) {
- buffer := &bytes.Buffer{}
- encoder := json.NewEncoder(buffer)
- encoder.SetEscapeHTML(false)
- err := encoder.Encode(bpo)
- return buffer.Bytes(), err
-}
diff --git a/distribution/commands/createbundle.go b/distribution/commands/createbundle.go
deleted file mode 100644
index d220aa605..000000000
--- a/distribution/commands/createbundle.go
+++ /dev/null
@@ -1,100 +0,0 @@
-package commands
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/distribution/services"
- distributionServicesUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
-)
-
-type CreateBundleCommand struct {
- serverDetails *config.ServerDetails
- releaseBundlesParams distributionServicesUtils.ReleaseBundleParams
- spec *spec.SpecFiles
- dryRun bool
- detailedSummary bool
- summary *clientutils.Sha256Summary
-}
-
-func NewReleaseBundleCreateCommand() *CreateBundleCommand {
- return &CreateBundleCommand{}
-}
-
-func (cb *CreateBundleCommand) SetServerDetails(serverDetails *config.ServerDetails) *CreateBundleCommand {
- cb.serverDetails = serverDetails
- return cb
-}
-
-func (cb *CreateBundleCommand) SetReleaseBundleCreateParams(params distributionServicesUtils.ReleaseBundleParams) *CreateBundleCommand {
- cb.releaseBundlesParams = params
- return cb
-}
-
-func (cb *CreateBundleCommand) SetSpec(spec *spec.SpecFiles) *CreateBundleCommand {
- cb.spec = spec
- return cb
-}
-
-func (cb *CreateBundleCommand) SetDryRun(dryRun bool) *CreateBundleCommand {
- cb.dryRun = dryRun
- return cb
-}
-
-func (cb *CreateBundleCommand) Run() error {
- servicesManager, err := utils.CreateDistributionServiceManager(cb.serverDetails, cb.dryRun)
- if err != nil {
- return err
- }
-
- for _, spec := range cb.spec.Files {
- params, err := spec.ToCommonParams()
- if err != nil {
- return err
- }
- recursive, err := spec.IsRecursive(true)
- if err != nil {
- return err
- }
- params.Recursive = recursive
- cb.releaseBundlesParams.SpecFiles = append(cb.releaseBundlesParams.SpecFiles, params)
- }
-
- params := services.CreateReleaseBundleParams{ReleaseBundleParams: cb.releaseBundlesParams}
- summary, err := servicesManager.CreateReleaseBundle(params)
- if cb.detailedSummary {
- cb.summary = summary
- }
- return err
-}
-
-func (cb *CreateBundleCommand) ServerDetails() (*config.ServerDetails, error) {
- return cb.serverDetails, nil
-}
-
-func (cb *CreateBundleCommand) CommandName() string {
- return "rt_bundle_create"
-}
-
-func (cb *CreateBundleCommand) SetSummary(summary *clientutils.Sha256Summary) *CreateBundleCommand {
- cb.summary = summary
- return cb
-}
-
-func (cb *CreateBundleCommand) GetSummary() *clientutils.Sha256Summary {
- return cb.summary
-}
-
-func (cb *CreateBundleCommand) SetDetailedSummary(detailedSummary bool) *CreateBundleCommand {
- cb.detailedSummary = detailedSummary
- return cb
-}
-
-func (cb *CreateBundleCommand) IsDetailedSummary() bool {
- return cb.detailedSummary
-}
-
-func (cb *CreateBundleCommand) IsSignImmediately() bool {
- return cb.releaseBundlesParams.SignImmediately
-}
diff --git a/distribution/commands/deletebundle.go b/distribution/commands/deletebundle.go
deleted file mode 100644
index 0dc9b0cc8..000000000
--- a/distribution/commands/deletebundle.go
+++ /dev/null
@@ -1,123 +0,0 @@
-package commands
-
-import (
- "encoding/json"
- "fmt"
- "github.com/jfrog/jfrog-client-go/utils/distribution"
-
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
- "github.com/jfrog/jfrog-client-go/distribution/services"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
- "github.com/jfrog/jfrog-client-go/utils/errorutils"
- "github.com/jfrog/jfrog-client-go/utils/log"
-)
-
-type DeleteReleaseBundleCommand struct {
- serverDetails *config.ServerDetails
- deleteBundlesParams services.DeleteDistributionParams
- distributionRules *spec.DistributionRules
- dryRun bool
- quiet bool
-}
-
-func NewReleaseBundleDeleteParams() *DeleteReleaseBundleCommand {
- return &DeleteReleaseBundleCommand{}
-}
-
-func (db *DeleteReleaseBundleCommand) SetServerDetails(serverDetails *config.ServerDetails) *DeleteReleaseBundleCommand {
- db.serverDetails = serverDetails
- return db
-}
-
-func (db *DeleteReleaseBundleCommand) SetDistributeBundleParams(params services.DeleteDistributionParams) *DeleteReleaseBundleCommand {
- db.deleteBundlesParams = params
- return db
-}
-
-func (db *DeleteReleaseBundleCommand) SetDistributionRules(distributionRules *spec.DistributionRules) *DeleteReleaseBundleCommand {
- db.distributionRules = distributionRules
- return db
-}
-
-func (db *DeleteReleaseBundleCommand) SetDryRun(dryRun bool) *DeleteReleaseBundleCommand {
- db.dryRun = dryRun
- return db
-}
-
-func (db *DeleteReleaseBundleCommand) SetQuiet(quiet bool) *DeleteReleaseBundleCommand {
- db.quiet = quiet
- return db
-}
-
-func (db *DeleteReleaseBundleCommand) Run() error {
- servicesManager, err := utils.CreateDistributionServiceManager(db.serverDetails, db.dryRun)
- if err != nil {
- return err
- }
-
- for _, spec := range db.distributionRules.DistributionRules {
- db.deleteBundlesParams.DistributionRules = append(db.deleteBundlesParams.DistributionRules, spec.ToDistributionCommonParams())
- }
-
- distributionRulesEmpty := db.distributionRulesEmpty()
- if !db.quiet {
- confirm, err := db.confirmDelete(distributionRulesEmpty)
- if err != nil {
- return err
- }
- if !confirm {
- return nil
- }
- }
-
- if distributionRulesEmpty && db.deleteBundlesParams.DeleteFromDistribution {
- return servicesManager.DeleteLocalReleaseBundle(db.deleteBundlesParams)
- }
- return servicesManager.DeleteReleaseBundle(db.deleteBundlesParams)
-}
-
-func (db *DeleteReleaseBundleCommand) ServerDetails() (*config.ServerDetails, error) {
- return db.serverDetails, nil
-}
-
-func (db *DeleteReleaseBundleCommand) CommandName() string {
- return "rt_bundle_delete"
-}
-
-// Return true iff there are no distribution rules
-func (db *DeleteReleaseBundleCommand) distributionRulesEmpty() bool {
- return db.distributionRules == nil ||
- len(db.distributionRules.DistributionRules) == 0 ||
- len(db.distributionRules.DistributionRules) == 1 && db.distributionRules.DistributionRules[0].IsEmpty()
-}
-
-func (db *DeleteReleaseBundleCommand) confirmDelete(distributionRulesEmpty bool) (bool, error) {
- message := fmt.Sprintf("Are you sure you want to delete the release bundle \"%s\"/\"%s\" ", db.deleteBundlesParams.Name, db.deleteBundlesParams.Version)
- if distributionRulesEmpty && db.deleteBundlesParams.DeleteFromDistribution {
- return coreutils.AskYesNo(message+"locally from distribution?\n"+
- "You can avoid this confirmation message by adding --quiet to the command.", false), nil
- }
-
- var distributionRulesBodies []distribution.DistributionRulesBody
- for _, rule := range db.deleteBundlesParams.DistributionRules {
- distributionRulesBodies = append(distributionRulesBodies, distribution.DistributionRulesBody{
- SiteName: rule.GetSiteName(),
- CityName: rule.GetCityName(),
- CountryCodes: rule.GetCountryCodes(),
- })
- }
- bytes, err := json.Marshal(distributionRulesBodies)
- if err != nil {
- return false, errorutils.CheckError(err)
- }
-
- log.Output(clientutils.IndentJson(bytes))
- if db.deleteBundlesParams.DeleteFromDistribution {
- log.Output("This command will also delete the release bundle locally from distribution.")
- }
- return coreutils.AskYesNo(message+"with the above distribution rules?\n"+
- "You can avoid this confirmation message by adding --quiet to the command.", false), nil
-}
diff --git a/distribution/commands/distributebundle.go b/distribution/commands/distributebundle.go
deleted file mode 100644
index c2a18452c..000000000
--- a/distribution/commands/distributebundle.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package commands
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/utils/distribution"
-)
-
-type DistributeReleaseBundleV1Command struct {
- serverDetails *config.ServerDetails
- distributeBundlesParams distribution.DistributionParams
- distributionRules *spec.DistributionRules
- sync bool
- maxWaitMinutes int
- dryRun bool
- autoCreateRepo bool
-}
-
-func NewReleaseBundleDistributeV1Command() *DistributeReleaseBundleV1Command {
- return &DistributeReleaseBundleV1Command{}
-}
-
-func (db *DistributeReleaseBundleV1Command) SetServerDetails(serverDetails *config.ServerDetails) *DistributeReleaseBundleV1Command {
- db.serverDetails = serverDetails
- return db
-}
-
-func (db *DistributeReleaseBundleV1Command) SetDistributeBundleParams(params distribution.DistributionParams) *DistributeReleaseBundleV1Command {
- db.distributeBundlesParams = params
- return db
-}
-
-func (db *DistributeReleaseBundleV1Command) SetDistributionRules(distributionRules *spec.DistributionRules) *DistributeReleaseBundleV1Command {
- db.distributionRules = distributionRules
- return db
-}
-
-func (db *DistributeReleaseBundleV1Command) SetSync(sync bool) *DistributeReleaseBundleV1Command {
- db.sync = sync
- return db
-}
-
-func (db *DistributeReleaseBundleV1Command) SetMaxWaitMinutes(maxWaitMinutes int) *DistributeReleaseBundleV1Command {
- db.maxWaitMinutes = maxWaitMinutes
- return db
-}
-
-func (db *DistributeReleaseBundleV1Command) SetDryRun(dryRun bool) *DistributeReleaseBundleV1Command {
- db.dryRun = dryRun
- return db
-}
-
-func (db *DistributeReleaseBundleV1Command) SetAutoCreateRepo(autoCreateRepo bool) *DistributeReleaseBundleV1Command {
- db.autoCreateRepo = autoCreateRepo
- return db
-}
-
-func (db *DistributeReleaseBundleV1Command) Run() error {
- servicesManager, err := utils.CreateDistributionServiceManager(db.serverDetails, db.dryRun)
- if err != nil {
- return err
- }
-
- for _, rule := range db.distributionRules.DistributionRules {
- db.distributeBundlesParams.DistributionRules = append(db.distributeBundlesParams.DistributionRules, rule.ToDistributionCommonParams())
- }
-
- if db.sync {
- return servicesManager.DistributeReleaseBundleSync(db.distributeBundlesParams, db.maxWaitMinutes, db.autoCreateRepo)
- }
- return servicesManager.DistributeReleaseBundle(db.distributeBundlesParams, db.autoCreateRepo)
-}
-
-func (db *DistributeReleaseBundleV1Command) ServerDetails() (*config.ServerDetails, error) {
- return db.serverDetails, nil
-}
-
-func (db *DistributeReleaseBundleV1Command) CommandName() string {
- return "rt_distribute_bundle"
-}
diff --git a/distribution/commands/signBundle.go b/distribution/commands/signBundle.go
deleted file mode 100644
index 7710c61f9..000000000
--- a/distribution/commands/signBundle.go
+++ /dev/null
@@ -1,68 +0,0 @@
-package commands
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/distribution/services"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
-)
-
-type SignBundleCommand struct {
- serverDetails *config.ServerDetails
- signBundlesParams services.SignBundleParams
- detailedSummary bool
- summary *clientutils.Sha256Summary
-}
-
-func NewReleaseBundleSignCommand() *SignBundleCommand {
- return &SignBundleCommand{}
-}
-
-func (sb *SignBundleCommand) SetServerDetails(serverDetails *config.ServerDetails) *SignBundleCommand {
- sb.serverDetails = serverDetails
- return sb
-}
-
-func (sb *SignBundleCommand) SetReleaseBundleSignParams(params services.SignBundleParams) *SignBundleCommand {
- sb.signBundlesParams = params
- return sb
-}
-
-func (sb *SignBundleCommand) Run() error {
- servicesManager, err := utils.CreateDistributionServiceManager(sb.serverDetails, false)
- if err != nil {
- return err
- }
-
- summary, err := servicesManager.SignReleaseBundle(sb.signBundlesParams)
- if sb.detailedSummary {
- sb.summary = summary
- }
- return err
-}
-
-func (sb *SignBundleCommand) ServerDetails() (*config.ServerDetails, error) {
- return sb.serverDetails, nil
-}
-
-func (sb *SignBundleCommand) CommandName() string {
- return "rt_sign_bundle"
-}
-
-func (sb *SignBundleCommand) SetSummary(summary *clientutils.Sha256Summary) *SignBundleCommand {
- sb.summary = summary
- return sb
-}
-
-func (sb *SignBundleCommand) GetSummary() *clientutils.Sha256Summary {
- return sb.summary
-}
-
-func (sb *SignBundleCommand) SetDetailedSummary(detailedSummary bool) *SignBundleCommand {
- sb.detailedSummary = detailedSummary
- return sb
-}
-
-func (sb *SignBundleCommand) IsDetailedSummary() bool {
- return sb.detailedSummary
-}
diff --git a/distribution/commands/updatebundle.go b/distribution/commands/updatebundle.go
deleted file mode 100644
index 63e11be65..000000000
--- a/distribution/commands/updatebundle.go
+++ /dev/null
@@ -1,100 +0,0 @@
-package commands
-
-import (
- "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
- "github.com/jfrog/jfrog-cli-core/v2/common/spec"
- "github.com/jfrog/jfrog-cli-core/v2/utils/config"
- "github.com/jfrog/jfrog-client-go/distribution/services"
- distributionServicesUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils"
- clientutils "github.com/jfrog/jfrog-client-go/utils"
-)
-
-type UpdateBundleCommand struct {
- serverDetails *config.ServerDetails
- releaseBundlesParams distributionServicesUtils.ReleaseBundleParams
- spec *spec.SpecFiles
- dryRun bool
- detailedSummary bool
- summary *clientutils.Sha256Summary
-}
-
-func NewReleaseBundleUpdateCommand() *UpdateBundleCommand {
- return &UpdateBundleCommand{}
-}
-
-func (cb *UpdateBundleCommand) SetServerDetails(serverDetails *config.ServerDetails) *UpdateBundleCommand {
- cb.serverDetails = serverDetails
- return cb
-}
-
-func (cb *UpdateBundleCommand) SetReleaseBundleUpdateParams(params distributionServicesUtils.ReleaseBundleParams) *UpdateBundleCommand {
- cb.releaseBundlesParams = params
- return cb
-}
-
-func (cb *UpdateBundleCommand) SetSpec(spec *spec.SpecFiles) *UpdateBundleCommand {
- cb.spec = spec
- return cb
-}
-
-func (cb *UpdateBundleCommand) SetDryRun(dryRun bool) *UpdateBundleCommand {
- cb.dryRun = dryRun
- return cb
-}
-
-func (cb *UpdateBundleCommand) Run() error {
- servicesManager, err := utils.CreateDistributionServiceManager(cb.serverDetails, cb.dryRun)
- if err != nil {
- return err
- }
-
- for _, spec := range cb.spec.Files {
- params, err := spec.ToCommonParams()
- if err != nil {
- return err
- }
- recursive, err := spec.IsRecursive(true)
- if err != nil {
- return err
- }
- params.Recursive = recursive
- cb.releaseBundlesParams.SpecFiles = append(cb.releaseBundlesParams.SpecFiles, params)
- }
-
- params := services.UpdateReleaseBundleParams{ReleaseBundleParams: cb.releaseBundlesParams}
- summary, err := servicesManager.UpdateReleaseBundle(params)
- if cb.detailedSummary {
- cb.summary = summary
- }
- return err
-}
-
-func (cb *UpdateBundleCommand) ServerDetails() (*config.ServerDetails, error) {
- return cb.serverDetails, nil
-}
-
-func (cb *UpdateBundleCommand) CommandName() string {
- return "rt_bundle_update"
-}
-
-func (cb *UpdateBundleCommand) SetSummary(summary *clientutils.Sha256Summary) *UpdateBundleCommand {
- cb.summary = summary
- return cb
-}
-
-func (cb *UpdateBundleCommand) GetSummary() *clientutils.Sha256Summary {
- return cb.summary
-}
-
-func (cb *UpdateBundleCommand) SetDetailedSummary(detailedSummary bool) *UpdateBundleCommand {
- cb.detailedSummary = detailedSummary
- return cb
-}
-
-func (cb *UpdateBundleCommand) IsDetailedSummary() bool {
- return cb.detailedSummary
-}
-
-func (cb *UpdateBundleCommand) IsSignImmediately() bool {
- return cb.releaseBundlesParams.SignImmediately
-}
diff --git a/go.mod b/go.mod
index 7071e65ac..3edf2a942 100644
--- a/go.mod
+++ b/go.mod
@@ -23,7 +23,6 @@ require (
github.com/urfave/cli v1.22.16
github.com/vbauerster/mpb/v8 v8.9.1
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
- golang.org/x/mod v0.22.0
golang.org/x/sync v0.10.0
golang.org/x/term v0.28.0
golang.org/x/text v0.21.0
@@ -60,7 +59,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
- github.com/mattn/go-isatty v0.0.17 // indirect
+ github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-tty v0.0.3 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
@@ -89,6 +88,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
+ golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/tools v0.29.0 // indirect
@@ -96,7 +96,7 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
)
-// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250121093504-a3e981c875d7
+// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20241225183733-80a5e1ba7a2c
// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd
diff --git a/go.sum b/go.sum
index 62bb016f9..627abfc0c 100644
--- a/go.sum
+++ b/go.sum
@@ -124,8 +124,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
-github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
-github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
@@ -252,6 +252,7 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=