use of com.bluenimble.platform.api.impls.ApiByteArrayOutput in project serverless by bluenimble.
the class DownloadRootKeysSpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String paraphrase = (String) request.get(Spec.Paraphrase);
try {
KeyPair kp = api.space().getRootKeys();
JsonObject oKeys = new JsonObject();
oKeys.set(Output.Name, Json.getString(request.getNode(), ApiRequest.Fields.Node.Id) + " " + Json.getString(request.getNode(), ApiRequest.Fields.Node.Version));
oKeys.set(Output.Endpoint, request.getScheme() + "://" + request.getEndpoint() + Lang.SLASH + api.space().getNamespace() + Lang.SLASH + api.getNamespace());
oKeys.set(KeyPair.Fields.AccessKey, kp.accessKey());
oKeys.set(KeyPair.Fields.SecretKey, kp.secretKey());
oKeys.set(CommonSpec.Role, "SUPER");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Json.encrypt(oKeys, paraphrase, out);
return new ApiByteArrayOutput(Output.KeysName + Lang.DOT + Output.KeysExt, Base64.encodeBase64(out.toByteArray()), ApiContentTypes.Stream, Output.KeysExt).set(ApiOutput.Defaults.Disposition, "attachment");
} catch (Exception e) {
throw new ApiServiceExecutionException(e.getMessage()).status(ApiResponse.FORBIDDEN);
}
}
use of com.bluenimble.platform.api.impls.ApiByteArrayOutput in project serverless by bluenimble.
the class GetKeysSpi method toOutput.
private ApiOutput toOutput(KeyPair kp, String paraphrase, ApiSpace keysSpace, Api api, ApiRequest request) throws EncryptionProviderException {
JsonObject oKeys = new JsonObject();
oKeys.set(Output.Name, keysSpace.getName());
oKeys.set(Output.Space, keysSpace.getNamespace());
oKeys.set(Output.Endpoint, request.getScheme() + "://" + request.getEndpoint() + Lang.SLASH + api.space().getNamespace() + Lang.SLASH + api.getNamespace());
oKeys.set(Output.Domain, request.getScheme() + "://" + request.getEndpoint() + Lang.SLASH + keysSpace.getNamespace());
if (kp.expiryDate() != null) {
oKeys.set(KeyPair.Fields.ExpiryDate, Lang.toUTC(kp.expiryDate()));
}
oKeys.set(KeyPair.Fields.AccessKey, kp.accessKey());
oKeys.set(KeyPair.Fields.SecretKey, kp.secretKey());
Iterator<String> props = kp.properties();
if (props != null) {
JsonObject oProps = new JsonObject();
oKeys.set(KeyPair.Fields.Properties, oProps);
while (props.hasNext()) {
String p = props.next();
oProps.set(p, kp.property(p));
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
Json.encrypt(oKeys, paraphrase, out);
return new ApiByteArrayOutput(keysSpace.getNamespace() + Lang.DOT + Output.KeysExt, Base64.encodeBase64(out.toByteArray()), ApiContentTypes.Stream, Output.KeysExt).set(ApiOutput.Defaults.Disposition, "attachment");
}
Aggregations