Class OpenSshConfigFile.HostEntry

  • All Implemented Interfaces:
    SshConfigStore.HostConfig
    Enclosing class:
    OpenSshConfigFile

    public static class OpenSshConfigFile.HostEntry
    extends java.lang.Object
    implements SshConfigStore.HostConfig
    A host entry from the ssh config file. Any merging of global values and of several matching host entries, %-substitutions, and ~ replacement have all been done.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<java.lang.String,​java.lang.String> ALIASES
      OpenSSH has renamed some config keys.
      private static java.util.Set<java.lang.String> LIST_KEYS
      Keys that take a whitespace-separated list of elements as argument.
      private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> listOptions  
      private static java.util.Set<java.lang.String> MULTI_KEYS
      Keys that can be specified multiple times, building up a list.
      private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> multiOptions  
      private java.util.Map<java.lang.String,​java.lang.String> options  
      private java.util.List<java.lang.String> patterns  
    • Constructor Summary

      Constructors 
      Constructor Description
      HostEntry()
      Constructor used to build the merged entry; never matches anything
      HostEntry​(java.util.List<java.lang.String> patterns)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getMultiValuedOptions()
      Retrieves an unmodifiable map of all multi-valued options, with case-insensitive lookup by keys.
      java.util.Map<java.lang.String,​java.lang.String> getOptions()
      Retrieves an unmodifiable map of all single-valued options, with case-insensitive lookup by keys.
      java.lang.String getValue​(java.lang.String key)
      Retrieves the value of a single-valued key, or the first if the key has multiple values.
      java.util.List<java.lang.String> getValues​(java.lang.String key)
      Retrieves the values of a multi or list-valued key.
      static boolean isListKey​(java.lang.String key)
      Does the key take a whitespace-separated list of values?
      (package private) boolean matches​(java.lang.String hostName)  
      (package private) void merge​(OpenSshConfigFile.HostEntry entry)  
      private java.util.List<java.lang.String> replaceTilde​(java.util.List<java.lang.String> values, java.io.File home)  
      void setValue​(java.lang.String key, java.lang.String value)
      Sets the value of a single-valued key if it not set yet, or adds a value to a multi-valued key.
      void setValue​(java.lang.String key, java.util.List<java.lang.String> values)
      Sets the values of a multi- or list-valued key.
      (package private) void substitute​(java.lang.String originalHostName, int port, java.lang.String userName, java.lang.String localUserName, java.io.File home, boolean fillDefaults)  
      private java.util.List<java.lang.String> substitute​(java.util.List<java.lang.String> values, java.lang.String allowed, OpenSshConfigFile.Replacer r, boolean withEnv)  
      private static java.lang.String toKey​(java.lang.String key)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • MULTI_KEYS

        private static final java.util.Set<java.lang.String> MULTI_KEYS
        Keys that can be specified multiple times, building up a list. (I.e., those are the keys that do not follow the general rule of "first occurrence wins".)
      • LIST_KEYS

        private static final java.util.Set<java.lang.String> LIST_KEYS
        Keys that take a whitespace-separated list of elements as argument. Because the dequote-handling is different, we must handle those in the parser. There are a few other keys that take comma-separated lists as arguments, but for the parser those are single arguments that must be quoted if they contain whitespace, and taking them apart is the responsibility of the user of those keys.
      • ALIASES

        private static final java.util.Map<java.lang.String,​java.lang.String> ALIASES
        OpenSSH has renamed some config keys. This maps old names to new names.
      • options

        private java.util.Map<java.lang.String,​java.lang.String> options
      • multiOptions

        private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> multiOptions
      • listOptions

        private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> listOptions
      • patterns

        private final java.util.List<java.lang.String> patterns
    • Constructor Detail

      • HostEntry

        public HostEntry()
        Constructor used to build the merged entry; never matches anything
      • HostEntry

        public HostEntry​(java.util.List<java.lang.String> patterns)
        Parameters:
        patterns - to be used in matching against host name.
    • Method Detail

      • matches

        boolean matches​(java.lang.String hostName)
      • toKey

        private static java.lang.String toKey​(java.lang.String key)
      • getValue

        public java.lang.String getValue​(java.lang.String key)
        Retrieves the value of a single-valued key, or the first if the key has multiple values. Keys are case-insensitive, so getValue("HostName") == getValue("HOSTNAME").
        Specified by:
        getValue in interface SshConfigStore.HostConfig
        Parameters:
        key - to get the value of
        Returns:
        the value, or null if none
      • getValues

        public java.util.List<java.lang.String> getValues​(java.lang.String key)
        Retrieves the values of a multi or list-valued key. Keys are case-insensitive, so getValue("HostName") == getValue("HOSTNAME").
        Specified by:
        getValues in interface SshConfigStore.HostConfig
        Parameters:
        key - to get the values of
        Returns:
        a possibly empty list of values
      • setValue

        public void setValue​(java.lang.String key,
                             java.lang.String value)
        Sets the value of a single-valued key if it not set yet, or adds a value to a multi-valued key. If the value is null, the key is removed altogether, whether it is single-, list-, or multi-valued.
        Parameters:
        key - to modify
        value - to set or add
      • setValue

        public void setValue​(java.lang.String key,
                             java.util.List<java.lang.String> values)
        Sets the values of a multi- or list-valued key.
        Parameters:
        key - to set
        values - a non-empty list of values
      • isListKey

        public static boolean isListKey​(java.lang.String key)
        Does the key take a whitespace-separated list of values?
        Parameters:
        key - to check
        Returns:
        true if the key is a list-valued key.
      • substitute

        private java.util.List<java.lang.String> substitute​(java.util.List<java.lang.String> values,
                                                            java.lang.String allowed,
                                                            OpenSshConfigFile.Replacer r,
                                                            boolean withEnv)
      • replaceTilde

        private java.util.List<java.lang.String> replaceTilde​(java.util.List<java.lang.String> values,
                                                              java.io.File home)
      • substitute

        void substitute​(java.lang.String originalHostName,
                        int port,
                        java.lang.String userName,
                        java.lang.String localUserName,
                        java.io.File home,
                        boolean fillDefaults)
      • getOptions

        @NonNull
        public java.util.Map<java.lang.String,​java.lang.String> getOptions()
        Retrieves an unmodifiable map of all single-valued options, with case-insensitive lookup by keys.
        Specified by:
        getOptions in interface SshConfigStore.HostConfig
        Returns:
        all single-valued options
      • getMultiValuedOptions

        @NonNull
        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getMultiValuedOptions()
        Retrieves an unmodifiable map of all multi-valued options, with case-insensitive lookup by keys.
        Specified by:
        getMultiValuedOptions in interface SshConfigStore.HostConfig
        Returns:
        all multi-valued options
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object