From da4639df62b6948bae382e067a1b38446665602e Mon Sep 17 00:00:00 2001 From: Srinivas Yeleti Date: Tue, 4 Mar 2025 05:44:21 +0000 Subject: [PATCH 1/6] display the error when the auth fails --- component/azstorage/azstorage.go | 2 +- component/azstorage/block_blob.go | 7 +++++-- component/azstorage/block_blob_test.go | 13 +++++++++++++ component/azstorage/datalake.go | 7 +++++-- component/azstorage/datalake_test.go | 13 +++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/component/azstorage/azstorage.go b/component/azstorage/azstorage.go index 1cd7e450d..1eb43ddd7 100644 --- a/component/azstorage/azstorage.go +++ b/component/azstorage/azstorage.go @@ -159,7 +159,7 @@ func (az *AzStorage) configureAndTest(isParent bool) error { err = az.storage.TestPipeline() if err != nil { log.Err("AzStorage::configureAndTest : Failed to validate credentials [%s]", err.Error()) - return fmt.Errorf("failed to authenticate credentials for %s", az.Name()) + return fmt.Errorf("failed to authenticate credentials for %s, [%s]", az.Name(), err.Error()) } } diff --git a/component/azstorage/block_blob.go b/component/azstorage/block_blob.go index 07d174451..cbdf04d65 100644 --- a/component/azstorage/block_blob.go +++ b/component/azstorage/block_blob.go @@ -48,6 +48,7 @@ import ( "syscall" "time" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob" @@ -199,8 +200,10 @@ func (bb *BlockBlob) TestPipeline() error { // we are just validating the auth mode used. So, no need to iterate over the pages _, err := listBlobPager.NextPage(context.Background()) if err != nil { - log.Err("BlockBlob::TestPipeline : Failed to validate account with given auth %s", err.Error) - return err + var respErr *azcore.ResponseError + errors.As(err, &respErr) + log.Err("BlockBlob::TestPipeline : Failed to validate account with given auth %s", err.Error()) + return fmt.Errorf("BlockBlob: [%s]", respErr.ErrorCode) } return nil diff --git a/component/azstorage/block_blob_test.go b/component/azstorage/block_blob_test.go index e81ddcdfe..ad1f2ff1a 100644 --- a/component/azstorage/block_blob_test.go +++ b/component/azstorage/block_blob_test.go @@ -335,6 +335,19 @@ func (s *blockBlobTestSuite) TestNoEndpoint() { s.assert.Nil(err) } +func (s *blockBlobTestSuite) TestContainerNotFound() { + defer s.cleanupTest() + // Setup + s.tearDownTestHelper(false) // Don't delete the generated container. + config := fmt.Sprintf("azstorage:\n account-name: %s\n type: block\n account-key: %s\n mode: key\n container: %s\n fail-unsupported-op: true", + storageTestConfigurationParameters.BlockAccount, storageTestConfigurationParameters.BlockKey, "foo") + s.setupTestHelper(config, "foo", false) + + err := s.az.storage.TestPipeline() + s.assert.NotNil(err) + s.assert.Contains(err.Error(), "ContainerNotFound") +} + func (s *blockBlobTestSuite) TestListContainers() { defer s.cleanupTest() // Setup diff --git a/component/azstorage/datalake.go b/component/azstorage/datalake.go index 75793eadb..578366aff 100644 --- a/component/azstorage/datalake.go +++ b/component/azstorage/datalake.go @@ -35,6 +35,7 @@ package azstorage import ( "context" + "errors" "fmt" "net/url" "os" @@ -199,8 +200,10 @@ func (dl *Datalake) TestPipeline() error { // we are just validating the auth mode used. So, no need to iterate over the pages _, err := listPathPager.NextPage(context.Background()) if err != nil { - log.Err("Datalake::TestPipeline : Failed to validate account with given auth %s", err.Error) - return err + var respErr *azcore.ResponseError + errors.As(err, &respErr) + log.Err("Datalake::TestPipeline : Failed to validate account with given auth %s", err.Error()) + return fmt.Errorf("Datalake: [%s]", respErr.ErrorCode) } return dl.BlockBlob.TestPipeline() diff --git a/component/azstorage/datalake_test.go b/component/azstorage/datalake_test.go index 236efd3a8..d4a97165f 100644 --- a/component/azstorage/datalake_test.go +++ b/component/azstorage/datalake_test.go @@ -202,6 +202,19 @@ func (s *datalakeTestSuite) TestNoEndpoint() { s.assert.Nil(err) } +func (s *datalakeTestSuite) TestFileSystemNotFound() { + defer s.cleanupTest() + // Setup + s.tearDownTestHelper(false) // Don't delete the generated container. + config := fmt.Sprintf("azstorage:\n account-name: %s\n type: adls\n account-key: %s\n mode: key\n container: %s\n fail-unsupported-op: true", + storageTestConfigurationParameters.AdlsAccount, storageTestConfigurationParameters.AdlsKey, "foo") + s.setupTestHelper(config, "foo", false) + + err := s.az.storage.TestPipeline() + s.assert.NotNil(err) + s.assert.Contains(err.Error(), "FilesystemNotFound") +} + func (s *datalakeTestSuite) TestListContainers() { defer s.cleanupTest() // Setup From 6d502da9289a9d37b2527bd6357c618c06d26564 Mon Sep 17 00:00:00 2001 From: Srinivas Yeleti Date: Tue, 4 Mar 2025 08:05:54 +0000 Subject: [PATCH 2/6] modify Ouput Strings --- component/azstorage/azstorage.go | 2 +- component/azstorage/block_blob.go | 7 +++++-- component/azstorage/datalake.go | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/component/azstorage/azstorage.go b/component/azstorage/azstorage.go index 1eb43ddd7..e543eedc7 100644 --- a/component/azstorage/azstorage.go +++ b/component/azstorage/azstorage.go @@ -159,7 +159,7 @@ func (az *AzStorage) configureAndTest(isParent bool) error { err = az.storage.TestPipeline() if err != nil { log.Err("AzStorage::configureAndTest : Failed to validate credentials [%s]", err.Error()) - return fmt.Errorf("failed to authenticate credentials for %s, [%s]", az.Name(), err.Error()) + return fmt.Errorf("Failed to Authenticate %s Credentials with Error [%s]", az.Name(), err.Error()) } } diff --git a/component/azstorage/block_blob.go b/component/azstorage/block_blob.go index cbdf04d65..6a177a839 100644 --- a/component/azstorage/block_blob.go +++ b/component/azstorage/block_blob.go @@ -200,10 +200,13 @@ func (bb *BlockBlob) TestPipeline() error { // we are just validating the auth mode used. So, no need to iterate over the pages _, err := listBlobPager.NextPage(context.Background()) if err != nil { + log.Err("BlockBlob::TestPipeline : Failed to validate account with given auth %s", err.Error()) var respErr *azcore.ResponseError errors.As(err, &respErr) - log.Err("BlockBlob::TestPipeline : Failed to validate account with given auth %s", err.Error()) - return fmt.Errorf("BlockBlob: [%s]", respErr.ErrorCode) + if respErr != nil { + return fmt.Errorf("BlockBlob: [%s]", respErr.ErrorCode) + } + return err } return nil diff --git a/component/azstorage/datalake.go b/component/azstorage/datalake.go index 578366aff..1a45a66d0 100644 --- a/component/azstorage/datalake.go +++ b/component/azstorage/datalake.go @@ -200,10 +200,13 @@ func (dl *Datalake) TestPipeline() error { // we are just validating the auth mode used. So, no need to iterate over the pages _, err := listPathPager.NextPage(context.Background()) if err != nil { + log.Err("Datalake::TestPipeline : Failed to validate account with given auth %s", err.Error()) var respErr *azcore.ResponseError errors.As(err, &respErr) - log.Err("Datalake::TestPipeline : Failed to validate account with given auth %s", err.Error()) - return fmt.Errorf("Datalake: [%s]", respErr.ErrorCode) + if respErr != nil { + return fmt.Errorf("Datalake: [%s]", respErr.ErrorCode) + } + return err } return dl.BlockBlob.TestPipeline() From ca919eb434f97cdb17982ff0b2e891e8e4a811f1 Mon Sep 17 00:00:00 2001 From: Srinivas Yeleti Date: Tue, 4 Mar 2025 08:07:32 +0000 Subject: [PATCH 3/6] modify Ouput Strings --- component/azstorage/azstorage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/azstorage/azstorage.go b/component/azstorage/azstorage.go index e543eedc7..e352b2e7f 100644 --- a/component/azstorage/azstorage.go +++ b/component/azstorage/azstorage.go @@ -159,7 +159,7 @@ func (az *AzStorage) configureAndTest(isParent bool) error { err = az.storage.TestPipeline() if err != nil { log.Err("AzStorage::configureAndTest : Failed to validate credentials [%s]", err.Error()) - return fmt.Errorf("Failed to Authenticate %s Credentials with Error [%s]", az.Name(), err.Error()) + return fmt.Errorf("failed to authenticate %s credentials with error [%s]", az.Name(), err.Error()) } } From d1cbd2544e6f0592e300d2d5406474a81df6f137 Mon Sep 17 00:00:00 2001 From: syeleti-msft Date: Tue, 4 Mar 2025 19:18:45 +0530 Subject: [PATCH 4/6] Update component/azstorage/block_blob.go Co-authored-by: Vikas Bhansali <64532198+vibhansa-msft@users.noreply.github.com> --- component/azstorage/block_blob.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/azstorage/block_blob.go b/component/azstorage/block_blob.go index 6a177a839..e5274a042 100644 --- a/component/azstorage/block_blob.go +++ b/component/azstorage/block_blob.go @@ -204,7 +204,7 @@ func (bb *BlockBlob) TestPipeline() error { var respErr *azcore.ResponseError errors.As(err, &respErr) if respErr != nil { - return fmt.Errorf("BlockBlob: [%s]", respErr.ErrorCode) + return fmt.Errorf("BlockBlob::TestPipeline : [%s]", respErr.ErrorCode) } return err } From 1c5a2c12c3492567744f38d0c454e5c0c8cf4c66 Mon Sep 17 00:00:00 2001 From: syeleti-msft Date: Tue, 4 Mar 2025 19:18:57 +0530 Subject: [PATCH 5/6] Update component/azstorage/datalake.go Co-authored-by: Vikas Bhansali <64532198+vibhansa-msft@users.noreply.github.com> --- component/azstorage/datalake.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/azstorage/datalake.go b/component/azstorage/datalake.go index 1a45a66d0..b9d1ce2bf 100644 --- a/component/azstorage/datalake.go +++ b/component/azstorage/datalake.go @@ -204,7 +204,7 @@ func (dl *Datalake) TestPipeline() error { var respErr *azcore.ResponseError errors.As(err, &respErr) if respErr != nil { - return fmt.Errorf("Datalake: [%s]", respErr.ErrorCode) + return fmt.Errorf("Datalake::TestPipeline : [%s]", respErr.ErrorCode) } return err } From 569328b9a8335649deafaad44b59b45f383653f5 Mon Sep 17 00:00:00 2001 From: Srinivas Yeleti Date: Wed, 5 Mar 2025 04:28:42 +0000 Subject: [PATCH 6/6] go fmt --- component/azstorage/block_blob.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component/azstorage/block_blob.go b/component/azstorage/block_blob.go index e5274a042..d4e3e3945 100644 --- a/component/azstorage/block_blob.go +++ b/component/azstorage/block_blob.go @@ -204,7 +204,7 @@ func (bb *BlockBlob) TestPipeline() error { var respErr *azcore.ResponseError errors.As(err, &respErr) if respErr != nil { - return fmt.Errorf("BlockBlob::TestPipeline : [%s]", respErr.ErrorCode) + return fmt.Errorf("BlockBlob::TestPipeline : [%s]", respErr.ErrorCode) } return err }