Search in sources :

Example 1 with ToolStartupException

use of com.bluenimble.platform.cli.ToolStartupException in project serverless by bluenimble.

the class AbstractTool method startup.

@Override
public void startup(String[] args) throws ToolStartupException {
    for (Command command : getCommands()) {
        command.onStartup(this);
    }
    startTime = new Date();
    writeln(Lang.BLANK);
    printer.textLn(0, getDescription(), FColor.CYAN.name(), null);
    writeln(Lang.BLANK);
    writeln(Lang.BLANK);
    printer.textLn(0, startTime.toString(), FColor.YELLOW.name(), null);
    try {
        prompt();
        onReady();
        prompt();
    } catch (Throwable th) {
    // IGNORE
    }
    addShutdownHook();
    // signle run
    if (args != null && args.length > 0) {
        for (int i = 0; i < args.length; i++) {
            try {
                processCommand(args[i]);
            } catch (IOException e) {
                throw new ToolStartupException(e);
            }
        }
        try {
            processCommand("quit");
        } catch (IOException e) {
            throw new ToolStartupException(e);
        }
        return;
    }
}
Also used : Command(com.bluenimble.platform.cli.command.Command) IOException(java.io.IOException) ToolStartupException(com.bluenimble.platform.cli.ToolStartupException) Date(java.util.Date)

Example 2 with ToolStartupException

use of com.bluenimble.platform.cli.ToolStartupException in project serverless by bluenimble.

the class BlueNimble method loadKeys.

private static String loadKeys(Tool tool, File s, String currentSecret) throws ToolStartupException {
    String sname = s.getName().substring(0, s.getName().lastIndexOf(Lang.DOT)).toLowerCase();
    InputStream in = null;
    try {
        in = new FileInputStream(s);
        Keys keys = new Keys(sname, Json.load(new ByteArrayInputStream(Base64.decodeBase64(IOUtils.toString(in))), tool.getParaphrase(true)));
        KeysMap.put(sname, keys);
        if (sname.equals(currentSecret)) {
            useKeys(sname);
        }
    } catch (Exception e) {
        tool.printer().error("Can't load keys " + s.getName() + ". Cause: " + e.getMessage());
    } finally {
        IOUtils.closeQuietly(in);
    }
    return sname;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) InstallI18nException(com.bluenimble.platform.cli.InstallI18nException) ToolStartupException(com.bluenimble.platform.cli.ToolStartupException) IOException(java.io.IOException)

Example 3 with ToolStartupException

use of com.bluenimble.platform.cli.ToolStartupException in project serverless by bluenimble.

the class BlueNimble method loadKeys.

public static void loadKeys(Tool tool) throws ToolStartupException {
    File keysFolder = keysFolder();
    if (!keysFolder.exists()) {
        keysFolder.mkdirs();
    }
    if (!keysFolder.isDirectory()) {
        throw new ToolStartupException(keysFolder.getAbsolutePath() + " isn't valid forder to store bluenimble keys");
    }
    String sCurrentKeys = Json.getString(Config, CliSpec.Config.CurrentKeys);
    File[] keys = keysFolder.listFiles(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isFile() && f.getName().endsWith(CliSpec.KeysExt);
        }
    });
    if (keys == null || keys.length == 0) {
        Config.remove(CliSpec.Config.CurrentKeys);
        return;
    }
    for (File s : keys) {
        loadKeys(tool, s, sCurrentKeys);
    }
}
Also used : ToolStartupException(com.bluenimble.platform.cli.ToolStartupException) FileFilter(java.io.FileFilter) File(java.io.File)

Aggregations

ToolStartupException (com.bluenimble.platform.cli.ToolStartupException)3 IOException (java.io.IOException)2 InstallI18nException (com.bluenimble.platform.cli.InstallI18nException)1 Command (com.bluenimble.platform.cli.command.Command)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1