2424import java .io .PrintStream ;
2525import java .nio .charset .StandardCharsets ;
2626import java .util .ArrayList ;
27+ import java .util .HashSet ;
2728import java .util .List ;
2829import java .util .Map ;
2930import java .util .Properties ;
31+ import java .util .Set ;
3032import java .util .concurrent .ExecutorService ;
3133import java .util .concurrent .Executors ;
3234import java .util .concurrent .ThreadFactory ;
@@ -101,8 +103,10 @@ public static void main(String[] args) throws Exception {
101103 .build ();
102104 ExecutorService executorService = DynamicExecutors .newScalingThreadPool (
103105 1 , 20 , 60 * 1000 , factory );
104- ImmutableMap .Builder <String , Map .Entry <String , BlobStore >> locators =
106+ ImmutableMap .Builder <Map .Entry <String , String >,
107+ Map .Entry <String , BlobStore >> locators =
105108 ImmutableMap .builder ();
109+ Set <Map .Entry <String , String >> parsedLocations = new HashSet <>();
106110 for (File propertiesFile : options .propertiesFiles ) {
107111 Properties properties = new Properties ();
108112 try (InputStream is = new FileInputStream (propertiesFile )) {
@@ -117,14 +121,43 @@ public static void main(String[] args) throws Exception {
117121
118122 String s3ProxyAuthorizationString = properties .getProperty (
119123 S3ProxyConstants .PROPERTY_AUTHORIZATION );
124+ ImmutableList .Builder <String > locatorBuckets =
125+ new ImmutableList .Builder <>();
126+ for (String key : properties .stringPropertyNames ()) {
127+ if (key .startsWith (S3ProxyConstants .PROPERTY_BUCKET_LOCATOR )) {
128+ locatorBuckets .add (properties .getProperty (key ));
129+ }
130+ }
131+ ImmutableList <String > buckets = locatorBuckets .build ();
132+ String localIdentity = null ;
133+ String localCredential = null ;
120134 if (AuthenticationType .fromString (s3ProxyAuthorizationString ) !=
121135 AuthenticationType .NONE ) {
122- String localIdentity = properties .getProperty (
136+ localIdentity = properties .getProperty (
123137 S3ProxyConstants .PROPERTY_IDENTITY );
124- String localCredential = properties .getProperty (
138+ localCredential = properties .getProperty (
125139 S3ProxyConstants .PROPERTY_CREDENTIAL );
126- locators .put (localIdentity , Maps .immutableEntry (
127- localCredential , blobStore ));
140+ Map .Entry <String , String > key = Maps .immutableEntry (
141+ localIdentity , null );
142+ if (!parsedLocations .contains (key )) {
143+ locators .put (key , Maps .immutableEntry (
144+ localCredential , blobStore ));
145+ parsedLocations .add (key );
146+ }
147+ }
148+ if (!buckets .isEmpty ()) {
149+ for (String bucket : buckets ) {
150+ Map .Entry <String , String > key = Maps .immutableEntry (
151+ localIdentity , bucket );
152+ if (!parsedLocations .add (key )) {
153+ System .err .printf ("The same bucket locator cannot be" +
154+ " used in two properties files: %s\n " ,
155+ bucket );
156+ System .exit (1 );
157+ }
158+ locators .put (key ,
159+ Maps .immutableEntry (localCredential , blobStore ));
160+ }
128161 }
129162
130163 S3Proxy .Builder s3ProxyBuilder2 = S3Proxy .Builder
@@ -149,23 +182,22 @@ public static void main(String[] args) throws Exception {
149182 throw e ;
150183 }
151184
152- final Map <String , Map .Entry <String , BlobStore >> locator =
153- locators .build ();
185+ final Map <Map . Entry < String , String >, Map .Entry <String , BlobStore >>
186+ locator = locators .build ();
154187 if (!locator .isEmpty ()) {
155188 s3Proxy .setBlobStoreLocator (new BlobStoreLocator () {
156189 @ Override
157190 public Map .Entry <String , BlobStore > locateBlobStore (
158191 String identity , String container , String blob ) {
192+ Map .Entry <String , BlobStore > entry = locator .get (
193+ Maps .immutableEntry (identity , container ));
194+ if (entry != null ) {
195+ return entry ;
196+ }
159197 if (identity == null ) {
160- if (locator .size () == 1 ) {
161- return locator .entrySet ().iterator ().next ()
162- .getValue ();
163- }
164- throw new IllegalArgumentException (
165- "cannot use anonymous access with multiple" +
166- " backends" );
198+ return locator .entrySet ().iterator ().next ().getValue ();
167199 }
168- return locator .get (identity );
200+ return locator .get (Maps . immutableEntry ( identity , null ) );
169201 }
170202 });
171203 }
0 commit comments