github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/go/publishwithheaders.go (about)

     1  package _go
     2  
     3  import (
     4  	"net/http"
     5  
     6  	rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient"
     7  	"github.com/cobalt77/jfrog-client-go/artifactory/services/utils"
     8  	"github.com/cobalt77/jfrog-client-go/auth"
     9  	"github.com/cobalt77/jfrog-client-go/utils/errorutils"
    10  	"github.com/cobalt77/jfrog-client-go/utils/version"
    11  )
    12  
    13  func init() {
    14  	register(&publishWithHeader{})
    15  }
    16  
    17  // Support for Artifactory older then 6.5.0 API
    18  type publishWithHeader struct {
    19  }
    20  
    21  func (pwh *publishWithHeader) isCompatible(artifactoryVersion string) bool {
    22  	propertiesApi := "6.5.0"
    23  	version := version.NewVersion(artifactoryVersion)
    24  	if version.Compare(propertiesApi) > 0 {
    25  		return true
    26  	}
    27  	return false
    28  }
    29  
    30  func (pwh *publishWithHeader) PublishPackage(params GoParams, client *rthttpclient.ArtifactoryHttpClient, ArtDetails auth.ServiceDetails) error {
    31  	url, err := utils.BuildArtifactoryUrl(ArtDetails.GetUrl(), "api/go/"+params.GetTargetRepo(), make(map[string]string))
    32  	clientDetails := ArtDetails.CreateHttpClientDetails()
    33  	addHeaders(params, &clientDetails)
    34  	err = addPropertiesHeaders(params.GetProps(), &clientDetails.Headers)
    35  	if err != nil {
    36  		return err
    37  	}
    38  	resp, _, err := client.UploadFile(params.GetZipPath(), url, "", &clientDetails, GoUploadRetries, nil)
    39  	if err != nil {
    40  		return err
    41  	}
    42  	return errorutils.CheckResponseStatus(resp, http.StatusCreated)
    43  }
    44  
    45  func addPropertiesHeaders(props string, headers *map[string]string) error {
    46  	properties, err := utils.ParseProperties(props, utils.JoinCommas)
    47  	if err != nil {
    48  		return err
    49  	}
    50  	headersMap := properties.ToHeadersMap()
    51  	for k, v := range headersMap {
    52  		utils.AddHeader("X-ARTIFACTORY-PROPERTY-"+k, v, headers)
    53  	}
    54  	return nil
    55  }