use of co.cask.cdap.cli.CLIConnectionConfig in project cdap by caskdata.
the class ConnectCommand method execute.
@Override
public void execute(Arguments arguments, PrintStream output) throws Exception {
String instanceURI = arguments.get(ArgumentName.INSTANCE_URI.toString());
String verifySSLCertString = arguments.getOptional(ArgumentName.VERIFY_SSL_CERT.toString());
boolean verifySSLCert = verifySSLCertString != null ? Boolean.valueOf(verifySSLCertString) : true;
CLIConnectionConfig connection = instanceURIParser.parse(instanceURI);
try {
cliConfig.tryConnect(connection, verifySSLCert, output, debug);
} catch (Exception e) {
output.println("Failed to connect to " + instanceURI + ": " + e.getMessage());
if (debug) {
e.printStackTrace(output);
}
}
}
use of co.cask.cdap.cli.CLIConnectionConfig in project cdap by caskdata.
the class InstanceURIParser method parse.
public CLIConnectionConfig parse(String uriString) {
if (!uriString.contains("://")) {
uriString = DEFAULT_PROTOCOL + "://" + uriString;
}
URI uri = URI.create(uriString);
NamespaceId namespace = (uri.getPath() == null || uri.getPath().isEmpty() || "/".equals(uri.getPath())) ? NamespaceId.DEFAULT : new NamespaceId(uri.getPath().substring(1));
String hostname = uri.getHost();
boolean sslEnabled = "https".equals(uri.getScheme());
int port = uri.getPort();
if (port == -1) {
port = sslEnabled ? cConf.getInt(Constants.Router.ROUTER_SSL_PORT) : cConf.getInt(Constants.Router.ROUTER_PORT);
}
ConnectionConfig config = ConnectionConfig.builder().setHostname(hostname).setPort(port).setSSLEnabled(sslEnabled).build();
return new CLIConnectionConfig(config, namespace, null);
}
use of co.cask.cdap.cli.CLIConnectionConfig in project cdap by caskdata.
the class InstanceURIParserTest method testParseTrailingSlash.
@Test
public void testParseTrailingSlash() {
CConfiguration cConf = CConfiguration.create();
InstanceURIParser parser = new InstanceURIParser(cConf);
Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, true), parser.parse("https://somehost:1234/"));
}
use of co.cask.cdap.cli.CLIConnectionConfig in project cdap by caskdata.
the class InstanceURIParserTest method testParse.
@Test
public void testParse() {
CConfiguration cConf = CConfiguration.create();
int defaultSSLPort = cConf.getInt(Constants.Router.ROUTER_SSL_PORT);
int defaultPort = cConf.getInt(Constants.Router.ROUTER_PORT);
NamespaceId someNamespace = new NamespaceId("nsx");
InstanceURIParser parser = new InstanceURIParser(cConf);
Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultPort, false), parser.parse("somehost"));
Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultPort, false), parser.parse("http://somehost"));
Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", defaultSSLPort, true), parser.parse("https://somehost"));
Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false), parser.parse("somehost:1234"));
Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, false), parser.parse("http://somehost:1234"));
Assert.assertEquals(new CLIConnectionConfig(NamespaceId.DEFAULT, "somehost", 1234, true), parser.parse("https://somehost:1234"));
Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, false), parser.parse("somehost:1234/nsx"));
Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, false), parser.parse("http://somehost:1234/nsx"));
Assert.assertEquals(new CLIConnectionConfig(someNamespace, "somehost", 1234, true), parser.parse("https://somehost:1234/nsx"));
}
Aggregations