From fd68e78960aded5047121ca9feb418004758eaac Mon Sep 17 00:00:00 2001 From: xxchan Date: Sun, 25 Apr 2021 13:27:29 +0800 Subject: [PATCH 1/5] add SSE part in formatFileObject --- utils.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils.go b/utils.go index be214fc..0e8afdb 100644 --- a/utils.go +++ b/utils.go @@ -294,6 +294,12 @@ func (s *Storage) formatFileObject(v azblob.BlobItemInternal) (o *typ.Object, er if value := v.Properties.AccessTier; value != "" { sm.AccessTier = string(value) } + if v.Properties.CustomerProvidedKeySha256 != nil && *v.Properties.CustomerProvidedKeySha256 != "" { + sm.EncryptionKeySha256 = *v.Properties.CustomerProvidedKeySha256 + } + if v.Properties.EncryptionScope != nil && *v.Properties.EncryptionScope != "" { + sm.EncryptionScope = *v.Properties.EncryptionScope + } o.SetServiceMetadata(sm) return o, nil From f73078fbd22dd9d9c75f18a05b8959749c6fe464 Mon Sep 17 00:00:00 2001 From: xxchan Date: Sun, 25 Apr 2021 13:50:07 +0800 Subject: [PATCH 2/5] refactor --- utils.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils.go b/utils.go index 0e8afdb..bc46d2e 100644 --- a/utils.go +++ b/utils.go @@ -283,8 +283,8 @@ func (s *Storage) formatFileObject(v azblob.BlobItemInternal) (o *typ.Object, er if v.Properties.ContentLength != nil { o.SetContentLength(*v.Properties.ContentLength) } - if v.Properties.ContentType != nil && *v.Properties.ContentType != "" { - o.SetContentType(*v.Properties.ContentType) + if value := *v.Properties.ContentType; len(value) != 0 { + o.SetContentType(value) } if len(v.Properties.ContentMD5) > 0 { o.SetContentMd5(base64.StdEncoding.EncodeToString(v.Properties.ContentMD5)) @@ -294,11 +294,11 @@ func (s *Storage) formatFileObject(v azblob.BlobItemInternal) (o *typ.Object, er if value := v.Properties.AccessTier; value != "" { sm.AccessTier = string(value) } - if v.Properties.CustomerProvidedKeySha256 != nil && *v.Properties.CustomerProvidedKeySha256 != "" { - sm.EncryptionKeySha256 = *v.Properties.CustomerProvidedKeySha256 + if value := *v.Properties.CustomerProvidedKeySha256; len(value) != 0 { + sm.EncryptionKeySha256 = value } - if v.Properties.EncryptionScope != nil && *v.Properties.EncryptionScope != "" { - sm.EncryptionScope = *v.Properties.EncryptionScope + if value := *v.Properties.EncryptionScope; len(value) != 0 { + sm.EncryptionScope = value } o.SetServiceMetadata(sm) From dda342dd3149b95a4762435bd1bd8777f28d3418 Mon Sep 17 00:00:00 2001 From: xxchan Date: Sun, 25 Apr 2021 14:35:58 +0800 Subject: [PATCH 3/5] fix NPE and do not check "" --- utils.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils.go b/utils.go index bc46d2e..2d13473 100644 --- a/utils.go +++ b/utils.go @@ -283,8 +283,8 @@ func (s *Storage) formatFileObject(v azblob.BlobItemInternal) (o *typ.Object, er if v.Properties.ContentLength != nil { o.SetContentLength(*v.Properties.ContentLength) } - if value := *v.Properties.ContentType; len(value) != 0 { - o.SetContentType(value) + if v.Properties.ContentType != nil { + o.SetContentType(*v.Properties.ContentType) } if len(v.Properties.ContentMD5) > 0 { o.SetContentMd5(base64.StdEncoding.EncodeToString(v.Properties.ContentMD5)) @@ -294,11 +294,11 @@ func (s *Storage) formatFileObject(v azblob.BlobItemInternal) (o *typ.Object, er if value := v.Properties.AccessTier; value != "" { sm.AccessTier = string(value) } - if value := *v.Properties.CustomerProvidedKeySha256; len(value) != 0 { - sm.EncryptionKeySha256 = value + if v.Properties.CustomerProvidedKeySha256 != nil { + sm.EncryptionKeySha256 = *v.Properties.CustomerProvidedKeySha256 } - if value := *v.Properties.EncryptionScope; len(value) != 0 { - sm.EncryptionScope = value + if v.Properties.EncryptionScope != nil { + sm.EncryptionScope = *v.Properties.EncryptionScope } o.SetServiceMetadata(sm) From 2ef4e8936ac6c44037a0a04433550675c5eeb929 Mon Sep 17 00:00:00 2001 From: xxchan Date: Sun, 25 Apr 2021 15:09:35 +0800 Subject: [PATCH 4/5] add ServerEncrypted --- generated.go | 2 ++ service.toml | 5 ++++- storage.go | 4 ++++ utils.go | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/generated.go b/generated.go index 9be3c49..c7a5175 100644 --- a/generated.go +++ b/generated.go @@ -43,6 +43,8 @@ type ObjectMetadata struct { EncryptionKeySha256 string // EncryptionScope EncryptionScope string + // ServerEncrypted + ServerEncrypted bool } // GetObjectMetadata will get ObjectMetadata from Object. diff --git a/service.toml b/service.toml index aa25404..61d0cd3 100644 --- a/service.toml +++ b/service.toml @@ -48,4 +48,7 @@ type = "string" type = "string" [infos.object.meta.encryption-scope] -type = "string" \ No newline at end of file +type = "string" + +[infos.object.meta.server-encrypted] +type = "bool" diff --git a/storage.go b/storage.go index 4fe82e3..3302fba 100644 --- a/storage.go +++ b/storage.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "fmt" "io" + "strconv" "github.com/Azure/azure-storage-blob-go/azblob" @@ -209,6 +210,9 @@ func (s *Storage) stat(ctx context.Context, path string, opt pairStorageStat) (o if v := output.EncryptionScope(); v != "" { sm.EncryptionScope = v } + if v, err := strconv.ParseBool(output.IsServerEncrypted()); err != nil { + sm.ServerEncrypted = v + } o.SetServiceMetadata(sm) return o, nil diff --git a/utils.go b/utils.go index 2d13473..5b10c53 100644 --- a/utils.go +++ b/utils.go @@ -300,6 +300,9 @@ func (s *Storage) formatFileObject(v azblob.BlobItemInternal) (o *typ.Object, er if v.Properties.EncryptionScope != nil { sm.EncryptionScope = *v.Properties.EncryptionScope } + if v.Properties.ServerEncrypted != nil { + sm.ServerEncrypted = *v.Properties.ServerEncrypted + } o.SetServiceMetadata(sm) return o, nil From eb8c811ab5e232d5d33f9bcb7c289717a4c22683 Mon Sep 17 00:00:00 2001 From: xxchan Date: Sun, 25 Apr 2021 15:17:59 +0800 Subject: [PATCH 5/5] fix --- storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage.go b/storage.go index 3302fba..61a455e 100644 --- a/storage.go +++ b/storage.go @@ -210,7 +210,7 @@ func (s *Storage) stat(ctx context.Context, path string, opt pairStorageStat) (o if v := output.EncryptionScope(); v != "" { sm.EncryptionScope = v } - if v, err := strconv.ParseBool(output.IsServerEncrypted()); err != nil { + if v, err := strconv.ParseBool(output.IsServerEncrypted()); err == nil { sm.ServerEncrypted = v } o.SetServiceMetadata(sm)