aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/platform
diff options
context:
space:
mode:
authorGravatar Michael Banfield <micban@google.com>2018-08-09 13:45:35 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-08-09 13:49:03 -0700
commit874437315670566611808674ec5a0741ae557314 (patch)
tree3997027ae6952155a34dc6a0c94a90db4c5b2a29 /tensorflow/core/platform
parent9e39a9bacb29ffc3c5c7d61729d4fd54c203ebf5 (diff)
Make allowed bucket locations case insensitive.
PiperOrigin-RevId: 208104156
Diffstat (limited to 'tensorflow/core/platform')
-rw-r--r--tensorflow/core/platform/cloud/gcs_file_system.cc16
-rw-r--r--tensorflow/core/platform/cloud/gcs_file_system_test.cc12
2 files changed, 17 insertions, 11 deletions
diff --git a/tensorflow/core/platform/cloud/gcs_file_system.cc b/tensorflow/core/platform/cloud/gcs_file_system.cc
index 67c872ac67..9d33787bd5 100644
--- a/tensorflow/core/platform/cloud/gcs_file_system.cc
+++ b/tensorflow/core/platform/cloud/gcs_file_system.cc
@@ -618,9 +618,11 @@ bool StringPieceIdentity(StringPiece str, StringPiece* value) {
}
/// \brief Utility function to split a comma delimited list of strings to an
-/// unordered set
-bool SplitByCommaToSet(StringPiece list, std::unordered_set<string>* set) {
- std::vector<string> vector = str_util::Split(list, ",");
+/// unordered set, lowercasing all values.
+bool SplitByCommaToLowercaseSet(StringPiece list,
+ std::unordered_set<string>* set) {
+ std::vector<string> vector =
+ str_util::Split(tensorflow::str_util::Lowercase(list), ",");
*set = std::unordered_set<string>(vector.begin(), vector.end());
return true;
}
@@ -778,7 +780,8 @@ GcsFileSystem::GcsFileSystem() {
throttle_.SetConfig(config);
}
- GetEnvVar(kAllowedBucketLocations, SplitByCommaToSet, &allowed_locations_);
+ GetEnvVar(kAllowedBucketLocations, SplitByCommaToLowercaseSet,
+ &allowed_locations_);
}
GcsFileSystem::GcsFileSystem(
@@ -1155,8 +1158,11 @@ Status GcsFileSystem::GetBucketLocation(const string& bucket,
Status status = GetBucketMetadata(bucket, &result_buffer);
Json::Value result;
TF_RETURN_IF_ERROR(ParseJson(result_buffer, &result));
+ string bucket_location;
TF_RETURN_IF_ERROR(
- GetStringValue(result, kBucketMetadataLocationKey, location));
+ GetStringValue(result, kBucketMetadataLocationKey, &bucket_location));
+ // Lowercase the GCS location to be case insensitive for allowed locations.
+ *location = tensorflow::str_util::Lowercase(bucket_location);
return Status::OK();
};
diff --git a/tensorflow/core/platform/cloud/gcs_file_system_test.cc b/tensorflow/core/platform/cloud/gcs_file_system_test.cc
index ee2b034d74..14376ad339 100644
--- a/tensorflow/core/platform/cloud/gcs_file_system_test.cc
+++ b/tensorflow/core/platform/cloud/gcs_file_system_test.cc
@@ -98,7 +98,7 @@ TEST(GcsFileSystemTest,
"Timeouts: 5 1 10\n",
R"(
{
- "location":"us-east1"
+ "location":"US-EAST1"
})")});
GcsFileSystem fs(std::unique_ptr<AuthProvider>(new FakeAuthProvider),
@@ -124,7 +124,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithLocationConstraintCaching) {
"Timeouts: 5 1 10\n",
R"(
{
- "location":"us-east1"
+ "location":"US-EAST1"
})"),
new FakeHttpRequest(
"Uri: https://www.googleapis.com/storage/v1/b/anotherbucket\n"
@@ -132,7 +132,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithLocationConstraintCaching) {
"Timeouts: 5 1 10\n",
R"(
{
- "location":"us-east1"
+ "location":"US-EAST1"
})"),
new FakeHttpRequest(
"Uri: https://www.googleapis.com/storage/v1/b/bucket\n"
@@ -140,7 +140,7 @@ TEST(GcsFileSystemTest, NewRandomAccessFile_WithLocationConstraintCaching) {
"Timeouts: 5 1 10\n",
R"(
{
- "location":"us-east1"
+ "location":"US-EAST1"
})")});
GcsFileSystem fs(std::unique_ptr<AuthProvider>(new FakeAuthProvider),
@@ -181,7 +181,7 @@ TEST(GcsFileSystemTest,
"Timeouts: 5 1 10\n",
R"(
{
- "location":"barfoo"
+ "location":"BARFOO"
})")});
GcsFileSystem fs(std::unique_ptr<AuthProvider>(new FakeAuthProvider),
@@ -3076,7 +3076,7 @@ TEST(GcsFileSystemTest, BucketLocationConstraintEnvironmentVariableTest) {
GcsFileSystem fs1;
EXPECT_EQ(*kAllowedLocationsAuto, fs1.allowed_locations());
- setenv("GCS_ALLOWED_BUCKET_LOCATIONS", "custom,list", 1);
+ setenv("GCS_ALLOWED_BUCKET_LOCATIONS", "CUSTOM,list", 1);
GcsFileSystem fs2;
EXPECT_EQ(std::unordered_set<string>({"custom", "list"}),
fs2.allowed_locations());