diff --git a/generated.go b/generated.go index 8a76233..a45af7a 100644 --- a/generated.go +++ b/generated.go @@ -53,22 +53,42 @@ const ( pairUseArnRegion = "s3_use_arn_region" ) -// Service available metadata. -const ( - MetadataServerSideEncryption = "s3-server-side-encryption" - - MetadataServerSideEncryptionAwsKmsKeyID = "s3-server-side-encryption-aws-kms-key-id" - - MetadataServerSideEncryptionBucketKeyEnabled = "s3-server-side-encryption-bucket-key-enabled" - - MetadataServerSideEncryptionContext = "s3-server-side-encryption-context" - - MetadataServerSideEncryptionCustomerAlgorithm = "s3-server-side-encryption-customer-algorithm" +// ObjectMetadata stores service metadata for object. +type ObjectMetadata struct { + // ServerSideEncryption + ServerSideEncryption string + // ServerSideEncryptionAwsKmsKeyID + ServerSideEncryptionAwsKmsKeyID string + // ServerSideEncryptionBucketKeyEnabled + ServerSideEncryptionBucketKeyEnabled bool + // ServerSideEncryptionContext + ServerSideEncryptionContext string + // ServerSideEncryptionCustomerAlgorithm + ServerSideEncryptionCustomerAlgorithm string + // ServerSideEncryptionCustomerKeyMd5 + ServerSideEncryptionCustomerKeyMd5 string + // StorageClass + StorageClass string +} - MetadataServerSideEncryptionCustomerKeyMd5 = "s3-server-side-encryption-customer-key-md5" +// GetObjectMetadata will get ObjectMetadata from Object. +// +// - This function should not be called by service implementer. +// - The returning ObjectMetadata is read only and should not be modified. +func GetObjectMetadata(o *Object) ObjectMetadata { + om, ok := o.GetServiceMetadata() + if ok { + return om.(ObjectMetadata) + } + return ObjectMetadata{} +} - MetadataStorageClass = "s3-storage-class" -) +// setObjectMetadata will set ObjectMetadata into Object. +// +// - This function should only be called once, please make sure all data has been written before set. +func setObjectMetadata(o *Object, om ObjectMetadata) { + o.SetServiceMetadata(om) +} // WithDefaultServicePairs will apply default_service_pairs value to Options // DefaultServicePairs set default pairs for service actions diff --git a/go.mod b/go.mod index 73f21de..4bf6455 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.14 require ( github.com/aos-dev/go-integration-test/v3 v3.0.0-20210205075620-0b779f4b3afc - github.com/aos-dev/go-storage/v3 v3.5.1-0.20210421092104-4de248aed1f1 + github.com/aos-dev/go-storage/v3 v3.5.1-0.20210423112617-6847a93345fd github.com/aws/aws-sdk-go v1.38.24 github.com/google/uuid v1.2.0 ) diff --git a/go.sum b/go.sum index 869b546..b7cb9ab 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,14 @@ github.com/Xuanwo/templateutils v0.0.0-20201019101431-c73b871118f2/go.mod h1:x0qS7gfgEm24b8V9U+0zBEBAu/VpxZhO/+EWtpgEgDw= -github.com/Xuanwo/templateutils v0.0.0-20201216100309-46f73cd4e4b1 h1:SQ8kQujQ0yl39YBMU0xZ+yyfxx/qSWfGWlCPNzHp5kw= -github.com/Xuanwo/templateutils v0.0.0-20201216100309-46f73cd4e4b1/go.mod h1:x0qS7gfgEm24b8V9U+0zBEBAu/VpxZhO/+EWtpgEgDw= +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/aos-dev/go-integration-test/v3 v3.0.0-20210205075620-0b779f4b3afc h1:s8BQqJwWe2yoTGJFOsIxnkwwMsnDqMgkO39yzEP4smw= github.com/aos-dev/go-integration-test/v3 v3.0.0-20210205075620-0b779f4b3afc/go.mod h1:2VqxZhJVvI1jKTTERWHfCBMZQaJt10xoEJ+CxbfYZlo= github.com/aos-dev/go-storage/v3 v3.0.1-0.20210205074802-e8a5b22166c2/go.mod h1:JznhvyhPDnETfZ3RyWm3mT/S5ic+uuYFWagSIkUZujc= -github.com/aos-dev/go-storage/v3 v3.5.1-0.20210421092104-4de248aed1f1 h1:Kkb/cVJRwc77lXGcnV2ThUC4QUqybiEVrFwq8qnM4V4= -github.com/aos-dev/go-storage/v3 v3.5.1-0.20210421092104-4de248aed1f1/go.mod h1:JFshvl851ZDDXtFGWDFKqkg34QEPH0xuhLJ2LjikZYc= +github.com/aos-dev/go-storage/v3 v3.5.1-0.20210423112617-6847a93345fd h1:FEBrz+fo4V+6jMxnbmkI0M+3m5MYriF5SijFF/Sz5cM= +github.com/aos-dev/go-storage/v3 v3.5.1-0.20210423112617-6847a93345fd/go.mod h1:ZQwybmoCcTWUOWg+G15gT/NQJoI8G8KH1pF41TuJqYk= github.com/aos-dev/specs/go v0.0.0-20210205073047-af8ef94af73d/go.mod h1:XTNlLZtPA1inITyDH5hNnQXVjvvKUvo+lurs5GYB8NA= -github.com/aos-dev/specs/go v0.0.0-20210420062803-1a60efa2eae3 h1:LiW0Ki0Gw6opu11JwMhxWw5M+V6I9JypJ5eAIp+Rqt4= -github.com/aos-dev/specs/go v0.0.0-20210420062803-1a60efa2eae3/go.mod h1:gNah3KaPJEfysh7uCCX+sYjQC3g2yx2VgBkFlT945Ws= +github.com/aos-dev/specs/go v0.0.0-20210423110314-8361397c2bf3 h1:e65ozDhdfHfhnDpZF9SLcY5mwtAg/sAvNIUAkFd+4D0= +github.com/aos-dev/specs/go v0.0.0-20210423110314-8361397c2bf3/go.mod h1:gNah3KaPJEfysh7uCCX+sYjQC3g2yx2VgBkFlT945Ws= github.com/aws/aws-sdk-go v1.38.24 h1:zbKHDxFepE77ihVMZ+wZ62Ci646zkorN8rB5s4fj4kU= github.com/aws/aws-sdk-go v1.38.24/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/dave/dst v0.26.2 h1:lnxLAKI3tx7MgLNVDirFCsDTlTG9nKTk7GcptKcWSwY= diff --git a/service.toml b/service.toml index 25bb5b2..435d5bc 100644 --- a/service.toml +++ b/service.toml @@ -123,4 +123,4 @@ type = "string" type = "string" [infos.object.meta.server-side-encryption-bucket-key-enabled] -type = "string" \ No newline at end of file +type = "bool" \ No newline at end of file diff --git a/storage.go b/storage.go index b2e38b4..65528c5 100644 --- a/storage.go +++ b/storage.go @@ -4,11 +4,9 @@ import ( "context" "encoding/base64" "fmt" - "io" - "strconv" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/s3" + "io" "github.com/aos-dev/go-storage/v3/pkg/iowrap" . "github.com/aos-dev/go-storage/v3/types" @@ -93,24 +91,24 @@ func (s *Storage) createMultipart(ctx context.Context, path string, opt pairStor o.Mode |= ModePart o.SetMultipartID(aws.StringValue(output.UploadId)) - sm := make(map[string]string) + var sm ObjectMetadata if v := aws.StringValue(output.ServerSideEncryption); v != "" { - sm[MetadataServerSideEncryption] = v + sm.ServerSideEncryption = v } if v := aws.StringValue(output.SSEKMSKeyId); v != "" { - sm[MetadataServerSideEncryptionAwsKmsKeyID] = v + sm.ServerSideEncryptionAwsKmsKeyID = v } if v := aws.StringValue(output.SSEKMSEncryptionContext); v != "" { - sm[MetadataServerSideEncryptionContext] = v + sm.ServerSideEncryptionContext = v } if v := aws.StringValue(output.SSECustomerAlgorithm); v != "" { - sm[MetadataServerSideEncryptionCustomerAlgorithm] = v + sm.ServerSideEncryptionCustomerAlgorithm = v } if v := aws.StringValue(output.SSECustomerKeyMD5); v != "" { - sm[MetadataServerSideEncryptionCustomerKeyMd5] = v + sm.ServerSideEncryptionCustomerKeyMd5 = v } if output.BucketKeyEnabled != nil { - sm[MetadataServerSideEncryptionBucketKeyEnabled] = strconv.FormatBool(aws.BoolValue(output.BucketKeyEnabled)) + sm.ServerSideEncryptionBucketKeyEnabled = aws.BoolValue(output.BucketKeyEnabled) } o.SetServiceMetadata(sm) @@ -424,24 +422,25 @@ func (s *Storage) stat(ctx context.Context, path string, opt pairStorageStat) (o if output.ETag != nil { o.SetEtag(*output.ETag) } - sm := make(map[string]string) + + var sm ObjectMetadata if v := aws.StringValue(output.StorageClass); v != "" { - sm[MetadataStorageClass] = v + sm.StorageClass = v } if v := aws.StringValue(output.ServerSideEncryption); v != "" { - sm[MetadataServerSideEncryption] = v + sm.ServerSideEncryption = v } if v := aws.StringValue(output.SSEKMSKeyId); v != "" { - sm[MetadataServerSideEncryptionAwsKmsKeyID] = v + sm.ServerSideEncryptionAwsKmsKeyID = v } if v := aws.StringValue(output.SSECustomerAlgorithm); v != "" { - sm[MetadataServerSideEncryptionCustomerAlgorithm] = v + sm.ServerSideEncryptionCustomerAlgorithm = v } if v := aws.StringValue(output.SSECustomerKeyMD5); v != "" { - sm[MetadataServerSideEncryptionCustomerKeyMd5] = v + sm.ServerSideEncryptionCustomerKeyMd5 = v } if output.BucketKeyEnabled != nil { - sm[MetadataServerSideEncryptionBucketKeyEnabled] = strconv.FormatBool(aws.BoolValue(output.BucketKeyEnabled)) + sm.ServerSideEncryptionBucketKeyEnabled = aws.BoolValue(output.BucketKeyEnabled) } o.SetServiceMetadata(sm) diff --git a/utils.go b/utils.go index 487c073..6695c2d 100644 --- a/utils.go +++ b/utils.go @@ -276,9 +276,9 @@ func (s *Storage) formatFileObject(v *s3.Object) (o *typ.Object, err error) { o.SetEtag(*v.ETag) } - sm := make(map[string]string) + var sm ObjectMetadata if value := aws.StringValue(v.StorageClass); value != "" { - sm[MetadataStorageClass] = value + sm.StorageClass = value } o.SetServiceMetadata(sm)