-
Notifications
You must be signed in to change notification settings - Fork 394
/
external.go
64 lines (53 loc) · 1.97 KB
/
external.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package ultest
import (
"context"
"storj.io/storj/cmd/uplink/ulext"
"storj.io/storj/cmd/uplink/ulfs"
"storj.io/uplink"
)
var accesses = map[string]string{
"TestAccessA": "12edqrJX1V243n5fWtUrwpMQXL8gKdY2wbyqRPSG3rsA1tzmZiQjtCyF896egifN2C2qdY6g5S1t6e8iDhMUon9Pb7HdecBFheAcvmN8652mqu8hRx5zcTUaRTWfFCKS2S6DHmTeqPUHJLEp6cJGXNHcdqegcKfeahVZGP4rTagHvFGEraXjYRJ3knAcWDGW6BxACqogEWez6r274JiUBfs4yRSbRNRqUEURd28CwDXMSHLRKKA7TEDKEdQ",
"TestAccessB": "1QiUjN497AySNH4ZX3wJCUZZNGKzpJwmZ1EcjKGgNR3Z9ADLawZNJbHXqm6VjH71nbWRRX6KfR9HHCr8sH3G9LA8e9qGuqWqkPPeskbD3Z12y4NuyxzwHYvcTSxa3Xk35Ts3ESGvP4785Rgeu5H8BF4kDriic6tRVUTPcAaYGCbHJPC2AfyPijLg4zZ627EuzeuWuo12mWGWiAZW3JJaVwD4657UJTGaUcuQqZxsjA1eTDkNFRfbv7zt9nW5si3E8FC6ZZFQ",
}
type external struct {
ulext.External
fs ulfs.Filesystem
project *uplink.Project
}
func newExternal(fs ulfs.Filesystem, project *uplink.Project) *external {
return &external{
fs: fs,
project: project,
}
}
func (ex *external) OpenFilesystem(ctx context.Context, access string, options ...ulext.Option) (ulfs.Filesystem, error) {
return ex.fs, nil
}
func (ex *external) OpenProject(ctx context.Context, access string, options ...ulext.Option) (*uplink.Project, error) {
return ex.project, nil
}
func (ex *external) OpenAccess(accessName string) (access *uplink.Access, err error) {
accessDefault, accesses, err := ex.GetAccessInfo(true)
if err != nil {
return nil, err
}
if accessName != "" {
accessDefault = accessName
}
if data, ok := accesses[accessDefault]; ok {
access, err = uplink.ParseAccess(data)
} else {
access, err = uplink.ParseAccess(accessDefault)
// TODO: if this errors then it's probably a name so don't report an error
// that says "it failed to parse"
}
if err != nil {
return nil, err
}
return access, nil
}
func (ex *external) GetAccessInfo(required bool) (string, map[string]string, error) {
return accesses["TestAccessA"], accesses, nil
}