use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SelectRecordsExample method createUserRecords.
/**
* Create some example user records.
*/
private static void createUserRecords() {
Random random = new Random();
for (int i = 0; i < 30; i++) {
try {
client.execute(GNSCommand.createGUID(accountGuidEntry, "user-" + i));
GuidEntry userGuid = GuidUtils.getGUIDKeys("user-" + i);
System.out.print("+");
// Randomly place the in the region
double lon = LEFT_LON + (RIGHT_LON - LEFT_LON) * random.nextDouble();
double lat = BOTTOM_LAT + (TOP_LAT - BOTTOM_LAT) * random.nextDouble();
client.execute(GNSCommand.setLocation(userGuid, lon, lat));
// Add some additional random attributes
client.execute(GNSCommand.fieldUpdate(userGuid, "age", random.nextInt(40) + 20));
client.execute(GNSCommand.fieldUpdate(userGuid, "preference", random.nextInt(2) == 0 ? "Long" : "Short"));
} catch (ClientException e) {
// Catch the normal case where the records already exist
if (ResponseCode.CONFLICTING_GUID_EXCEPTION.equals(e.getCode())) {
System.out.print(".");
} else {
System.out.println("Problem creating user: " + e.getMessage());
}
} catch (IOException e) {
System.out.println("Problem creating user: " + e.getMessage());
}
}
System.out.println();
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class Select method parse.
@Override
public void parse(String commandText) throws Exception {
try {
GNSClientCommands gnsClient = module.getGnsClient();
StringTokenizer st = new StringTokenizer(commandText.trim());
GuidEntry guidEntry;
switch(st.countTokens()) {
case 2:
guidEntry = null;
break;
case 3:
String alias = st.nextToken();
guidEntry = KeyPairUtils.getGuidEntry(module.getGnsInstance(), alias);
if (guidEntry == null) {
console.printString("Unknown alias " + alias);
console.printNewline();
return;
}
break;
default:
wrongArguments();
return;
}
String field = st.nextToken();
String value = st.nextToken();
JSONArray result;
if (guidEntry != null) {
result = gnsClient.select(guidEntry, field, value);
} else {
result = gnsClient.select(field, value);
}
console.printString(result.toString());
console.printNewline();
} catch (IOException | ClientException e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class SetDefaultGuid method parse.
@Override
public void parse(String commandText) throws Exception {
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 1) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
GNSClientCommands gnsClient = module.getGnsClient();
try {
try {
gnsClient.lookupGuid(aliasName);
} catch (ClientException e) {
console.printString("Alias " + aliasName + " is not registered in the GNS\n");
return;
}
if (!module.isSilent()) {
console.printString("Looking up alias " + aliasName + " GUID and certificates...\n");
}
GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
if (myGuid == null) {
console.printString("You do not have the private key for alias " + aliasName);
console.printNewline();
return;
}
// Success, let's update the console prompt with the new alias name
// module.setCurrentGuid(myGuid);
module.setDefaultGuidAndCheckForVerified(myGuid);
if (!module.isSilent()) {
console.printString("Default GUID set to " + aliasName + "\n");
}
} catch (IOException e) {
console.printString("Failed to access the GNS ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class PrivateKeyExport method parse.
@Override
public void parse(String commandText) throws Exception {
try {
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 2) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
String filename = st.nextToken();
if (!module.isSilent()) {
console.printString("Looking up alias " + aliasName + " GUID and certificates...\n");
}
GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
if (myGuid == null) {
console.printString("You do not have the private key for alias " + aliasName);
console.printNewline();
return;
}
if (KeyPairUtils.writePrivateKeyToPKCS8File(myGuid.getPrivateKey(), filename)) {
console.printString("Private key for " + aliasName + " stored in " + filename + " in " + myGuid.getPrivateKey().getFormat() + " format.");
console.printNewline();
}
} catch (Exception e) {
console.printString("Failed to save keys ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class CreateSomeRecordsForDns method createAnARecord.
// Creates an A record in the GNS
private static void createAnARecord(String domain, String address) throws Exception {
// domains need to end with a period
if (!domain.endsWith(".")) {
domain = domain + ".";
}
GuidEntry guid = GuidUtils.lookupOrCreateGuid(client, accountGuid, domain);
client.fieldUpdate(guid, "A", address);
System.out.println("Value of A in " + guid.getEntityName() + " is " + client.fieldRead(guid, "A"));
}
Aggregations