feat: replication bucket name (#440)

* chore: gofmt

* chore: update openapi gen files

* feat: add replication-bucket-name flag

* fix: fix tests

* chore: rename to replication-bucket

* feat: show remote bucket name or id

* chore: fmt fixup

* chore: update openapi to master

* chore: fix openapi generation
This commit is contained in:
Jeffrey Smith II
2022-08-18 14:21:50 -04:00
committed by GitHub
parent 051a6aafc4
commit 5c7c34f16d
22 changed files with 420 additions and 218 deletions

View File

@ -34,10 +34,11 @@ func (c Client) Create(ctx context.Context, params *BucketsCreateParams) error {
return err
}
var rr []api.RetentionRule
reqBody := api.PostBucketRequest{
OrgID: orgId,
Name: params.Name,
RetentionRules: []api.RetentionRule{},
RetentionRules: &rr,
SchemaType: &params.SchemaType,
}
if params.Description != "" {
@ -57,7 +58,7 @@ func (c Client) Create(ctx context.Context, params *BucketsCreateParams) error {
if sgd > 0 {
rule.SetShardGroupDurationSeconds(int64(sgd.Round(time.Second) / time.Second))
}
reqBody.RetentionRules = append(reqBody.RetentionRules, *rule)
*reqBody.RetentionRules = append(*reqBody.RetentionRules, *rule)
}
bucket, err := c.PostBuckets(ctx).PostBucketRequest(reqBody).Execute()

View File

@ -70,13 +70,14 @@ func TestBucketsCreate(t *testing.T) {
bucketsApi.EXPECT().
PostBucketsExecute(tmock.MatchedBy(func(in api.ApiPostBucketsRequest) bool {
body := in.GetPostBucketRequest()
retentionRules := *body.RetentionRules
return assert.NotNil(t, body) &&
assert.Equal(t, "123", body.OrgID) &&
assert.Equal(t, "my-bucket", body.Name) &&
assert.Equal(t, "my cool bucket", *body.Description) &&
assert.Len(t, body.RetentionRules, 1) &&
assert.Equal(t, int64(86400), body.RetentionRules[0].EverySeconds) &&
assert.Equal(t, int64(3600), *body.RetentionRules[0].ShardGroupDurationSeconds)
assert.Len(t, retentionRules, 1) &&
assert.Equal(t, int64(86400), retentionRules[0].EverySeconds) &&
assert.Equal(t, int64(3600), *retentionRules[0].ShardGroupDurationSeconds)
})).
Return(api.Bucket{
Id: api.PtrString("456"),
@ -101,13 +102,14 @@ func TestBucketsCreate(t *testing.T) {
bucketsApi.EXPECT().
PostBucketsExecute(tmock.MatchedBy(func(in api.ApiPostBucketsRequest) bool {
body := in.GetPostBucketRequest()
retentionRules := *body.RetentionRules
return assert.NotNil(t, body) &&
assert.Equal(t, "123", body.OrgID) &&
assert.Equal(t, "my-bucket", body.Name) &&
assert.Nil(t, body.Description) &&
assert.Len(t, body.RetentionRules, 1) &&
assert.Equal(t, int64(86400), body.RetentionRules[0].EverySeconds) &&
assert.Nil(t, body.RetentionRules[0].ShardGroupDurationSeconds)
assert.Len(t, *body.RetentionRules, 1) &&
assert.Equal(t, int64(86400), retentionRules[0].EverySeconds) &&
assert.Nil(t, retentionRules[0].ShardGroupDurationSeconds)
})).
Return(api.Bucket{
Id: api.PtrString("456"),
@ -168,13 +170,14 @@ func TestBucketsCreate(t *testing.T) {
bucketsApi.EXPECT().
PostBucketsExecute(tmock.MatchedBy(func(in api.ApiPostBucketsRequest) bool {
body := in.GetPostBucketRequest()
retentionRules := *body.RetentionRules
return assert.NotNil(t, body) &&
assert.Equal(t, "123", body.OrgID) &&
assert.Equal(t, "my-bucket", body.Name) &&
assert.Equal(t, "my cool bucket", *body.Description) &&
assert.Len(t, body.RetentionRules, 1) &&
assert.Equal(t, int64(86400), body.RetentionRules[0].EverySeconds) &&
assert.Equal(t, int64(3600), *body.RetentionRules[0].ShardGroupDurationSeconds)
assert.Len(t, *body.RetentionRules, 1) &&
assert.Equal(t, int64(86400), retentionRules[0].EverySeconds) &&
assert.Equal(t, int64(3600), *retentionRules[0].ShardGroupDurationSeconds)
})).
Return(api.Bucket{
Id: api.PtrString("456"),
@ -210,13 +213,14 @@ func TestBucketsCreate(t *testing.T) {
bucketsApi.EXPECT().
PostBucketsExecute(tmock.MatchedBy(func(in api.ApiPostBucketsRequest) bool {
body := in.GetPostBucketRequest()
retentionRules := *body.RetentionRules
return assert.NotNil(t, body) &&
assert.Equal(t, "123", body.OrgID) &&
assert.Equal(t, "my-bucket", body.Name) &&
assert.Equal(t, "my cool bucket", *body.Description) &&
assert.Len(t, body.RetentionRules, 1) &&
assert.Equal(t, int64(86400), body.RetentionRules[0].EverySeconds) &&
assert.Equal(t, int64(3600), *body.RetentionRules[0].ShardGroupDurationSeconds)
assert.Len(t, *body.RetentionRules, 1) &&
assert.Equal(t, int64(86400), retentionRules[0].EverySeconds) &&
assert.Equal(t, int64(3600), *retentionRules[0].ShardGroupDurationSeconds)
})).
Return(api.Bucket{
Id: api.PtrString("456"),

View File

@ -11,7 +11,6 @@ import (
)
// ColumnsFormat is a type which defines the supported formats
//
type ColumnsFormat int
const (

View File

@ -22,6 +22,7 @@ type CreateParams struct {
RemoteID string
LocalBucketID string
RemoteBucketID string
RemoteBucketName string
MaxQueueSize int64
DropNonRetryableData bool
NoDropNonRetryableData bool
@ -29,6 +30,9 @@ type CreateParams struct {
}
func (c Client) Create(ctx context.Context, params *CreateParams) error {
if params.RemoteBucketID == "" && params.RemoteBucketName == "" {
return fmt.Errorf("please supply one of: remote-bucket-id, remote-bucket-name")
}
orgID, err := params.GetOrgID(ctx, c.ActiveConfig, c.OrganizationsApi)
if err != nil {
return err
@ -40,11 +44,16 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
OrgID: orgID,
RemoteID: params.RemoteID,
LocalBucketID: params.LocalBucketID,
RemoteBucketID: params.RemoteBucketID,
MaxQueueSizeBytes: params.MaxQueueSize,
MaxAgeSeconds: params.MaxAge,
}
if params.RemoteBucketID != "" {
body.RemoteBucketID = &params.RemoteBucketID
} else {
body.RemoteBucketName = &params.RemoteBucketName
}
// set optional params if specified
if params.Description != "" {
body.Description = &params.Description
@ -231,7 +240,7 @@ func (c Client) printReplication(opts printReplicationOpts) error {
return c.PrintJSON(v)
}
headers := []string{"ID", "Name", "Org ID", "Remote ID", "Local Bucket ID", "Remote Bucket ID",
headers := []string{"ID", "Name", "Org ID", "Remote ID", "Local Bucket ID", "Remote Bucket ID", "Remote Bucket Name",
"Current Queue Bytes", "Max Queue Bytes", "Latest Status Code", "Drop Non-Retryable Data"}
if opts.deleted {
headers = append(headers, "Deleted")
@ -243,13 +252,19 @@ func (c Client) printReplication(opts printReplicationOpts) error {
var rows []map[string]interface{}
for _, r := range opts.replications {
bucketID := r.GetRemoteBucketID()
if r.GetRemoteBucketName() != "" {
// This hides the default id that is required due to platform.ID implementation details
bucketID = ""
}
row := map[string]interface{}{
"ID": r.GetId(),
"Name": r.GetName(),
"Org ID": r.GetOrgID(),
"Remote ID": r.GetRemoteID(),
"Local Bucket ID": r.GetLocalBucketID(),
"Remote Bucket ID": r.GetRemoteBucketID(),
"Remote Bucket ID": bucketID,
"Remote Bucket Name": r.GetRemoteBucketName(),
"Current Queue Bytes": r.GetCurrentQueueSizeBytes(),
"Max Queue Bytes": r.GetMaxQueueSizeBytes(),
"Latest Status Code": r.GetLatestResponseCode(),

View File

@ -318,7 +318,8 @@ func (c Client) restoreBucketLegacy(ctx context.Context, bkt br.ManifestBucketEn
rps[i].ShardGroupDurationSeconds = &sgd
}
bucketReq := *api.NewPostBucketRequest(bkt.OrganizationID, bkt.BucketName, rps)
bucketReq := *api.NewPostBucketRequest(bkt.OrganizationID, bkt.BucketName)
bucketReq.RetentionRules = &rps
bucketReq.Description = bkt.Description
newBkt, err := c.PostBuckets(ctx).PostBucketRequest(bucketReq).Execute()