Search in sources :

Example 11 with CliException

use of com.fathomdb.cli.CliException in project platformlayer by platformlayer.

the class ListJobs method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    JobDataList jobs = (JobDataList) o;
    switch(getFormat()) {
        case JSON:
            JsonHelper<JobDataList> jsonHelper = JsonHelper.build(JobDataList.class);
            boolean formatted = true;
            try {
                String json = jsonHelper.marshal(jobs, formatted);
                writer.println(json);
                return;
            } catch (IOException e) {
                throw new CliException("Error formatting for output", e);
            }
    }
    Ansi ansi = new Ansi(writer);
    for (JobData job : jobs.getJobs()) {
        // JobState state = job.state;
        // if (state != null) {
        // ansi.setColorBlue();
        // switch (job.state) {
        // case FAILED:
        // ansi.setColorRed();
        // break;
        //
        // case SUCCESS:
        // ansi.setColorGreen();
        // break;
        //
        // case RUNNING:
        // ansi.setColorBlue();
        // break;
        //
        // default:
        // ansi.setColorBlue();
        // break;
        // }
        // }
        writer.println(job.key);
    }
    ansi.reset();
}
Also used : CliException(com.fathomdb.cli.CliException) JobDataList(org.platformlayer.jobs.model.JobDataList) IOException(java.io.IOException) JobData(org.platformlayer.jobs.model.JobData) Ansi(com.fathomdb.cli.commands.Ansi)

Example 12 with CliException

use of com.fathomdb.cli.CliException in project platformlayer by platformlayer.

the class CreateUser method runCommand.

@Override
public Object runCommand() throws RepositoryException, GeneralSecurityException, IOException, OpsException {
    if (password == null && keystore == null && certPath == null) {
        throw new CliException("Either key or password or cert is required");
    }
    UserDatabase userRepository = getContext().getUserRepository();
    Certificate[] certificateChain = null;
    if (keystore != null) {
        certificateChain = getContext().getCertificateChain(keystore, keystoreSecret, keyAlias);
    } else if (certPath != null) {
        certificateChain = getContext().loadCertificateChain(certPath);
    }
    OpsUser user = userRepository.createUser(username, password, certificateChain);
    return user;
}
Also used : CliException(com.fathomdb.cli.CliException) UserDatabase(org.platformlayer.auth.UserDatabase) OpsUser(org.platformlayer.auth.OpsUser) Certificate(java.security.cert.Certificate)

Aggregations

CliException (com.fathomdb.cli.CliException)12 IOException (java.io.IOException)4 NoCloseInputStream (com.fathomdb.io.NoCloseInputStream)3 File (java.io.File)3 InputStream (java.io.InputStream)3 PlatformLayerClient (org.platformlayer.PlatformLayerClient)3 UserDatabase (org.platformlayer.auth.UserDatabase)3 Ansi (com.fathomdb.cli.commands.Ansi)2 Certificate (java.security.cert.Certificate)2 ProjectEntity (org.platformlayer.auth.ProjectEntity)2 UserEntity (org.platformlayer.auth.UserEntity)2 UntypedItem (org.platformlayer.common.UntypedItem)2 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)2 Element (org.w3c.dom.Element)2 ClientAction (com.fathomdb.cli.output.ClientAction)1 CryptoKey (com.fathomdb.crypto.CryptoKey)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InetAddress (java.net.InetAddress)1 KeyStore (java.security.KeyStore)1