Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/465#discussion_r23465125
  
    --- Diff: 
core/src/main/java/brooklyn/location/basic/LocationConfigUtils.java ---
    @@ -20,39 +20,355 @@
     
     import static brooklyn.util.JavaGroovyEquivalents.groovyTruth;
     
    +import java.io.ByteArrayInputStream;
     import java.io.File;
    -import java.io.IOException;
    +import java.security.KeyPair;
    +import java.security.PublicKey;
     import java.util.Arrays;
    +import java.util.Iterator;
     import java.util.List;
     import java.util.Map;
    +import java.util.Set;
     
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
     import brooklyn.config.ConfigKey;
     import brooklyn.entity.basic.ConfigKeys;
    +import brooklyn.internal.BrooklynFeatureEnablement;
    +import brooklyn.location.cloud.CloudLocationConfig;
     import brooklyn.management.ManagementContext;
    +import brooklyn.util.ResourceUtils;
     import brooklyn.util.collections.MutableMap;
    +import brooklyn.util.collections.MutableSet;
     import brooklyn.util.config.ConfigBag;
    +import brooklyn.util.crypto.AuthorizedKeysParser;
    +import brooklyn.util.crypto.SecureKeys;
    +import brooklyn.util.crypto.SecureKeys.PassphraseProblem;
    +import brooklyn.util.exceptions.Exceptions;
     import brooklyn.util.os.Os;
     import brooklyn.util.text.StringFunctions;
     import brooklyn.util.text.Strings;
     
    -import com.google.common.base.Charsets;
     import com.google.common.base.Objects;
     import com.google.common.collect.ImmutableList;
     import com.google.common.collect.Iterables;
     import com.google.common.collect.Lists;
    -import com.google.common.io.Files;
     
     public class LocationConfigUtils {
     
         private static final Logger log = 
LoggerFactory.getLogger(LocationConfigUtils.class);
    +
    +    /** Creates an instance of {@link OsCredential} by inspecting {@link 
LocationConfigKeys#PASSWORD}; 
    +     * {@link LocationConfigKeys#PRIVATE_KEY_DATA} and {@link 
LocationConfigKeys#PRIVATE_KEY_FILE};
    +     * {@link LocationConfigKeys#PRIVATE_KEY_PASSPHRASE} if needed, and
    +     * {@link LocationConfigKeys#PRIVATE_KEY_DATA} and {@link 
LocationConfigKeys#PRIVATE_KEY_FILE}
    +     * (defaulting to the private key file + ".pub"). 
    +     **/
    +    public static OsCredential getOsCredential(ConfigBag config) {
    +        return OsCredential.newInstance(config);
    +    }
         
    +    /** Convenience class for holding private/public keys and passwords, 
inferring from config keys.
    +     * See {@link LocationConfigUtils#getOsCredential(ConfigBag)}. */
    +    public static class OsCredential {
    --- End diff --
    
    This code would be cleaner if there was a separate builder, and then 
OsCredential was immutable. With that pattern, we wouldn't need calls to 
`infer()` in each method, or the `dirty()`. We'd also have a clearer separation 
of which fields are for configuring it, and which are about the actual state 
(and thus behaviour of the constructed `OsCredential`).
    
    It would also hide the many builder methods from users of the 
`OsCredential`, simplifying things for such programmers.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to