From 7b72ef5cfcf45328c2e268ab651007bc57a63ce7 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 1 Dec 2011 19:05:35 -0500 Subject: [PATCH] reinstated arg so that we are binary compatible for drop-in w/whirr --- ...CredentialsFromImageOrOverridingCredentials.java | 13 ++++++++++--- .../jclouds/compute/options/RunScriptOptions.java | 13 +++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) 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