use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class IndexerApiRequestTrack method update.
@Override
public void update(ApiConsumer consumer) {
if (consumer == null) {
return;
}
JsonObject oConsumer = new JsonObject();
oConsumer.set(ApiConsumer.Fields.Type, consumer.get(ApiConsumer.Fields.Type));
oConsumer.set(ApiConsumer.Fields.Id, consumer.get(ApiConsumer.Fields.Id));
oConsumer.set(ApiConsumer.Fields.Token, consumer.get(ApiConsumer.Fields.Token));
oConsumer.set(ApiConsumer.Fields.AccessKey, consumer.get(ApiConsumer.Fields.AccessKey));
track.set(Fields.Consumer, oConsumer);
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class Json method load.
public static JsonObject load(ClassLoader loader, String name) throws Exception {
if (Lang.isNullOrEmpty(name)) {
throw new NullPointerException("load with no parameters");
}
InputStream is = null;
try {
if (name.indexOf(Lang.URL_ACCESSOR) > 0) {
URL url = new URL(name);
is = url.openStream();
} else {
is = loader.getResourceAsStream(name);
}
return new JsonObject(IOUtils.toString(is));
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ex) {
ex.printStackTrace(System.err);
}
}
}
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class Json method main.
public static void main(String[] args) throws Exception {
// byte [] bytes = Base64.decode (IOUtils.toString (new FileInputStream ("C:\\Users\\LINVI\\bluenimble\\keys\\bnx.keys")));
// System.out.println (Json.load (new ByteArrayInputStream (bytes), "alpha00000000000"));
// System.out.println (Base64.encode (IOUtils.toByteArray (new FileInputStream (new File ("/tmp/bnx.keys")))));
/*
{
"name": "Bluemible Bnx Develepment Environment",
"issuer": "Alpha Works",
"endpoint": {
"default": "http://tempo.bluenimble.space/sys/mgm"
},
"space": "bnx",
"accessKey": "XW3ZCJ+WFRQXMBTNXAB0",
"secretKey": "YYX+oxbaTAkTVVYPLkniwp9als6i3ZzzQLBoi2av"
}
should become https://sys.bluenimble.space/mgm
These are
https://apis.bluenimble.space/customer
https://apis.bluenimble.space/partner
https://apis.bluenimble.space/partner
// read the encrypted/encoded keys file
byte [] bytes = Base64.decodeBase64 (IOUtils.toString (new FileInputStream ("C:\\Users\\LINVI\\bluenimble\\keys\\lead.keys")));
// parse json with an encryption paraphrase
JsonObject oKeys = Json.load (new ByteArrayInputStream (bytes), "alpha00000000000");
oKeys.set ("endpoint", "https://apis.bluenimble.space/mgm/4d8d38bd-deac-4ad8-a695-a7fbfd087c3b");
Json.store (oKeys, new File ("/tmp/lead.keys.bin"), "alpha00000000000");
System.out.println (
Base64.encodeBase64String (IOUtils.toByteArray (new FileInputStream (new File ("/tmp/lead.keys.bin"))))
);
*/
JsonObject keys = Json.load(new File("tests/files/demos-plain.keys"));
store(keys, new File("tests/files/demos.keys.bin"), "python.123000000");
System.out.println(Base64.encodeBase64String(IOUtils.toByteArray(new FileInputStream(new File("tests/files/demos.keys.bin")))));
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class Json method store.
public static void store(JsonObject source, File file, String paraphrase, boolean base64) throws IOException {
if (source == null) {
source = new JsonObject();
}
OutputStream os = null;
try {
os = Lang.isNullOrEmpty(paraphrase) ? new FileOutputStream(file) : new ByteArrayOutputStream();
IOUtils.copy(new ByteArrayInputStream(source.toString(2).getBytes()), os);
} finally {
if (Lang.isNullOrEmpty(paraphrase)) {
IOUtils.closeQuietly(os);
}
}
if (!Lang.isNullOrEmpty(paraphrase)) {
OutputStream out = null;
try {
out = base64 ? new ByteArrayOutputStream() : new FileOutputStream(file);
EncryptionProvider.Default.crypt(new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray()), out, pad(paraphrase), Mode.Encrypt);
if (base64) {
byte[] bytes = Base64.encodeBase64(((ByteArrayOutputStream) out).toByteArray());
out = new FileOutputStream(file);
out.write(bytes);
out.flush();
}
} catch (EncryptionProviderException e) {
throw new IOException(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(out);
}
}
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class Json method load.
public static JsonObject load(InputStream stream, String salt) throws Exception {
if (!Lang.isNullOrEmpty(salt)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncryptionProvider.Default.crypt(stream, out, salt, Mode.Decrypt);
stream = new ByteArrayInputStream(out.toByteArray());
}
return new JsonObject(IOUtils.toString(stream));
}
Aggregations