Class HostConfigEntry

    • Field Detail

      • STD_CONFIG_FILENAME

        public static final String STD_CONFIG_FILENAME
        Standard OpenSSH config file name
        See Also:
        Constant Field Values
      • EXCLUSIVE_IDENTITIES_CONFIG_PROP

        public static final String EXCLUSIVE_IDENTITIES_CONFIG_PROP
        Use only the identities specified in the host entry (if any)
        See Also:
        Constant Field Values
      • DEFAULT_EXCLUSIVE_IDENTITIES

        public static final boolean DEFAULT_EXCLUSIVE_IDENTITIES
        See Also:
        Constant Field Values
      • IDENTITY_AGENT

        public static final String IDENTITY_AGENT
        The IdentityAgent configuration. If not set in the HostConfigEntry, the value of this property is null, which means that a default SSH agent is to be used, if it is running. Other values defined by OpenSSH are:
          none
          No SHH agent is to be used at all, even if one is running.
          SSH_AUTH_SOCK
          The SSH agent listening on the Unix domain socket given by the environment variable SSH_AUTH_SOCK shall be used. If the environment variable is not set, no SSH agent is used.
          other
          For OpenSSH, the value shall resolve to the file name of a Unix domain socket to use to connect to an SSH agent.
        See Also:
        Constant Field Values
      • EXPLICIT_PROPERTIES

        public static final NavigableSet<String> EXPLICIT_PROPERTIES
        A case insensitive NavigableSet of the properties that receive special handling
      • hostName

        protected String hostName
      • port

        protected int port
      • username

        protected String username
      • proxyJump

        protected String proxyJump
      • exclusiveIdentites

        protected Boolean exclusiveIdentites
    • Constructor Detail

      • HostConfigEntry

        public HostConfigEntry()
      • HostConfigEntry

        public HostConfigEntry​(String pattern,
                               String host,
                               int port,
                               String username)
      • HostConfigEntry

        public HostConfigEntry​(String pattern,
                               String host,
                               int port,
                               String username,
                               String proxyJump)
    • Method Detail

      • collate

        public void collate​(HostConfigEntry that)
        Merges that into this via underride. That is, any value present in this entry takes precedence over the given entry. Only this object is modified. The given entry remains unchanged.
        Parameters:
        that - The HostConfigEntry to merge.
      • getHost

        public String getHost()
        Returns:
        The pattern(s) represented by this entry
      • setHost

        public void setHost​(String host)
      • getHostName

        public String getHostName()
        Returns:
        The effective host name to connect to if the pattern matches
      • setHostName

        public void setHostName​(String hostName)
      • getPort

        public int getPort()
        Returns:
        A port override - if positive
      • setPort

        public void setPort​(int port)
      • getProxyJump

        public String getProxyJump()
        Returns:
        the host to use as a proxy
      • setProxyJump

        public void setProxyJump​(String proxyJump)
      • getIdentities

        public Collection<String> getIdentities()
        Returns:
        The current identities file paths - may be null/empty
      • addIdentity

        public void addIdentity​(Path path)
        Parameters:
        path - A Path to a file that contains an identity key - never null
      • addIdentity

        public void addIdentity​(String id)
        Adds a path to an identity file
        Parameters:
        id - The identity path to add - never null
      • isIdentitiesOnly

        public boolean isIdentitiesOnly()
        Returns:
        true if must use only the identities in this entry
      • setIdentitiesOnly

        public void setIdentitiesOnly​(boolean identitiesOnly)
      • getProperties

        public Map<String,​String> getProperties()
        Returns:
        A Map of extra properties that have been read - may be null/empty, or even contain some values that have been parsed and set as members of the entry (e.g., host, port, etc.). Note: multi-valued keys use a comma-separated list of values
      • getProperty

        public String getProperty​(String name)
        Parameters:
        name - Property name - never null/empty
        Returns:
        Property value or null if no such property
        See Also:
        getProperty(String, String)
      • getProperty

        public String getProperty​(String name,
                                  String defaultValue)
        Parameters:
        name - Property name - never null/empty
        defaultValue - Default value to return if no such property
        Returns:
        The property value or the default one if no such property
      • appendPropertyValue

        public String appendPropertyValue​(String name,
                                          String value)
        Appends a value using a comma to an existing one. If no previous value then same as calling setProperty(String, String).
        Parameters:
        name - Property name - never null/empty
        value - The value to be appended - ignored if null/empty
        Returns:
        The value before appending - null if no previous value
      • setProperty

        public String setProperty​(String name,
                                  String value)
        Sets / Replaces the property value
        Parameters:
        name - Property name - never null/empty
        value - Property value - if null/empty then removeProperty(String) is called
        Returns:
        The previous property value - null if no such name
      • removeProperty

        public String removeProperty​(String name)
        Parameters:
        name - Property name - never null/empty
        Returns:
        The removed property value - null if no such property name
      • setProperties

        public void setProperties​(Map<String,​String> properties)
        Parameters:
        properties - The properties to set - if null then an empty map is effectively set. Note: it is highly recommended to use a case insensitive key mapper.
      • appendNonEmptyPort

        public static <A extends Appendable> A appendNonEmptyPort​(A sb,
                                                                  String name,
                                                                  int port)
                                                           throws IOException
        Type Parameters:
        A - The Appendable type
        Parameters:
        sb - The target appender
        name - The property name - never null/empty
        port - The port value - ignored if non-positive
        Returns:
        The target appender after having appended (or not) the value
        Throws:
        IOException - If failed to append the requested data
        See Also:
        appendNonEmptyProperty(Appendable, String, Object)
      • appendNonEmptyProperty

        public static <A extends Appendable> A appendNonEmptyProperty​(A sb,
                                                                      String name,
                                                                      Object value)
                                                               throws IOException
        Type Parameters:
        A - The Appendable type
        Parameters:
        sb - The target appender
        name - The property name - never null/empty
        value - The property value - ignored if null. Note: if the string representation of the value contains any commas, they are assumed to indicate a multi-valued property which is broken down to individual lines - one per value.
        Returns:
        The target appender after having appended (or not) the value
        Throws:
        IOException - If failed to append the requested data
        See Also:
        appendNonEmptyValues(Appendable, String, Object...)
      • appendNonEmptyValues

        public static <A extends Appendable> A appendNonEmptyValues​(A sb,
                                                                    String name,
                                                                    Object... values)
                                                             throws IOException
        Type Parameters:
        A - The Appendable type
        Parameters:
        sb - The target appender
        name - The property name - never null/empty
        values - The values to be added - one per line - ignored if null/empty
        Returns:
        The target appender after having appended (or not) the value
        Throws:
        IOException - If failed to append the requested data
        See Also:
        appendNonEmptyValues(Appendable, String, Collection)
      • appendNonEmptyValues

        public static <A extends Appendable> A appendNonEmptyValues​(A sb,
                                                                    String name,
                                                                    Collection<?> values)
                                                             throws IOException
        Type Parameters:
        A - The Appendable type
        Parameters:
        sb - The target appender
        name - The property name - never null/empty
        values - The values to be added - one per line - ignored if null/empty
        Returns:
        The target appender after having appended (or not) the value
        Throws:
        IOException - If failed to append the requested data
      • parseConfigValue

        public static List<String> parseConfigValue​(String value)
        Checks if this is a multi-value - allow space and comma
        Parameters:
        value - The value - ignored if null/empty (after trimming)
        Returns:
        A List of the encountered values
      • getDefaultHostConfigFile

        public static Path getDefaultHostConfigFile()
        Returns:
        The default Path location of the OpenSSH hosts entries configuration file