diff --git a/compute/src/main/java/org/jclouds/compute/functions/DefaultCredentialsFromImageOrOverridingCredentials.java b/compute/src/main/java/org/jclouds/compute/functions/DefaultCredentialsFromImageOrOverridingCredentials.java index 6bc8f8fd61..5689f2ebed 100644 --- a/compute/src/main/java/org/jclouds/compute/functions/DefaultCredentialsFromImageOrOverridingCredentials.java +++ b/compute/src/main/java/org/jclouds/compute/functions/DefaultCredentialsFromImageOrOverridingCredentials.java @@ -21,9 +21,10 @@ package org.jclouds.compute.functions; import javax.inject.Singleton; import org.jclouds.compute.domain.Template; -import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials.Builder; +import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Function; @@ -36,8 +37,14 @@ public class DefaultCredentialsFromImageOrOverridingCredentials implements Funct @Override public LoginCredentials apply(Template template) { - TemplateOptions options = template.getOptions(); - Builder builder = LoginCredentials.builder(template.getImage().getDefaultCredentials()); + RunScriptOptions options = template.getOptions(); + LoginCredentials defaultCreds = template.getImage().getDefaultCredentials(); + return overrideDefaultCredentialsWithOptionsIfPresent(defaultCreds, options); + } + + public static LoginCredentials overrideDefaultCredentialsWithOptionsIfPresent( + @Nullable LoginCredentials defaultCreds, RunScriptOptions options) { + Builder builder = LoginCredentials.builder(defaultCreds); if (options.getLoginUser() != null) builder.user(options.getLoginUser()); if (options.getLoginPassword() != null) diff --git a/compute/src/main/java/org/jclouds/compute/options/RunScriptOptions.java b/compute/src/main/java/org/jclouds/compute/options/RunScriptOptions.java index 4c6ce0e0e4..41a49bdb0c 100644 --- a/compute/src/main/java/org/jclouds/compute/options/RunScriptOptions.java +++ b/compute/src/main/java/org/jclouds/compute/options/RunScriptOptions.java @@ -21,6 +21,7 @@ package org.jclouds.compute.options; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.domain.Credentials; import org.jclouds.domain.LoginCredentials; import org.jclouds.javax.annotation.Nullable; @@ -330,6 +331,18 @@ public class RunScriptOptions { return authenticateSudo; } + /** + * This will be removed in jclouds 1.4.0 + * @see #getLoginPassword + * @see #getLoginPrivateKey + * @see #getLoginUser + */ + @Deprecated + public Credentials getOverridingCredentials() { + return DefaultCredentialsFromImageOrOverridingCredentials.overrideDefaultCredentialsWithOptionsIfPresent(null, + this); + } + /** * * @return the login password for