use of com.cinchapi.concourse.PermissionException in project concourse by cinchapi.
the class ConcourseShell method main.
/**
* Run the program...
*
* @param args
* @throws Exception
*/
public static void main(String... args) throws Exception {
try {
ConcourseShell cash = new ConcourseShell();
Options opts = new Options();
JCommander parser = null;
try {
parser = new JCommander(opts, args);
} catch (Exception e) {
die(e.getMessage());
}
parser.setProgramName("concourse-shell");
if (opts.help) {
parser.usage();
System.exit(1);
}
if (!Strings.isNullOrEmpty(opts.prefs)) {
opts.prefs = FileOps.expandPath(opts.prefs, 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();
}
if (Strings.isNullOrEmpty(opts.password)) {
cash.setExpandEvents(false);
opts.password = cash.console.readLine("Password [" + opts.username + "]: ", '*');
}
try {
cash.concourse = Concourse.connect(opts.host, opts.port, opts.username, opts.password, opts.environment);
cash.whoami = opts.username;
} catch (Exception e) {
if (e.getCause() instanceof TTransportException) {
die("Unable to connect to the Concourse Server at " + opts.host + ":" + opts.port);
} else if (e.getCause() instanceof SecurityException) {
die("Invalid username/password combination.");
} else {
die(e.getMessage());
}
}
if (!opts.ignoreRunCommands) {
cash.loadExternalScript(opts.ext);
}
if (!Strings.isNullOrEmpty(opts.run)) {
try {
String result = cash.evaluate(opts.run);
System.out.println(result);
cash.concourse.exit();
System.exit(0);
} catch (IrregularEvaluationResult e) {
die(e.getMessage());
}
} else {
try {
cash.enableInteractiveSettings();
} catch (PermissionException e) {
die(e.getMessage());
}
boolean running = true;
String input = "";
while (running) {
boolean extraLineBreak = true;
boolean clearInput = true;
boolean clearPrompt = false;
try {
input = input + cash.console.readLine().trim();
String result = cash.evaluate(input);
System.out.println(result);
} catch (UserInterruptException e) {
if (Strings.isNullOrEmpty(e.getPartialLine()) && Strings.isNullOrEmpty(input)) {
cash.console.println("Type EXIT to quit.");
}
} catch (HelpRequest e) {
String text = getHelpText(e.topic);
if (!Strings.isNullOrEmpty(text)) {
Process p = Runtime.getRuntime().exec(new String[] { "sh", "-c", "echo \"" + text + "\" | less > /dev/tty" });
p.waitFor();
}
cash.console.getHistory().removeLast();
} catch (ExitRequest e) {
running = false;
cash.console.getHistory().removeLast();
} catch (NewLineRequest e) {
extraLineBreak = false;
} catch (ProgramCrash e) {
die(e.getMessage());
} catch (MultiLineRequest e) {
extraLineBreak = false;
clearInput = false;
clearPrompt = true;
} catch (IrregularEvaluationResult e) {
System.err.println(e.getMessage());
} finally {
if (extraLineBreak) {
cash.console.print("\n");
}
if (clearInput) {
input = "";
}
if (clearPrompt) {
cash.console.setPrompt("> ");
} else {
cash.console.setPrompt(cash.defaultPrompt);
}
}
}
cash.concourse.exit();
System.exit(0);
}
} finally {
TerminalFactory.get().restore();
}
}
use of com.cinchapi.concourse.PermissionException in project concourse by cinchapi.
the class PermissionTest method testPermissionChangeTakesImmediateEffect.
@Test
public void testPermissionChangeTakesImmediateEffect() {
createUser("jeff", "jeff", "user");
grant("jeff", "write", "production");
Concourse client2 = Concourse.connect(SERVER_HOST, SERVER_PORT, "jeff", "jeff", "production");
long record = client2.add("name", "jeff");
grant("jeff", "read", "production");
try {
client2.add("name", "jeff");
Assert.fail();
} catch (PermissionException e) {
Assert.assertEquals(ImmutableSet.of(record), client2.inventory());
}
}
use of com.cinchapi.concourse.PermissionException in project concourse by cinchapi.
the class PermissionTest method testDriverIsUsableAfterPermissionException.
@Test
public void testDriverIsUsableAfterPermissionException() {
createUser("jeff", "jeff", "user");
Concourse client2 = Concourse.connect(SERVER_HOST, SERVER_PORT, "jeff", "jeff");
grant("jeff", "read", "");
long record = client.add("foo", "foo");
try {
client2.set("foo", "bar", record);
Assert.fail();
} catch (PermissionException e) {
Assert.assertEquals("foo", client2.get("foo", record));
}
}
Aggregations