Exemplo n.º 1
0
func UploadFile(f *os.File, url string, artifactoryDetails *config.ArtifactoryDetails,
	details *ioutils.FileDetails, httpClientsDetails ioutils.HttpClientDetails) (*http.Response, []byte, error) {
	var err error
	if details == nil {
		details, err = ioutils.GetFileDetails(f.Name())
	}
	if err != nil {
		return nil, nil, err
	}
	headers := map[string]string{
		"X-Checksum-Sha1": details.Sha1,
		"X-Checksum-Md5":  details.Md5,
	}
	AddAuthHeaders(headers, artifactoryDetails)
	requestClientDetails := httpClientsDetails.Clone()
	cliutils.MergeMaps(headers, requestClientDetails.Headers)

	return ioutils.UploadFile(f, url, *requestClientDetails)
}
Exemplo n.º 2
0
func uploadFile(artifact cliutils.Artifact, url, logMsgPrefix string, bintrayDetails *config.BintrayDetails) (bool, error) {
	log.Info(logMsgPrefix+"Uploading artifact:", artifact.LocalPath)

	f, err := os.Open(artifact.LocalPath)
	err = cliutils.CheckError(err)
	if err != nil {
		return false, err
	}
	defer f.Close()
	httpClientsDetails := utils.GetBintrayHttpClientDetails(bintrayDetails)
	resp, body, err := ioutils.UploadFile(f, url, httpClientsDetails)
	if err != nil {
		return false, err
	}
	log.Debug(logMsgPrefix+"Bintray response:", resp.Status)
	if resp.StatusCode != 201 && resp.StatusCode != 200 {
		log.Error(logMsgPrefix + "Bintray response: " + resp.Status + "\n" + cliutils.IndentJson(body))
	}

	return resp.StatusCode == 201 || resp.StatusCode == 200, nil
}