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