use of io.pravega.cli.admin.utils.CLIConfig in project pravega by pravega.
the class ControllerCommand method createContext.
/**
* Creates a context for child classes consisting of a REST client to execute calls against the Controller.
*
* @return REST client.
*/
protected Context createContext() {
CLIConfig config = getCLIControllerConfig();
ClientConfig clientConfig = new ClientConfig();
clientConfig.register(JacksonJsonProvider.class);
clientConfig.property("sun.net.http.allowRestrictedHeaders", "true");
ClientBuilder builder = ClientBuilder.newBuilder().withConfig(clientConfig);
// If TLS parameters are configured, set them in client.
if (config.isTlsEnabled()) {
SSLContext tlsContext;
try {
KeyStore ks = createTrustStore(config.getTruststore());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
tlsContext = SSLContext.getInstance("TLS");
tlsContext.init(null, tmf.getTrustManagers(), null);
} catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | KeyManagementException e) {
String message = String.format("Encountered exception while trying to use the given truststore: %s", config.getTruststore());
log.error(message, e);
return null;
}
builder.sslContext(tlsContext);
}
Client client = builder.build();
// If authorization parameters are configured, set them in the client.
if (config.isAuthEnabled()) {
HttpAuthenticationFeature auth = HttpAuthenticationFeature.basic(config.getUserName(), config.getPassword());
client = client.register(auth);
}
return new Context(client);
}
use of io.pravega.cli.admin.utils.CLIConfig in project pravega by pravega.
the class AdminCommandStateTest method testAdminCommandStateCreationWithConfigFile.
@Test
public void testAdminCommandStateCreationWithConfigFile() throws IOException {
System.setProperty("pravega.configurationFile", "../../config/admin-cli.properties");
@Cleanup AdminCommandState commandState = new AdminCommandState();
CLIConfig config = commandState.getConfigBuilder().build().getConfig(CLIConfig::builder);
Assert.assertNotNull(config.getMetadataBackend());
}
Aggregations