github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/createreplication.go (about) 1 package services 2 3 import ( 4 "encoding/json" 5 "errors" 6 "net/http" 7 8 rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient" 9 "github.com/cobalt77/jfrog-client-go/artifactory/services/utils" 10 "github.com/cobalt77/jfrog-client-go/auth" 11 clientutils "github.com/cobalt77/jfrog-client-go/utils" 12 "github.com/cobalt77/jfrog-client-go/utils/errorutils" 13 "github.com/cobalt77/jfrog-client-go/utils/log" 14 ) 15 16 type CreateReplicationService struct { 17 client *rthttpclient.ArtifactoryHttpClient 18 ArtDetails auth.ServiceDetails 19 } 20 21 func NewCreateReplicationService(client *rthttpclient.ArtifactoryHttpClient) *CreateReplicationService { 22 return &CreateReplicationService{client: client} 23 } 24 25 func (rs *CreateReplicationService) GetJfrogHttpClient() *rthttpclient.ArtifactoryHttpClient { 26 return rs.client 27 } 28 29 func (rs *CreateReplicationService) performRequest(params *utils.ReplicationBody) error { 30 content, err := json.Marshal(params) 31 if err != nil { 32 return errorutils.CheckError(err) 33 } 34 httpClientsDetails := rs.ArtDetails.CreateHttpClientDetails() 35 utils.SetContentType("application/vnd.org.jfrog.artifactory.replications.ReplicationConfigRequest+json", &httpClientsDetails.Headers) 36 var url = rs.ArtDetails.GetUrl() + "api/replications/" + params.RepoKey 37 var resp *http.Response 38 var body []byte 39 log.Info("Creating replication..") 40 operationString := "creating" 41 resp, body, err = rs.client.SendPut(url, content, &httpClientsDetails) 42 if err != nil { 43 return err 44 } 45 if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated { 46 return errorutils.CheckError(errors.New("Artifactory response: " + resp.Status + "\n" + clientutils.IndentJson(body))) 47 } 48 log.Debug("Artifactory response:", resp.Status) 49 log.Info("Done " + operationString + " repository.") 50 return nil 51 } 52 53 func (rs *CreateReplicationService) CreateReplication(params CreateReplicationParams) error { 54 return rs.performRequest(utils.CreateReplicationBody(params.ReplicationParams)) 55 } 56 57 func NewCreateReplicationParams() CreateReplicationParams { 58 return CreateReplicationParams{} 59 } 60 61 type CreateReplicationParams struct { 62 utils.ReplicationParams 63 }