@@ -184,9 +184,20 @@ std::string errno_to_string() {
184
184
}
185
185
186
186
std::shared_ptr<azure::storage_lite::storage_credential> get_credential (
187
- const std::string& account) {
188
- const auto key = std::getenv (" TF_AZURE_STORAGE_KEY" );
189
- if (key != nullptr ) {
187
+ const std::string& account, const std::string& container) {
188
+ const std::string sas_account_container_env =
189
+ " TF_AZURE_STORAGE_" + account + " _" + container + " _SAS" ;
190
+ const std::string sas_account_env = " TF_AZURE_STORAGE_" + account + " _SAS" ;
191
+ if (const auto sas = std::getenv (sas_account_container_env.c_str ())) {
192
+ return std::make_shared<
193
+ azure::storage_lite::shared_access_signature_credential>(sas);
194
+ } else if (const auto sas = std::getenv (sas_account_env.c_str ())) {
195
+ return std::make_shared<
196
+ azure::storage_lite::shared_access_signature_credential>(sas);
197
+ } else if (const auto sas = std::getenv (" TF_AZURE_STORAGE_SAS" )) {
198
+ return std::make_shared<
199
+ azure::storage_lite::shared_access_signature_credential>(sas);
200
+ } else if (const auto key = std::getenv (" TF_AZURE_STORAGE_KEY" )) {
190
201
return std::make_shared<azure::storage_lite::shared_key_credential>(account,
191
202
key);
192
203
} else {
@@ -195,7 +206,7 @@ std::shared_ptr<azure::storage_lite::storage_credential> get_credential(
195
206
}
196
207
197
208
azure::storage_lite::blob_client_wrapper CreateAzBlobClientWrapper (
198
- const std::string& account) {
209
+ const std::string& account, const std::string& container ) {
199
210
azure::storage_lite::logger::set_logger (
200
211
[](azure::storage_lite::log_level level, const std::string& log_msg) {
201
212
switch (level) {
@@ -232,7 +243,7 @@ azure::storage_lite::blob_client_wrapper CreateAzBlobClientWrapper(
232
243
const auto blob_endpoint =
233
244
std::string (blob_endpoint_env ? blob_endpoint_env : " " );
234
245
235
- auto credentials = get_credential (account);
246
+ auto credentials = get_credential (account, container );
236
247
auto storage_account = std::make_shared<azure::storage_lite::storage_account>(
237
248
account, credentials, use_https, blob_endpoint);
238
249
auto blob_client =
@@ -324,10 +335,12 @@ class AzBlobRandomAccessFile {
324
335
TF_SetStatus (status, TF_OK, " " );
325
336
return 0 ;
326
337
}
327
- auto blob_client = CreateAzBlobClientWrapper (account_);
338
+ auto blob_client = CreateAzBlobClientWrapper (account_, container_ );
328
339
auto blob_property = blob_client.get_blob_property (container_, object_);
329
340
if (errno != 0 ) {
330
- TF_SetStatus (status, TF_INTERNAL, " Failed to get properties" );
341
+ std::string error_message =
342
+ absl::StrCat (" Failed to get properties " , errno);
343
+ TF_SetStatus (status, TF_INTERNAL, error_message.c_str ());
331
344
return 0 ;
332
345
}
333
346
int64_t file_size = blob_property.size ;
@@ -433,7 +446,7 @@ class AzBlobWritableFile {
433
446
return ;
434
447
}
435
448
436
- auto blob_client = CreateAzBlobClientWrapper (account_);
449
+ auto blob_client = CreateAzBlobClientWrapper (account_, container_ );
437
450
blob_client.upload_file_to_blob (tmp_content_filename_, container_, object_);
438
451
if (errno != 0 ) {
439
452
std::string error_message =
@@ -476,7 +489,7 @@ Status GetMatchingPaths(const std::string& pattern, std::vector<std::string>* re
476
489
TF_RETURN_IF_ERROR(
477
490
ParseAzBlobPathClass(fixed_prefix, true, &account, &container, &object));
478
491
479
- auto blob_client = CreateAzBlobClientWrapper(account);
492
+ auto blob_client = CreateAzBlobClientWrapper(account, container );
480
493
481
494
std::vector<std::string> blobs;
482
495
TF_RETURN_IF_ERROR(ListResources(fixed_prefix, "", blob_client, &blobs));
@@ -637,7 +650,7 @@ static void CreateDir(const TF_Filesystem* filesystem, const char* path,
637
650
}
638
651
639
652
// Blob storage has virtual folders. We can make sure the container exists
640
- auto blob_client_wrapper = CreateAzBlobClientWrapper (account);
653
+ auto blob_client_wrapper = CreateAzBlobClientWrapper (account, container );
641
654
642
655
if (blob_client_wrapper.container_exists (container)) {
643
656
TF_SetStatus (status, TF_OK, " " );
@@ -667,7 +680,7 @@ static void DeleteFile(const TF_Filesystem* filesystem, const char* path,
667
680
return ;
668
681
}
669
682
670
- auto blob_client = CreateAzBlobClientWrapper (account);
683
+ auto blob_client = CreateAzBlobClientWrapper (account, container );
671
684
672
685
blob_client.delete_blob (container, object);
673
686
if (errno != 0 ) {
@@ -698,7 +711,7 @@ static void DeleteDir(const TF_Filesystem* filesystem, const char* path,
698
711
return ;
699
712
}
700
713
701
- auto blob_client = CreateAzBlobClientWrapper (account);
714
+ auto blob_client = CreateAzBlobClientWrapper (account, container );
702
715
703
716
// Check container exists
704
717
// Just pull out the first path component representing the container
@@ -764,7 +777,7 @@ static void RenameFile(const TF_Filesystem* filesystem, const char* src,
764
777
return ;
765
778
}
766
779
767
- auto blob_client = CreateAzBlobClientWrapper (src_account);
780
+ auto blob_client = CreateAzBlobClientWrapper (src_account, src_container );
768
781
769
782
blob_client.start_copy (src_container, src_object, dst_container, dst_object);
770
783
if (errno != 0 ) {
@@ -860,7 +873,7 @@ static void PathExists(const TF_Filesystem* filesystem, const char* path,
860
873
return ;
861
874
}
862
875
863
- auto blob_client = CreateAzBlobClientWrapper (account);
876
+ auto blob_client = CreateAzBlobClientWrapper (account, container );
864
877
auto blob_exists = blob_client.blob_exists (container, object);
865
878
if (errno != 0 ) {
866
879
std::string error_message = absl::StrCat (
@@ -889,7 +902,7 @@ static bool IsDirectory(const TF_Filesystem* filesystem, const char* path,
889
902
return false ;
890
903
}
891
904
892
- auto blob_client = CreateAzBlobClientWrapper (account);
905
+ auto blob_client = CreateAzBlobClientWrapper (account, container );
893
906
894
907
if (container.empty ()) {
895
908
TF_SetStatus (status, TF_UNIMPLEMENTED,
@@ -935,7 +948,7 @@ static void Stat(const TF_Filesystem* filesystem, const char* path,
935
948
return ;
936
949
}
937
950
938
- auto blob_client = CreateAzBlobClientWrapper (account);
951
+ auto blob_client = CreateAzBlobClientWrapper (account, container );
939
952
940
953
if (IsDirectory (filesystem, path, status)) {
941
954
stats->length = 0 ;
@@ -972,7 +985,7 @@ static int GetChildren(const TF_Filesystem* filesystem, const char* path,
972
985
return 0 ;
973
986
}
974
987
975
- auto blob_client = CreateAzBlobClientWrapper (account);
988
+ auto blob_client = CreateAzBlobClientWrapper (account, container );
976
989
977
990
std::string continuation_token;
978
991
if (container.empty ()) {
@@ -1049,7 +1062,7 @@ static int64_t GetFileSize(const TF_Filesystem* filesystem, const char* path,
1049
1062
return 0 ;
1050
1063
}
1051
1064
1052
- auto blob_client = CreateAzBlobClientWrapper (account);
1065
+ auto blob_client = CreateAzBlobClientWrapper (account, container );
1053
1066
auto blob_property = blob_client.get_blob_property (container, object);
1054
1067
if (errno != 0 ) {
1055
1068
std::string error_message = absl::StrCat (
0 commit comments