/
createreplication.go
58 lines (49 loc) · 1.84 KB
/
createreplication.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
54
55
56
57
58
package services
import (
"encoding/json"
"net/http"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"github.com/jfrog/jfrog-client-go/auth"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
)
type CreateReplicationService struct {
client *jfroghttpclient.JfrogHttpClient
ArtDetails auth.ServiceDetails
}
func NewCreateReplicationService(client *jfroghttpclient.JfrogHttpClient) *CreateReplicationService {
return &CreateReplicationService{client: client}
}
func (rs *CreateReplicationService) GetJfrogHttpClient() *jfroghttpclient.JfrogHttpClient {
return rs.client
}
func (rs *CreateReplicationService) performRequest(params *utils.UpdateReplicationBody) error {
content, err := json.Marshal(params)
if err != nil {
return errorutils.CheckError(err)
}
httpClientsDetails := rs.ArtDetails.CreateHttpClientDetails()
utils.SetContentType("application/vnd.org.jfrog.artifactory.replications.ReplicationConfigRequest+json", &httpClientsDetails.Headers)
var url = rs.ArtDetails.GetUrl() + "api/replications/" + params.RepoKey
log.Info("Creating replication...")
resp, body, err := rs.client.SendPut(url, content, &httpClientsDetails)
if err != nil {
return err
}
if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK, http.StatusCreated); err != nil {
return err
}
log.Debug("Artifactory response:", resp.Status)
log.Info("Done creating replication.")
return nil
}
func (rs *CreateReplicationService) CreateReplication(params CreateReplicationParams) error {
return rs.performRequest(utils.CreateUpdateReplicationBody(params.ReplicationParams))
}
func NewCreateReplicationParams() CreateReplicationParams {
return CreateReplicationParams{}
}
type CreateReplicationParams struct {
utils.ReplicationParams
}