github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/updatereplication.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 UpdateReplicationService struct { 17 client *rthttpclient.ArtifactoryHttpClient 18 ArtDetails auth.ServiceDetails 19 } 20 21 func NewUpdateReplicationService(client *rthttpclient.ArtifactoryHttpClient) *UpdateReplicationService { 22 return &UpdateReplicationService{client: client} 23 } 24 25 func (rs *UpdateReplicationService) GetJfrogHttpClient() *rthttpclient.ArtifactoryHttpClient { 26 return rs.client 27 } 28 29 func (rs *UpdateReplicationService) 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("Update replication...") 40 operationString := "updating" 41 resp, body, err = rs.client.SendPost(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 *UpdateReplicationService) UpdateReplication(params UpdateReplicationParams) error { 54 return rs.performRequest(utils.CreateReplicationBody(params.ReplicationParams)) 55 } 56 57 func NewUpdateReplicationParams() UpdateReplicationParams { 58 return UpdateReplicationParams{} 59 } 60 61 type UpdateReplicationParams struct { 62 utils.ReplicationParams 63 }