Package com.fathomdb.cli

Examples of com.fathomdb.cli.CliException


  }

  @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;
View Full Code Here


    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));
View Full Code Here

    // 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;
View Full Code Here

      try {
        data = ByteStreams.toByteArray(stream);

        json = new String(data, Charsets.UTF_8);
      } catch (IOException e) {
        throw new CliException("Error reading stdin", e);
      }
    }

    JSONObject jsonObject = new JSONObject(json);

    PlatformLayerKey parentKey = null;
    if (parent != null || !tags.isEmpty()) {

      JSONObject tagsObject = null;
      if (jsonObject.has("tags")) {
        tagsObject = jsonObject.getJSONObject("tags");
      } else {
        tagsObject = new JSONObject();
        jsonObject.put("tags", tagsObject);
      }

      JSONArray tagsArray;
      if (tagsObject.has("tags")) {
        tagsArray = tagsObject.getJSONArray("tags");
      } else {
        tagsArray = new JSONArray();
        tagsObject.put("tags", tagsArray);
      }

      if (parent != null) {
        parentKey = parent.resolve(getContext());
        Tag parentTag = Tag.buildParentTag(parentKey);

        JSONObject jsonTag = new JSONObject();
        jsonTag.put("key", parentTag.getKey());
        jsonTag.put("value", parentTag.getValue());

        tagsArray.put(jsonTag);
      }

      for (String tag : tags) {
        int equalsIndex = tag.indexOf('=');
        if (equalsIndex == -1) {
          throw new CliException("Expected tagname=tagvalue");
        }

        String tagName = tag.substring(0, equalsIndex);
        String tagValue = tag.substring(equalsIndex + 1);
View Full Code Here

  public UserDatabase getUserRepository() {
    try {
      return injector.getInstance(UserDatabase.class);
    } catch (ConfigurationException e) {
      throw new CliException("Database not configured; must set auth.system.module in configuration");
    }
  }
View Full Code Here

    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);
    }
View Full Code Here

  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);
  }
View Full Code Here

  @Override
  protected void changeItem(UntypedItemXml item) {
    Element element = getElement(item, key);

    if (element == null) {
      throw new CliException("Cannot find element: " + key);
    }

    element.setTextContent(value);
  }
View Full Code Here

  @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();
View Full Code Here

      ProjectId project = key.getProject();
      if (project == null) {
        project = client.getProject();
      }
      if (project == null) {
        throw new CliException("Cannot determine project");
      }
      String projectKey = project.getKey();
      String serviceKey = "service-" + key.getServiceType().getKey();

      File sshKey = IoUtils.resolve("~/.credentials/ssh/" + projectKey + "/" + serviceKey);
View Full Code Here

TOP

Related Classes of com.fathomdb.cli.CliException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.