use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiTest method testSaveRetrieve.
public void testSaveRetrieve() {
String randomApiString = this.getRandomString();
this.api.saveApi(new ApiResult(0, randomApiString, "privateKey", "", ""));
ApiResult apiResult = this.api.getApiByPublicKey(randomApiString);
assertThat(apiResult.getPublicKey()).isEqualTo(randomApiString);
assertThat(apiResult.getPrivateKey()).isEqualTo("privateKey");
this.api.deleteApiByPublicKey(randomApiString);
}
use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiTest method testMultipleRetrieveCache.
public void testMultipleRetrieveCache() {
String randomApiString = this.getRandomString();
this.api.saveApi(new ApiResult(0, randomApiString, "privateKey", "", ""));
for (int i = 0; i < 500; i++) {
ApiResult apiResult = this.api.getApiByPublicKey(randomApiString);
assertThat(apiResult.getPublicKey()).isEqualTo(randomApiString);
assertThat(apiResult.getPrivateKey()).isEqualTo("privateKey");
}
this.api.deleteApiByPublicKey(randomApiString);
}
use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiTest method testGetAllApi.
public void testGetAllApi() {
String randomApi1 = this.getRandomString();
String randomApi2 = this.getRandomString();
this.api.saveApi(new ApiResult(0, randomApi1, "privateKey", "", ""));
this.api.saveApi(new ApiResult(0, randomApi2, "privateKey", "", ""));
assertThat(this.api.getAllApi().size()).isEqualTo(2);
this.api.deleteApiByPublicKey(randomApi1);
this.api.deleteApiByPublicKey(randomApi2);
}
use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class ApiService method createKeys.
/**
* Creates a public and private key with access to the API
* TODO allow creation of permissions for keys
*/
public ApiResult createKeys() {
String publicKey = "APIK-" + RandomStringUtils.randomAlphanumeric(27);
String privateKey = RandomStringUtils.randomAlphanumeric(32);
ApiResult apiResult = new ApiResult(-1, publicKey, privateKey, Values.EMPTYSTRING, Values.EMPTYSTRING);
this.api.saveApi(apiResult);
return apiResult;
}
use of com.searchcode.app.model.ApiResult in project searchcode-server by boyter.
the class Api method getAllApi.
public synchronized List<ApiResult> getAllApi() {
List<ApiResult> apiResults = new ArrayList<>();
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
connection = this.dbConfig.getConnection();
preparedStatement = connection.prepareStatement("select rowid,publickey,privatekey,lastused,data from api;");
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
int rowId = resultSet.getInt("rowid");
String d_publicKey = resultSet.getString("publickey");
String privateKey = resultSet.getString("privatekey");
String lastUsed = resultSet.getString("lastused");
String data = resultSet.getString("data");
apiResults.add(new ApiResult(rowId, d_publicKey, privateKey, lastUsed, data));
}
} catch (SQLException ex) {
Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} finally {
this.helpers.closeQuietly(resultSet);
this.helpers.closeQuietly(preparedStatement);
}
return apiResults;
}
Aggregations