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;
}
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;
}
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();
}
}
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);
}
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();
}
Aggregations