-
Notifications
You must be signed in to change notification settings - Fork 35
/
helper.go
83 lines (76 loc) · 2.52 KB
/
helper.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package storage
import (
"github.com/viant/afs"
"github.com/viant/afs/option"
"github.com/viant/afs/storage"
"github.com/viant/endly"
"github.com/viant/endly/model/location"
"github.com/viant/endly/service/system/storage/copy"
)
func getSourceWithOptions(context *endly.Context, rule *copy.Rule) (*location.Resource, *option.Source, error) {
source, err := context.ExpandResource(rule.Source)
if err != nil {
return nil, nil, err
}
ruleOptions, err := rule.SourceStorageOpts(context)
if err != nil {
return nil, nil, err
}
sourceOptions, err := StorageOptions(context, source, ruleOptions...)
if err != nil {
return nil, nil, err
}
return source, option.NewSource(sourceOptions...), nil
}
func getDestWithOptions(context *endly.Context, rule *copy.Rule, modifier option.Modifier) (*location.Resource, *option.Dest, error) {
ruleOptions, err := rule.DestStorageOpts(context, modifier)
if err != nil {
return nil, nil, err
}
dest, err := context.ExpandResource(rule.Dest)
if err != nil {
return nil, nil, err
}
sourceOptions, err := StorageOptions(context, dest, ruleOptions...)
if err != nil {
return nil, nil, err
}
return dest, option.NewDest(sourceOptions...), nil
}
// GetResourceWithOptions returns resource with afs storage option
func GetResourceWithOptions(context *endly.Context, resource *location.Resource, options ...storage.Option) (*location.Resource, []storage.Option, error) {
resource, err := context.ExpandResource(resource)
if err != nil {
return nil, nil, err
}
sourceOptions, err := StorageOptions(context, resource)
if len(options) > 0 {
sourceOptions = append(sourceOptions, options...)
}
return resource, sourceOptions, err
}
// UseMemoryService sets flag on context to always use memory service (testing only)
func UseMemoryService(context *endly.Context) afs.Service {
state := context.State()
state.Put(useMemoryService, true)
return fsFaker
}
// IsCompressable returns true if resource can be compress via shell command.
func IsCompressable(protScheme string) bool {
return protScheme == "" || protScheme == "scp" || protScheme == "file" || protScheme == "ssh"
}
// Copy transfers data for provided transfer definition.
func Copy(context *endly.Context, transfers ...*copy.Rule) (interface{}, error) {
if transfers == nil {
return nil, nil
}
transferService, err := context.Service(ServiceID)
if err != nil {
return nil, err
}
response := transferService.Run(context, &CopyRequest{Transfers: transfers})
if response.Err != nil {
return nil, response.Err
}
return nil, nil
}