diff --git a/core/src/main/java/org/jclouds/ContextBuilder.java b/core/src/main/java/org/jclouds/ContextBuilder.java index 106c28f0e7..2d28474026 100644 --- a/core/src/main/java/org/jclouds/ContextBuilder.java +++ b/core/src/main/java/org/jclouds/ContextBuilder.java @@ -297,11 +297,17 @@ public class ContextBuilder { Properties unexpanded = currentStateToUnexpandedProperties(); - ImmutableSet keysToResolve = ImmutableSet.of(PROPERTY_ENDPOINT, PROPERTY_IDENTITY, PROPERTY_CREDENTIAL, - PROPERTY_API, PROPERTY_API_VERSION, PROPERTY_BUILD_VERSION); + Set keysToResolve = ImmutableSet.of(PROPERTY_IDENTITY, PROPERTY_CREDENTIAL, PROPERTY_ENDPOINT, + PROPERTY_API, PROPERTY_API_VERSION, PROPERTY_BUILD_VERSION); - ImmutableSet optionalKeys = apiMetadata.getCredentialName().isPresent() ? ImmutableSet. of() - : ImmutableSet.of(PROPERTY_CREDENTIAL); + Set optionalKeys; + if (credentialsSupplierOption.isPresent()) { + optionalKeys = ImmutableSet.of(PROPERTY_IDENTITY, PROPERTY_CREDENTIAL); + } else if (!apiMetadata.getCredentialName().isPresent()) { + optionalKeys = ImmutableSet.of(PROPERTY_CREDENTIAL); + } else { + optionalKeys = ImmutableSet.of(); + } Properties resolved = resolveProperties(unexpanded, providerId, keysToResolve, optionalKeys); @@ -401,8 +407,8 @@ public class ContextBuilder { String scopedProperty = ImmutableList.copyOf(Splitter.on('.').split(key)).get(1); mutable.setProperty(key, searchPropertiesForProviderScopedProperty(mutable, providerId,scopedProperty)); } catch (NoSuchElementException e){ - if (!optionalKeys.contains(key)) - throw e; + if (!optionalKeys.contains(key)) + throw e; } } return mutable; diff --git a/core/src/test/java/org/jclouds/ContextBuilderTest.java b/core/src/test/java/org/jclouds/ContextBuilderTest.java index 7d24ffac3d..a6a89d8ee3 100644 --- a/core/src/test/java/org/jclouds/ContextBuilderTest.java +++ b/core/src/test/java/org/jclouds/ContextBuilderTest.java @@ -64,10 +64,7 @@ public class ContextBuilderTest { @ConfiguresHttpCommandExecutorService static class HttpModule extends AbstractModule { - - @Override protected void configure() { - } } @@ -124,9 +121,6 @@ public class ContextBuilderTest { @Test public void testProviderMetadataWithCredentialsSetSupplier() { - Properties overrides = new Properties(); - overrides.setProperty(Constants.PROPERTY_IDENTITY, "foo"); - overrides.setProperty(Constants.PROPERTY_CREDENTIAL, "BAR"); ContextBuilder withCredsSupplier = testContextBuilder().credentialsSupplier( ofInstance(new Credentials("foo", "BAR"))); Credentials creds = withCredsSupplier.buildInjector() @@ -239,14 +233,10 @@ public class ContextBuilderTest { public void testBuilder() { Module module1 = new AbstractModule() { - - @Override protected void configure() { } }; Module module2 = new AbstractModule() { - - @Override protected void configure() { } };