@@ -28,6 +28,7 @@ import (
28
28
"strings"
29
29
30
30
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
31
+ "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
31
32
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
32
33
_ "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
33
34
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
@@ -56,7 +57,7 @@ const (
56
57
57
58
// BlobClient is a minimal Azure Blob client for fetching objects.
58
59
type BlobClient struct {
59
- azblob.ServiceClient
60
+ * azblob.ServiceClient
60
61
}
61
62
62
63
// NewClient creates a new Azure Blob storage client.
@@ -162,9 +163,13 @@ func ValidateSecret(secret *corev1.Secret) error {
162
163
// BucketExists returns if an object storage bucket with the provided name
163
164
// exists, or returns a (client) error.
164
165
func (c * BlobClient ) BucketExists (ctx context.Context , bucketName string ) (bool , error ) {
165
- container := c .ServiceClient .NewContainerClient (bucketName )
166
- _ , err := container .GetProperties (ctx , nil )
166
+ container , err := c .ServiceClient .NewContainerClient (bucketName )
167
167
if err != nil {
168
+ return false , err
169
+ }
170
+ _ , err = container .GetProperties (ctx , nil )
171
+ if err != nil {
172
+ // TODO: Think this is now wrapped in an InternalError
168
173
var stgErr * azblob.StorageError
169
174
if errors .As (err , & stgErr ) {
170
175
if stgErr .ErrorCode == azblob .StorageErrorCodeContainerNotFound {
@@ -181,8 +186,14 @@ func (c *BlobClient) BucketExists(ctx context.Context, bucketName string) (bool,
181
186
// writes it to targetPath.
182
187
// It returns the etag of the successfully fetched file, or any error.
183
188
func (c * BlobClient ) FGetObject (ctx context.Context , bucketName , objectName , localPath string ) (string , error ) {
184
- container := c .ServiceClient .NewContainerClient (bucketName )
185
- blob := container .NewBlobClient (objectName )
189
+ container , err := c .ServiceClient .NewContainerClient (bucketName )
190
+ if err != nil {
191
+ return "" , err
192
+ }
193
+ blob , err := container .NewBlobClient (objectName )
194
+ if err != nil {
195
+ return "" , err
196
+ }
186
197
187
198
// Verify if destination already exists.
188
199
dirStatus , err := os .Stat (localPath )
@@ -245,13 +256,15 @@ func (c *BlobClient) FGetObject(ctx context.Context, bucketName, objectName, loc
245
256
// If the underlying client or the visit callback returns an error,
246
257
// it returns early.
247
258
func (c * BlobClient ) VisitObjects (ctx context.Context , bucketName string , visit func (path , etag string ) error ) error {
248
- container := c .ServiceClient .NewContainerClient (bucketName )
259
+ container , err := c .ServiceClient .NewContainerClient (bucketName )
260
+ if err != nil {
261
+ return err
262
+ }
249
263
250
- items := container .ListBlobsFlat (& azblob.ContainerListBlobFlatSegmentOptions {})
264
+ items := container .ListBlobsFlat (& azblob.ContainerListBlobsFlatOptions {})
251
265
for items .NextPage (ctx ) {
252
266
resp := items .PageResponse ()
253
-
254
- for _ , blob := range resp .ContainerListBlobFlatSegmentResult .Segment .BlobItems {
267
+ for _ , blob := range resp .Segment .BlobItems {
255
268
if err := visit (* blob .Name , fmt .Sprintf ("%x" , * blob .Properties .Etag )); err != nil {
256
269
err = fmt .Errorf ("listing objects from bucket '%s' failed: %w" , bucketName , err )
257
270
return err
@@ -302,7 +315,7 @@ func tokenCredentialFromSecret(secret *corev1.Secret) (azcore.TokenCredential, e
302
315
if clientSecret , hasClientSecret := secret .Data [clientSecretField ]; hasClientSecret && len (clientSecret ) > 0 {
303
316
opts := & azidentity.ClientSecretCredentialOptions {}
304
317
if authorityHost , hasAuthorityHost := secret .Data [authorityHostField ]; hasAuthorityHost {
305
- opts .AuthorityHost = azidentity . AuthorityHost (authorityHost )
318
+ opts .Cloud = cloud. Configuration { ActiveDirectoryAuthorityHost : string (authorityHost )}
306
319
}
307
320
return azidentity .NewClientSecretCredential (string (tenantID ), string (clientID ), string (clientSecret ), opts )
308
321
}
@@ -313,7 +326,7 @@ func tokenCredentialFromSecret(secret *corev1.Secret) (azcore.TokenCredential, e
313
326
}
314
327
opts := & azidentity.ClientCertificateCredentialOptions {}
315
328
if authorityHost , hasAuthorityHost := secret .Data [authorityHostField ]; hasAuthorityHost {
316
- opts .AuthorityHost = azidentity . AuthorityHost (authorityHost )
329
+ opts .Cloud = cloud. Configuration { ActiveDirectoryAuthorityHost : string (authorityHost )}
317
330
}
318
331
if v , sendChain := secret .Data [clientCertificateSendChainField ]; sendChain {
319
332
opts .SendCertificateChain = string (v ) == "1" || strings .ToLower (string (v )) == "true"
@@ -360,7 +373,7 @@ func chainCredentialWithSecret(secret *corev1.Secret) (azcore.TokenCredential, e
360
373
credOpts := & azidentity.EnvironmentCredentialOptions {}
361
374
if secret != nil {
362
375
if authorityHost , hasAuthorityHost := secret .Data [authorityHostField ]; hasAuthorityHost {
363
- credOpts .AuthorityHost = azidentity . AuthorityHost (authorityHost )
376
+ credOpts .Cloud = cloud. Configuration { ActiveDirectoryAuthorityHost : string (authorityHost )}
364
377
}
365
378
}
366
379
0 commit comments