#include <iostream>
#include <log/logger.hpp>
+#include <exception>
PostgresJobProvider::PostgresJobProvider( const std::string& server, const std::string& user, const std::string& password, const std::string& database ):
c("dbname="+database+" host="+server+" user="+user+" password=" + password + " client_encoding=UTF-8 application_name=cassiopeia-client"){
pqxx::result r = txn.exec(q);
if( r.affected_rows() != 1 ) {
- throw "No database entry found.";
+ throw std::runtime_error("No database entry found.");
}
txn.commit();
}
pqxx::result r = txn.exec(q);
if( r.affected_rows() != 1 ) {
- throw "No database entry found.";
+ throw std::runtime_error("No database entry found.");
}
txn.commit();
}
pqxx::result r = txn.exec(q);
if( r.size() != 1 ) {
- throw "Error, no or multiple certs found";
+ throw std::runtime_error("Error, no or multiple certs found");
}
auto ro = r[0];
std::string read_id;
if( r.size() != 1) {
- throw "Error while inserting new ca cert not found";
+ throw std::runtime_error("Error while inserting new ca cert not found");
} else {
read_id = r[0]["id"].as<std::string>();
}
std::string serial = res->serial;
std::transform(serial.begin(), serial.end(), serial.begin(), ::tolower);
+ if(serial[0] == '0'){
+ serial = serial.substr(1);
+ }
std::string q = "UPDATE certs SET crt_name=" + txn.quote( res->crt_name ) + ", serial=" + txn.quote( serial ) + ", \"caid\" = " + txn.quote( read_id ) + ", created=" + txn.quote( pgTime(res->before) ) + ", expire=" + txn.quote( pgTime(res->after) ) + " WHERE id=" + txn.quote( job->target );
// TODO write more thingies back
r = txn.exec( q );
if( r.affected_rows() != 1 ){
- throw "Only one row should be updated.";
+ throw std::runtime_error("Only one row should be updated.");
}
txn.commit();
}
pqxx::result r = txn.exec( q );
if( r.size() != 1) {
- throw "Only one row expected but multiple found.";
+ throw std::runtime_error("Only one row expected but multiple found.");
}
}
void PostgresJobProvider::writeBackRevocation( std::shared_ptr<Job> job, std::string date ) {
- logger::errorf( "Revoking at " + date);
+ logger::notef( "Revoking at %s", date);
pqxx::work txn(c);
- logger::errorf( "executing" );
+ logger::note( "executing" );
pqxx::result r = txn.exec( "UPDATE certs SET revoked = " + txn.quote( pgTime( date ) ) + " WHERE id = " + txn.quote( job->target ) );
if( r.affected_rows() != 1 ){
- throw "Only one row should be updated.";
+ throw std::runtime_error("Only one row should be updated.");
}
- logger::errorf( "committing" );
+ logger::note( "committing" );
txn.commit();
- logger::errorf( "committed" );
+ logger::note( "committed" );
}