func AddAuthHeaders(headers map[string]string, artifactoryDetails *config.ArtifactoryDetails) map[string]string {
	if headers == nil {
		headers = make(map[string]string)
	}
	if artifactoryDetails.SshAuthHeaders != nil {
		cliutils.MergeMaps(artifactoryDetails.SshAuthHeaders, headers)
	}
	return headers
}
Exemple #2
0
func (httpClientDetails HttpClientDetails) Clone() *HttpClientDetails {
	headers := make(map[string]string)
	cliutils.MergeMaps(httpClientDetails.Headers, headers)
	return &HttpClientDetails{
		User:      httpClientDetails.User,
		Password:  httpClientDetails.Password,
		ApiKey:    httpClientDetails.ApiKey,
		Headers:   headers,
		Transport: httpClientDetails.Transport}
}
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)
}