/** * Return a {@link ConnectionPool} that has no limit on the number of * connections it can manage to the Concourse instance at {@code host}: * {@code port} on behalf of the user identified by {@code username} and * {@code password}, but will try to use previously created connections * before establishing new ones for any request. * * @param prefs * @return the ConnectionPool */ public static ConnectionPool newCachedConnectionPool(String prefs) { ConcourseClientPreferences cp = ConcourseClientPreferences .from(Paths.get(prefs)); return new CachedConnectionPool(cp.getHost(), cp.getPort(), cp.getUsername(), new String(cp.getPassword()), cp.getEnvironment(), DEFAULT_POOL_SIZE); }
/** * Set the connection port. * * @param port * @return this */ public ConnectionBuilder port(int port) { prefs.setPort(port); return this; }
/** * Set the connection password. * * @param password * @return this */ public ConnectionBuilder password(String password) { prefs.setPassword(password.toCharArray()); return this; }
/** * Create a new connection using the information specified in the * {@code prefs}. * * @param prefs a {@link ConcourseClientPreferences prefs} handler * @return the connection */ public static Concourse connectWithPrefs(ConcourseClientPreferences prefs) { return connect(prefs.getHost(), prefs.getPort(), prefs.getUsername(), String.valueOf(prefs.getPassword()), prefs.getEnvironment()); }
getLaunchDirectory()); ConcourseClientPreferences prefs = ConcourseClientPreferences .from(Paths.get(options.prefs)); options.username = prefs.getUsername(); options.password = new String(prefs.getPasswordExplicit()); options.host = prefs.getHost(); options.port = prefs.getPort(); options.environment = prefs.getEnvironment();
prefs); ConcourseClientPreferences ccp = ConcourseClientPreferences .from(Paths.get(FileOps.touch(prefs.toString()))); ccp.setPort(getClientPort()); ccp.setUsername("admin"); ccp.setPassword("admin".toCharArray());
@Test public void testGetPasswordExplicitWhenAbset() { appendLine("username = foo"); appendLine("host = localhost"); ConcourseClientPreferences prefs = ConcourseClientPreferences .from(prefsPath); Assert.assertEquals(ConcourseClientPreferences.NO_PASSWORD_DEFINED, prefs.getPasswordExplicit()); }
/** * Return a {@link ConcourseClientPreferences} handler that is sourced from * a concourse_client.prefs file in the current working directory. * * @return the handler */ public static ConcourseClientPreferences fromCurrentWorkingDirectory() { return from(Paths.get("concourse_client.prefs")); }
/** * Set the connection username. * * @param username * @return this */ public ConnectionBuilder username(String username) { prefs.setUsername(username); return this; }
System.getProperty("user.dir.real")); ConcourseClientPreferences prefs = ConcourseClientPreferences .from(Paths.get(opts.prefs)); opts.username = prefs.getUsername(); opts.password = new String(prefs.getPasswordExplicit()); opts.host = prefs.getHost(); opts.port = prefs.getPort(); opts.environment = prefs.getEnvironment();
@Test public void testGetPasswordExplicitWhenPresent() { appendLine("username = foo"); appendLine("host = localhost"); appendLine("password = foofoo"); ConcourseClientPreferences prefs = ConcourseClientPreferences .from(prefsPath); Assert.assertEquals("foofoo", new String(prefs.getPasswordExplicit())); }
/** * Return a {@link ConcourseClientPreferences} handler that is sourced from * a concourse_client.prefs file in the user's home directory. * * @return the handler */ public static ConcourseClientPreferences fromUserHomeDirectory() { return from(Paths.get(System.getProperty("user.home") + File.separator + "concourse_client.prefs")); }
/** * Return a {@link ConcourseClientPreferences} wrapper that is backed by the * configuration information in {@code file}. * * @param file the absolute path to the preferences file (relative paths * will resolve to the user's home directory) * @return the preferences * @deprecated use {@link ConcourseServerPreferences#from(Path...)} instead */ @Deprecated public static ConcourseClientPreferences open(String file) { return from(Paths.get(file)); }
/** * Return a new {@link ConnectionPool} with a fixed number of * connections to the Concourse instance defined in the client {@code prefs} * on behalf of the user defined in the client {@code prefs}. * <p> * If all the connections from the pool are active, subsequent request * attempts will block until a connection is returned. * </p> * * @param prefs * @param poolSize * @return the ConnectionPool */ public static ConnectionPool newFixedConnectionPool(String prefs, int poolSize) { ConcourseClientPreferences cp = ConcourseClientPreferences .from(Paths.get(prefs)); return new FixedConnectionPool(cp.getHost(), cp.getPort(), cp.getUsername(), new String(cp.getPassword()), cp.getEnvironment(), poolSize); }
/** * Create a new connection using the information specified in the prefs * {@code file}. * * @param file the absolute path to the prefs file that contains the * information for the Concourse deployment (relative paths will * resolve to the user's home directory) * @return the handle */ public static Concourse connectWithPrefs(String file) { ConcourseClientPreferences prefs = ConcourseClientPreferences .from(Paths.get(file)); return connectWithPrefs(prefs); }