Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #523 Add capability to specify proxy for repository replications #524

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions artifactory/services/createreplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (rs *CreateReplicationService) GetJfrogHttpClient() *jfroghttpclient.JfrogH
return rs.client
}

func (rs *CreateReplicationService) performRequest(params *utils.ReplicationBody) error {
func (rs *CreateReplicationService) performRequest(params *utils.UpdateReplicationBody) error {
content, err := json.Marshal(params)
if err != nil {
return errorutils.CheckError(err)
Expand All @@ -50,7 +50,7 @@ func (rs *CreateReplicationService) performRequest(params *utils.ReplicationBody
}

func (rs *CreateReplicationService) CreateReplication(params CreateReplicationParams) error {
return rs.performRequest(utils.CreateReplicationBody(params.ReplicationParams))
return rs.performRequest(utils.CreateUpdateReplicationBody(params.ReplicationParams))
}

func NewCreateReplicationParams() CreateReplicationParams {
Expand Down
10 changes: 8 additions & 2 deletions artifactory/services/getreplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ func (drs *GetReplicationService) GetReplication(repoKey string) ([]utils.Replic
if err != nil {
return nil, err
}
var replicationConf []utils.ReplicationParams
if err := json.Unmarshal(body, &replicationConf); err != nil {
var replicationBody []utils.GetReplicationBody
if err := json.Unmarshal(body, &replicationBody); err != nil {
return nil, errorutils.CheckError(err)
}

var replicationConf = make([]utils.ReplicationParams, len(replicationBody))
for i, body := range replicationBody {
replicationConf[i] = *utils.CreateReplicationParams(body)
}

return replicationConf, nil
}

Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/updatereplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (rs *UpdateReplicationService) GetJfrogHttpClient() *jfroghttpclient.JfrogH
return rs.client
}

func (rs *UpdateReplicationService) performRequest(params *utils.ReplicationBody) error {
func (rs *UpdateReplicationService) performRequest(params *utils.UpdateReplicationBody) error {
content, err := json.Marshal(params)
if err != nil {
return errorutils.CheckError(err)
Expand All @@ -50,7 +50,7 @@ func (rs *UpdateReplicationService) performRequest(params *utils.ReplicationBody
}

func (rs *UpdateReplicationService) UpdateReplication(params UpdateReplicationParams) error {
return rs.performRequest(utils.CreateReplicationBody(params.ReplicationParams))
return rs.performRequest(utils.CreateUpdateReplicationBody(params.ReplicationParams))
}

func NewUpdateReplicationParams() UpdateReplicationParams {
Expand Down
62 changes: 47 additions & 15 deletions artifactory/services/utils/replication.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utils

type ReplicationBody struct {
type replicationBody struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One downside of this change to have two new structs of GetReplicationBody and UpdateReplicationBody rather than overriding the JSONUnmarshal function is that this change is no longer backwards compatible.

Even if I keep choose to keep replicationBody exposed, the function specs in artifactory/services/createreplication.go and artifactory/services/getreplication.go will be changed which are backward incompatible changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guent4 -
We're mostly okay with breaking compatibility following APO changes. If a public API changed, we make sure to note it in the release notes.

Username string `json:"username"`
Password string `json:"password"`
URL string `json:"url"`
Expand All @@ -15,13 +15,24 @@ type ReplicationBody struct {
PathPrefix string `json:"pathPrefix"`
}

type GetReplicationBody struct {
replicationBody
ProxyRef string `json:"proxyRef"`
}

type UpdateReplicationBody struct {
replicationBody
Proxy string `json:"proxy"`
}

type ReplicationParams struct {
Username string
Password string
Url string
CronExp string
// Source replication repository.
RepoKey string
Proxy string
EnableEventReplication bool
SocketTimeoutMillis int
Enabled bool
Expand All @@ -32,19 +43,40 @@ type ReplicationParams struct {
IncludePathPrefixPattern string
}

func CreateReplicationBody(params ReplicationParams) *ReplicationBody {
return &ReplicationBody{
Username: params.Username,
Password: params.Password,
URL: params.Url,
CronExp: params.CronExp,
RepoKey: params.RepoKey,
EnableEventReplication: params.EnableEventReplication,
SocketTimeoutMillis: params.SocketTimeoutMillis,
Enabled: params.Enabled,
SyncDeletes: params.SyncDeletes,
SyncProperties: params.SyncProperties,
SyncStatistics: params.SyncStatistics,
PathPrefix: params.PathPrefix,
func CreateUpdateReplicationBody(params ReplicationParams) *UpdateReplicationBody {
return &UpdateReplicationBody{
replicationBody: replicationBody{
Username: params.Username,
Password: params.Password,
URL: params.Url,
CronExp: params.CronExp,
RepoKey: params.RepoKey,
EnableEventReplication: params.EnableEventReplication,
SocketTimeoutMillis: params.SocketTimeoutMillis,
Enabled: params.Enabled,
SyncDeletes: params.SyncDeletes,
SyncProperties: params.SyncProperties,
SyncStatistics: params.SyncStatistics,
PathPrefix: params.PathPrefix,
},
Proxy: params.Proxy,
}
}

func CreateReplicationParams(body GetReplicationBody) *ReplicationParams {
return &ReplicationParams{
Username: body.Username,
Password: body.Password,
Url: body.URL,
CronExp: body.CronExp,
RepoKey: body.RepoKey,
Proxy: body.ProxyRef,
EnableEventReplication: body.EnableEventReplication,
SocketTimeoutMillis: body.SocketTimeoutMillis,
Enabled: body.Enabled,
SyncDeletes: body.SyncDeletes,
SyncProperties: body.SyncProperties,
SyncStatistics: body.SyncStatistics,
PathPrefix: body.PathPrefix,
}
}