Search in sources :

Example 6 with CliException

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

the class KeystoneCliContext method getCertificateChain.

public Certificate[] getCertificateChain(String keystore, String keystoreSecret, String keyAlias) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
    if (getOptions().isServerMode()) {
        throw new IllegalArgumentException("Files not supported in server mode");
    }
    if (keystoreSecret == null) {
        keystoreSecret = KeyStoreUtils.DEFAULT_KEYSTORE_SECRET;
    }
    KeyStore keyStore = KeyStoreUtils.load(new File(keystore), keystoreSecret);
    if (keyAlias == null) {
        List<String> keyAliases = KeyStoreUtils.getKeyAliases(keyStore);
        if (keyAliases.size() == 0) {
            throw new CliException("No keys found in keystore");
        }
        if (keyAliases.size() != 1) {
            System.out.println("Found keys:\n\t" + Joiner.on("\n\t").join(keyAliases));
            throw new CliException("Multiple keys found in keystore; specify --alias");
        }
        keyAlias = keyAliases.get(0);
    }
    Certificate[] certificateChain = keyStore.getCertificateChain(keyAlias);
    return certificateChain;
}
Also used : CliException(com.fathomdb.cli.CliException) KeyStore(java.security.KeyStore) File(java.io.File) Certificate(java.security.cert.Certificate)

Example 7 with CliException

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

the class CreateProject method runCommand.

@Override
public Object runCommand() throws RepositoryException {
    UserDatabase userRepository = getContext().getUserRepository();
    // We need to login to unlock the user key so we can encrypt the project key!
    UserEntity me = getContext().loginDirect();
    if (projectKey.contains("@@")) {
        throw new CliException("Project names with @@ are reserved for system uses");
    }
    ProjectEntity project = userRepository.createProject(projectKey, me);
    return project;
}
Also used : CliException(com.fathomdb.cli.CliException) ProjectEntity(org.platformlayer.auth.ProjectEntity) UserDatabase(org.platformlayer.auth.UserDatabase) UserEntity(org.platformlayer.auth.UserEntity)

Example 8 with CliException

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

the class AddConfig method changeItem.

@Override
protected void changeItem(UntypedItemXml item) {
    Element element = getElement(item, property);
    if (element == null) {
        throw new CliException("Cannot find element: " + property);
    }
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getLocalName();
    Node parentNode = element.getParentNode();
    String parentNamespaceUri = parentNode.getNamespaceURI();
    String parentTag = parentNode.getLocalName();
    String pathKey = parentNamespaceUri + ":" + parentTag + ":" + namespaceURI + ":" + localName;
    if ("http://platformlayer.org/service/platformlayer/v1.0:platformLayerService:http://platformlayer.org/service/platformlayer/v1.0:config".equals(pathKey)) {
        Element newNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "property");
        Element keyNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "key");
        keyNode.setTextContent(key);
        Element valueNode = element.getOwnerDocument().createElementNS(NAMESPACE_URI_CORE, "value");
        valueNode.setTextContent(value);
        newNode.appendChild(keyNode);
        newNode.appendChild(valueNode);
        element.appendChild(newNode);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : CliException(com.fathomdb.cli.CliException) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node)

Example 9 with CliException

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

the class SetProperty method runCommand.

@Override
public Object runCommand() throws PlatformLayerClientException, IOException {
    PlatformLayerClient client = getPlatformLayerClient();
    if (stdin) {
        if (value != null) {
            throw new CliException("You cannot specify a value when using -stdin");
        }
        InputStream stream = new NoCloseInputStream(System.in);
        byte[] data = ByteStreams.toByteArray(stream);
        if ("base64".equals(format)) {
            value = Base64.encode(data);
        } else {
            value = new String(data);
        }
    } else {
        if (value == null) {
            throw new CliException("Value is required (if not using -stdin)");
        }
    }
    return runCommand(path);
}
Also used : PlatformLayerClient(org.platformlayer.PlatformLayerClient) NoCloseInputStream(com.fathomdb.io.NoCloseInputStream) CliException(com.fathomdb.cli.CliException) NoCloseInputStream(com.fathomdb.io.NoCloseInputStream) InputStream(java.io.InputStream)

Example 10 with CliException

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

the class ListJobExecutions method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    JobExecutionList jobs = (JobExecutionList) o;
    switch(getFormat()) {
        case JSON:
            JsonHelper<JobExecutionList> jsonHelper = JsonHelper.build(JobExecutionList.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 (JobExecutionData job : jobs) {
        JobState state = job.state;
        if (state != null) {
            switch(job.state) {
                case FAILED:
                    ansi.setColorRed();
                    break;
                case SUCCESS:
                    ansi.setColorGreen();
                    break;
                case RUNNING:
                    ansi.setColorBlue();
                    break;
                default:
                    ansi.setColorBlue();
                    break;
            }
        } else {
            ansi.setColorBlue();
        }
        writer.println(job.getJobId() + "/" + job.executionId);
    }
    ansi.reset();
}
Also used : CliException(com.fathomdb.cli.CliException) JobExecutionData(org.platformlayer.jobs.model.JobExecutionData) JobState(org.platformlayer.jobs.model.JobState) IOException(java.io.IOException) JobExecutionList(org.platformlayer.jobs.model.JobExecutionList) Ansi(com.fathomdb.cli.commands.Ansi)

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