use of com.fathomdb.cli.CliException in project platformlayer by platformlayer.
the class JoinProject method runCommand.
@Override
public Object runCommand() throws RepositoryException, IOException {
UserDatabase userRepository = getContext().getUserRepository();
UserEntity me = getContext().loginDirect();
ProjectEntity project = userRepository.findProjectByKey(projectKey.getKey());
if (project == null) {
throw new CliException("Project not found: " + projectKey.getKey());
}
SecretStore secretStore = new SecretStore(project.secretData);
CryptoKey projectSecret = secretStore.getSecretFromUser(me);
if (projectSecret == null) {
String msg = "Cannot retrieve project secret.";
msg += " Is " + me.key + " a member of " + project.getName() + "?";
throw new CliException(msg);
}
if (Strings.isNullOrEmpty(roleKey)) {
throw new CliException("Role is required");
}
RoleId role = new RoleId(roleKey);
userRepository.addUserToProject(username.getKey(), project.getName(), projectSecret, Collections.singletonList(role));
return project;
}
use of com.fathomdb.cli.CliException in project platformlayer by platformlayer.
the class ConfigurationOptions method buildPlatformLayerClient.
public PlatformLayerClient buildPlatformLayerClient() throws IOException, OpsException {
HttpPlatformLayerClient client;
if (configFile == null) {
throw new IllegalArgumentException("Config file is required");
}
InputStream is = null;
try {
if (configFile.equals("-")) {
// Read from stdin
// Don't auto-close it: that terminates nailgun
is = new NoCloseInputStream(System.in);
} else {
if (isServerMode()) {
throw new IllegalArgumentException("Must pass config file over stdin in server mode");
}
File file = IoUtils.resolve(configFile);
if (!file.exists()) {
throw new FileNotFoundException("Configuration file not found: " + file);
}
is = new FileInputStream(file);
}
final Properties properties = new Properties();
try {
properties.load(is);
} catch (IOException e) {
throw new IOException("Error reading configuration file", e);
}
if (properties.getProperty("platformlayer.username") == null) {
throw new CliException("User property not set in configuration file");
}
if (debug) {
client = buildPlatformLayerClient(properties, debug);
} else {
String propertiesKey = PropertyUtils.serialize(properties);
try {
client = platformLayerClientCache.get(propertiesKey, new Callable<HttpPlatformLayerClient>() {
@Override
public HttpPlatformLayerClient call() throws Exception {
return buildPlatformLayerClient(properties, false);
}
});
} catch (ExecutionException e) {
throw new CliException("Error building platformlayer client", e);
}
}
} finally {
if (is != System.in) {
Closeables.closeQuietly(is);
}
}
return client;
}
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 SetProperty method changeItem.
@Override
protected void changeItem(UntypedItemXml item) {
Element element = getElement(item, key);
if (element == null) {
throw new CliException("Cannot find element: " + key);
}
element.setTextContent(value);
}
Aggregations