@@ -19,7 +19,7 @@ import (
1919const (
2020 AnonymousAccess = 0
2121 ServicePrincipalAccess = 1
22- ManagedIdentityAccess = 2
22+ AzureCLIAccess = 2
2323)
2424
2525type AzureBlobStorage struct {
@@ -36,13 +36,13 @@ func (abs *AzureBlobStorage) Upload(
3636
3737 localFile , err := os .OpenFile (localFileName , os .O_RDONLY , 0 )
3838 if err != nil {
39- return fmt .Errorf ("Failed to open local file for upload:\n %w" , err )
39+ return fmt .Errorf ("failed to open local file for upload:\n %w" , err )
4040 }
4141 defer localFile .Close ()
4242
4343 _ , err = abs .theClient .UploadFile (ctx , containerName , blobName , localFile , nil )
4444 if err != nil {
45- return fmt .Errorf ("Failed to upload local file to blob:\n %w" , err )
45+ return fmt .Errorf ("failed to upload local file to blob:\n %w" , err )
4646 }
4747
4848 uploadEndTime := time .Now ()
@@ -77,7 +77,7 @@ func (abs *AzureBlobStorage) Download(
7777
7878 _ , err = abs .theClient .DownloadFile (ctx , containerName , blobName , localFile , nil )
7979 if err != nil {
80- return fmt .Errorf ("Failed to download blob to local file:\n %w" , err )
80+ return fmt .Errorf ("failed to download blob to local file:\n %w" , err )
8181 }
8282
8383 downloadEndTime := time .Now ()
@@ -94,7 +94,7 @@ func (abs *AzureBlobStorage) Delete(
9494 deleteStartTime := time .Now ()
9595 _ , err = abs .theClient .DeleteBlob (ctx , containerName , blobName , nil )
9696 if err != nil {
97- return fmt .Errorf ("Failed to delete blob:\n %w" , err )
97+ return fmt .Errorf ("failed to delete blob:\n %w" , err )
9898 }
9999 deleteEndTime := time .Now ()
100100 logger .Log .Infof (" delete time: %v" , deleteEndTime .Sub (deleteStartTime ))
@@ -103,49 +103,45 @@ func (abs *AzureBlobStorage) Delete(
103103}
104104
105105func Create (tenantId string , userName string , password string , storageAccount string , authenticationType int ) (abs * AzureBlobStorage , err error ) {
106-
107106 url := "https://" + storageAccount + ".blob.core.windows.net/"
108107
109108 abs = & AzureBlobStorage {}
110109
111- if authenticationType == AnonymousAccess {
112-
110+ switch authenticationType {
111+ case AnonymousAccess :
113112 abs .theClient , err = azblob .NewClientWithNoCredential (url , nil )
114113 if err != nil {
115- return nil , fmt .Errorf ("Unable to init azure blob storage read-only client:\n %w" , err )
114+ return nil , fmt .Errorf ("unable to init azure blob storage read-only client:\n %w" , err )
116115 }
117116
118117 return abs , nil
119118
120- } else if authenticationType == ServicePrincipalAccess {
121-
119+ case ServicePrincipalAccess :
122120 credential , err := azidentity .NewClientSecretCredential (tenantId , userName , password , nil )
123121 if err != nil {
124- return nil , fmt .Errorf ("Unable to init azure service principal identity:\n %w" , err )
122+ return nil , fmt .Errorf ("unable to init azure service principal identity:\n %w" , err )
125123 }
126124
127125 abs .theClient , err = azblob .NewClient (url , credential , nil )
128126 if err != nil {
129- return nil , fmt .Errorf ("Unable to init azure blob storage read-write client:\n %w" , err )
127+ return nil , fmt .Errorf ("unable to init azure blob storage read-write client:\n %w" , err )
130128 }
131129
132130 return abs , nil
133131
134- } else if authenticationType == ManagedIdentityAccess {
135-
136- credential , err := azidentity .NewDefaultAzureCredential (nil )
132+ case AzureCLIAccess :
133+ credential , err := azidentity .NewAzureCLICredential (nil )
137134 if err != nil {
138- return nil , fmt .Errorf ("Unable to init azure managed identity:\n %w" , err )
135+ return nil , fmt .Errorf ("unable to init azure managed identity:\n %w" , err )
139136 }
140137
141138 abs .theClient , err = azblob .NewClient (url , credential , nil )
142139 if err != nil {
143- return nil , fmt .Errorf ("Unable to init azure blob storage read-write client:\n %w" , err )
140+ return nil , fmt .Errorf ("unable to init azure blob storage read-write client:\n %w" , err )
144141 }
145142
146143 return abs , nil
147-
148144 }
149145
150- return nil , errors .New ("Unknown authentication type. " )
146+ return nil , errors .New ("unknown authentication type" )
151147}
0 commit comments