@@ -10,15 +10,13 @@ import (
1010 "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1111 "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
1212 "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror"
13- "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
1413)
1514
1615type AzureStorage struct {
1716 Storage
18- client * azblob.Client
19- containerClient * container.Client
20- containerName string
21- logger * log.Logger
17+ client * azblob.Client
18+ containerName string
19+ logger * log.Logger
2220}
2321
2422func getCredentials () (* azidentity.DefaultAzureCredential , error ) {
@@ -37,14 +35,12 @@ func NewAzureBlobStorage(ctx context.Context, storageAccountName string, contain
3735 return nil , err
3836 }
3937
40- containerClient := client .ServiceClient ().NewContainerClient (containerName )
41-
4238 azureStorage := & AzureStorage {
43- client : client ,
44- containerClient : containerClient ,
45- containerName : containerName ,
46- logger : logger ,
39+ client : client ,
40+ containerName : containerName ,
41+ logger : logger ,
4742 }
43+
4844 return azureStorage , nil
4945}
5046
@@ -54,7 +50,6 @@ func (s *AzureStorage) Type() string {
5450
5551func (s * AzureStorage ) Get (ctx context.Context , token string , filename string , rng * Range ) (io.ReadCloser , uint64 , error ) {
5652 key := fmt .Sprintf ("%s/%s" , token , filename )
57- blobClient := s .containerClient .NewBlobClient (key )
5853
5954 var options * azblob.DownloadStreamOptions
6055 if rng != nil {
@@ -66,7 +61,7 @@ func (s *AzureStorage) Get(ctx context.Context, token string, filename string, r
6661 }
6762 }
6863
69- resp , err := blobClient . DownloadStream (ctx , options )
64+ resp , err := s . client . DownloadStream (ctx , s . containerName , key , options )
7065 if err != nil {
7166 return nil , 0 , err
7267 }
@@ -75,7 +70,9 @@ func (s *AzureStorage) Get(ctx context.Context, token string, filename string, r
7570
7671func (s * AzureStorage ) Head (ctx context.Context , token string , filename string ) (contentLength uint64 , err error ) {
7772 key := fmt .Sprintf ("%s/%s" , token , filename )
78- props , err := s .containerClient .NewBlobClient (key ).GetProperties (ctx , nil )
73+ containerClient := s .client .ServiceClient ().NewContainerClient (s .containerName )
74+ props , err := containerClient .NewBlobClient (key ).GetProperties (ctx , nil )
75+
7976 if err != nil {
8077 return 0 , err
8178 }
@@ -90,20 +87,16 @@ func (s *AzureStorage) Put(ctx context.Context, token string, filename string, r
9087
9188func (s * AzureStorage ) Delete (ctx context.Context , token string , filename string ) error {
9289 key := fmt .Sprintf ("%s/%s" , token , filename )
93- blobClient := s .containerClient .NewBlobClient (key )
94- _ , err := blobClient .Delete (ctx , nil )
95- if err != nil {
96- return err
97- }
98- return nil
90+ _ , err := s .client .DeleteBlob (ctx , s .containerName , key , nil )
91+ return err
9992}
10093
10194func (s * AzureStorage ) IsNotExist (err error ) bool {
10295 return bloberror .HasCode (err , bloberror .BlobNotFound )
10396}
10497
10598func (s * AzureStorage ) Purge (ctx context.Context , days time.Duration ) error {
106- pager := s .containerClient .NewListBlobsFlatPager (nil )
99+ pager := s .client .NewListBlobsFlatPager (s . containerName , nil )
107100
108101 for pager .More () {
109102 page , err := pager .NextPage (ctx )
@@ -113,10 +106,9 @@ func (s *AzureStorage) Purge(ctx context.Context, days time.Duration) error {
113106
114107 for _ , blob := range page .Segment .BlobItems {
115108 if time .Since (* blob .Properties .LastModified ) > days {
116- blobClient := s .containerClient .NewBlobClient (* blob .Name )
117- _ , err := blobClient .Delete (ctx , nil )
118- if err != nil {
119- continue
109+ key := * blob .Name
110+ if _ , err := s .client .DeleteBlob (ctx , s .containerName , key , nil ); err != nil {
111+ return err
120112 }
121113 }
122114 }
0 commit comments