use of keywhiz.cli.configs.DeleteActionConfig in project keywhiz by square.
the class DeleteActionTest method setUp.
@Before
public void setUp() {
deleteActionConfig = new DeleteActionConfig();
deleteAction = new DeleteAction(deleteActionConfig, keywhizClient);
yes = new ByteArrayInputStream("Y".getBytes(UTF_8));
// empty line, not yes or no, then no
no = new ByteArrayInputStream("\nOther\nN".getBytes(UTF_8));
}
use of keywhiz.cli.configs.DeleteActionConfig in project keywhiz by square.
the class CommandExecutor method executeCommand.
public void executeCommand() throws IOException {
if (command == null) {
if (config.version) {
System.out.println("Version: " + APP_VERSION);
} else {
System.err.println("Must specify a command.");
parentCommander.usage();
}
return;
}
HttpUrl url;
if (Strings.isNullOrEmpty(config.url)) {
url = HttpUrl.parse("https://localhost:4444");
System.out.println("Server URL not specified (--url flag), assuming " + url);
} else {
url = HttpUrl.parse(config.url);
if (url == null) {
System.err.print("Invalid URL " + config.url);
return;
}
}
KeywhizClient client;
OkHttpClient httpClient;
String user = config.getUser().orElse(USER_NAME.value());
Path cookiePath = cookieDir.resolve(format(".keywhiz.%s.cookie", user));
try {
List<HttpCookie> cookieList = ClientUtils.loadCookies(cookiePath);
httpClient = ClientUtils.sslOkHttpClient(config.getDevTrustStore(), cookieList);
client = new KeywhizClient(mapper, httpClient, url);
// Try a simple get request to determine whether or not the cookies are still valid
if (!client.isLoggedIn()) {
throw new UnauthorizedException();
}
} catch (IOException e) {
// Either could not find the cookie file, or the cookies were expired -- must login manually.
httpClient = ClientUtils.sslOkHttpClient(config.getDevTrustStore(), ImmutableList.of());
client = new KeywhizClient(mapper, httpClient, url);
char[] password = ClientUtils.readPassword(user);
client.login(user, password);
Arrays.fill(password, '\0');
}
// Save/update the cookies if we logged in successfully
ClientUtils.saveCookies(cookiePath);
Printing printing = new Printing(client);
Command cmd = Command.valueOf(command.toUpperCase().trim());
switch(cmd) {
case LIST:
new ListAction((ListActionConfig) commands.get(command), client, printing).run();
break;
case DESCRIBE:
new DescribeAction((DescribeActionConfig) commands.get(command), client, printing).run();
break;
case ADD:
new AddAction((AddActionConfig) commands.get(command), client, mapper).run();
break;
case UPDATE:
new UpdateAction((UpdateActionConfig) commands.get(command), client, mapper).run();
break;
case DELETE:
new DeleteAction((DeleteActionConfig) commands.get(command), client).run();
break;
case ASSIGN:
new AssignAction((AssignActionConfig) commands.get(command), client).run();
break;
case UNASSIGN:
new UnassignAction((UnassignActionConfig) commands.get(command), client).run();
break;
case VERSIONS:
new ListVersionsAction((ListVersionsActionConfig) commands.get(command), client, printing).run();
break;
case ROLLBACK:
new RollbackAction((RollbackActionConfig) commands.get(command), client).run();
break;
case RENAME:
new RenameAction((RenameActionConfig) commands.get(command), client).run();
case LOGIN:
// User is already logged in at this point
break;
default:
commander.usage();
}
}
Aggregations