aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/storage.go
blob: 654ed85a8608c37527886768a465185c5e40622d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cli

import (
	"context"

	"tsne.dev/hopper/internal/bunny"
)

// storageAPI is the full storage surface the dry-run decorator delegates to.
// Its read side (List) must stay real even under --dry-run; its
// write side (Upload/Delete) is what the decorator stubs. The real
// *bunny.Client satisfies this, as does the recording fake used in tests.
type storageAPI interface {
	Upload(ctx context.Context, path string, body []byte) error
	List(ctx context.Context, dir string) *bunny.Iterator
	Delete(ctx context.Context, path string) error
	DeleteDir(ctx context.Context, path string) error
}

func newStorageAPI(endpoint, zone, accessKey string) storageAPI {
	var api storageAPI = bunny.NewAPI(endpoint, zone, accessKey)
	if dryRun {
		api = dryRunStorageAPI{api}
	}
	return api
}

type dryRunStorageAPI struct {
	upstream storageAPI
}

func (api dryRunStorageAPI) List(ctx context.Context, dir string) *bunny.Iterator {
	return api.upstream.List(ctx, dir)
}

func (api dryRunStorageAPI) Upload(ctx context.Context, path string, body []byte) error {
	return nil
}

func (api dryRunStorageAPI) Delete(ctx context.Context, path string) error {
	return nil
}

func (api dryRunStorageAPI) DeleteDir(ctx context.Context, path string) error {
	return nil
}