Skip to content

Commit

Permalink
Added struct SRAddOptions and SREditOptions
Browse files Browse the repository at this point in the history
Needed to support options while adding/updating site replication

Signed-off-by: Shubhendu Ram Tripathi <[email protected]>
  • Loading branch information
shtripat committed Sep 29, 2023
1 parent 94d0205 commit b46c74d
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions cluster-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,19 @@ type ReplicateAddStatus struct {
InitialSyncErrorMessage string `json:"initialSyncErrorMessage,omitempty"`
}

// SRAddOptions holds SR Add options
type SRAddOptions struct {
ReplicateILMExpiry bool
}

func (o *SRAddOptions) getURLValues() url.Values {
urlValues := make(url.Values)
urlValues.Set("replicateILMExpiry", strconv.FormatBool(o.ReplicateILMExpiry))
return urlValues
}

// SiteReplicationAdd - sends the SR add API call.
func (adm *AdminClient) SiteReplicationAdd(ctx context.Context, sites []PeerSite) (ReplicateAddStatus, error) {
func (adm *AdminClient) SiteReplicationAdd(ctx context.Context, sites []PeerSite, opts SRAddOptions) (ReplicateAddStatus, error) {
sitesBytes, err := json.Marshal(sites)
if err != nil {
return ReplicateAddStatus{}, nil
Expand All @@ -68,7 +79,7 @@ func (adm *AdminClient) SiteReplicationAdd(ctx context.Context, sites []PeerSite
return ReplicateAddStatus{}, err
}

q := make(url.Values)
q := opts.getURLValues()
q.Set("api-version", SiteReplAPIVersion)

reqData := requestData{
Expand Down Expand Up @@ -106,6 +117,7 @@ type SiteReplicationInfo struct {
Name string `json:"name,omitempty"`
Sites []PeerInfo `json:"sites,omitempty"`
ServiceAccountAccessKey string `json:"serviceAccountAccessKey,omitempty"`
ReplicateILMExpiry bool `json:"replicate-ilm-expiry"`
}

// SiteReplicationInfo - returns cluster replication information.
Expand Down Expand Up @@ -419,6 +431,7 @@ const (
SRBucketMetaTypeObjectLockConfig = "object-lock-config"
SRBucketMetaTypeSSEConfig = "sse-config"
SRBucketMetaTypeQuotaConfig = "quota-config"
SRBucketMetaILMConfig = "ilm-config"
)

// SRBucketMeta - represents a bucket metadata change that will be copied to a peer.
Expand Down Expand Up @@ -446,6 +459,10 @@ type SRBucketMeta struct {
// Quota has a json representation use it as is.
Quota json.RawMessage `json:"quota,omitempty"`

// Since ILM config does not have a json representation, we use its xml
// byte respresentation.
ILMConfig *string `json:"ilmConfig,omitempty"`

// UpdatedAt - timestamp of last update
UpdatedAt time.Time `json:"updatedAt,omitempty"`
}
Expand Down Expand Up @@ -504,6 +521,10 @@ type SRBucketInfo struct {
// quota config in json representation
QuotaConfig *string `json:"quotaConfig,omitempty"`

// Since ILM config does not have a json representation, we use its xml
// byte representation
ILMConfig *string `kson:"ilmConfig,omitempty"`

// time stamps of bucket metadata updates
PolicyUpdatedAt time.Time `json:"policyTimestamp,omitempty"`
TagConfigUpdatedAt time.Time `json:"tagTimestamp,omitempty"`
Expand All @@ -512,6 +533,7 @@ type SRBucketInfo struct {
VersioningConfigUpdatedAt time.Time `json:"versioningTimestamp,omitempty"`
ReplicationConfigUpdatedAt time.Time `json:"replicationConfigTimestamp,omitempty"`
QuotaConfigUpdatedAt time.Time `json:"quotaTimestamp,omitempty"`
ILMConfigUpdatedAt time.Time `json:"ilmTimestamp,omitempty"`
CreatedAt time.Time `json:"bucketTimestamp,omitempty"`
DeletedAt time.Time `json:"bucketDeletedTimestamp,omitempty"`
Location string `json:"location,omitempty"`
Expand Down Expand Up @@ -848,8 +870,20 @@ type ReplicateEditStatus struct {
ErrDetail string `json:"errorDetail,omitempty"`
}

// SREditOptions holds SR Add options
type SREditOptions struct {
DisableILMExpiryReplication bool
}

func (o *SREditOptions) getURLValues() url.Values {
urlValues := make(url.Values)
urlValues.Set("disableILMExpiryReplication", strconv.FormatBool(o.DisableILMExpiryReplication))
return urlValues
}


Check failure on line 884 in cluster-commands.go

View workflow job for this annotation

GitHub Actions / Lint checks Go 1.21.x

File is not `gofumpt`-ed (gofumpt)
// SiteReplicationEdit - sends the SR edit API call.
func (adm *AdminClient) SiteReplicationEdit(ctx context.Context, site PeerInfo) (ReplicateEditStatus, error) {
func (adm *AdminClient) SiteReplicationEdit(ctx context.Context, site PeerInfo, opts SREditOptions) (ReplicateEditStatus, error) {
sitesBytes, err := json.Marshal(site)
if err != nil {
return ReplicateEditStatus{}, nil
Expand All @@ -859,7 +893,7 @@ func (adm *AdminClient) SiteReplicationEdit(ctx context.Context, site PeerInfo)
return ReplicateEditStatus{}, err
}

q := make(url.Values)
q := opts.getURLValues()
q.Set("api-version", SiteReplAPIVersion)

reqData := requestData{
Expand Down

0 comments on commit b46c74d

Please sign in to comment.