mirror of
https://github.com/restic/restic.git
synced 2026-11-21 21:12:42 +00:00
Update github.com/kurin/blazer to 0.5.1
This adds support for B2 application keys.
This commit is contained in:
1 parent
57873502f8
commit
2437f11af7
10 files changed
+276
-24
No files matched your search
+2
@@ -154,6 +154,7 @@ type beKeyInterface interface {
|
||||
name() string
|
||||
expires() time.Time
|
||||
secret() string
|
||||
id() string
|
||||
}
|
||||
|
||||
type beKey struct {
|
||||
@@ -711,6 +712,7 @@ func (b *beKey) caps() []string { return b.k.caps() }
|
||||
func (b *beKey) name() string { return b.k.name() }
|
||||
func (b *beKey) expires() time.Time { return b.k.expires() }
|
||||
func (b *beKey) secret() string { return b.k.secret() }
|
||||
func (b *beKey) id() string { return b.k.id() }
|
||||
|
||||
func jitter(d time.Duration) time.Duration {
|
||||
f := float64(d)
|
||||
|
||||
+2
@@ -105,6 +105,7 @@ type b2KeyInterface interface {
|
||||
name() string
|
||||
expires() time.Time
|
||||
secret() string
|
||||
id() string
|
||||
}
|
||||
|
||||
type b2Root struct {
|
||||
@@ -508,3 +509,4 @@ func (b *b2Key) caps() []string { return b.b.Capabilities }
|
||||
func (b *b2Key) name() string { return b.b.Name }
|
||||
func (b *b2Key) expires() time.Time { return b.b.Expires }
|
||||
func (b *b2Key) secret() string { return b.b.Secret }
|
||||
func (b *b2Key) id() string { return b.b.ID }
|
||||
+63
-3
@@ -1014,6 +1014,68 @@ func TestVerifyReader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestListBucketsWithKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bucket, done := startLiveTest(ctx, t)
|
||||
defer done()
|
||||
|
||||
key, err := bucket.CreateKey(ctx, "testKey", Capabilities("listBuckets"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
client, err := NewClient(ctx, key.ID(), key.Secret())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := client.Bucket(ctx, bucket.Name()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListBucketContentsWithKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bucket, done := startLiveTest(ctx, t)
|
||||
defer done()
|
||||
|
||||
for _, path := range []string{"foo/bar", "foo/baz", "foo", "bar", "baz"} {
|
||||
if _, _, err := writeFile(ctx, bucket, path, 1, 1e8); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
key, err := bucket.CreateKey(ctx, "testKey", Capabilities("listBuckets", "listFiles"), Prefix("foo/"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
client, err := NewClient(ctx, key.ID(), key.Secret())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
obucket, err := client.Bucket(ctx, bucket.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
iter := obucket.List(ctx)
|
||||
var got []string
|
||||
for iter.Next() {
|
||||
got = append(got, iter.Object().Name())
|
||||
}
|
||||
if iter.Err() != nil {
|
||||
t.Fatal(iter.Err())
|
||||
}
|
||||
want := []string{"foo/bar", "foo/baz"}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("error listing objects with restricted key: got %v, want %v", got, want)
|
||||
}
|
||||
iter2 := obucket.List(ctx, ListHidden())
|
||||
for iter2.Next() {
|
||||
}
|
||||
if iter2.Err() != nil {
|
||||
t.Error(iter2.Err())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateDeleteKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
bucket, done := startLiveTest(ctx, t)
|
||||
@@ -1049,9 +1111,7 @@ func TestCreateDeleteKey(t *testing.T) {
|
||||
|
||||
for _, e := range table {
|
||||
var opts []KeyOption
|
||||
for _, cap := range e.cap {
|
||||
opts = append(opts, Capability(cap))
|
||||
}
|
||||
opts = append(opts, Capabilities(e.cap...))
|
||||
if e.d != 0 {
|
||||
opts = append(opts, Lifetime(e.d))
|
||||
}
|
||||
|
||||
+7
-3
@@ -47,6 +47,10 @@ func (k *Key) Delete(ctx context.Context) error { return k.k.del(ctx) }
|
||||
// operations.
|
||||
func (k *Key) Secret() string { return k.k.secret() }
|
||||
|
||||
// ID returns the application key ID. This, plus the secret, is necessary to
|
||||
// authenticate to B2.
|
||||
func (k *Key) ID() string { return k.k.id() }
|
||||
|
||||
type keyOptions struct {
|
||||
caps []string
|
||||
prefix string
|
||||
@@ -69,10 +73,10 @@ func Deadline(t time.Time) KeyOption {
|
||||
return Lifetime(d)
|
||||
}
|
||||
|
||||
// Capability requests a key with the given capability.
|
||||
func Capability(cap string) KeyOption {
|
||||
// Capabilities requests a key with the given capability.
|
||||
func Capabilities(caps ...string) KeyOption {
|
||||
return func(k *keyOptions) {
|
||||
k.caps = append(k.caps, cap)
|
||||
k.caps = append(k.caps, caps...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user