Repository navigation
feat(b2): add a replication setup helper - #137
Open
ffumero2003 wants to merge 2 commits into
Open
ffumero2003 wants to merge 2 commits into
ffumero2003 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
blazer can set a raw replication configuration on a bucket (via
Bucket.Update) buthas no helper that provisions the correctly-scoped source/destination keys and wires
up the two-sided setup in one call. Every peer tool ships one (TypeScript
addReplicationRule, PythonReplicationSetupHelper, CLIReplicationSetup).What it enables
One-call, one-direction replication setup between two buckets: mint correctly scoped
source/destination keys, wire the key mapping and the rule, and leave existing
rules/mappings intact.
Changes
b2/replication.go— a lean, idiomatic helper (not a stateful wizard), in packageb2:SetupReplication(ctx, src, dst *Bucket, opts ...ReplicationOption) error— mintsa destination key (write capabilities) and, for a source with no replication yet, a
source key (read capabilities); reuses the source bucket's existing
SourceApplicationKeyIDwhen it already replicates elsewhere (that key isbucket-wide — replacing it would break existing destinations); merges the key
mapping into the destination and appends the rule to the source (auto priority and
name, honoring prefix / include-existing-files options) without clobbering existing
rules or mappings.
ReplicationStatus(ctx, src *Bucket) ([]ReplicationRuleStatus, error)— aconfig-level reader of the configured rules (no per-file scan).
WithRuleName,WithRulePriority,WithFileNamePrefix,WithIncludeExistingFiles.b2/replication_setup_test.go— unit tests for priority computation,merge-don't-clobber, the two-bucket update payloads, and source-key reuse.
.sdkharness/tests/conformance/bucket.replication_helper(+tests.tsvrow,contract-count bump) — the repo-owned conformance scenario.
Design notes
Built entirely on the existing
mainsurface (CreateKey+Bucket.Update+Attrs); no dependency on the create-time replication-config change. The helper is asingle function by design — blazer stays a primitive-exposing library, and orchestration
beyond this (per-file monitoring, key reuse/cleanup, cross-profile setup, pause/unpause)
is intentionally left out of v1.
Verification
go build ./...— clean.go test ./b2/... -race -count=1— green (incl. the source-key-reuse regression test).golangci-lint run --new-from-rev=origin/main ./...— 0 issues.bucket.replication_helper@simulator — PASS (two-sided setup + configreadback; re-run does not duplicate).
case proving the source key is reused (not replaced) with auto-incrementing rule
priority, all green.
Closes #136