public class HostConfigEntry extends HostPatternsHolder implements MutableUserHolder
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_EXCLUSIVE_IDENTITIES |
static String |
EXCLUSIVE_IDENTITIES_CONFIG_PROP
Use only the identities specified in the host entry (if any)
|
static NavigableSet<String> |
EXPLICIT_PROPERTIES
A case insensitive
NavigableSet of the properties that receive special handling |
static char |
HOME_TILDE_CHAR |
static String |
HOST_CONFIG_PROP |
static String |
HOST_NAME_CONFIG_PROP |
static String |
IDENTITY_FILE_CONFIG_PROP |
static char |
LOCAL_HOME_MACRO |
static char |
LOCAL_HOST_MACRO |
static char |
LOCAL_USER_MACRO |
static String |
MULTI_VALUE_SEPARATORS |
static char |
PATH_MACRO_CHAR |
static String |
PORT_CONFIG_PROP |
static String |
PROXY_JUMP_CONFIG_PROP |
static char |
REMOTE_HOST_MACRO |
static char |
REMOTE_PORT_MACRO |
static char |
REMOTE_USER_MACRO |
static String |
STD_CONFIG_FILENAME
Standard OpenSSH config file name
|
static String |
USER_CONFIG_PROP |
ALL_HOSTS_PATTERN, NEGATION_CHAR_PATTERN, NON_STANDARD_PORT_PATTERN_ENCLOSURE_END_DELIM, NON_STANDARD_PORT_PATTERN_ENCLOSURE_START_DELIM, PATTERN_CHARS, PORT_VALUE_DELIMITER, SINGLE_CHAR_PATTERN, WILDCARD_PATTERN
Constructor and Description |
---|
HostConfigEntry() |
HostConfigEntry(String pattern,
String host,
int port,
String username) |
HostConfigEntry(String pattern,
String host,
int port,
String username,
String proxyJump) |
Modifier and Type | Method and Description |
---|---|
void |
addIdentity(Path path) |
void |
addIdentity(String id)
Adds a path to an identity file
|
<A extends Appendable> |
append(A sb) |
static <A extends Appendable> |
appendHostConfigEntries(A sb,
Collection<? extends HostConfigEntry> entries) |
static <A extends Appendable> |
appendNonEmptyPort(A sb,
String name,
int port) |
static <A extends Appendable> |
appendNonEmptyProperties(A sb,
Map<String,?> props)
Appends the extra properties - while skipping the
EXPLICIT_PROPERTIES ones |
static <A extends Appendable> |
appendNonEmptyProperty(A sb,
String name,
Object value) |
static <A extends Appendable> |
appendNonEmptyValues(A sb,
String name,
Collection<?> values) |
static <A extends Appendable> |
appendNonEmptyValues(A sb,
String name,
Object... values) |
String |
appendPropertyValue(String name,
String value)
Appends a value using a comma to an existing one.
|
static StringBuilder |
appendUserHome(StringBuilder sb) |
static StringBuilder |
appendUserHome(StringBuilder sb,
Path userHome) |
static StringBuilder |
appendUserHome(StringBuilder sb,
String userHome) |
static HostConfigEntry |
findBestMatch(Collection<? extends HostConfigEntry> matches)
Finds the best match out of the given ones.
|
static HostConfigEntry |
findBestMatch(Iterable<? extends HostConfigEntry> matches)
Finds the best match out of the given ones.
|
static HostConfigEntry |
findBestMatch(Iterator<? extends HostConfigEntry> matches)
Finds the best match out of the given ones.
|
static Path |
getDefaultHostConfigFile() |
String |
getHost() |
String |
getHostName() |
Collection<String> |
getIdentities() |
int |
getPort() |
Map<String,String> |
getProperties() |
String |
getProperty(String name) |
String |
getProperty(String name,
String defaultValue) |
String |
getProxyJump() |
String |
getUsername() |
boolean |
isIdentitiesOnly() |
static HostConfigEntry |
normalizeEntry(HostConfigEntry entry,
String host,
int port,
String username,
String proxyJump) |
static List<String> |
parseConfigValue(String value)
Checks if this is a multi-value - allow space and comma
|
boolean |
processGlobalValues(HostConfigEntry globalEntry)
Updates the values that are not already configured with those from the global entry
|
void |
processProperty(String name,
Collection<String> valsList,
boolean ignoreAlreadyInitialized) |
static List<HostConfigEntry> |
readHostConfigEntries(BufferedReader rdr)
Reads configuration entries
|
static List<HostConfigEntry> |
readHostConfigEntries(InputStream inStream,
boolean okToClose) |
static List<HostConfigEntry> |
readHostConfigEntries(Path path,
OpenOption... options) |
static List<HostConfigEntry> |
readHostConfigEntries(Reader rdr,
boolean okToClose) |
static List<HostConfigEntry> |
readHostConfigEntries(URL url) |
String |
removeProperty(String name) |
String |
resolveHostName(String originalHost) |
static String |
resolveHostName(String originalName,
String entryName)
Resolves the effective target host
|
static String |
resolveIdentityFilePath(String id,
String host,
int port,
String username) |
int |
resolvePort(int originalPort)
Resolves the effective port to use
|
static int |
resolvePort(int originalPort,
int entryPort)
Resolves the effective port to use
|
String |
resolveProxyJump(String originalProxyJump)
Resolves the effective proxyJump
|
static String |
resolveProxyJump(String originalProxyJump,
String entryProxyJump)
Resolves the effective proxyJump
|
String |
resolveUsername(String originalUser)
Resolves the effective username
|
static String |
resolveUsername(String originalUser,
String entryUser)
Resolves the effective username
|
void |
setHost(Collection<String> patterns) |
void |
setHost(String host) |
void |
setHostName(String hostName) |
void |
setIdentities(Collection<String> identities) |
void |
setIdentitiesOnly(boolean identitiesOnly) |
void |
setPort(int port) |
void |
setProperties(Map<String,String> properties) |
String |
setProperty(String name,
String value)
Sets / Replaces the property value
|
void |
setProxyJump(String proxyJump) |
void |
setUsername(String username) |
static HostConfigEntryResolver |
toHostConfigEntryResolver(Collection<? extends HostConfigEntry> entries) |
String |
toString() |
static List<HostConfigEntry> |
updateEntriesList(List<HostConfigEntry> entries,
HostConfigEntry curEntry) |
boolean |
updateGlobalHostName(String name) |
boolean |
updateGlobalIdentities(Collection<String> ids) |
boolean |
updateGlobalIdentityOnly(boolean identitiesOnly) |
boolean |
updateGlobalPort(int portValue) |
Map<String,String> |
updateGlobalProperties(Map<String,String> props)
Sets all the properties for which no current value exists in the entry
|
boolean |
updateGlobalUserName(String user) |
static void |
writeHostConfigEntries(OutputStream outputStream,
boolean okToClose,
Collection<? extends HostConfigEntry> entries) |
static void |
writeHostConfigEntries(Path path,
Collection<? extends HostConfigEntry> entries,
OpenOption... options) |
findMatchingEntries, findMatchingEntries, getPatterns, isHostMatch, isHostMatch, isHostMatch, isPortMatch, isSpecificHostPattern, isValidPatternChar, parsePatterns, parsePatterns, setPatterns, toPattern
public static final String STD_CONFIG_FILENAME
public static final String HOST_CONFIG_PROP
public static final String HOST_NAME_CONFIG_PROP
public static final String PORT_CONFIG_PROP
public static final String USER_CONFIG_PROP
public static final String PROXY_JUMP_CONFIG_PROP
public static final String IDENTITY_FILE_CONFIG_PROP
public static final String EXCLUSIVE_IDENTITIES_CONFIG_PROP
public static final boolean DEFAULT_EXCLUSIVE_IDENTITIES
public static final NavigableSet<String> EXPLICIT_PROPERTIES
NavigableSet
of the properties that receive special handlingpublic static final String MULTI_VALUE_SEPARATORS
public static final char HOME_TILDE_CHAR
public static final char PATH_MACRO_CHAR
public static final char LOCAL_HOME_MACRO
public static final char LOCAL_USER_MACRO
public static final char LOCAL_HOST_MACRO
public static final char REMOTE_HOST_MACRO
public static final char REMOTE_USER_MACRO
public static final char REMOTE_PORT_MACRO
public String getHost()
public void setHost(String host)
public void setHost(Collection<String> patterns)
public String getHostName()
public void setHostName(String hostName)
public int getPort()
public void setPort(int port)
public int resolvePort(int originalPort)
originalPort
- The original requested portresolvePort(int, int)
public String getUsername()
getUsername
in interface UsernameHolder
null
/emptypublic void setUsername(String username)
setUsername
in interface MutableUserHolder
public String resolveUsername(String originalUser)
originalUser
- The original requested usernamenull
/empty then it is used, otherwise
the original one.resolveUsername(String)
public String getProxyJump()
public void setProxyJump(String proxyJump)
public String resolveProxyJump(String originalProxyJump)
originalProxyJump
- The original requested proxyJumpnull
/empty then it is used,
otherwise the original one.resolveUsername(String)
public Collection<String> getIdentities()
null
/emptypublic void addIdentity(Path path)
path
- A Path
to a file that contains an identity key - never null
public void addIdentity(String id)
id
- The identity path to add - never null
public void setIdentities(Collection<String> identities)
public boolean isIdentitiesOnly()
true
if must use only the identities in this entrypublic void setIdentitiesOnly(boolean identitiesOnly)
public Map<String,String> getProperties()
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 valuespublic String getProperty(String name)
name
- Property name - never null
/emptynull
if no such propertygetProperty(String, String)
public String getProperty(String name, String defaultValue)
name
- Property name - never null
/emptydefaultValue
- Default value to return if no such propertypublic boolean processGlobalValues(HostConfigEntry globalEntry)
globalEntry
- The global entry - ignored if null
or same reference as this entrytrue
if anything updatedpublic Map<String,String> updateGlobalProperties(Map<String,String> props)
props
- The global properties - ignored if null
/emptyMap
of the updated propertiespublic boolean updateGlobalIdentities(Collection<String> ids)
ids
- Global identities - ignored if null
/empty or already have configured identitiestrue
if updated identitiespublic boolean updateGlobalUserName(String user)
user
- The global user name - ignored if null
/empty or already have a configured usertrue
if updated the usernamepublic boolean updateGlobalHostName(String name)
name
- The global host name - ignored if null
/empty or already have a configured target hosttrue
if updated the target hostpublic boolean updateGlobalPort(int portValue)
portValue
- The global port value - ignored if not positive or already have a configured porttrue
if updated the port valuepublic boolean updateGlobalIdentityOnly(boolean identitiesOnly)
identitiesOnly
- Whether to use only the identities in this entry. Ignored if already settrue
if updated the option valuepublic void processProperty(String name, Collection<String> valsList, boolean ignoreAlreadyInitialized)
name
- Property name - never null
/emptyvalsList
- The available values for the propertyignoreAlreadyInitialized
- If false
and one of the "known" properties is encountered then
throws an exceptionIllegalArgumentException
- If an existing value is overwritten and ignoreAlreadyInitialized is
false
(except for IDENTITY_FILE_CONFIG_PROP
which is
cumulativeHOST_NAME_CONFIG_PROP
,
PORT_CONFIG_PROP
,
USER_CONFIG_PROP
,
IDENTITY_FILE_CONFIG_PROP
public String appendPropertyValue(String name, String value)
setProperty(String, String)
.name
- Property name - never null
/emptyvalue
- The value to be appended - ignored if null
/emptynull
if no previous valuepublic String setProperty(String name, String value)
name
- Property name - never null
/emptyvalue
- Property value - if null
/empty then removeProperty(String)
is callednull
if no such namepublic String removeProperty(String name)
name
- Property name - never null
/emptynull
if no such property namepublic void setProperties(Map<String,String> properties)
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.public <A extends Appendable> A append(A sb) throws IOException
IOException
public static <A extends Appendable> A appendNonEmptyPort(A sb, String name, int port) throws IOException
A
- The Appendable
typesb
- The target appendername
- The property name - never null
/emptyport
- The port value - ignored if non-positiveIOException
- If failed to append the requested dataappendNonEmptyProperty(Appendable, String, Object)
public static <A extends Appendable> A appendNonEmptyProperties(A sb, Map<String,?> props) throws IOException
EXPLICIT_PROPERTIES
onesA
- The Appendable
typesb
- The target appenderprops
- The Map
of properties - ignored if null
/emptyIOException
- If failed to append the requested dataappendNonEmptyProperty(Appendable, String, Object)
public static <A extends Appendable> A appendNonEmptyProperty(A sb, String name, Object value) throws IOException
A
- The Appendable
typesb
- The target appendername
- The property name - never null
/emptyvalue
- 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.IOException
- If failed to append the requested dataappendNonEmptyValues(Appendable, String, Object...)
public static <A extends Appendable> A appendNonEmptyValues(A sb, String name, Object... values) throws IOException
A
- The Appendable
typesb
- The target appendername
- The property name - never null
/emptyvalues
- The values to be added - one per line - ignored if null
/emptyIOException
- If failed to append the requested dataappendNonEmptyValues(Appendable, String, Collection)
public static <A extends Appendable> A appendNonEmptyValues(A sb, String name, Collection<?> values) throws IOException
A
- The Appendable
typesb
- The target appendername
- The property name - never null
/emptyvalues
- The values to be added - one per line - ignored if null
/emptyIOException
- If failed to append the requested datapublic static HostConfigEntryResolver toHostConfigEntryResolver(Collection<? extends HostConfigEntry> entries)
entries
- The entries - ignored if null
/emptyHostConfigEntryResolver
wrapper using the entriespublic static HostConfigEntry normalizeEntry(HostConfigEntry entry, String host, int port, String username, String proxyJump) throws IOException
entry
- The original entry - ignored if null
host
- The original host name / addressport
- The original portusername
- The original user nameproxyJump
- And optional proxy jump settingIOException
- If failed to normalize the entryresolveHostName(String)
,
resolvePort(int)
,
resolveUsername(String)
,
resolveIdentityFilePath(String, String, int, String)
public static String resolveHostName(String originalName, String entryName)
originalName
- The original requested hostentryName
- The configured hostnull
/empty then it is used, otherwise the
original one.public static String resolveUsername(String originalUser, String entryUser)
originalUser
- The original requested usernameentryUser
- The configured host entry usernamenull
/empty then it is used, otherwise
the original one.public static int resolvePort(int originalPort, int entryPort)
originalPort
- The original requested portentryPort
- The configured host entry portpublic static String resolveProxyJump(String originalProxyJump, String entryProxyJump)
originalProxyJump
- The original requested proxyJumpentryProxyJump
- The configured host entry proxyJumpnull
/empty then it is used,
otherwise the original one.public static List<HostConfigEntry> readHostConfigEntries(Path path, OpenOption... options) throws IOException
IOException
public static List<HostConfigEntry> readHostConfigEntries(URL url) throws IOException
IOException
public static List<HostConfigEntry> readHostConfigEntries(InputStream inStream, boolean okToClose) throws IOException
IOException
public static List<HostConfigEntry> readHostConfigEntries(Reader rdr, boolean okToClose) throws IOException
IOException
public static List<HostConfigEntry> readHostConfigEntries(BufferedReader rdr) throws IOException
rdr
- The BufferedReader
to useList
of read HostConfigEntry
-iesIOException
- If failed to parse the read configurationpublic static HostConfigEntry findBestMatch(Collection<? extends HostConfigEntry> matches)
matches
- The available matches - ignored if null
/emptynull
if no matches or no best match foundfindBestMatch(Iterator)
public static HostConfigEntry findBestMatch(Iterable<? extends HostConfigEntry> matches)
matches
- The available matches - ignored if null
/emptynull
if no matches or no best match foundfindBestMatch(Iterator)
public static HostConfigEntry findBestMatch(Iterator<? extends HostConfigEntry> matches)
matches
- The available matches - ignored if null
/emptynull
if no matches or no best match foundHostPatternsHolder.isSpecificHostPattern(String)
public static List<HostConfigEntry> updateEntriesList(List<HostConfigEntry> entries, HostConfigEntry curEntry)
public static void writeHostConfigEntries(Path path, Collection<? extends HostConfigEntry> entries, OpenOption... options) throws IOException
IOException
public static void writeHostConfigEntries(OutputStream outputStream, boolean okToClose, Collection<? extends HostConfigEntry> entries) throws IOException
IOException
public static <A extends Appendable> A appendHostConfigEntries(A sb, Collection<? extends HostConfigEntry> entries) throws IOException
IOException
public static List<String> parseConfigValue(String value)
value
- The value - ignored if null
/empty (after trimming)List
of the encountered valuespublic static String resolveIdentityFilePath(String id, String host, int port, String username) throws IOException
IOException
public static StringBuilder appendUserHome(StringBuilder sb)
public static StringBuilder appendUserHome(StringBuilder sb, Path userHome)
public static StringBuilder appendUserHome(StringBuilder sb, String userHome)
Copyright © 2018–2021 The Apache Software Foundation. All rights reserved.