diff --git a/services/dropbox/doc.go b/services/dropbox/doc.go index 3d7114ed9..00e555f32 100644 --- a/services/dropbox/doc.go +++ b/services/dropbox/doc.go @@ -3,4 +3,4 @@ Package dropbox provides support for Dropbox (https://www.dropbox.com/). */ package dropbox -//go:generate go run -tags tools go.beyondstorage.io/v5/cmd/definitions service.toml +//go:generate go run ./internal/cmd diff --git a/services/dropbox/generated.go b/services/dropbox/generated.go index 1972dedf0..b57198807 100644 --- a/services/dropbox/generated.go +++ b/services/dropbox/generated.go @@ -3,24 +3,22 @@ package dropbox import ( "context" + "errors" "io" "net/http" "strings" "time" - . "go.beyondstorage.io/v5/pairs" - "go.beyondstorage.io/v5/pkg/httpclient" "go.beyondstorage.io/v5/services" - . "go.beyondstorage.io/v5/types" + "go.beyondstorage.io/v5/types" ) var ( - _ Storager + _ types.Storager _ services.ServiceError - _ httpclient.Options + _ strings.Reader _ time.Duration _ http.Request - _ Error ) // Type is the type for dropbox @@ -35,7 +33,7 @@ type ObjectSystemMetadata struct { // // - This function should not be called by service implementer. // - The returning ObjectServiceMetadata is read only and should not be modified. -func GetObjectSystemMetadata(o *Object) ObjectSystemMetadata { +func GetObjectSystemMetadata(o *types.Object) ObjectSystemMetadata { sm, ok := o.GetSystemMetadata() if ok { return sm.(ObjectSystemMetadata) @@ -46,20 +44,19 @@ func GetObjectSystemMetadata(o *Object) ObjectSystemMetadata { // setObjectSystemMetadata will set ObjectSystemMetadata into Object. // // - This function should only be called once, please make sure all data has been written before set. -func setObjectSystemMetadata(o *Object, sm ObjectSystemMetadata) { +func setObjectSystemMetadata(o *types.Object, sm ObjectSystemMetadata) { o.SetSystemMetadata(sm) } // StorageSystemMetadata stores system metadata for object. type StorageSystemMetadata struct { - UploadSessionID string } // GetStorageSystemMetadata will get StorageSystemMetadata from Storage. // // - This function should not be called by service implementer. // - The returning StorageServiceMetadata is read only and should not be modified. -func GetStorageSystemMetadata(s *StorageMeta) StorageSystemMetadata { +func GetStorageSystemMetadata(s *types.StorageMeta) StorageSystemMetadata { sm, ok := s.GetSystemMetadata() if ok { return sm.(StorageSystemMetadata) @@ -70,143 +67,253 @@ func GetStorageSystemMetadata(s *StorageMeta) StorageSystemMetadata { // setStorageSystemMetadata will set StorageSystemMetadata into Storage. // // - This function should only be called once, please make sure all data has been written before set. -func setStorageSystemMetadata(s *StorageMeta, sm StorageSystemMetadata) { +func setStorageSystemMetadata(s *types.StorageMeta, sm StorageSystemMetadata) { s.SetSystemMetadata(sm) } -// WithDefaultStoragePairs will apply default_storage_pairs value to Options. -func WithDefaultStoragePairs(v DefaultStoragePairs) Pair { - return Pair{Key: "default_storage_pairs", Value: v} +type Factory struct { + Credential string + WorkDir string } -// WithStorageFeatures will apply storage_features value to Options. -func WithStorageFeatures(v StorageFeatures) Pair { - return Pair{Key: "storage_features", Value: v} -} +func (f *Factory) FromString(conn string) (err error) { + slash := strings.IndexByte(conn, '/') + question := strings.IndexByte(conn, '?') -var pairMap = map[string]string{"content_md5": "string", "content_type": "string", "context": "context.Context", "continuation_token": "string", "credential": "string", "default_content_type": "string", "default_io_callback": "func([]byte)", "default_storage_pairs": "DefaultStoragePairs", "endpoint": "string", "expire": "time.Duration", "http_client_options": "*httpclient.Options", "interceptor": "Interceptor", "io_callback": "func([]byte)", "list_mode": "ListMode", "location": "string", "multipart_id": "string", "name": "string", "object_mode": "ObjectMode", "offset": "int64", "size": "int64", "storage_features": "StorageFeatures", "work_dir": "string"} -var ( - _ Appender = &Storage{} - _ Direr = &Storage{} - _ Storager = &Storage{} -) + var partService, partStorage, partParams string -type StorageFeatures struct { + if question != -1 { + if len(conn) > question { + partParams = conn[question+1:] + } + conn = conn[:question] + } + + if slash != -1 { + partService = conn[:slash] + partStorage = conn[slash:] + } else { + partService = conn + } + + if partService != "" { + f.Credential = partService + } + if partStorage != "" { + f.WorkDir = partStorage + } + if partParams != "" { + xs := strings.Split(partParams, "&") + for _, v := range xs { + var key, value string + vs := strings.SplitN(v, "=", 2) + key = vs[0] + if len(vs) > 1 { + value = vs[1] + } + switch key { + case "credential": + f.Credential = value + case "work_dir": + f.WorkDir = value + } + } + } + return nil +} +func (f *Factory) WithPairs(ps ...types.Pair) (err error) { + for _, v := range ps { + switch v.Key { + case "credential": + f.Credential = v.Value.(string) + case "work_dir": + f.WorkDir = v.Value.(string) + } + } + return nil +} +func (f *Factory) FromMap(m map[string]interface{}) (err error) { + return errors.New("FromMap not implemented") +} +func (f *Factory) NewServicer() (srv types.Servicer, err error) { + return f.newService() +} +func (f *Factory) NewStorager() (sto types.Storager, err error) { + return f.newStorage() +} +func (f *Factory) serviceFeatures() (s types.ServiceFeatures) { + return +} +func (f *Factory) storageFeatures() (s types.StorageFeatures) { + s.CommitAppend = true + s.Create = true + s.CreateAppend = true + s.CreateDir = true + s.Delete = true + s.List = true + s.Metadata = true + s.Read = true + s.Stat = true + s.Write = true + s.WriteAppend = true + s.WriteEmptyObject = true + return } -// pairStorageNew is the parsed struct -type pairStorageNew struct { - pairs []Pair +var _ types.Servicer = &Service{} - // Required pairs - HasCredential bool - Credential string - // Optional pairs - HasDefaultContentType bool - DefaultContentType string - HasDefaultIoCallback bool - DefaultIoCallback func([]byte) - HasDefaultStoragePairs bool - DefaultStoragePairs DefaultStoragePairs - HasHTTPClientOptions bool - HTTPClientOptions *httpclient.Options - HasStorageFeatures bool - StorageFeatures StorageFeatures - HasWorkDir bool - WorkDir string - // Enable features +// Deprecated: Use types.ServiceFeatures instead. +type ServiceFeatures = types.ServiceFeatures + +// Deprecated: Use types.DefaultServicePairs instead. +type DefaultServicePairs = types.DefaultServicePairs + +func (s *Service) Features() types.ServiceFeatures { + return s.features } -// parsePairStorageNew will parse Pair slice into *pairStorageNew -func parsePairStorageNew(opts []Pair) (pairStorageNew, error) { +type pairServiceCreate struct { + pairs []types.Pair +} + +func (s *Service) parsePairServiceCreate(opts []types.Pair) (pairServiceCreate, error) { result := - pairStorageNew{pairs: opts} + pairServiceCreate{pairs: opts} for _, v := range opts { switch v.Key { - case "credential": - if result.HasCredential { - continue - } - result.HasCredential = true - result.Credential = v.Value.(string) - case "default_content_type": - if result.HasDefaultContentType { - continue - } - result.HasDefaultContentType = true - result.DefaultContentType = v.Value.(string) - case "default_io_callback": - if result.HasDefaultIoCallback { - continue - } - result.HasDefaultIoCallback = true - result.DefaultIoCallback = v.Value.(func([]byte)) - case "default_storage_pairs": - if result.HasDefaultStoragePairs { - continue - } - result.HasDefaultStoragePairs = true - result.DefaultStoragePairs = v.Value.(DefaultStoragePairs) - case "http_client_options": - if result.HasHTTPClientOptions { - continue - } - result.HasHTTPClientOptions = true - result.HTTPClientOptions = v.Value.(*httpclient.Options) - case "storage_features": - if result.HasStorageFeatures { - continue - } - result.HasStorageFeatures = true - result.StorageFeatures = v.Value.(StorageFeatures) - case "work_dir": - if result.HasWorkDir { - continue - } - result.HasWorkDir = true - result.WorkDir = v.Value.(string) + default: + return pairServiceCreate{}, services.PairUnsupportedError{Pair: v} } } - // Enable features + return result, nil +} +func (s *Service) Create(name string, pairs ...types.Pair) (store types.Storager, err error) { + err = types.NewOperationNotImplementedError("create") + return +} +func (s *Service) CreateWithContext(ctx context.Context, name string, pairs ...types.Pair) (store types.Storager, err error) { + err = types.NewOperationNotImplementedError("create") + return +} + +type pairServiceDelete struct { + pairs []types.Pair +} - // Default pairs - if result.HasDefaultContentType { - result.HasDefaultStoragePairs = true - result.DefaultStoragePairs.Write = append(result.DefaultStoragePairs.Write, WithContentType(result.DefaultContentType)) +func (s *Service) parsePairServiceDelete(opts []types.Pair) (pairServiceDelete, error) { + result := + pairServiceDelete{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairServiceDelete{}, services.PairUnsupportedError{Pair: v} + } } - if result.HasDefaultIoCallback { - result.HasDefaultStoragePairs = true - result.DefaultStoragePairs.Read = append(result.DefaultStoragePairs.Read, WithIoCallback(result.DefaultIoCallback)) - result.DefaultStoragePairs.Write = append(result.DefaultStoragePairs.Write, WithIoCallback(result.DefaultIoCallback)) + return result, nil +} +func (s *Service) Delete(name string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("delete") + return +} +func (s *Service) DeleteWithContext(ctx context.Context, name string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("delete") + return +} + +type pairServiceGet struct { + pairs []types.Pair +} + +func (s *Service) parsePairServiceGet(opts []types.Pair) (pairServiceGet, error) { + result := + pairServiceGet{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairServiceGet{}, services.PairUnsupportedError{Pair: v} + } } - if !result.HasCredential { - return pairStorageNew{}, services.PairRequiredError{Keys: []string{"credential"}} + return result, nil +} +func (s *Service) Get(name string, pairs ...types.Pair) (store types.Storager, err error) { + err = types.NewOperationNotImplementedError("get") + return +} +func (s *Service) GetWithContext(ctx context.Context, name string, pairs ...types.Pair) (store types.Storager, err error) { + err = types.NewOperationNotImplementedError("get") + return +} + +type pairServiceList struct { + pairs []types.Pair +} + +func (s *Service) parsePairServiceList(opts []types.Pair) (pairServiceList, error) { + result := + pairServiceList{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairServiceList{}, services.PairUnsupportedError{Pair: v} + } } return result, nil } +func (s *Service) List(pairs ...types.Pair) (sti *types.StoragerIterator, err error) { + err = types.NewOperationNotImplementedError("list") + return +} +func (s *Service) ListWithContext(ctx context.Context, pairs ...types.Pair) (sti *types.StoragerIterator, err error) { + err = types.NewOperationNotImplementedError("list") + return +} + +var _ types.Storager = &Storage{} + +// Deprecated: Use types.StorageFeatures instead. +type StorageFeatures = types.StorageFeatures + +// Deprecated: Use types.DefaultStoragePairs instead. +type DefaultStoragePairs = types.DefaultStoragePairs + +func (s *Storage) Features() types.StorageFeatures { + return s.features +} -// DefaultStoragePairs is default pairs for specific action -type DefaultStoragePairs struct { - CommitAppend []Pair - Create []Pair - CreateAppend []Pair - CreateDir []Pair - Delete []Pair - List []Pair - Metadata []Pair - Read []Pair - Stat []Pair - Write []Pair - WriteAppend []Pair +type pairStorageCombineBlock struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageCombineBlock(opts []types.Pair) (pairStorageCombineBlock, error) { + result := + pairStorageCombineBlock{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCombineBlock{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) CombineBlock(o *types.Object, bids []string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("combine_block") + return } +func (s *Storage) CombineBlockWithContext(ctx context.Context, o *types.Object, bids []string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("combine_block") + return +} + type pairStorageCommitAppend struct { - pairs []Pair - // Required pairs - // Optional pairs + pairs []types.Pair } -func (s *Storage) parsePairStorageCommitAppend(opts []Pair) (pairStorageCommitAppend, error) { +func (s *Storage) parsePairStorageCommitAppend(opts []types.Pair) (pairStorageCommitAppend, error) { result := pairStorageCommitAppend{pairs: opts} @@ -216,19 +323,84 @@ func (s *Storage) parsePairStorageCommitAppend(opts []Pair) (pairStorageCommitAp return pairStorageCommitAppend{}, services.PairUnsupportedError{Pair: v} } } + return result, nil +} +func (s *Storage) CommitAppend(o *types.Object, pairs ...types.Pair) (err error) { + ctx := context.Background() + return s.CommitAppendWithContext(ctx, o, pairs...) +} +func (s *Storage) CommitAppendWithContext(ctx context.Context, o *types.Object, pairs ...types.Pair) (err error) { + defer func() { + err = + s.formatError("commit_append", err) + }() + pairs = append(pairs, s.defaultPairs.CommitAppend...) + var opt pairStorageCommitAppend + + opt, err = s.parsePairStorageCommitAppend(pairs) + if err != nil { + return + } + return s.commitAppend(ctx, o, opt) +} + +type pairStorageCompleteMultipart struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageCompleteMultipart(opts []types.Pair) (pairStorageCompleteMultipart, error) { + result := + pairStorageCompleteMultipart{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCompleteMultipart{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) CompleteMultipart(o *types.Object, parts []*types.Part, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("complete_multipart") + return +} +func (s *Storage) CompleteMultipartWithContext(ctx context.Context, o *types.Object, parts []*types.Part, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("complete_multipart") + return +} + +type pairStorageCopy struct { + pairs []types.Pair +} +func (s *Storage) parsePairStorageCopy(opts []types.Pair) (pairStorageCopy, error) { + result := + pairStorageCopy{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCopy{}, services.PairUnsupportedError{Pair: v} + } + } return result, nil } +func (s *Storage) Copy(src string, dst string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("copy") + return +} +func (s *Storage) CopyWithContext(ctx context.Context, src string, dst string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("copy") + return +} type pairStorageCreate struct { - pairs []Pair - // Required pairs - // Optional pairs + pairs []types.Pair HasObjectMode bool - ObjectMode ObjectMode + ObjectMode types.ObjectMode } -func (s *Storage) parsePairStorageCreate(opts []Pair) (pairStorageCreate, error) { +func (s *Storage) parsePairStorageCreate(opts []types.Pair) (pairStorageCreate, error) { result := pairStorageCreate{pairs: opts} @@ -239,135 +411,580 @@ func (s *Storage) parsePairStorageCreate(opts []Pair) (pairStorageCreate, error) continue } result.HasObjectMode = true - result.ObjectMode = v.Value.(ObjectMode) + result.ObjectMode = v.Value.(types.ObjectMode) default: return pairStorageCreate{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) Create(path string, pairs ...types.Pair) (o *types.Object) { + pairs = append(pairs, s.defaultPairs.Create...) + var opt pairStorageCreate + + // Ignore error while handling local functions. + opt, _ = s.parsePairStorageCreate(pairs) + return s.create(path, opt) +} + +type pairStorageCreateAppend struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageCreateAppend(opts []types.Pair) (pairStorageCreateAppend, error) { + result := + pairStorageCreateAppend{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCreateAppend{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) CreateAppend(path string, pairs ...types.Pair) (o *types.Object, err error) { + ctx := context.Background() + return s.CreateAppendWithContext(ctx, path, pairs...) +} +func (s *Storage) CreateAppendWithContext(ctx context.Context, path string, pairs ...types.Pair) (o *types.Object, err error) { + defer func() { + err = + s.formatError("create_append", err, path) + }() + pairs = append(pairs, s.defaultPairs.CreateAppend...) + var opt pairStorageCreateAppend + + opt, err = s.parsePairStorageCreateAppend(pairs) + if err != nil { + return + } + return s.createAppend(ctx, strings.ReplaceAll(path, "\\", "/"), opt) +} + +type pairStorageCreateBlock struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageCreateBlock(opts []types.Pair) (pairStorageCreateBlock, error) { + result := + pairStorageCreateBlock{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCreateBlock{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) CreateBlock(path string, pairs ...types.Pair) (o *types.Object, err error) { + err = types.NewOperationNotImplementedError("create_block") + return +} +func (s *Storage) CreateBlockWithContext(ctx context.Context, path string, pairs ...types.Pair) (o *types.Object, err error) { + err = types.NewOperationNotImplementedError("create_block") + return +} + +type pairStorageCreateDir struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageCreateDir(opts []types.Pair) (pairStorageCreateDir, error) { + result := + pairStorageCreateDir{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCreateDir{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) CreateDir(path string, pairs ...types.Pair) (o *types.Object, err error) { + ctx := context.Background() + return s.CreateDirWithContext(ctx, path, pairs...) +} +func (s *Storage) CreateDirWithContext(ctx context.Context, path string, pairs ...types.Pair) (o *types.Object, err error) { + defer func() { + err = + s.formatError("create_dir", err, path) + }() + pairs = append(pairs, s.defaultPairs.CreateDir...) + var opt pairStorageCreateDir + + opt, err = s.parsePairStorageCreateDir(pairs) + if err != nil { + return + } + return s.createDir(ctx, strings.ReplaceAll(path, "\\", "/"), opt) +} + +type pairStorageCreateLink struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageCreateLink(opts []types.Pair) (pairStorageCreateLink, error) { + result := + pairStorageCreateLink{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCreateLink{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) CreateLink(path string, target string, pairs ...types.Pair) (o *types.Object, err error) { + err = types.NewOperationNotImplementedError("create_link") + return +} +func (s *Storage) CreateLinkWithContext(ctx context.Context, path string, target string, pairs ...types.Pair) (o *types.Object, err error) { + err = types.NewOperationNotImplementedError("create_link") + return +} + +type pairStorageCreateMultipart struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageCreateMultipart(opts []types.Pair) (pairStorageCreateMultipart, error) { + result := + pairStorageCreateMultipart{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCreateMultipart{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) CreateMultipart(path string, pairs ...types.Pair) (o *types.Object, err error) { + err = types.NewOperationNotImplementedError("create_multipart") + return +} +func (s *Storage) CreateMultipartWithContext(ctx context.Context, path string, pairs ...types.Pair) (o *types.Object, err error) { + err = types.NewOperationNotImplementedError("create_multipart") + return +} + +type pairStorageCreatePage struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageCreatePage(opts []types.Pair) (pairStorageCreatePage, error) { + result := + pairStorageCreatePage{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageCreatePage{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) CreatePage(path string, pairs ...types.Pair) (o *types.Object, err error) { + err = types.NewOperationNotImplementedError("create_page") + return +} +func (s *Storage) CreatePageWithContext(ctx context.Context, path string, pairs ...types.Pair) (o *types.Object, err error) { + err = types.NewOperationNotImplementedError("create_page") + return +} + +type pairStorageDelete struct { + pairs []types.Pair + HasObjectMode bool + ObjectMode types.ObjectMode +} + +func (s *Storage) parsePairStorageDelete(opts []types.Pair) (pairStorageDelete, error) { + result := + pairStorageDelete{pairs: opts} + + for _, v := range opts { + switch v.Key { + case "object_mode": + if result.HasObjectMode { + continue + } + result.HasObjectMode = true + result.ObjectMode = v.Value.(types.ObjectMode) + default: + return pairStorageDelete{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) Delete(path string, pairs ...types.Pair) (err error) { + ctx := context.Background() + return s.DeleteWithContext(ctx, path, pairs...) +} +func (s *Storage) DeleteWithContext(ctx context.Context, path string, pairs ...types.Pair) (err error) { + defer func() { + err = + s.formatError("delete", err, path) + }() + pairs = append(pairs, s.defaultPairs.Delete...) + var opt pairStorageDelete + + opt, err = s.parsePairStorageDelete(pairs) + if err != nil { + return + } + return s.delete(ctx, strings.ReplaceAll(path, "\\", "/"), opt) +} + +type pairStorageFetch struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageFetch(opts []types.Pair) (pairStorageFetch, error) { + result := + pairStorageFetch{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageFetch{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) Fetch(path string, url string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("fetch") + return +} +func (s *Storage) FetchWithContext(ctx context.Context, path string, url string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("fetch") + return +} + +type pairStorageList struct { + pairs []types.Pair + HasListMode bool + ListMode types.ListMode +} + +func (s *Storage) parsePairStorageList(opts []types.Pair) (pairStorageList, error) { + result := + pairStorageList{pairs: opts} + + for _, v := range opts { + switch v.Key { + case "list_mode": + if result.HasListMode { + continue + } + result.HasListMode = true + result.ListMode = v.Value.(types.ListMode) + default: + return pairStorageList{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) List(path string, pairs ...types.Pair) (oi *types.ObjectIterator, err error) { + ctx := context.Background() + return s.ListWithContext(ctx, path, pairs...) +} +func (s *Storage) ListWithContext(ctx context.Context, path string, pairs ...types.Pair) (oi *types.ObjectIterator, err error) { + defer func() { + err = + s.formatError("list", err, path) + }() + pairs = append(pairs, s.defaultPairs.List...) + var opt pairStorageList + + opt, err = s.parsePairStorageList(pairs) + if err != nil { + return + } + return s.list(ctx, strings.ReplaceAll(path, "\\", "/"), opt) +} + +type pairStorageListBlock struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageListBlock(opts []types.Pair) (pairStorageListBlock, error) { + result := + pairStorageListBlock{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageListBlock{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) ListBlock(o *types.Object, pairs ...types.Pair) (bi *types.BlockIterator, err error) { + err = types.NewOperationNotImplementedError("list_block") + return +} +func (s *Storage) ListBlockWithContext(ctx context.Context, o *types.Object, pairs ...types.Pair) (bi *types.BlockIterator, err error) { + err = types.NewOperationNotImplementedError("list_block") + return +} + +type pairStorageListMultipart struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageListMultipart(opts []types.Pair) (pairStorageListMultipart, error) { + result := + pairStorageListMultipart{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageListMultipart{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) ListMultipart(o *types.Object, pairs ...types.Pair) (pi *types.PartIterator, err error) { + err = types.NewOperationNotImplementedError("list_multipart") + return +} +func (s *Storage) ListMultipartWithContext(ctx context.Context, o *types.Object, pairs ...types.Pair) (pi *types.PartIterator, err error) { + err = types.NewOperationNotImplementedError("list_multipart") + return +} + +type pairStorageMetadata struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageMetadata(opts []types.Pair) (pairStorageMetadata, error) { + result := + pairStorageMetadata{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageMetadata{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) Metadata(pairs ...types.Pair) (meta *types.StorageMeta) { + pairs = append(pairs, s.defaultPairs.Metadata...) + var opt pairStorageMetadata + + // Ignore error while handling local functions. + opt, _ = s.parsePairStorageMetadata(pairs) + return s.metadata(opt) +} + +type pairStorageMove struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageMove(opts []types.Pair) (pairStorageMove, error) { + result := + pairStorageMove{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageMove{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) Move(src string, dst string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("move") + return +} +func (s *Storage) MoveWithContext(ctx context.Context, src string, dst string, pairs ...types.Pair) (err error) { + err = types.NewOperationNotImplementedError("move") + return +} + +type pairStorageQuerySignHTTPCompleteMultipart struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageQuerySignHTTPCompleteMultipart(opts []types.Pair) (pairStorageQuerySignHTTPCompleteMultipart, error) { + result := + pairStorageQuerySignHTTPCompleteMultipart{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageQuerySignHTTPCompleteMultipart{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) QuerySignHTTPCompleteMultipart(o *types.Object, parts []*types.Part, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_complete_multipart") + return +} +func (s *Storage) QuerySignHTTPCompleteMultipartWithContext(ctx context.Context, o *types.Object, parts []*types.Part, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_complete_multipart") + return +} + +type pairStorageQuerySignHTTPCreateMultipart struct { + pairs []types.Pair +} + +func (s *Storage) parsePairStorageQuerySignHTTPCreateMultipart(opts []types.Pair) (pairStorageQuerySignHTTPCreateMultipart, error) { + result := + pairStorageQuerySignHTTPCreateMultipart{pairs: opts} + + for _, v := range opts { + switch v.Key { + default: + return pairStorageQuerySignHTTPCreateMultipart{}, services.PairUnsupportedError{Pair: v} + } + } + return result, nil +} +func (s *Storage) QuerySignHTTPCreateMultipart(path string, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_create_multipart") + return +} +func (s *Storage) QuerySignHTTPCreateMultipartWithContext(ctx context.Context, path string, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_create_multipart") + return +} -type pairStorageCreateAppend struct { - pairs []Pair - // Required pairs - // Optional pairs +type pairStorageQuerySignHTTPDelete struct { + pairs []types.Pair } -func (s *Storage) parsePairStorageCreateAppend(opts []Pair) (pairStorageCreateAppend, error) { +func (s *Storage) parsePairStorageQuerySignHTTPDelete(opts []types.Pair) (pairStorageQuerySignHTTPDelete, error) { result := - pairStorageCreateAppend{pairs: opts} + pairStorageQuerySignHTTPDelete{pairs: opts} for _, v := range opts { switch v.Key { default: - return pairStorageCreateAppend{}, services.PairUnsupportedError{Pair: v} + return pairStorageQuerySignHTTPDelete{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) QuerySignHTTPDelete(path string, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_delete") + return +} +func (s *Storage) QuerySignHTTPDeleteWithContext(ctx context.Context, path string, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_delete") + return +} -type pairStorageCreateDir struct { - pairs []Pair - // Required pairs - // Optional pairs +type pairStorageQuerySignHTTPListMultipart struct { + pairs []types.Pair } -func (s *Storage) parsePairStorageCreateDir(opts []Pair) (pairStorageCreateDir, error) { +func (s *Storage) parsePairStorageQuerySignHTTPListMultipart(opts []types.Pair) (pairStorageQuerySignHTTPListMultipart, error) { result := - pairStorageCreateDir{pairs: opts} + pairStorageQuerySignHTTPListMultipart{pairs: opts} for _, v := range opts { switch v.Key { default: - return pairStorageCreateDir{}, services.PairUnsupportedError{Pair: v} + return pairStorageQuerySignHTTPListMultipart{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) QuerySignHTTPListMultipart(o *types.Object, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_list_multipart") + return +} +func (s *Storage) QuerySignHTTPListMultipartWithContext(ctx context.Context, o *types.Object, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_list_multipart") + return +} -type pairStorageDelete struct { - pairs []Pair - // Required pairs - // Optional pairs - HasObjectMode bool - ObjectMode ObjectMode +type pairStorageQuerySignHTTPRead struct { + pairs []types.Pair } -func (s *Storage) parsePairStorageDelete(opts []Pair) (pairStorageDelete, error) { +func (s *Storage) parsePairStorageQuerySignHTTPRead(opts []types.Pair) (pairStorageQuerySignHTTPRead, error) { result := - pairStorageDelete{pairs: opts} + pairStorageQuerySignHTTPRead{pairs: opts} for _, v := range opts { switch v.Key { - case "object_mode": - if result.HasObjectMode { - continue - } - result.HasObjectMode = true - result.ObjectMode = v.Value.(ObjectMode) default: - return pairStorageDelete{}, services.PairUnsupportedError{Pair: v} + return pairStorageQuerySignHTTPRead{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) QuerySignHTTPRead(path string, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_read") + return +} +func (s *Storage) QuerySignHTTPReadWithContext(ctx context.Context, path string, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_read") + return +} -type pairStorageList struct { - pairs []Pair - // Required pairs - // Optional pairs - HasListMode bool - ListMode ListMode +type pairStorageQuerySignHTTPWrite struct { + pairs []types.Pair } -func (s *Storage) parsePairStorageList(opts []Pair) (pairStorageList, error) { +func (s *Storage) parsePairStorageQuerySignHTTPWrite(opts []types.Pair) (pairStorageQuerySignHTTPWrite, error) { result := - pairStorageList{pairs: opts} + pairStorageQuerySignHTTPWrite{pairs: opts} for _, v := range opts { switch v.Key { - case "list_mode": - if result.HasListMode { - continue - } - result.HasListMode = true - result.ListMode = v.Value.(ListMode) default: - return pairStorageList{}, services.PairUnsupportedError{Pair: v} + return pairStorageQuerySignHTTPWrite{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) QuerySignHTTPWrite(path string, size int64, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_write") + return +} +func (s *Storage) QuerySignHTTPWriteWithContext(ctx context.Context, path string, size int64, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_write") + return +} -type pairStorageMetadata struct { - pairs []Pair - // Required pairs - // Optional pairs +type pairStorageQuerySignHTTPWriteMultipart struct { + pairs []types.Pair } -func (s *Storage) parsePairStorageMetadata(opts []Pair) (pairStorageMetadata, error) { +func (s *Storage) parsePairStorageQuerySignHTTPWriteMultipart(opts []types.Pair) (pairStorageQuerySignHTTPWriteMultipart, error) { result := - pairStorageMetadata{pairs: opts} + pairStorageQuerySignHTTPWriteMultipart{pairs: opts} for _, v := range opts { switch v.Key { default: - return pairStorageMetadata{}, services.PairUnsupportedError{Pair: v} + return pairStorageQuerySignHTTPWriteMultipart{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) QuerySignHTTPWriteMultipart(o *types.Object, size int64, index int, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_write_multipart") + return +} +func (s *Storage) QuerySignHTTPWriteMultipartWithContext(ctx context.Context, o *types.Object, size int64, index int, expire time.Duration, pairs ...types.Pair) (req *http.Request, err error) { + err = types.NewOperationNotImplementedError("query_sign_http_write_multipart") + return +} type pairStorageRead struct { - pairs []Pair - // Required pairs - // Optional pairs + pairs []types.Pair HasIoCallback bool IoCallback func([]byte) HasOffset bool @@ -376,7 +993,7 @@ type pairStorageRead struct { Size int64 } -func (s *Storage) parsePairStorageRead(opts []Pair) (pairStorageRead, error) { +func (s *Storage) parsePairStorageRead(opts []types.Pair) (pairStorageRead, error) { result := pairStorageRead{pairs: opts} @@ -404,19 +1021,34 @@ func (s *Storage) parsePairStorageRead(opts []Pair) (pairStorageRead, error) { return pairStorageRead{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) Read(path string, w io.Writer, pairs ...types.Pair) (n int64, err error) { + ctx := context.Background() + return s.ReadWithContext(ctx, path, w, pairs...) +} +func (s *Storage) ReadWithContext(ctx context.Context, path string, w io.Writer, pairs ...types.Pair) (n int64, err error) { + defer func() { + err = + s.formatError("read", err, path) + }() + pairs = append(pairs, s.defaultPairs.Read...) + var opt pairStorageRead + + opt, err = s.parsePairStorageRead(pairs) + if err != nil { + return + } + return s.read(ctx, strings.ReplaceAll(path, "\\", "/"), w, opt) +} type pairStorageStat struct { - pairs []Pair - // Required pairs - // Optional pairs + pairs []types.Pair HasObjectMode bool - ObjectMode ObjectMode + ObjectMode types.ObjectMode } -func (s *Storage) parsePairStorageStat(opts []Pair) (pairStorageStat, error) { +func (s *Storage) parsePairStorageStat(opts []types.Pair) (pairStorageStat, error) { result := pairStorageStat{pairs: opts} @@ -427,19 +1059,34 @@ func (s *Storage) parsePairStorageStat(opts []Pair) (pairStorageStat, error) { continue } result.HasObjectMode = true - result.ObjectMode = v.Value.(ObjectMode) + result.ObjectMode = v.Value.(types.ObjectMode) default: return pairStorageStat{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) Stat(path string, pairs ...types.Pair) (o *types.Object, err error) { + ctx := context.Background() + return s.StatWithContext(ctx, path, pairs...) +} +func (s *Storage) StatWithContext(ctx context.Context, path string, pairs ...types.Pair) (o *types.Object, err error) { + defer func() { + err = + s.formatError("stat", err, path) + }() + pairs = append(pairs, s.defaultPairs.Stat...) + var opt pairStorageStat + + opt, err = s.parsePairStorageStat(pairs) + if err != nil { + return + } + return s.stat(ctx, strings.ReplaceAll(path, "\\", "/"), opt) +} type pairStorageWrite struct { - pairs []Pair - // Required pairs - // Optional pairs + pairs []types.Pair HasContentMd5 bool ContentMd5 string HasContentType bool @@ -448,7 +1095,7 @@ type pairStorageWrite struct { IoCallback func([]byte) } -func (s *Storage) parsePairStorageWrite(opts []Pair) (pairStorageWrite, error) { +func (s *Storage) parsePairStorageWrite(opts []types.Pair) (pairStorageWrite, error) { result := pairStorageWrite{pairs: opts} @@ -476,17 +1123,32 @@ func (s *Storage) parsePairStorageWrite(opts []Pair) (pairStorageWrite, error) { return pairStorageWrite{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } +func (s *Storage) Write(path string, r io.Reader, size int64, pairs ...types.Pair) (n int64, err error) { + ctx := context.Background() + return s.WriteWithContext(ctx, path, r, size, pairs...) +} +func (s *Storage) WriteWithContext(ctx context.Context, path string, r io.Reader, size int64, pairs ...types.Pair) (n int64, err error) { + defer func() { + err = + s.formatError("write", err, path) + }() + pairs = append(pairs, s.defaultPairs.Write...) + var opt pairStorageWrite + + opt, err = s.parsePairStorageWrite(pairs) + if err != nil { + return + } + return s.write(ctx, strings.ReplaceAll(path, "\\", "/"), r, size, opt) +} type pairStorageWriteAppend struct { - pairs []Pair - // Required pairs - // Optional pairs + pairs []types.Pair } -func (s *Storage) parsePairStorageWriteAppend(opts []Pair) (pairStorageWriteAppend, error) { +func (s *Storage) parsePairStorageWriteAppend(opts []types.Pair) (pairStorageWriteAppend, error) { result := pairStorageWriteAppend{pairs: opts} @@ -496,203 +1158,101 @@ func (s *Storage) parsePairStorageWriteAppend(opts []Pair) (pairStorageWriteAppe return pairStorageWriteAppend{}, services.PairUnsupportedError{Pair: v} } } - return result, nil } -func (s *Storage) CommitAppend(o *Object, pairs ...Pair) (err error) { +func (s *Storage) WriteAppend(o *types.Object, r io.Reader, size int64, pairs ...types.Pair) (n int64, err error) { ctx := context.Background() - return s.CommitAppendWithContext(ctx, o, pairs...) + return s.WriteAppendWithContext(ctx, o, r, size, pairs...) } -func (s *Storage) CommitAppendWithContext(ctx context.Context, o *Object, pairs ...Pair) (err error) { +func (s *Storage) WriteAppendWithContext(ctx context.Context, o *types.Object, r io.Reader, size int64, pairs ...types.Pair) (n int64, err error) { defer func() { err = - s.formatError("commit_append", err) + s.formatError("write_append", err) }() - if !o.Mode.IsAppend() { - err = services.ObjectModeInvalidError{Expected: ModeAppend, Actual: o.Mode} - return - } - pairs = append(pairs, s.defaultPairs.CommitAppend...) - var opt pairStorageCommitAppend + pairs = append(pairs, s.defaultPairs.WriteAppend...) + var opt pairStorageWriteAppend - opt, err = s.parsePairStorageCommitAppend(pairs) + opt, err = s.parsePairStorageWriteAppend(pairs) if err != nil { return } - return s.commitAppend(ctx, o, opt) + return s.writeAppend(ctx, o, r, size, opt) } -func (s *Storage) Create(path string, pairs ...Pair) (o *Object) { - pairs = append(pairs, s.defaultPairs.Create...) - var opt pairStorageCreate - // Ignore error while handling local functions. - opt, _ = s.parsePairStorageCreate(pairs) - return s.create(path, opt) +type pairStorageWriteBlock struct { + pairs []types.Pair } -func (s *Storage) CreateAppend(path string, pairs ...Pair) (o *Object, err error) { - ctx := context.Background() - return s.CreateAppendWithContext(ctx, path, pairs...) -} -func (s *Storage) CreateAppendWithContext(ctx context.Context, path string, pairs ...Pair) (o *Object, err error) { - defer func() { - err = - s.formatError("create_append", err, path) - }() - pairs = append(pairs, s.defaultPairs.CreateAppend...) - var opt pairStorageCreateAppend +func (s *Storage) parsePairStorageWriteBlock(opts []types.Pair) (pairStorageWriteBlock, error) { + result := + pairStorageWriteBlock{pairs: opts} - opt, err = s.parsePairStorageCreateAppend(pairs) - if err != nil { - return + for _, v := range opts { + switch v.Key { + default: + return pairStorageWriteBlock{}, services.PairUnsupportedError{Pair: v} + } } - return s.createAppend(ctx, strings.ReplaceAll(path, "\\", "/"), opt) -} -func (s *Storage) CreateDir(path string, pairs ...Pair) (o *Object, err error) { - ctx := context.Background() - return s.CreateDirWithContext(ctx, path, pairs...) + return result, nil } -func (s *Storage) CreateDirWithContext(ctx context.Context, path string, pairs ...Pair) (o *Object, err error) { - defer func() { - err = - s.formatError("create_dir", err, path) - }() - - pairs = append(pairs, s.defaultPairs.CreateDir...) - var opt pairStorageCreateDir - - opt, err = s.parsePairStorageCreateDir(pairs) - if err != nil { - return - } - return s.createDir(ctx, strings.ReplaceAll(path, "\\", "/"), opt) +func (s *Storage) WriteBlock(o *types.Object, r io.Reader, size int64, bid string, pairs ...types.Pair) (n int64, err error) { + err = types.NewOperationNotImplementedError("write_block") + return } -func (s *Storage) Delete(path string, pairs ...Pair) (err error) { - ctx := context.Background() - return s.DeleteWithContext(ctx, path, pairs...) +func (s *Storage) WriteBlockWithContext(ctx context.Context, o *types.Object, r io.Reader, size int64, bid string, pairs ...types.Pair) (n int64, err error) { + err = types.NewOperationNotImplementedError("write_block") + return } -func (s *Storage) DeleteWithContext(ctx context.Context, path string, pairs ...Pair) (err error) { - defer func() { - err = - s.formatError("delete", err, path) - }() - - pairs = append(pairs, s.defaultPairs.Delete...) - var opt pairStorageDelete - opt, err = s.parsePairStorageDelete(pairs) - if err != nil { - return - } - return s.delete(ctx, strings.ReplaceAll(path, "\\", "/"), opt) -} -func (s *Storage) List(path string, pairs ...Pair) (oi *ObjectIterator, err error) { - ctx := context.Background() - return s.ListWithContext(ctx, path, pairs...) +type pairStorageWriteMultipart struct { + pairs []types.Pair } -func (s *Storage) ListWithContext(ctx context.Context, path string, pairs ...Pair) (oi *ObjectIterator, err error) { - defer func() { - err = - s.formatError("list", err, path) - }() - pairs = append(pairs, s.defaultPairs.List...) - var opt pairStorageList +func (s *Storage) parsePairStorageWriteMultipart(opts []types.Pair) (pairStorageWriteMultipart, error) { + result := + pairStorageWriteMultipart{pairs: opts} - opt, err = s.parsePairStorageList(pairs) - if err != nil { - return + for _, v := range opts { + switch v.Key { + default: + return pairStorageWriteMultipart{}, services.PairUnsupportedError{Pair: v} + } } - return s.list(ctx, strings.ReplaceAll(path, "\\", "/"), opt) -} -func (s *Storage) Metadata(pairs ...Pair) (meta *StorageMeta) { - pairs = append(pairs, s.defaultPairs.Metadata...) - var opt pairStorageMetadata - - // Ignore error while handling local functions. - opt, _ = s.parsePairStorageMetadata(pairs) - return s.metadata(opt) -} -func (s *Storage) Read(path string, w io.Writer, pairs ...Pair) (n int64, err error) { - ctx := context.Background() - return s.ReadWithContext(ctx, path, w, pairs...) + return result, nil } -func (s *Storage) ReadWithContext(ctx context.Context, path string, w io.Writer, pairs ...Pair) (n int64, err error) { - defer func() { - err = - s.formatError("read", err, path) - }() - - pairs = append(pairs, s.defaultPairs.Read...) - var opt pairStorageRead - - opt, err = s.parsePairStorageRead(pairs) - if err != nil { - return - } - return s.read(ctx, strings.ReplaceAll(path, "\\", "/"), w, opt) +func (s *Storage) WriteMultipart(o *types.Object, r io.Reader, size int64, index int, pairs ...types.Pair) (n int64, part *types.Part, err error) { + err = types.NewOperationNotImplementedError("write_multipart") + return } -func (s *Storage) Stat(path string, pairs ...Pair) (o *Object, err error) { - ctx := context.Background() - return s.StatWithContext(ctx, path, pairs...) +func (s *Storage) WriteMultipartWithContext(ctx context.Context, o *types.Object, r io.Reader, size int64, index int, pairs ...types.Pair) (n int64, part *types.Part, err error) { + err = types.NewOperationNotImplementedError("write_multipart") + return } -func (s *Storage) StatWithContext(ctx context.Context, path string, pairs ...Pair) (o *Object, err error) { - defer func() { - err = - s.formatError("stat", err, path) - }() - - pairs = append(pairs, s.defaultPairs.Stat...) - var opt pairStorageStat - opt, err = s.parsePairStorageStat(pairs) - if err != nil { - return - } - return s.stat(ctx, strings.ReplaceAll(path, "\\", "/"), opt) -} -func (s *Storage) Write(path string, r io.Reader, size int64, pairs ...Pair) (n int64, err error) { - ctx := context.Background() - return s.WriteWithContext(ctx, path, r, size, pairs...) +type pairStorageWritePage struct { + pairs []types.Pair } -func (s *Storage) WriteWithContext(ctx context.Context, path string, r io.Reader, size int64, pairs ...Pair) (n int64, err error) { - defer func() { - err = - s.formatError("write", err, path) - }() - pairs = append(pairs, s.defaultPairs.Write...) - var opt pairStorageWrite +func (s *Storage) parsePairStorageWritePage(opts []types.Pair) (pairStorageWritePage, error) { + result := + pairStorageWritePage{pairs: opts} - opt, err = s.parsePairStorageWrite(pairs) - if err != nil { - return + for _, v := range opts { + switch v.Key { + default: + return pairStorageWritePage{}, services.PairUnsupportedError{Pair: v} + } } - return s.write(ctx, strings.ReplaceAll(path, "\\", "/"), r, size, opt) + return result, nil } -func (s *Storage) WriteAppend(o *Object, r io.Reader, size int64, pairs ...Pair) (n int64, err error) { - ctx := context.Background() - return s.WriteAppendWithContext(ctx, o, r, size, pairs...) +func (s *Storage) WritePage(o *types.Object, r io.Reader, size int64, offset int64, pairs ...types.Pair) (n int64, err error) { + err = types.NewOperationNotImplementedError("write_page") + return } -func (s *Storage) WriteAppendWithContext(ctx context.Context, o *Object, r io.Reader, size int64, pairs ...Pair) (n int64, err error) { - defer func() { - err = - s.formatError("write_append", err) - }() - if !o.Mode.IsAppend() { - err = services.ObjectModeInvalidError{Expected: ModeAppend, Actual: o.Mode} - return - } - pairs = append(pairs, s.defaultPairs.WriteAppend...) - var opt pairStorageWriteAppend - - opt, err = s.parsePairStorageWriteAppend(pairs) - if err != nil { - return - } - return s.writeAppend(ctx, o, r, size, opt) +func (s *Storage) WritePageWithContext(ctx context.Context, o *types.Object, r io.Reader, size int64, offset int64, pairs ...types.Pair) (n int64, err error) { + err = types.NewOperationNotImplementedError("write_page") + return } func init() { - services.RegisterStorager(Type, NewStorager) - services.RegisterSchema(Type, pairMap) + services.RegisterFactory(Type, &Factory{}) } diff --git a/services/dropbox/go.mod b/services/dropbox/go.mod index a1d81e7fe..49624a30d 100644 --- a/services/dropbox/go.mod +++ b/services/dropbox/go.mod @@ -10,3 +10,5 @@ require ( ) require golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78 // indirect + +replace go.beyondstorage.io/v5 => ../../ diff --git a/services/dropbox/go.sum b/services/dropbox/go.sum index a8b10ecfb..284481bdf 100644 --- a/services/dropbox/go.sum +++ b/services/dropbox/go.sum @@ -33,26 +33,18 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Xuanwo/gg v0.2.0 h1:axbZmA0qmidh3s9PA86GqvBXVQ3o7Bbpf0aImGtlimA= -github.com/Xuanwo/gg v0.2.0/go.mod h1:0fLiiSxR87u2UA0ZNZiKZXuz3jnJdbDHWtU2xpdcH3s= +github.com/Xuanwo/gg v0.3.0 h1:jHasK7tJ4o/IjpcxPbabQ4zVO+hln85DvNYhq5GamcA= +github.com/Xuanwo/gg v0.3.0/go.mod h1:0fLiiSxR87u2UA0ZNZiKZXuz3jnJdbDHWtU2xpdcH3s= github.com/Xuanwo/go-bufferpool v0.2.0 h1:DXzqJD9lJufXbT/03GrcEvYOs4gXYUj9/g5yi6Q9rUw= github.com/Xuanwo/go-bufferpool v0.2.0/go.mod h1:Mle++9GGouhOwGj52i9PJLNAPmW2nb8PWBP7JJzNCzk= -github.com/Xuanwo/templateutils v0.1.0 h1:WpkWOqQtIQ2vAIpJLa727DdN8WtxhUkkbDGa6UhntJY= -github.com/Xuanwo/templateutils v0.1.0/go.mod h1:OdE0DJ+CJxDBq6psX5DPV+gOZi8bhuHuVUpPCG++Wb8= +github.com/Xuanwo/templateutils v0.2.0 h1:jnhiP1DMyK1Rv9qgaGCrEm/r6TseAsf7eC092gVld0Q= +github.com/Xuanwo/templateutils v0.2.0/go.mod h1:OdE0DJ+CJxDBq6psX5DPV+gOZi8bhuHuVUpPCG++Wb8= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/dave/dst v0.26.2 h1:lnxLAKI3tx7MgLNVDirFCsDTlTG9nKTk7GcptKcWSwY= -github.com/dave/dst v0.26.2/go.mod h1:UMDJuIRPfyUCC78eFuB+SV/WI8oDeyFDvM/JR6NI3IU= -github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ= -github.com/dave/jennifer v1.2.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= -github.com/dave/kerr v0.0.0-20170318121727-bc25dd6abe8e/go.mod h1:qZqlPyPvfsDJt+3wHJ1EvSXDuVjFTK0j2p/ca+gtsb8= -github.com/dave/rebecca v0.9.1/go.mod h1:N6XYdMD/OKw3lkF3ywh8Z6wPGuwNFDNtWYEMFWEmXBA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -104,7 +96,6 @@ github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/pprof v0.0.0-20181127221834-b4f47329b966/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= @@ -126,51 +117,38 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/kevinburke/go-bindata v3.22.0+incompatible h1:/JmqEhIWQ7GRScV0WjX/0tqBrC5D21ALg0H0U/KZ/ts= -github.com/kevinburke/go-bindata v3.22.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= -github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.6 h1:lH+Snxmzl92r1jww8/jYPqKkhs3C9AF4LunzU56ZZr4= -github.com/smartystreets/goconvey v1.6.6/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= +github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= +github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= +github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= -github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.beyondstorage.io/credential v1.0.0 h1:xJ7hBXmeUE0+rbW+RYZSz4KgHpXvc9g7oQ56f8dXdBk= go.beyondstorage.io/credential v1.0.0/go.mod h1:7KAYievVw4a8u/eLZmnQt65Z91n84sMQj3LFbt8Xous= -go.beyondstorage.io/v5 v5.0.0 h1:k9Axfgbt+oZXoDwSBVCl1XANHSL4rkNTGP2Lz9YdJe0= -go.beyondstorage.io/v5 v5.0.0/go.mod h1:3wV9gCQnqu7tD/3LMeo2yimUKIeTSHpTc6wHSb0yY20= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -golang.org/x/arch v0.0.0-20180920145803-b19384d3c130/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -206,7 +184,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -254,7 +231,6 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -328,14 +304,12 @@ golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjs golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -418,11 +392,10 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/src-d/go-billy.v4 v4.3.0/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/services/dropbox/internal/cmd/main.go b/services/dropbox/internal/cmd/main.go new file mode 100644 index 000000000..9558a7f2e --- /dev/null +++ b/services/dropbox/internal/cmd/main.go @@ -0,0 +1,9 @@ +package main + +import ( + def "go.beyondstorage.io/v5/definitions" +) + +func main() { + def.GenerateService(Metadata, "generated.go") +} diff --git a/services/dropbox/internal/cmd/meta.go b/services/dropbox/internal/cmd/meta.go new file mode 100644 index 000000000..33cbf0554 --- /dev/null +++ b/services/dropbox/internal/cmd/meta.go @@ -0,0 +1,68 @@ +package main + +import ( + def "go.beyondstorage.io/v5/definitions" + "go.beyondstorage.io/v5/types" +) + +var Metadata = def.Metadata{ + Name: "dropbox", + Pairs: []def.Pair{}, + Infos: []def.Info{ + infoObjectMetaUploadSessionId, + }, + Factory: []def.Pair{ + def.PairCredential, + def.PairWorkDir, + }, + Service: def.Service{ + Features: types.ServiceFeatures{}, + }, + Storage: def.Storage{ + Features: types.StorageFeatures{ + WriteEmptyObject: true, + + Create: true, + CreateDir: true, + CreateAppend: true, + Delete: true, + List: true, + Metadata: true, + Read: true, + Stat: true, + Write: true, + WriteAppend: true, + CommitAppend: true, + }, + + Create: []def.Pair{ + def.PairObjectMode, + }, + Delete: []def.Pair{ + def.PairObjectMode, + }, + List: []def.Pair{ + def.PairListMode, + }, + Read: []def.Pair{ + def.PairOffset, + def.PairIoCallback, + def.PairSize, + }, + Write: []def.Pair{ + def.PairContentMD5, + def.PairContentType, + def.PairIoCallback, + }, + Stat: []def.Pair{ + def.PairObjectMode, + }, + }, +} + +var infoObjectMetaUploadSessionId = def.Info{ + Namespace: def.NamespaceObject, + Category: def.CategoryMeta, + Name: "upload_session_id", + Type: def.Type{Name: "string"}, +} diff --git a/services/dropbox/service.toml b/services/dropbox/service.toml deleted file mode 100644 index f76dad232..000000000 --- a/services/dropbox/service.toml +++ /dev/null @@ -1,31 +0,0 @@ -name = "dropbox" - - -[namespace.storage] -implement = ["appender", "direr"] - -[namespace.storage.new] -required = ["credential"] -optional = ["work_dir", "http_client_options"] - -[namespace.storage.op.create] -optional = ["object_mode"] - -[namespace.storage.op.delete] -optional = ["object_mode"] - -[namespace.storage.op.list] -optional = ["list_mode"] - -[namespace.storage.op.read] -optional = ["offset", "io_callback", "size"] - -[namespace.storage.op.stat] -optional = ["object_mode"] - -[namespace.storage.op.write] -optional = ["content_md5", "content_type", "io_callback"] - -[infos.object.meta.upload-session-id] -type = "string" -description = "a unique identifier for the upload session, refer to https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start" diff --git a/services/dropbox/storage.go b/services/dropbox/storage.go index 7bfc99803..4f2f0cbbf 100644 --- a/services/dropbox/storage.go +++ b/services/dropbox/storage.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "strings" "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox" "github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files" @@ -148,6 +149,10 @@ func (s *Storage) delete(ctx context.Context, path string, opt pairStorageDelete } func (s *Storage) list(ctx context.Context, path string, opt pairStorageList) (oi *types.ObjectIterator, err error) { + if !strings.HasSuffix(path, "/") { + path += "/" + } + input := &objectPageStatus{ limit: 200, path: s.getAbsPath(path), @@ -179,7 +184,8 @@ func (s *Storage) nextObjectPage(ctx context.Context, page *types.ObjectPage) er if input.cursor == "" { output, err = s.client.ListFolder(&files.ListFolderArg{ - Path: input.path, + Path: input.path, + Recursive: input.recursive, }) } else { output, err = s.client.ListFolderContinue(&files.ListFolderContinueArg{ @@ -194,9 +200,9 @@ func (s *Storage) nextObjectPage(ctx context.Context, page *types.ObjectPage) er var o *types.Object switch meta := v.(type) { case *files.FolderMetadata: - o = s.formatFolderObject(meta.Name, meta) + o = s.formatFolderObject(input.path, meta) case *files.FileMetadata: - o = s.formatFileObject(meta.Name, meta) + o = s.formatFileObject(input.path, meta) } page.Data = append(page.Data, o) diff --git a/services/dropbox/tools.go b/services/dropbox/tools.go deleted file mode 100644 index 3039c3659..000000000 --- a/services/dropbox/tools.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build tools -// +build tools - -package dropbox - -import ( - _ "go.beyondstorage.io/v5/cmd/definitions" -) diff --git a/services/dropbox/utils.go b/services/dropbox/utils.go index 6e139dd2a..426d81c6c 100644 --- a/services/dropbox/utils.go +++ b/services/dropbox/utils.go @@ -14,8 +14,45 @@ import ( typ "go.beyondstorage.io/v5/types" ) +// Service is the dropbox config. +// It is not usable, only for generate code +type Service struct { + f Factory + + defaultPairs typ.DefaultServicePairs + features typ.ServiceFeatures + + typ.UnimplementedServicer +} + +// String implements Servicer.String +func (s *Service) String() string { + return fmt.Sprintf("Servicer azfile") +} + +// NewServicer is not usable, only for generate code +func NewServicer(pairs ...typ.Pair) (typ.Servicer, error) { + f := Factory{} + err := f.WithPairs(pairs...) + if err != nil { + return nil, err + } + return f.NewServicer() +} + +// newService is not usable, only for generate code +func (f *Factory) newService() (srv *Service, err error) { + srv = &Service{ + f: *f, + features: f.serviceFeatures(), + } + return +} + // Storage is the dropbox client. type Storage struct { + f Factory + client files.Client workDir string @@ -24,8 +61,6 @@ type Storage struct { features StorageFeatures typ.UnimplementedStorager - typ.UnimplementedAppender - typ.UnimplementedDirer } // String implements Storager.String @@ -38,27 +73,27 @@ func (s *Storage) String() string { // NewStorager will create Storager only. func NewStorager(pairs ...typ.Pair) (typ.Storager, error) { - return newStorager(pairs...) + f := Factory{} + err := f.WithPairs(pairs...) + if err != nil { + return nil, err + } + return f.newStorage() } // New will create a new client. -func newStorager(pairs ...typ.Pair) (store *Storage, err error) { +func (f *Factory) newStorage() (store *Storage, err error) { defer func() { if err != nil { - err = services.InitError{Op: "new_storager", Type: Type, Err: formatError(err), Pairs: pairs} + err = services.InitError{Op: "new_storager", Type: Type, Err: formatError(err)} } }() - opt, err := parsePairStorageNew(pairs) - if err != nil { - return - } - cfg := dropbox.Config{ // Client: httpclient.New(opt.HTTPClientOptions), } - cred, err := credential.Parse(opt.Credential) + cred, err := credential.Parse(f.Credential) if err != nil { return nil, err } @@ -67,25 +102,19 @@ func newStorager(pairs ...typ.Pair) (store *Storage, err error) { case credential.ProtocolAPIKey: cfg.Token = cred.APIKey() default: - return nil, services.PairUnsupportedError{Pair: ps.WithCredential(opt.Credential)} + return nil, services.PairUnsupportedError{Pair: ps.WithCredential(f.Credential)} } store = &Storage{ - client: files.New(cfg), + f: *f, + features: f.storageFeatures(), + client: files.New(cfg), workDir: "/", } - if opt.HasDefaultStoragePairs { - store.defaultPairs = opt.DefaultStoragePairs - } - - if opt.HasStorageFeatures { - store.features = opt.StorageFeatures - } - - if opt.HasWorkDir { - store.workDir = opt.WorkDir + if f.WorkDir != "" { + store.workDir = f.WorkDir } return } @@ -153,6 +182,12 @@ func (s *Storage) formatError(op string, err error, path ...string) error { } } +// getRelPath will get object storage's rel path. +func (s *Storage) getRelPath(path string) string { + prefix := s.workDir + "/" + return strings.TrimPrefix(path, prefix) +} + func (s *Storage) newObject(done bool) *typ.Object { return typ.NewObject(s, done) } @@ -160,7 +195,7 @@ func (s *Storage) newObject(done bool) *typ.Object { func (s *Storage) formatFolderObject(path string, v *files.FolderMetadata) (o *typ.Object) { o = s.newObject(true) o.ID = v.Id - o.Path = path + o.Path = s.getRelPath(path) o.Mode |= typ.ModeDir return o @@ -169,7 +204,7 @@ func (s *Storage) formatFolderObject(path string, v *files.FolderMetadata) (o *t func (s *Storage) formatFileObject(path string, v *files.FileMetadata) (o *typ.Object) { o = s.newObject(true) o.ID = v.Id - o.Path = path + o.Path = s.getRelPath(path) + v.Metadata.Name o.Mode |= typ.ModeRead o.SetContentLength(int64(v.Size))