-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatastore_s3.go
78 lines (66 loc) · 1.76 KB
/
datastore_s3.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
package cc
import (
"errors"
"io"
"log"
filestore "github.com/usace/filesapi"
)
const (
S3ROOT = "root"
)
type S3DataStore struct {
fs filestore.FileStore
root string
}
/*
func (s3ds *S3DataStore) Copy(destStore FileDataStore, srcpath string, destpath string) error {
fsgoi := filestore.GetObjectInput{
Path: filestore.PathConfig{Path: srcpath},
}
reader, err := s3ds.fs.GetObject(fsgoi)
if err != nil {
return err
}
return destStore.Put(reader, destpath)
}
*/
func (s3ds *S3DataStore) Get(path string, datapath string) (io.ReadCloser, error) {
log.Println("S3 Datastore does not use the datapath. It will be ignored")
fsgoi := filestore.GetObjectInput{
Path: filestore.PathConfig{Path: s3ds.root + "/" + path},
}
return s3ds.fs.GetObject(fsgoi)
}
func (s3ds *S3DataStore) Put(reader io.Reader, path string, destDataPath string) (int, error) {
poi := filestore.PutObjectInput{
Source: filestore.ObjectSource{
Reader: reader,
},
Dest: filestore.PathConfig{Path: s3ds.root + "/" + path},
}
//@TODO fix the bytes transferred int
_, err := s3ds.fs.PutObject(poi)
return -1, err
}
func (s3ds *S3DataStore) Delete(path string) error {
return s3ds.Delete(s3ds.root + "/" + path)
}
func (s3ds *S3DataStore) GetSession() any {
return s3ds.fs
}
func (s3ds *S3DataStore) Connect(ds DataStore) (any, error) {
awsconfig := BuildS3Config(ds.DsProfile)
fs, err := filestore.NewFileStore(awsconfig)
if err != nil {
return nil, err
}
if root, ok := ds.Parameters[S3ROOT]; ok {
if rootstr, ok := root.(string); ok {
return &S3DataStore{fs, rootstr}, nil
} else {
return nil, errors.New("Invalid S3 Root parameter. Parameter must be a string.")
}
} else {
return nil, errors.New("Missing S3 Root parameter. Cannot create the store.")
}
}