| | | | | | | | | | AOSH Commands
add_username package username
add_postgres_user username
add_postgres_server_user username postgres_server server
wait_for_postgres_user_rebuild server
set_postgres_server_user_password username postgres_server server password
Simple API
/**
* Adds a PostgresUser to the system.
*
* @param aoClient the SimpleAOClient to use
* @param packageName the name of the Package
* @param username the new username to allocate
* @param postgresServer the name of the PostgreSQL server
* @param server the hostname of the server to add the account to
* @param password the password for the new account
*/
public static void addPostgresUser(
SimpleAOClient aoClient,
String packageName,
String username,
String postgresServer,
String server,
String password
) throws IOException, SQLException {
// Reserve the username
aoClient.addUsername(packageName, username);
// Indicate the username will be used for PostgreSQL accounts
aoClient.addPostgresUser(username);
// Grant access to the server
aoClient.addPostgresServerUser(username, postgresServer, server);
// Commit the changes before setting the password
aoClient.waitForPostgresUserRebuild(server);
// Set the password
aoClient.setPostgresServerUserPassword(username, postgresServer, server, password);
}
Full API
/**
* Adds a PostgresUser to the system.
*
* @param conn the AOServConnector to use
* @param packageName the name of the Package
* @param username the new username to allocate
* @param postgresServer the name of the PostgreSQL server
* @param server the hostname of the server to add the account to
* @param password the password for the new account
*
* @return the new PostgresServerUser
*/
public static PostgresServerUser addPostgresUser(
AOServConnector conn,
String packageName,
String username,
String postgresServer,
String server,
String password
) throws IOException, SQLException {
// Find the Package
Package pk=conn.getPackageTable().getPackage(packageName);
// Reserve the username
pk.addUsername(username);
Username un=conn.getUsernameTable().getUsername(username);
// Indicate the username will be used for PostgreSQL accounts
un.addPostgresUser();
PostgresUser pu=un.getPostgresUser();
// Resolve the Server
Server se=conn.getServerTable().getServer(server);
// Resolve the PostgresServer
PostgresServer ps=se.getPostgresServer(postgresServer);
// Grant access to the server
int psuPKey=pu.addPostgresServerUser(ps);
PostgresServerUser psu=conn.getPostgresServerUserTable().getPostgresServerUser(psuPKey);
// Commit the changes before setting the password
se.waitForPostgresUserRebuild();
// Set the password
psu.setPassword(password);
// Return the object
return psu;
}
| | | | | Copyright © 2000-2024 AO Industries, Inc. |
|