use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.
the class PGPPublicKeyAPI method uploadNewPGPPublicKey.
// end of getPGPPublicKeyByFingerprint()
@ApiMethod(name = "uploadNewPGPPublicKey", path = "uploadNewPGPPublicKey", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public PGPPublicKeyUploadReturn uploadNewPGPPublicKey(// final HttpServletRequest httpServletRequest,
final User googleUser, final PGPPublicKeyUploadForm pgpPublicKeyUploadForm) throws Exception {
// authorization
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
//
if (pgpPublicKeyUploadForm == null || pgpPublicKeyUploadForm.getAsciiArmored() == null || pgpPublicKeyUploadForm.getAsciiArmored().length() == 0) {
throw new Exception("ASCII-armored key is empty");
}
// --- LOG request form: (after check if not null)
LOG.warning(GSON.toJson(pgpPublicKeyUploadForm));
String asciiArmored = pgpPublicKeyUploadForm.getAsciiArmored();
PGPPublicKey pgpPublicKey = PGPTools.readPublicKeyFromString(asciiArmored);
// -> throws IOException, PGPException
LOG.warning(GSON.toJson(pgpPublicKey));
PGPPublicKeyData pgpPublicKeyData = PGPTools.checkPublicKey(pgpPublicKey, asciiArmored, cryptonomicaUser);
pgpPublicKeyData.setUserBirthday(cryptonomicaUser.getBirthday());
// -- add @Parent value: ---
pgpPublicKeyData.setCryptonomicaUserKey(Key.create(CryptonomicaUser.class, googleUser.getUserId()));
// save key
Key<PGPPublicKeyData> pgpPublicKeyDataKey = ofy().save().entity(pgpPublicKeyData).now();
// load key from DB and and create return object
String messageToUser = "Key " + pgpPublicKeyData.getFingerprint() + " saved in data base";
PGPPublicKeyGeneralView pgpPublicKeyGeneralView = new PGPPublicKeyGeneralView(ofy().load().key(pgpPublicKeyDataKey).now());
PGPPublicKeyUploadReturn pgpPublicKeyUploadReturn = new PGPPublicKeyUploadReturn(messageToUser, pgpPublicKeyGeneralView);
return pgpPublicKeyUploadReturn;
}
use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.
the class PGPPublicKeyAPI method getMyKeys.
@ApiMethod(name = "getMyKeys", path = "getMyKeys", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public // 4) by first and last names
SearchPGPPublicKeysReturn getMyKeys(// final HttpServletRequest httpServletRequest,
final User googleUser) throws Exception {
// authorization
UserTools.ensureCryptonomicaRegisteredUser(googleUser);
//
Key<CryptonomicaUser> cryptonomicaUserKey = Key.create(CryptonomicaUser.class, googleUser.getUserId());
List<PGPPublicKeyData> result = ofy().load().type(PGPPublicKeyData.class).ancestor(cryptonomicaUserKey).list();
SearchPGPPublicKeysReturn searchPGPPublicKeysReturn;
if (result.size() > 0) {
searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("this is list of your keys, if any:", new ArrayList<>(result));
} else {
searchPGPPublicKeysReturn = new SearchPGPPublicKeysReturn("You have no keys, yet.", new ArrayList<>(result));
}
return searchPGPPublicKeysReturn;
}
use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.
the class UploadAPI method getCsUploadURL.
@ApiMethod(name = "getCsUploadURL", path = "getCsUploadURL", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public GetCSuploadURLreturn getCsUploadURL(User googleUser) throws Exception {
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
//
String imageUploadUrl = BlobstoreServiceFactory.getBlobstoreService().createUploadUrl(// upload handler servlet address
"/cs-user-image-upload", UploadOptions.Builder.withGoogleStorageBucketName(// Cloud Storage bucket name (f.e. "cryptonomica-test.appspot.com")
Constants.GAE_PROJECT_DOMAIN));
String imageUploadKey = randomAlphanumeric(9);
//
cryptonomicaUser.setImageUploadLink(imageUploadUrl);
cryptonomicaUser.setImageUploadKey(imageUploadKey);
//
Key<CryptonomicaUser> cryptonomicaUserKey = ofy().save().entity(cryptonomicaUser).now();
LOG.warning("Upload URL: " + imageUploadUrl);
LOG.warning("Saved for user: " + cryptonomicaUserKey.getName());
LOG.warning("With imageUploadKey: " + imageUploadKey);
return new GetCSuploadURLreturn(imageUploadUrl, imageUploadKey, null);
}
use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.
the class UserSearchAndViewAPI method echo.
// end of getUserProfileById @ApiMethod
@ApiMethod(name = "echo", path = "echo", httpMethod = ApiMethod.HttpMethod.GET)
public /* >>>>>>>>>>>>>> this is for testing only
* curl -H "Content-Type: application/json" -X GET -d '{"message":"hello world"}' https://cryptonomica-server.appspot.com/_ah/api/userSearchAndViewAPI/v1/echo
* */
StringWrapperObject echo(@Named("message") String message, @Named("n") @Nullable Integer n) {
StringWrapperObject stringWrapperObject = new StringWrapperObject();
if (n != null && n >= 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i > 0) {
sb.append(" ");
}
sb.append(message);
}
stringWrapperObject.setMessage(sb.toString());
}
return stringWrapperObject;
}
use of com.google.api.server.spi.config.ApiMethod in project cryptonomica by Cryptonomica.
the class VerificationAPI method getVerificationByID.
/* --- Get verification info by verification ID: */
@ApiMethod(name = "getVerificationByID", path = "getVerificationByID", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public VerificationGeneralView getVerificationByID(final HttpServletRequest httpServletRequest, final User googleUser, @Named("verificationID") final String verificationID) throws // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
UnauthorizedException, BadRequestException, NotFoundException {
/* --- Check authorization: */
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
/* --- Check input: */
if (verificationID == null || verificationID.equals("")) {
throw new BadRequestException("Verification ID missing");
}
/* --- Load verification entity from DS: */
Verification verification = ofy().load().key(Key.create(Verification.class, verificationID)).now();
if (verification == null) {
throw new NotFoundException("Verification info not found");
}
/* --- Create new verification info representation: */
VerificationGeneralView verificationGeneralView = new VerificationGeneralView(verification);
LOG.warning(new Gson().toJson(verificationGeneralView));
return verificationGeneralView;
}
Aggregations