nacx commented on a change in pull request #88:
URL: https://github.com/apache/jclouds/pull/88#discussion_r522859800



##########
File path: 
providers/azureblob/src/test/java/org/jclouds/azure/storage/util/StorageUrlDelegateTest.java
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.azure.storage.util;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Properties;
+
+import org.jclouds.ContextBuilder;
+import org.jclouds.azure.storage.reference.AzureConstants;
+import org.jclouds.logging.config.NullLoggingModule;
+import org.jclouds.rest.internal.BaseRestApiTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Module;
+
+@Test(groups = "unit")
+public class StorageUrlDelegateTest {
+
+   private static final String ACCOUNT = "foo";
+   private static final ImmutableSet<Module> MODULES = ImmutableSet.<Module> 
of(new BaseRestApiTest.MockModule(),
+         new NullLoggingModule());
+
+   @Test
+   void testDefaultEndpoint() {
+
+      StorageUrlDelegate target = ContextBuilder
+            .newBuilder("azureblob")
+            .credentials(ACCOUNT, "?token")
+            .modules(MODULES)
+            .buildInjector().getInstance(StorageUrlDelegate.class);
+
+      assertEquals(target.configureStorageUrl(), 
"https://foo.blob.core.windows.net/";);
+   }
+
+   @Test
+   void testCustomEndpointWithoutStorageAccountPath() {
+
+      StorageUrlDelegate target = ContextBuilder
+            .newBuilder("azureblob").endpoint("http://localhost:10000";)
+            .credentials(ACCOUNT, "?token")
+            .modules(MODULES)
+            .buildInjector()
+            .getInstance(StorageUrlDelegate.class);
+
+      assertEquals(target.configureStorageUrl(), "http://localhost:10000/";);

Review comment:
       The problem here is that given random endpoints, we can't preconfigure a 
correct way of setting the account for every possible case. What bout this:
   
   Let's change the `StorageUrlDelegate` to an interface like this:
   ```java
   @ImplementedBy(StorageAccountInVhost.class)
   public interface StorageURLSupplier extends Supplier<URI> {
   }
   ```
   And have the default implementation be `StorageAccountInVhost`, which just 
keeps the current behavior, with the hardcoded endpoint and the identity in the 
host.
   
   Then we could have a:
   ```java
   public class AppendAccountToEndpoint implements StorageURLSupplier
   ```
   That just appends the identity to whatever endpoint is configured.
   
   To make it easier to configure, we could have a Guice module as well that 
does this (but is not included by default in the azure blob modules list:
   ```java
   public class AppendAccountToEndpointModule extends AbstractModule {
      @Override
      protected void configure() {
         bind(StorageURLSupplier.class).to(AppendAccountToEndpoint.class);
      }
   }
   ```
   With these three pieces there, you can plug in your storage URL strategy 
when creating the context by adding the `AppendAccountToEndpointModule` to the 
list of modules.
   
   This way we don't need the property, achieve the same behavior, but we also 
allow users to customize this further, as they can provide their own module to 
configure how the identity should be added to the endpoint.
   This approach may seem overkill, but it ensures correctness in configuration.
   
   WDYT?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to