github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/go/publishwithmatrixparams.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(&publishWithMatrixParams{})
    15  }
    16  
    17  // Support for Artifactory version between 6.5.0 and 6.6.1 API
    18  type publishWithMatrixParams struct {
    19  }
    20  
    21  func (pwmp *publishWithMatrixParams) isCompatible(artifactoryVersion string) bool {
    22  	propertiesApi := "6.5.0"
    23  	withoutApi := "6.6.1"
    24  	version := version.NewVersion(artifactoryVersion)
    25  	if version.Compare(propertiesApi) > 0 {
    26  		return false
    27  	}
    28  	if version.Compare(withoutApi) <= 0 {
    29  		return false
    30  	}
    31  	return true
    32  }
    33  
    34  func (pwmp *publishWithMatrixParams) PublishPackage(params GoParams, client *rthttpclient.ArtifactoryHttpClient, ArtDetails auth.ServiceDetails) error {
    35  	url, err := utils.BuildArtifactoryUrl(ArtDetails.GetUrl(), "api/go/"+params.GetTargetRepo(), make(map[string]string))
    36  	clientDetails := ArtDetails.CreateHttpClientDetails()
    37  	addHeaders(params, &clientDetails)
    38  
    39  	err = CreateUrlPath(params.GetModuleId(), params.GetVersion(), params.GetProps(), ".zip", &url)
    40  	if err != nil {
    41  		return err
    42  	}
    43  
    44  	resp, _, err := client.UploadFile(params.GetZipPath(), url, "", &clientDetails, GoUploadRetries, nil)
    45  	if err != nil {
    46  		return err
    47  	}
    48  	return errorutils.CheckResponseStatus(resp, http.StatusCreated)
    49  }