Esempio n. 1
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
}
Esempio n. 2
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
}
Esempio n. 3
0
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
}
Esempio n. 4
0
func getPackageFiles(packageName string) []tests.PackageSearchResultItem {
	apiUrl := bintrayConfig.ApiUrl + path.Join("packages", bintrayConfig.User, tests.BintrayRepo1, packageName, "files?include_unpublished=1")
	clientDetails := ioutils.HttpClientDetails{
		User:     bintrayConfig.User,
		Password: bintrayConfig.Key,
		Headers:  map[string]string{"Content-Type": "application/json"}}

	resp, body, _, err := ioutils.SendGet(apiUrl, true, clientDetails)
	if cliutils.CheckError(err) != nil {
		os.Exit(1)
	}
	if resp.StatusCode != 200 {
		log.Error(resp.Status)
		log.Error(string(body))
		os.Exit(1)
	}

	var result []tests.PackageSearchResultItem
	err = json.Unmarshal(body, &result)
	if err != nil {
		log.Error(err)
		os.Exit(1)
	}

	return result
}
Esempio n. 5
0
func TestArtifactoryDeleteFoldersBySpec(t *testing.T) {
	initArtifactoryTest(t)
	prepUploadFiles()
	prepCopyFiles()

	artifactoryCli.Exec("delete", "--spec="+tests.GetFilePath(tests.DeleteSpec), "--quiet=true")

	artHttpDetails := utils.GetArtifactoryHttpClientDetails(artifactoryDetails)
	resp, body, _, err := ioutils.SendGet(*tests.RtUrl+"api/storage/"+tests.Repo1+"/downloadTestResources", true, artHttpDetails)
	if err != nil || resp.StatusCode != 404 {
		t.Error("Coudln't delete path: " + tests.Repo1 + "/downloadTestResources/ " + string(body))
	}
	resp, body, _, err = ioutils.SendGet(*tests.RtUrl+"api/storage/"+tests.Repo2+"/downloadTestResources", true, artHttpDetails)
	if err != nil || resp.StatusCode != 404 {
		t.Error("Coudln't delete path: " + tests.Repo2 + "/downloadTestResources/ " + string(body))
	}

	cleanArtifactoryTest()
}
Esempio n. 6
0
func GetEncryptedPasswordFromArtifactory(artifactoryDetails *config.ArtifactoryDetails) (*http.Response, string, error) {
	err := initTransport(artifactoryDetails)
	if err != nil {
		return nil, "", err
	}
	apiUrl := artifactoryDetails.Url + "api/security/encryptedPassword"
	httpClientsDetails := GetArtifactoryHttpClientDetails(artifactoryDetails)
	resp, body, _, err := ioutils.SendGet(apiUrl, true, httpClientsDetails)
	return resp, string(body), err
}
Esempio n. 7
0
func isRepoExist(repoName string) bool {
	artHttpDetails := utils.GetArtifactoryHttpClientDetails(artifactoryDetails)
	resp, _, _, err := ioutils.SendGet(*tests.RtUrl+tests.RepoDetailsUrl+repoName, true, artHttpDetails)
	if err != nil {
		os.Exit(1)
	}

	if resp.StatusCode != 400 {
		return true
	}
	return false
}
Esempio n. 8
0
func TestArtifactoryDeleteFolderWithWildcard(t *testing.T) {
	initArtifactoryTest(t)
	prepUploadFiles()
	prepCopyFiles()

	specFile := tests.GetFilePath(tests.MoveCopyDeleteSpec)
	artifactoryCli.Exec("copy", "--spec="+specFile)

	artHttpDetails := utils.GetArtifactoryHttpClientDetails(artifactoryDetails)
	resp, _, _, _ := ioutils.SendGet(*tests.RtUrl+"api/storage/"+tests.Repo2+"/nonflat_recursive_target/nonflat_recursive_source/a/b/", true, artHttpDetails)
	if resp.StatusCode != 200 {
		t.Error("Missing folder in artifactory : " + tests.Repo2 + "/nonflat_recursive_target/nonflat_recursive_source/a/b/")
	}

	artifactoryCli.Exec("delete", tests.Repo2+"/nonflat_recursive_target/nonflat_recursive_source/*/b/", "--quiet=true")
	resp, _, _, _ = ioutils.SendGet(*tests.RtUrl+"api/storage/"+tests.Repo2+"/nonflat_recursive_target/nonflat_recursive_source/a/b/", true, artHttpDetails)
	if resp.StatusCode != 404 {
		t.Error("Couldn't delete folder in artifactory : " + tests.Repo2 + "/nonflat_recursive_target/nonflat_recursive_source/a/b/")
	}

	isExistInArtifactory(tests.Delete1, tests.GetFilePath(tests.SearchMoveDeleteRepoSpec), t)
	cleanArtifactoryTest()
}
Esempio n. 9
0
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
}
Esempio n. 10
0
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
}
Esempio n. 11
0
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
}
Esempio n. 12
0
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
}
Esempio n. 13
0
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
}