コード例 #1
0
ファイル: gpgsignfile.go プロジェクト: JFrogDev/jfrog-cli-go
func GpgSignFile(pathDetails *utils.PathDetails, passphrase string, bintrayDetails *config.BintrayDetails) error {
	if bintrayDetails.User == "" {
		bintrayDetails.User = pathDetails.Subject
	}
	url := bintrayDetails.ApiUrl + "gpg/" + pathDetails.Subject + "/" +
		pathDetails.Repo + "/" + pathDetails.Path

	var data string
	if passphrase != "" {
		data = "{ \"passphrase\": \"" + passphrase + "\" }"
	}

	log.Info("GPG signing file...")
	httpClientsDetails := utils.GetBintrayHttpClientDetails(bintrayDetails)
	resp, body, err := ioutils.SendPost(url, []byte(data), httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("GPG signed file", pathDetails.Path, ", details:")
	fmt.Println(cliutils.IndentJson(body))
	return nil
}
コード例 #2
0
ファイル: versionshow.go プロジェクト: JFrogDev/jfrog-cli-go
func ShowVersion(versionDetails *utils.VersionDetails, bintrayDetails *config.BintrayDetails) error {
	if bintrayDetails.User == "" {
		bintrayDetails.User = versionDetails.Subject
	}
	version := versionDetails.Version
	if versionDetails.Version == "" {
		versionDetails.Version = "_latest"
		version = "latest"
	}

	url := bintrayDetails.ApiUrl + "packages/" + versionDetails.Subject + "/" +
		versionDetails.Repo + "/" + versionDetails.Package + "/versions/" + versionDetails.Version

	log.Info("Getting version details...")
	httpClientsDetails := utils.GetBintrayHttpClientDetails(bintrayDetails)
	resp, body, _, _ := ioutils.SendGet(url, true, httpClientsDetails)

	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Version", version, "details:")
	fmt.Println(cliutils.IndentJson(body))
	return nil
}
コード例 #3
0
ファイル: delete.go プロジェクト: JFrogDev/jfrog-cli-go
func DeleteFiles(resultItems []utils.AqlSearchResultItem, flags *DeleteFlags) error {
	for _, v := range resultItems {
		fileUrl, err := utils.BuildArtifactoryUrl(flags.ArtDetails.Url, v.GetFullUrl(), make(map[string]string))
		if err != nil {
			return err
		}
		if flags.DryRun {
			log.Info("[Dry run] Deleting:", v.GetFullUrl())
			continue
		}

		log.Info("Deleting:", v.GetFullUrl())
		httpClientsDetails := utils.GetArtifactoryHttpClientDetails(flags.ArtDetails)
		resp, body, err := ioutils.SendDelete(fileUrl, nil, httpClientsDetails)
		if err != nil {
			return err
		}
		if resp.StatusCode != 204 {
			return cliutils.CheckError(errors.New("Artifactory response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
		}

		log.Debug("Artifactory response:", resp.Status)
	}
	return nil
}
コード例 #4
0
func OfflineUpdate(flags *OfflineUpdatesFlags) error {
	if err := buildUpdatesUrl(flags); err != nil {
		return err
	}
	vulnerabilities, components, last_update, err := getFilesList(flags)
	if err != nil {
		return err
	}
	zipSuffix := "_" + strconv.FormatInt(last_update, 10)
	xrayTempDir, err := getXrayTempDir()
	if err != nil {
		return err
	}
	if len(vulnerabilities) > 0 {
		log.Info("Downloading vulnerabilities...")
		if err := saveData(xrayTempDir, "vuln", zipSuffix, "", vulnerabilities); err != nil {
			return err
		}
	} else {
		log.Info("There aren't new vulnerabilities.")
	}

	if len(components) > 0 {
		log.Info("Downloading components...")
		if err := saveData(xrayTempDir, "comp", zipSuffix, "", components); err != nil {
			return err
		}
	} else {
		log.Info("There aren't new components.")
	}

	return nil
}
コード例 #5
0
ファイル: moveutils.go プロジェクト: JFrogDev/jfrog-cli-go
func moveFile(sourcePath, destPath string, flags *MoveFlags, moveType MoveType) (bool, error) {
	message := moveMsgs[moveType].MovingMsg + " artifact: " + sourcePath + " to: " + destPath
	if flags.DryRun == true {
		log.Info("[Dry run] ", message)
		return true, nil
	}

	log.Info(message)

	moveUrl := flags.ArtDetails.Url
	restApi := "api/" + string(moveType) + "/" + sourcePath
	requestFullUrl, err := BuildArtifactoryUrl(moveUrl, restApi, map[string]string{"to": destPath})
	if err != nil {
		return false, err
	}
	httpClientsDetails := GetArtifactoryHttpClientDetails(flags.ArtDetails)
	resp, body, err := ioutils.SendPost(requestFullUrl, nil, httpClientsDetails)
	if err != nil {
		return false, err
	}

	if resp.StatusCode != 200 {
		log.Error("Artifactory response: " + resp.Status + "\n" + cliutils.IndentJson(body))
	}

	log.Debug("Artifactory response:", resp.Status)
	return resp.StatusCode == 200, nil
}
コード例 #6
0
ファイル: buildpublish.go プロジェクト: JFrogDev/jfrog-cli-go
func BuildPublish(buildName, buildNumber string, flags *utils.BuildInfoFlags) error {
	err := utils.PreCommandSetup(flags)
	if err != nil {
		return err
	}

	buildData, err := utils.ReadBuildInfoFiles(buildName, buildNumber)
	if err != nil {
		return err
	}

	if len(buildData) == 0 {
		return cliutils.CheckError(fmt.Errorf("Can't find any files related to build name: %q, number: %q", buildName, buildNumber))
	}
	sort.Sort(buildData)
	buildInfo := createNewBuildInfo()
	buildInfo.Name = buildName
	buildInfo.Number = buildNumber
	buildGeneralDetails, err := utils.ReadBuildInfoGeneralDetails(buildName, buildNumber)
	if err != nil {
		return err
	}
	buildInfo.Started = buildGeneralDetails.Timestamp.Format("2006-01-02T15:04:05.000-0700")
	artifactsSet, dependenciesSet, env, err := prepareBuildInfoData(buildData, createIncludeFilter(flags), createExcludeFilter(flags))
	if err != nil {
		return err
	}
	if len(env) != 0 {
		buildInfo.Propertires = env
	}
	module := createModule(buildName, artifactsSet, dependenciesSet)
	buildInfo.Modules = append(buildInfo.Modules, module)
	marshaledBuildInfo, err := json.Marshal(buildInfo)
	if cliutils.CheckError(err) != nil {
		return err
	}
	if flags.IsDryRun() {
		fmt.Println(cliutils.IndentJson(marshaledBuildInfo))
		return nil
	}
	httpClientsDetails := utils.GetArtifactoryHttpClientDetails(flags.ArtDetails)
	utils.SetContentType("application/vnd.org.jfrog.artifactory+json", &httpClientsDetails.Headers)
	log.Info("Deploying build info...")
	resp, body, err := utils.PublishBuildInfo(flags.ArtDetails.Url, marshaledBuildInfo, httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 204 {
		return cliutils.CheckError(errors.New("Artifactory response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Artifactory response:", resp.Status)
	log.Info("Build info successfully deployed. Browse it in Artifactory under " + flags.ArtDetails.Url + "webapp/builds/" + buildName + "/" + buildNumber)
	if err = utils.RemoveBuildDir(buildName, buildNumber); err != nil {
		return err
	}
	return nil
}
コード例 #7
0
ファイル: buildclean.go プロジェクト: JFrogDev/jfrog-cli-go
func BuildClean(buildName, buildNumber string) (err error) {
	log.Info("Cleanning build info...")
	err = utils.RemoveBuildDir(buildName, buildNumber)
	if err != nil {
		return
	}
	log.Info("Cleaned build info", buildName, "#"+buildNumber+".")
	return err
}
コード例 #8
0
func BuildDistribute(buildName, buildNumber, targetRepo string, flags *BuildDistributionFlags) error {
	err := utils.PreCommandSetup(flags)
	if err != nil {
		return err
	}

	dryRun := ""
	if flags.DryRun == true {
		dryRun = "[Dry run] "
	}
	message := "Destributing build..."
	log.Info(dryRun + message)

	distributeUrl := flags.ArtDetails.Url
	restApi := path.Join("api/build/distribute/", buildName, buildNumber)
	requestFullUrl, err := utils.BuildArtifactoryUrl(distributeUrl, restApi, make(map[string]string))
	if err != nil {
		return err
	}

	data := BuildDistributionConfig{
		SourceRepos:           strings.Split(flags.SourceRepos, ","),
		TargetRepo:            targetRepo,
		Publish:               flags.Publish,
		OverrideExistingFiles: flags.OverrideExistingFiles,
		GpgPassphrase:         flags.GpgPassphrase,
		Async:                 flags.Async,
		DryRun:                flags.DryRun}
	requestContent, err := json.Marshal(data)
	if err != nil {
		return cliutils.CheckError(errors.New("Failed to execute request. " + cliutils.GetDocumentationMessage()))
	}

	httpClientsDetails := utils.GetArtifactoryHttpClientDetails(flags.ArtDetails)
	utils.SetContentType("application/json", &httpClientsDetails.Headers)

	resp, body, err := ioutils.SendPost(requestFullUrl, requestContent, httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Artifactory response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Artifactory response:", resp.Status)
	if flags.Async && !flags.DryRun {
		log.Info("Asynchronously distributed build", buildName, "#"+buildNumber, "to:", targetRepo, "repository, logs are avalable in Artifactory.")
		return nil
	}

	log.Info(dryRun+"Distributed build", buildName, "#"+buildNumber, "to:", targetRepo, "repository.")
	return nil
}
コード例 #9
0
func CreateVersion(versionDetails *utils.VersionDetails, flags *utils.VersionFlags) error {
	log.Info("Creating version...")
	resp, body, err := doCreateVersion(versionDetails, flags, flags.BintrayDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 201 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}
	log.Debug("Bintray response:", resp.Status)
	log.Info("Created version", versionDetails.Version+", details:")
	fmt.Println(cliutils.IndentJson(body))
	return nil
}
コード例 #10
0
ファイル: accesskeys.go プロジェクト: JFrogDev/jfrog-cli-go
func ShowAccessKeys(bintrayDetails *config.BintrayDetails, org string) error {
	path := GetAccessKeysPath(bintrayDetails, org)
	httpClientsDetails := utils.GetBintrayHttpClientDetails(bintrayDetails)
	log.Info("Getting access keys...")
	resp, body, _, _ := ioutils.SendGet(path, true, httpClientsDetails)
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Access keys details:")
	fmt.Println(cliutils.IndentJson(body))
	return nil
}
コード例 #11
0
ファイル: accesskeys.go プロジェクト: JFrogDev/jfrog-cli-go
func ShowAccessKey(flags *AccessKeyFlags, org string) (err error) {
	url := GetAccessKeyPath(flags.BintrayDetails, flags.Id, org)
	httpClientsDetails := utils.GetBintrayHttpClientDetails(flags.BintrayDetails)
	log.Info("Getting access key...")
	resp, body, _, _ := ioutils.SendGet(url, true, httpClientsDetails)
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Access keys details:")
	fmt.Println(cliutils.IndentJson(body))
	return
}
コード例 #12
0
ファイル: upload.go プロジェクト: JFrogDev/jfrog-cli-go
func uploadFiles(artifacts []cliutils.Artifact, baseUrl string, flags *UploadFlags) (totalUploaded,
	totalFailed int, err error) {

	size := len(artifacts)
	var wg sync.WaitGroup

	// Create an array of integers, to store the total file that were uploaded successfully.
	// Each array item is used by a single thread.
	uploadCount := make([]int, flags.Threads, flags.Threads)
	matrixParams := getMatrixParams(flags)
	for i := 0; i < flags.Threads; i++ {
		wg.Add(1)
		go func(threadId int) {
			logMsgPrefix := cliutils.GetLogMsgPrefix(threadId, flags.DryRun)
			for j := threadId; j < size; j += flags.Threads {
				if err != nil {
					break
				}
				url := baseUrl + artifacts[j].TargetPath + matrixParams
				if !flags.DryRun {
					uploaded, e := uploadFile(artifacts[j], url, logMsgPrefix, flags.BintrayDetails)
					if e != nil {
						err = e
						break
					}
					if uploaded {
						uploadCount[threadId]++
					}
				} else {
					log.Info("[Dry Run] Uploading artifact:", artifacts[j].LocalPath)
					uploadCount[threadId]++
				}
			}
			wg.Done()
		}(i)
	}
	wg.Wait()

	totalUploaded = 0
	for _, i := range uploadCount {
		totalUploaded += i
	}
	log.Info("Uploaded", strconv.Itoa(totalUploaded), "artifacts.")
	totalFailed = size - totalUploaded
	if totalFailed > 0 {
		log.Error("Failed uploading", strconv.Itoa(totalFailed), "artifacts.")
	}
	return
}
コード例 #13
0
func CreatePackage(packageDetails *utils.VersionDetails, flags *utils.PackageFlags) error {
	log.Info("Creating package...")
	resp, body, err := DoCreatePackage(packageDetails, flags)
	if err != nil {
		return err
	}
	if resp.StatusCode != 201 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Created package", packageDetails.Package+", details:")
	fmt.Println(cliutils.IndentJson(body))
	return nil
}
コード例 #14
0
ファイル: moveutils.go プロジェクト: JFrogDev/jfrog-cli-go
func MoveFilesWrapper(moveSpec *SpecFiles, flags *MoveFlags, moveType MoveType) (err error) {
	err = PreCommandSetup(flags)
	if err != nil {
		return
	}

	var successCount int
	var failedCount int

	for i := 0; i < len(moveSpec.Files); i++ {
		var successPartial, failedPartial int
		switch moveSpec.Get(i).GetSpecType() {
		case WILDCARD:
			successPartial, failedPartial, err = moveWildcard(moveSpec.Get(i), flags, moveType)
		case SIMPLE:
			successPartial, failedPartial, err = moveSimple(moveSpec.Get(i), flags, moveType)
		case AQL:
			successPartial, failedPartial, err = moveAql(moveSpec.Get(i), flags, moveType)
		}
		successCount += successPartial
		failedCount += failedPartial
		if err != nil {
			return
		}
	}

	log.Info(moveMsgs[moveType].MovedMsg, strconv.Itoa(successCount), "artifacts.")
	if failedCount > 0 {
		err = cliutils.CheckError(errors.New("Failed " + moveMsgs[moveType].MovingMsg + " " + strconv.Itoa(failedCount) + " artifacts."))
	}

	return
}
コード例 #15
0
func DownloadVersion(versionDetails *utils.VersionDetails, targetPath string, flags *utils.DownloadFlags) (totalDownloded, totalFailed int, err error) {
	ioutils.CreateTempDirPath()
	defer ioutils.RemoveTempDir()

	if flags.BintrayDetails.User == "" {
		flags.BintrayDetails.User = versionDetails.Subject
	}
	path := BuildDownloadVersionUrl(versionDetails, flags.BintrayDetails, flags.IncludeUnpublished)
	httpClientsDetails := utils.GetBintrayHttpClientDetails(flags.BintrayDetails)
	resp, body, _, _ := ioutils.SendGet(path, true, httpClientsDetails)
	if resp.StatusCode != 200 {
		err = cliutils.CheckError(errors.New(resp.Status + ". " + utils.ReadBintrayMessage(body)))
		return
	}
	var results []VersionFilesResult
	err = json.Unmarshal(body, &results)
	if cliutils.CheckError(err) != nil {
		return
	}

	totalDownloded, err = downloadFiles(results, versionDetails, targetPath, flags)
	log.Info("Downloaded", strconv.Itoa(totalDownloded), "artifacts.")
	totalFailed = len(results) - totalDownloded
	return
}
コード例 #16
0
ファイル: accesskeys.go プロジェクト: JFrogDev/jfrog-cli-go
func DeleteAccessKey(flags *AccessKeyFlags, org string) error {
	url := GetAccessKeyPath(flags.BintrayDetails, flags.Id, org)
	httpClientsDetails := utils.GetBintrayHttpClientDetails(flags.BintrayDetails)
	log.Info("Deleting access key...")
	resp, body, err := ioutils.SendDelete(url, nil, httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Deleted access key.")
	return nil
}
コード例 #17
0
ファイル: download.go プロジェクト: JFrogDev/jfrog-cli-go
func logDownloadTotals(buildDependencies [][]utils.DependenciesBuildInfo) {
	var totalDownloded int
	for _, v := range buildDependencies {
		totalDownloded += len(v)
	}
	log.Info("Downloaded", strconv.Itoa(totalDownloded), "artifacts.")
}
コード例 #18
0
func LogSearchResults(numOfArtifacts int) {
	var msgSuffix = "artifacts."
	if numOfArtifacts == 1 {
		msgSuffix = "artifact."
	}
	log.Info("Found", strconv.Itoa(numOfArtifacts), msgSuffix)
}
コード例 #19
0
func getFilesList(flags *OfflineUpdatesFlags) ([]string, []string, int64, error) {
	log.Info("Getting updates...")
	headers := make(map[string]string)
	headers["X-Xray-License"] = flags.License
	httpClientDetails := ioutils.HttpClientDetails{
		Headers: headers,
	}
	resp, body, _, err := ioutils.SendGet(updatesUrl, false, httpClientDetails)
	if err != nil {
		cliutils.CheckError(err)
		return nil, nil, 0, err
	}
	if resp.StatusCode != 200 {
		err := errors.New("Response: " + resp.Status)
		cliutils.CheckError(err)
		return nil, nil, 0, err
	}
	var urls FilesList
	json.Unmarshal(body, &urls)
	var vulnerabilities, components []string
	for _, v := range urls.Urls {
		if strings.Contains(v, VULNERABILITY) {
			vulnerabilities = append(vulnerabilities, v)
		} else if strings.Contains(v, COMPONENT) {
			components = append(components, v)
		}
	}
	return vulnerabilities, components, urls.Last_update, nil
}
コード例 #20
0
ファイル: delete.go プロジェクト: JFrogDev/jfrog-cli-go
func GetPathsToDelete(deleteSpec *utils.SpecFiles, flags *DeleteFlags) (resultItems []utils.AqlSearchResultItem, err error) {
	log.Info("Searching artifacts...")
	for i := 0; i < len(deleteSpec.Files); i++ {
		var isDirectoryDeleteBool bool
		isSimpleDirectoryDeleteBool, e := isSimpleDirectoryDelete(deleteSpec.Get(i))
		if e != nil {
			err = e
			return
		}
		if !isSimpleDirectoryDeleteBool {
			isDirectoryDeleteBool, e = isDirectoryDelete(deleteSpec.Get(i))
			if e != nil {
				err = e
				return
			}
		}
		switch {
		case deleteSpec.Get(i).GetSpecType() == utils.AQL:
			resultItemsTemp, e := utils.AqlSearchBySpec(deleteSpec.Get(i).Aql, flags)
			if e != nil {
				err = e
				return
			}
			resultItems = append(resultItems, resultItemsTemp...)

		case isSimpleDirectoryDeleteBool:
			simplePathItem := utils.AqlSearchResultItem{Path: deleteSpec.Get(i).Pattern}
			resultItems = append(resultItems, []utils.AqlSearchResultItem{simplePathItem}...)

		case isDirectoryDeleteBool:
			tempResultItems, e := utils.AqlSearchDefaultReturnFields(deleteSpec.Get(i).Pattern, true, "", flags)
			if e != nil {
				err = e
				return
			}
			paths, e := getDirsForDeleteFromFilesPaths(deleteSpec.Get(i).Pattern, tempResultItems)
			if e != nil {
				err = e
				return
			}
			resultItems = append(resultItems, paths...)
		default:
			isRecursive, e := cliutils.StringToBool(deleteSpec.Get(i).Recursive, true)
			if e != nil {
				err = e
				return
			}
			tempResultItems, e := utils.AqlSearchDefaultReturnFields(deleteSpec.Get(i).Pattern,
				isRecursive, deleteSpec.Get(i).Props, flags)
			if e != nil {
				err = e
				return
			}
			resultItems = append(resultItems, tempResultItems...)
		}
	}
	utils.LogSearchResults(len(resultItems))
	return
}
コード例 #21
0
ファイル: accesskeys.go プロジェクト: JFrogDev/jfrog-cli-go
func UpdateAccessKey(flags *AccessKeyFlags, org string) error {
	data := BuildAccessKeyJson(flags, false)
	url := GetAccessKeyPath(flags.BintrayDetails, flags.Id, org)
	httpClientsDetails := utils.GetBintrayHttpClientDetails(flags.BintrayDetails)
	log.Info("Updating access key...")
	resp, body, err := ioutils.SendPatch(url, []byte(data), httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Updated access key, details:")
	fmt.Println(cliutils.IndentJson(body))
	return nil
}
コード例 #22
0
ファイル: upload.go プロジェクト: JFrogDev/jfrog-cli-go
func uploadWildcard(artifacts []UploadData, flags *UploadFlags) (buildInfoArtifacts [][]utils.ArtifactBuildInfo, totalUploaded, totalFailed int, err error) {
	minChecksumDeploySize, e := getMinChecksumDeploySize()
	if e != nil {
		err = e
		return
	}

	size := len(artifacts)
	var wg sync.WaitGroup

	// Create an array of integers, to store the total file that were uploaded successfully.
	// Each array item is used by a single thread.
	uploadCount := make([]int, flags.Threads, flags.Threads)
	buildInfoArtifacts = make([][]utils.ArtifactBuildInfo, flags.Threads)
	for i := 0; i < flags.Threads; i++ {
		wg.Add(1)
		go func(threadId int) {
			logMsgPrefix := cliutils.GetLogMsgPrefix(threadId, flags.DryRun)
			for j := threadId; j < size && err == nil; j += flags.Threads {
				var e error
				var uploaded bool
				var target string
				var buildInfoArtifact utils.ArtifactBuildInfo
				target, e = utils.BuildArtifactoryUrl(flags.ArtDetails.Url, artifacts[j].Artifact.TargetPath, make(map[string]string))
				if e != nil {
					err = e
					break
				}
				buildInfoArtifact, uploaded, e = uploadFile(artifacts[j].Artifact.LocalPath, target, artifacts[j].Props, flags, minChecksumDeploySize, logMsgPrefix)
				if e != nil {
					err = e
					break
				}
				if uploaded {
					uploadCount[threadId]++
					buildInfoArtifacts[threadId] = append(buildInfoArtifacts[threadId], buildInfoArtifact)
				}
			}
			wg.Done()
		}(i)
	}
	wg.Wait()
	if err != nil {
		return
	}
	totalUploaded = 0
	for _, i := range uploadCount {
		totalUploaded += i
	}

	log.Info("Uploaded", strconv.Itoa(totalUploaded), "artifacts.")
	totalFailed = size - totalUploaded
	if totalFailed > 0 {
		log.Error("Failed uploading", strconv.Itoa(totalFailed), "artifacts.")
	}
	return
}
コード例 #23
0
ファイル: packageshow.go プロジェクト: JFrogDev/jfrog-cli-go
func ShowPackage(packageDetails *utils.VersionDetails, bintrayDetails *config.BintrayDetails) (err error) {
	if bintrayDetails.User == "" {
		bintrayDetails.User = packageDetails.Subject
	}
	url := bintrayDetails.ApiUrl + "packages/" + packageDetails.Subject + "/" +
		packageDetails.Repo + "/" + packageDetails.Package

	log.Info("Getting package details...")
	httpClientsDetails := utils.GetBintrayHttpClientDetails(bintrayDetails)
	resp, body, _, _ := ioutils.SendGet(url, true, httpClientsDetails)
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Package", packageDetails.Package, "details:")
	fmt.Println(cliutils.IndentJson(body))
	return
}
コード例 #24
0
ファイル: logs.go プロジェクト: JFrogDev/jfrog-cli-go
func LogsList(packageDetails *utils.VersionDetails, details *config.BintrayDetails) error {
	if details.User == "" {
		details.User = packageDetails.Subject
	}
	path := details.ApiUrl + "packages/" + packageDetails.Subject + "/" +
		packageDetails.Repo + "/" + packageDetails.Package + "/logs/"
	httpClientsDetails := utils.GetBintrayHttpClientDetails(details)
	log.Info("Getting logs...")
	resp, body, _, _ := ioutils.SendGet(path, true, httpClientsDetails)

	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Log details:")
	fmt.Println(cliutils.IndentJson(body))
	return nil
}
コード例 #25
0
ファイル: moveutils.go プロジェクト: JFrogDev/jfrog-cli-go
func moveAql(fileSpec *Files, flags *MoveFlags, moveType MoveType) (successCount, failedCount int, err error) {
	log.Info("Searching artifacts...")
	resultItems, err := AqlSearchBySpec(fileSpec.Aql, flags)
	if err != nil {
		return
	}
	LogSearchResults(len(resultItems))
	successCount, failedCount, err = moveFiles("", resultItems, fileSpec, flags, moveType)
	return
}
コード例 #26
0
ファイル: logs.go プロジェクト: JFrogDev/jfrog-cli-go
func DownloadLog(packageDetails *utils.VersionDetails, logName string,
	details *config.BintrayDetails) error {
	if details.User == "" {
		details.User = packageDetails.Subject
	}
	path := details.ApiUrl + "packages/" + packageDetails.Subject + "/" +
		packageDetails.Repo + "/" + packageDetails.Package + "/logs/" + logName
	httpClientsDetails := utils.GetBintrayHttpClientDetails(details)
	log.Info("Downloading logs...")
	resp, err := ioutils.DownloadFile(path, "", logName, httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status))
	}
	log.Debug("Bintray response:", resp.Status)
	log.Info("Downloaded log.")
	return nil
}
コード例 #27
0
ファイル: show.go プロジェクト: JFrogDev/jfrog-cli-go
func ShowEntitlement(flags *EntitlementFlags, details *utils.VersionDetails) error {
	url := BuildEntitlementUrl(flags.BintrayDetails, details, flags.Id)
	if flags.BintrayDetails.User == "" {
		flags.BintrayDetails.User = details.Subject
	}
	httpClientsDetails := utils.GetBintrayHttpClientDetails(flags.BintrayDetails)
	log.Info("Getting entitlement...")
	resp, body, _, err := ioutils.SendGet(url, true, httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Entitlement details:")
	fmt.Println(cliutils.IndentJson(body))
	return nil
}
コード例 #28
0
func DeleteVersion(versionDetails *utils.VersionDetails, bintrayDetails *config.BintrayDetails) error {
	if bintrayDetails.User == "" {
		bintrayDetails.User = versionDetails.Subject
	}
	url := bintrayDetails.ApiUrl + "packages/" + versionDetails.Subject + "/" +
		versionDetails.Repo + "/" + versionDetails.Package + "/versions/" + versionDetails.Version

	log.Info("Deleting version...")
	httpClientsDetails := utils.GetBintrayHttpClientDetails(bintrayDetails)
	resp, body, err := ioutils.SendDelete(url, nil, httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Deleted version", versionDetails.Version+".")
	return nil
}
コード例 #29
0
ファイル: download.go プロジェクト: JFrogDev/jfrog-cli-go
func downloadAqlResult(dependecies []DownloadData, flags *DownloadFlags) (buildDependencies [][]utils.DependenciesBuildInfo, err error) {
	size := len(dependecies)
	buildDependencies = make([][]utils.DependenciesBuildInfo, flags.Threads)
	var wg sync.WaitGroup
	for i := 0; i < flags.Threads; i++ {
		wg.Add(1)
		go func(threadId int) {
			logMsgPrefix := cliutils.GetLogMsgPrefix(threadId, flags.DryRun)
			for j := threadId; j < size && err == nil; j += flags.Threads {
				downloadPath, e := utils.BuildArtifactoryUrl(flags.ArtDetails.Url, dependecies[j].Dependency.GetFullUrl(), make(map[string]string))
				if e != nil {
					err = e
					break
				}
				log.Info(logMsgPrefix+"Downloading", dependecies[j].Dependency.GetFullUrl())
				if flags.DryRun {
					continue
				}

				regexpPattern := cliutils.PathToRegExp(dependecies[j].DownloadPath)
				placeHolderTarget, e := cliutils.ReformatRegexp(regexpPattern, dependecies[j].Dependency.GetFullUrl(), dependecies[j].Target)
				if e != nil {
					err = e
					break
				}
				localPath, localFileName := ioutils.GetLocalPathAndFile(dependecies[j].Dependency.Name, dependecies[j].Dependency.Path, placeHolderTarget, dependecies[j].Flat)
				shouldDownload, e := shouldDownloadFile(path.Join(localPath, dependecies[j].Dependency.Name), dependecies[j].Dependency.Actual_Md5, dependecies[j].Dependency.Actual_Sha1)
				if e != nil {
					err = e
					break
				}
				dependency := createBuildDependencyItem(dependecies[j].Dependency)
				if !shouldDownload {
					buildDependencies[threadId] = append(buildDependencies[threadId], dependency)
					log.Debug(logMsgPrefix, "File already exists locally.")
					continue
				}

				downloadFileDetails := createDownloadFileDetails(downloadPath, localPath, localFileName, nil, dependecies[j].Dependency.Size)
				e = downloadFile(downloadFileDetails, logMsgPrefix, flags)
				if e != nil {
					err = e
					break
				}
				buildDependencies[threadId] = append(buildDependencies[threadId], dependency)
			}
			wg.Done()
		}(i)
	}
	wg.Wait()
	logDownloadTotals(buildDependencies)
	return
}
コード例 #30
0
ファイル: update.go プロジェクト: JFrogDev/jfrog-cli-go
func UpdateEntitlement(flags *EntitlementFlags, details *utils.VersionDetails) error {
	path := BuildEntitlementUrl(flags.BintrayDetails, details, flags.Id)
	if flags.BintrayDetails.User == "" {
		flags.BintrayDetails.User = details.Subject
	}
	data := buildEntitlementJson(flags, true)
	httpClientsDetails := utils.GetBintrayHttpClientDetails(flags.BintrayDetails)
	log.Info("Updating entitlement...")
	resp, body, err := ioutils.SendPatch(path, []byte(data), httpClientsDetails)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return cliutils.CheckError(errors.New("Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body)))
	}

	log.Debug("Bintray response:", resp.Status)
	log.Info("Updated entitlement, details:")
	fmt.Println(cliutils.IndentJson(body))
	return err
}