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

     1  package services
     2  
     3  import (
     4  	"errors"
     5  	"net/http"
     6  
     7  	rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient"
     8  	"github.com/cobalt77/jfrog-client-go/artifactory/services/utils"
     9  	"github.com/cobalt77/jfrog-client-go/auth"
    10  	"github.com/cobalt77/jfrog-client-go/utils/errorutils"
    11  	"github.com/cobalt77/jfrog-client-go/utils/log"
    12  )
    13  
    14  type PingService struct {
    15  	client     *rthttpclient.ArtifactoryHttpClient
    16  	ArtDetails auth.ServiceDetails
    17  }
    18  
    19  func NewPingService(client *rthttpclient.ArtifactoryHttpClient) *PingService {
    20  	return &PingService{client: client}
    21  }
    22  
    23  func (ps *PingService) GetArtifactoryDetails() auth.ServiceDetails {
    24  	return ps.ArtDetails
    25  }
    26  
    27  func (ps *PingService) SetArtifactoryDetails(rt auth.ServiceDetails) {
    28  	ps.ArtDetails = rt
    29  }
    30  
    31  func (ps *PingService) GetJfrogHttpClient() (*rthttpclient.ArtifactoryHttpClient, error) {
    32  	return ps.client, nil
    33  }
    34  
    35  func (ps *PingService) IsDryRun() bool {
    36  	return false
    37  }
    38  
    39  func (ps *PingService) Ping() ([]byte, error) {
    40  	url, err := utils.BuildArtifactoryUrl(ps.ArtDetails.GetUrl(), "api/system/ping", nil)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  	httpClientDetails := ps.ArtDetails.CreateHttpClientDetails()
    45  	resp, respBody, _, err := ps.client.SendGet(url, true, &httpClientDetails)
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  	if resp.StatusCode != http.StatusOK {
    50  		return respBody, errorutils.CheckError(errors.New("Artifactory response: " + resp.Status))
    51  	}
    52  	log.Debug("Artifactory response: ", resp.Status)
    53  	return respBody, nil
    54  }