Exemple #1
0
  @ScriptUsage(
      description = "revoke procedure",
      arguments = {
        @ScriptArgument(name = "procedure name", type = "string", description = "procedure name"),
        @ScriptArgument(name = "type", type = "string", description = "user or group"),
        @ScriptArgument(name = "login name", type = "string", description = "login name")
      })
  public void revokeProcedure(String[] args) {
    String procName = args[0];
    String type = args[1];
    String target = args[2];

    Procedure p = procedureRegistry.getProcedure(procName);
    if (p == null) {
      context.println("procedure not found");
      return;
    }

    if (type.equals("user")) {
      p.getGrants().remove(target);
      procedureRegistry.updateProcedure(p);
    } else if (type.equals("group")) {
      Map<String, SecurityGroup> groupMap = getSecurityGroupMap();
      SecurityGroup old = groupMap.get(target);
      if (old != null) {
        p.getGrantGroups().remove(old.getGuid());
        procedureRegistry.updateProcedure(p);
      }
    } else {
      context.println("invalid type. use 'user' or 'group'");
      return;
    }

    context.println("revoked");
  }
Exemple #2
0
  public void procedures(String[] args) {
    context.println("Procedures");
    context.println("------------");

    for (Procedure p : procedureRegistry.getProcedures()) {
      int i = 0;
      String signature = p.getName() + "(";
      for (ProcedureParameter param : p.getParameters()) {
        if (i++ != 0) signature += ", ";
        signature += param;
      }
      signature += ")";

      context.println(signature + ", owner=" + p.getOwner());
    }
  }
Exemple #3
0
  public void updateProcedure(String[] args) {
    try {
      String name = readLine("name", null);
      Procedure old = procedureRegistry.getProcedure(name);
      if (old == null) {
        context.println("procedure not found: " + name);
        return;
      }

      Procedure proc = inputProcedure(old);
      proc.setCreated(old.getCreated());
      procedureRegistry.updateProcedure(proc);
      context.println("updated");
    } catch (InterruptedException e) {
      context.println("");
      context.println("interrupted");
    }
  }
Exemple #4
0
  private Procedure inputProcedure(Procedure old) throws InterruptedException {
    Procedure proc = new Procedure();

    if (old == null) proc.setName(readLine("name", null));
    else proc.setName(old.getName());

    proc.setOwner(readLine("owner", old != null ? old.getOwner() : null));
    proc.setGrants(
        new HashSet<String>(
            Strings.tokenize(
                readLine("grants", old != null ? Strings.join(old.getGrants(), ", ") : null),
                ",")));
    proc.setQueryString(readLine("query", old != null ? old.getQueryString() : null));

    List<ProcedureParameter> parameters = new ArrayList<ProcedureParameter>();
    context.println(
        "Type parameter definitions in \"type name\" format. e.g. \"string opt\", press enter to end.");
    int idx = 0;
    while (true) {
      ProcedureParameter oldParam = null;
      if (old != null && idx < old.getParameters().size()) {
        oldParam = old.getParameters().get(idx);
      }

      context.print("parameter? ");
      String line = context.readLine(oldParam != null ? oldParam.toString() : null);
      if (line.isEmpty()) break;

      int p = line.indexOf(" ");
      String type = line.substring(0, p).trim();
      String key = line.substring(p + 1).trim();

      parameters.add(new ProcedureParameter(key, type));
      idx++;
    }

    proc.setParameters(parameters);

    return proc;
  }