Skip to content

Commit

Permalink
fix(s3): qa driver
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Aug 17, 2024
1 parent 6d6d41f commit 83650e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/authorized_keys/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
logger := slog.Default()
host := pobj.GetEnv("SSH_HOST", "0.0.0.0")
port := pobj.GetEnv("SSH_PORT", "2222")
keyPath := pobj.GetEnv("SSH_AUTHORIZED_KEYS", "ssh_data/authorized_keys")
keyPath := pobj.GetEnv("SSH_AUTHORIZED_KEYS", "./ssh_data/authorized_keys")

st, err := pobj.EnvDriverDetector(logger)
if err != nil {
Expand Down
21 changes: 17 additions & 4 deletions storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,24 @@ func (s *StorageS3) ListObjects(bucket Bucket, dir string, recursive bool) ([]os
return fileList, err
}

for _, pref := range page.CommonPrefixes {
modTime := time.Time{}
fname := strings.TrimSuffix(strings.TrimPrefix(*pref.Prefix, prefix), "/")
info := &utils.VirtualFile{
FName: fname,
FIsDir: true,
FSize: 0,
FModTime: modTime,
}
fileList = append(fileList, info)
}

for _, obj := range page.Contents {
isDir := strings.HasSuffix(*obj.Key, string(os.PathSeparator))
modTime := obj.LastModified
fname := strings.TrimSuffix(strings.TrimPrefix(*obj.Key, prefix), "/")
info := &utils.VirtualFile{
FName: strings.TrimSuffix(strings.TrimPrefix(*obj.Key, prefix), "/"),
FIsDir: isDir,
FName: fname,
FIsDir: false,
FSize: *obj.Size,
FModTime: *modTime,
}
Expand Down Expand Up @@ -223,10 +235,11 @@ func (s *StorageS3) GetObject(bucket Bucket, fpath string) (utils.ReaderAtCloser
}

func (s *StorageS3) PutObject(bucket Bucket, fpath string, contents io.Reader, entry *utils.FileEntry) (string, int64, error) {
key := strings.TrimPrefix(fpath, "/")
uploader := manager.NewUploader(s.Client)
info, err := uploader.Upload(context.TODO(), &s3.PutObjectInput{
Bucket: aws.String(bucket.Name),
Key: aws.String(fpath),
Key: aws.String(key),
Body: contents,
})
if err != nil {
Expand Down

0 comments on commit 83650e2

Please sign in to comment.