diff --git a/generated.go b/generated.go index 2bbfdb7..4426d5e 100644 --- a/generated.go +++ b/generated.go @@ -4,8 +4,10 @@ package s3 import ( "context" "io" + "net/http" "time" + . "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/pkg/httpclient" "github.com/beyondstorage/go-storage/v4/services" . "github.com/beyondstorage/go-storage/v4/types" @@ -15,6 +17,8 @@ var _ Storager var _ services.ServiceError var _ httpclient.Options var _ time.Duration +var _ http.Request +var _ Error // Type is the type for s3 const Type = "s3" @@ -78,6 +82,16 @@ func setStorageSystemMetadata(s *StorageMeta, sm StorageSystemMetadata) { s.SetSystemMetadata(sm) } +// WithDefaultIoCallback will apply default_io_callback value to Options. +// +// IoCallback specify what todo every time we read data from source +func WithDefaultIoCallback(v func([]byte)) Pair { + return Pair{ + Key: "default_io_callback", + Value: v, + } +} + // WithDefaultServicePairs will apply default_service_pairs value to Options. // // DefaultServicePairs set default pairs for service actions @@ -88,6 +102,16 @@ func WithDefaultServicePairs(v DefaultServicePairs) Pair { } } +// WithDefaultStorageClass will apply default_storage_class value to Options. +// +// StorageClass +func WithDefaultStorageClass(v string) Pair { + return Pair{ + Key: "default_storage_class", + Value: v, + } +} + // WithDefaultStoragePairs will apply default_storage_pairs value to Options. // // DefaultStoragePairs set default pairs for storager actions @@ -101,10 +125,40 @@ func WithDefaultStoragePairs(v DefaultStoragePairs) Pair { // WithDisable100Continue will apply disable_100_continue value to Options. // // Disable100Continue set this to `true` to disable the SDK adding the `Expect: 100-Continue` header to PUT requests over 2MB of content -func WithDisable100Continue(v bool) Pair { +func WithDisable100Continue() Pair { return Pair{ Key: "disable_100_continue", - Value: v, + Value: true, + } +} + +// WithEnableVirtualDir will apply enable_virtual_dir value to Options. +// +// VirtualDir virtual_dir feature is designed for a service that doesn't have native dir support but wants to provide simulated operations. +// +// - If this feature is disabled (the default behavior), the service will behave like it doesn't have any dir support. +// - If this feature is enabled, the service will support simulated dir behavior in create_dir, create, list, delete, and so on. +// +// This feature was introduced in GSP-109. +func WithEnableVirtualDir() Pair { + return Pair{ + Key: "enable_virtual_dir", + Value: true, + } +} + +// WithEnableVirtualLink will apply enable_virtual_link value to Options. +// +// VirtualLink virtual_link feature is designed for a service that doesn't have native support for link. +// +// - If this feature is enabled, the service will run compatible mode: create link via native methods, but allow read link from old-style link object. +// - If this feature is not enabled, the service will run in native as other service. +// +// This feature was introduced in GSP-86. +func WithEnableVirtualLink() Pair { + return Pair{ + Key: "enable_virtual_link", + Value: true, } } @@ -121,10 +175,10 @@ func WithExceptedBucketOwner(v string) Pair { // WithForcePathStyle will apply force_path_style value to Options. // // ForcePathStyle see http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html for Amazon S3: Virtual Hosting of Buckets -func WithForcePathStyle(v bool) Pair { +func WithForcePathStyle() Pair { return Pair{ Key: "force_path_style", - Value: v, + Value: true, } } @@ -151,10 +205,10 @@ func WithServerSideEncryptionAwsKmsKeyID(v string) Pair { // WithServerSideEncryptionBucketKeyEnabled will apply server_side_encryption_bucket_key_enabled value to Options. // // ServerSideEncryptionBucketKeyEnabled specifies whether Amazon S3 should use an S3 Bucket Key for object encryption with server-side encryption using AWS KMS (SSE-KMS) -func WithServerSideEncryptionBucketKeyEnabled(v bool) Pair { +func WithServerSideEncryptionBucketKeyEnabled() Pair { return Pair{ Key: "server_side_encryption_bucket_key_enabled", - Value: v, + Value: true, } } @@ -221,20 +275,20 @@ func WithStorageFeatures(v StorageFeatures) Pair { // WithUseAccelerate will apply use_accelerate value to Options. // // UseAccelerate set this to `true` to enable S3 Accelerate feature -func WithUseAccelerate(v bool) Pair { +func WithUseAccelerate() Pair { return Pair{ Key: "use_accelerate", - Value: v, + Value: true, } } // WithUseArnRegion will apply use_arn_region value to Options. // // UseArnRegion set this to `true` to have the S3 service client to use the region specified in the ARN, when an ARN is provided as an argument to a bucket parameter -func WithUseArnRegion(v bool) Pair { +func WithUseArnRegion() Pair { return Pair{ Key: "use_arn_region", - Value: v, + Value: true, } } @@ -244,9 +298,13 @@ var pairMap = map[string]string{ "context": "context.Context", "continuation_token": "string", "credential": "string", + "default_io_callback": "func([]byte)", "default_service_pairs": "DefaultServicePairs", + "default_storage_class": "string", "default_storage_pairs": "DefaultStoragePairs", "disable_100_continue": "bool", + "enable_virtual_dir": "bool", + "enable_virtual_link": "bool", "endpoint": "string", "excepted_bucket_owner": "string", "expire": "time.Duration", @@ -305,6 +363,8 @@ type pairServiceNew struct { UseAccelerate bool HasUseArnRegion bool UseArnRegion bool + // Enable features + // Default pairs } // parsePairServiceNew will parse Pair slice into *pairServiceNew @@ -371,8 +431,15 @@ func parsePairServiceNew(opts []Pair) (pairServiceNew, error) { } result.HasUseArnRegion = true result.UseArnRegion = v.Value.(bool) + // Enable features + // Default pairs } } + + // Enable features + + // Default pairs + if !result.HasCredential { return pairServiceNew{}, services.PairRequiredError{Keys: []string{"credential"}} } @@ -660,6 +727,16 @@ type pairStorageNew struct { StorageFeatures StorageFeatures HasWorkDir bool WorkDir string + // Enable features + hasEnableVirtualDir bool + EnableVirtualDir bool + hasEnableVirtualLink bool + EnableVirtualLink bool + // Default pairs + hasDefaultIoCallback bool + DefaultIoCallback func([]byte) + hasDefaultStorageClass bool + DefaultStorageClass string } // parsePairStorageNew will parse Pair slice into *pairStorageNew @@ -702,8 +779,58 @@ func parsePairStorageNew(opts []Pair) (pairStorageNew, error) { } result.HasWorkDir = true result.WorkDir = v.Value.(string) + // Enable features + case "enable_virtual_dir": + if result.hasEnableVirtualDir { + continue + } + result.hasEnableVirtualDir = true + result.EnableVirtualDir = true + case "enable_virtual_link": + if result.hasEnableVirtualLink { + continue + } + result.hasEnableVirtualLink = true + result.EnableVirtualLink = true + // Default pairs + case "default_io_callback": + if result.hasDefaultIoCallback { + continue + } + result.hasDefaultIoCallback = true + result.DefaultIoCallback = v.Value.(func([]byte)) + case "default_storage_class": + if result.hasDefaultStorageClass { + continue + } + result.hasDefaultStorageClass = true + result.DefaultStorageClass = v.Value.(string) } } + + // Enable features + if result.hasEnableVirtualDir { + result.HasStorageFeatures = true + result.StorageFeatures.VirtualDir = true + } + if result.hasEnableVirtualLink { + result.HasStorageFeatures = true + result.StorageFeatures.VirtualLink = true + } + + // Default pairs + 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)) + result.DefaultStoragePairs.WriteMultipart = append(result.DefaultStoragePairs.WriteMultipart, WithIoCallback(result.DefaultIoCallback)) + } + if result.hasDefaultStorageClass { + result.HasDefaultStoragePairs = true + result.DefaultStoragePairs.CreateDir = append(result.DefaultStoragePairs.CreateDir, WithStorageClass(result.DefaultStorageClass)) + result.DefaultStoragePairs.Write = append(result.DefaultStoragePairs.Write, WithStorageClass(result.DefaultStorageClass)) + } + if !result.HasLocation { return pairStorageNew{}, services.PairRequiredError{Keys: []string{"location"}} } @@ -1372,6 +1499,8 @@ type pairStorageWriteMultipart struct { pairs []Pair HasExceptedBucketOwner bool ExceptedBucketOwner string + HasIoCallback bool + IoCallback func([]byte) HasServerSideEncryptionCustomerAlgorithm bool ServerSideEncryptionCustomerAlgorithm string HasServerSideEncryptionCustomerKey bool @@ -1393,6 +1522,13 @@ func (s *Storage) parsePairStorageWriteMultipart(opts []Pair) (pairStorageWriteM result.HasExceptedBucketOwner = true result.ExceptedBucketOwner = v.Value.(string) continue + case "io_callback": + if result.HasIoCallback { + continue + } + result.HasIoCallback = true + result.IoCallback = v.Value.(func([]byte)) + continue case "server_side_encryption_customer_algorithm": if result.HasServerSideEncryptionCustomerAlgorithm { continue diff --git a/go.mod b/go.mod index 0c9216a..a800f3f 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,6 @@ require ( github.com/aws/aws-sdk-go v1.40.1 github.com/beyondstorage/go-endpoint v1.1.0 github.com/beyondstorage/go-integration-test/v4 v4.3.0 - github.com/beyondstorage/go-storage/v4 v4.4.1-0.20210730075750-6e541b87ea46 + github.com/beyondstorage/go-storage/v4 v4.6.0 github.com/google/uuid v1.3.0 ) diff --git a/go.sum b/go.sum index 08146b3..21b6e86 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/beyondstorage/go-endpoint v1.1.0/go.mod h1:P2hknaGrziOJJKySv/XnAiVw/d github.com/beyondstorage/go-integration-test/v4 v4.3.0 h1:WZ95f78RKlHpvft8zHcMaoa2aaTF/jzlzINhMD0EMHY= github.com/beyondstorage/go-integration-test/v4 v4.3.0/go.mod h1:HKgzemQZpxoHBL49JYEUnLTb5eteUhzcvmmPL7EDT/Y= github.com/beyondstorage/go-storage/v4 v4.4.0/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw= -github.com/beyondstorage/go-storage/v4 v4.4.1-0.20210730075750-6e541b87ea46 h1:sUmtn3cWgpjetIv/lSzZ6AA9GnzvxPjalTvRY1ZDzOg= -github.com/beyondstorage/go-storage/v4 v4.4.1-0.20210730075750-6e541b87ea46/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw= +github.com/beyondstorage/go-storage/v4 v4.6.0 h1:a05dtbYjMZB7LrUSvVzzHwlx33B4yEmd5oQB7Itk7VY= +github.com/beyondstorage/go-storage/v4 v4.6.0/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw= 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= diff --git a/service.toml b/service.toml index e7e3e88..36ba3df 100644 --- a/service.toml +++ b/service.toml @@ -18,6 +18,7 @@ optional = ["location"] [namespace.storage] features = ["virtual_dir", "virtual_link"] implement = ["direr", "multiparter", "linker"] +defaultable = ["io_callback", "storage_class"] [namespace.storage.new] required = ["location", "name"] @@ -48,7 +49,7 @@ optional = ["excepted_bucket_owner", "multipart_id", "object_mode", "server_side optional = ["server_side_encryption_bucket_key_enabled", "excepted_bucket_owner", "server_side_encryption_customer_algorithm", "server_side_encryption_customer_key", "server_side_encryption_aws_kms_key_id", "server_side_encryption_context", "server_side_encryption"] [namespace.storage.op.write_multipart] -optional = ["excepted_bucket_owner", "server_side_encryption_customer_algorithm", "server_side_encryption_customer_key"] +optional = ["excepted_bucket_owner", "server_side_encryption_customer_algorithm", "server_side_encryption_customer_key", "io_callback"] [namespace.storage.op.list_multipart] optional = ["excepted_bucket_owner"] @@ -138,4 +139,4 @@ type = "string" type = "string" [infos.object.meta.server-side-encryption-bucket-key-enabled] -type = "bool" \ No newline at end of file +type = "bool"