Search in sources :

Example 1 with LoginWithCredentialsCommand

use of org.ow2.proactive_grid_cloud_portal.cli.cmd.LoginWithCredentialsCommand in project scheduling by ow2-proactive.

the class CommandFactory method getCommandList.

/**
 * Returns an ordered {@link Command} list for specified user arguments.
 *
 * @param cli the command-line arguments
 * @return an ordered {@link Command} list.
 */
protected List<Command> getCommandList(CommandLine cli, Map<String, Command> map, ApplicationContext currentContext) {
    LinkedList<Command> list = new LinkedList<>();
    if (map.containsKey(opt(COMMON_HELP))) {
        list.add(map.remove(opt(COMMON_HELP)));
        return list;
    }
    if (map.containsKey(opt(RM_HELP))) {
        list.add(map.remove(opt(RM_HELP)));
        return list;
    }
    if (map.containsKey(opt(SCHEDULER_HELP))) {
        list.add(map.remove(opt(SCHEDULER_HELP)));
        return list;
    }
    if (map.containsKey(opt(SILENT))) {
        list.add(map.remove(opt(SILENT)));
    }
    if (map.containsKey(opt(DEBUG))) {
        list.add(map.remove(opt(DEBUG)));
    }
    if (map.containsKey(opt(URL))) {
        list.addFirst(map.remove(opt(URL)));
    }
    if (map.containsKey(opt(INSECURE))) {
        list.add(map.remove(opt(INSECURE)));
    } else if (map.containsKey(opt(CA_CERTS))) {
        list.add(map.remove(opt(CA_CERTS)));
        if (map.containsKey(opt(CA_CERTS_PASSWORD))) {
            list.add(map.remove(opt(CA_CERTS_PASSWORD)));
        }
    }
    if (map.containsKey(opt(SESSION_ID))) {
        list.add(map.remove(opt(SESSION_ID)));
    } else if (map.containsKey(opt(SESSION_ID_FILE))) {
        list.add(map.remove(opt(SESSION_ID_FILE)));
    }
    if (map.containsKey(opt(PASSWORD))) {
        list.add(map.remove(opt(PASSWORD)));
    }
    if (map.containsKey(opt(LOGIN))) {
        list.add(map.remove(opt(LOGIN)));
    } else if (map.containsKey(opt(CREDENTIALS))) {
        list.add(map.remove(opt(CREDENTIALS)));
    } else {
        // auto login
        String resourceType = currentContext.getResourceType();
        String filename = resourceType + ".cc";
        File credFile = new File(DFLT_SESSION_DIR, filename);
        if (credFile.exists()) {
            list.add(new LoginWithCredentialsCommand(credFile.getAbsolutePath(), true));
        } else {
            String schedulerHome = ClasspathUtils.findSchedulerHome();
            File defaultCredentials = new File(schedulerHome, DEFAULT_CREDENTIALS_PATH);
            if (defaultCredentials.exists()) {
                list.add(new LoginWithCredentialsCommand(defaultCredentials.getAbsolutePath(), true));
            }
        }
    }
    if (map.containsKey(opt(INFRASTRUCTURE))) {
        list.add(map.remove(opt(INFRASTRUCTURE)));
    }
    if (map.containsKey(opt(POLICY))) {
        list.add(map.remove(opt(POLICY)));
    }
    if (map.isEmpty()) {
        list.add(new ImodeCommand());
    } else {
        Command output = map.remove(opt(OUTPUT));
        list.addAll(map.values());
        if (output != null) {
            list.add(output);
        }
    }
    return list;
}
Also used : Command(org.ow2.proactive_grid_cloud_portal.cli.cmd.Command) LoginWithCredentialsCommand(org.ow2.proactive_grid_cloud_portal.cli.cmd.LoginWithCredentialsCommand) ImodeCommand(org.ow2.proactive_grid_cloud_portal.cli.cmd.ImodeCommand) File(java.io.File) LinkedList(java.util.LinkedList) LoginWithCredentialsCommand(org.ow2.proactive_grid_cloud_portal.cli.cmd.LoginWithCredentialsCommand) ImodeCommand(org.ow2.proactive_grid_cloud_portal.cli.cmd.ImodeCommand)

Aggregations

File (java.io.File)1 LinkedList (java.util.LinkedList)1 Command (org.ow2.proactive_grid_cloud_portal.cli.cmd.Command)1 ImodeCommand (org.ow2.proactive_grid_cloud_portal.cli.cmd.ImodeCommand)1 LoginWithCredentialsCommand (org.ow2.proactive_grid_cloud_portal.cli.cmd.LoginWithCredentialsCommand)1