use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class AccountVerify method parse.
@Override
public void parse(String commandText) throws Exception {
try {
GNSClientCommands client = module.getGnsClient();
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 2) {
wrongArguments();
return;
}
String alias = st.nextToken();
GuidEntry guid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), alias);
if (guid == null) {
printString("Unable to retrieve GUID for alias " + alias + "\n");
return;
}
String code = st.nextToken();
try {
if (client.accountGuidVerify(guid, code).startsWith(GNSProtocol.OK_RESPONSE.toString())) {
printString("Account verified.\n");
module.setAccountVerified(true);
return;
}
// this happens if it was already verified, but we didn't notice
} catch (VerificationException e) {
module.setAccountVerified(true);
printString("Account already verified" + "\n");
return;
} catch (Exception e) {
printString("Account not verified: " + e + "\n");
}
} catch (Exception e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
module.setAccountVerified(false);
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class AclAdd method parse.
@Override
public void parse(String commandText) throws Exception {
try {
GNSClientCommands gnsClient = module.getGnsClient();
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 3) {
wrongArguments();
return;
}
String field = st.nextToken();
boolean isWrite = "write".equalsIgnoreCase(st.nextToken());
String guid = st.nextToken();
// Set ACL
gnsClient.aclAdd(isWrite ? AclAccessType.WRITE_WHITELIST : AclAccessType.READ_WHITELIST, module.getCurrentGuid(), field, "+ALL+".equals(guid) ? null : guid);
// Then read ACLs
JSONArray write = gnsClient.aclGet(isWrite ? AclAccessType.WRITE_WHITELIST : AclAccessType.READ_WHITELIST, module.getCurrentGuid(), field, module.getCurrentGuid().getGuid());
console.printString("New ACL is: " + write.toString());
console.printNewline();
} catch (Exception e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class AliasLookup method parse.
@Override
public void parse(String commandText) throws Exception {
try {
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 1) {
wrongArguments();
return;
}
String guid = st.nextToken();
GNSClientCommands gnsClient = module.getGnsClient();
JSONObject entityInfo = gnsClient.lookupGuidRecord(guid);
String alias = entityInfo.getString(GNSProtocol.GUID_RECORD_NAME.toString());
console.printString(guid + " has alias " + alias);
console.printNewline();
} catch (IOException | ClientException | JSONException e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class AclExists method parse.
@Override
public void parse(String commandText) throws Exception {
try {
GNSClientCommands gnsClient = module.getGnsClient();
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 2) {
wrongArguments();
return;
}
String field = st.nextToken();
boolean isWrite = "write".equalsIgnoreCase(st.nextToken());
// Set ACL
boolean exists = gnsClient.fieldAclExists(isWrite ? AclAccessType.WRITE_WHITELIST : AclAccessType.READ_WHITELIST, module.getCurrentGuid(), field);
if (exists) {
// Then read ACLs
JSONArray acl = gnsClient.aclGet(isWrite ? AclAccessType.WRITE_WHITELIST : AclAccessType.READ_WHITELIST, module.getCurrentGuid(), field, module.getCurrentGuid().getGuid());
console.printString((isWrite ? "Write" : "Read") + " ACL is: " + acl.toString());
console.printNewline();
} else {
console.printString((isWrite ? "Write" : "Read") + " ACL for field " + field + " does not exist");
console.printNewline();
}
} catch (IOException | ClientException e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.
the class FieldCreateList method parse.
@Override
public void parse(String commandText) throws Exception {
try {
StringTokenizer st = new StringTokenizer(commandText.trim());
if ((st.countTokens() != 1) && (st.countTokens() != 2)) {
wrongArguments();
return;
}
String field = st.nextToken();
String value = "";
if (st.hasMoreTokens()) {
value = st.nextToken();
}
GNSClientCommands gnsClient = module.getGnsClient();
gnsClient.fieldCreateList(module.getCurrentGuid().getGuid(), field, new JSONArray().put(value), module.getCurrentGuid());
console.printString("New field " + field + " created with value '" + value + "'");
console.printNewline();
} catch (IOException | ClientException e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
Aggregations