Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Logging update after latest upstream changes
Browse files Browse the repository at this point in the history
Signed-off-by: Miladinovic Bojan <fixed-term.bojan.miladinovic@se.bosch.com>
  • Loading branch information
Miladinovic Bojan committed Oct 29, 2019
1 parent fca1197 commit c25c338
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
5 changes: 4 additions & 1 deletion w3c-visserver-api/include/permmclient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
#define __PERMMCLIENT_H__

#include <jsoncons/json.hpp>
#include <memory>

using namespace std;
using namespace jsoncons;

json getPermToken(string clientName, string clientSecret);
class ILogger;

json getPermToken(std::shared_ptr<ILogger> logger, string clientName, string clientSecret);



Expand Down
2 changes: 1 addition & 1 deletion w3c-visserver-api/src/authenticator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int authenticator::validateToken(wschannel& channel, string authToken) {
json claims;
(void) channel;
for (auto& e : decoded.get_payload_claims()) {
std::cout << e.first << " = " << e.second.to_json() << std::endl;
logger->Log(LogLevel::INFO, e.first + " = " + e.second.as_string());
claims[e.first] = e.second.to_json().to_str();
}

Expand Down
13 changes: 7 additions & 6 deletions w3c-visserver-api/src/permmclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@

#include "exception.hpp"
#include "permmclient.hpp"
#include "ILogger.hpp"

using namespace std;

#define SERVER "/home/pratheek/socket/kuksa_w3c_perm_management"

json getPermToken(string clientName, string clientSecret) {
json getPermToken(std::shared_ptr<ILogger> logger, string clientName, string clientSecret) {

// Open unix socket connection.
struct sockaddr_un addr;
int fd;

if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
throw genException("Unable to create a unix socket");
//cout <<"Unable to create a unix socket"<<endl;
//logger->Log(LogLevel::ERROR, "Unable to create a unix socket");
}

memset(&addr, 0, sizeof(addr));
Expand All @@ -45,7 +46,7 @@ json getPermToken(string clientName, string clientSecret) {

if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
throw genException("Unable to connect to server");
//cout <<"Unable to connect to server"<<endl;
//logger->Log(LogLevel::ERROR, "Unable to connect to server");
}


Expand All @@ -59,15 +60,15 @@ json getPermToken(string clientName, string clientSecret) {
int length = request.length();
// Send and wait for response from the permmanagent daemon.
if(write(fd, request.c_str(), length) != length) {
cout << "Request not sent completely" <<endl;
logger->Log(LogLevel::ERROR, "Request not sent completely");
} else {
cout << "Request sent " <<endl;
logger->Log(LogLevel::INFO, "Request sent ");
}

char response_buf[1024 * 10] = {0};
read(fd, response_buf, sizeof(response_buf));

cout << "Response read from server "<<endl;
logger->Log(LogLevel::INFO, "Response read from server ");

string response(response_buf);
jsoncons::json respJson = jsoncons::json::parse(response);
Expand Down
10 changes: 5 additions & 5 deletions w3c-visserver-api/src/vsscommandprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ string vsscommandprocessor::processAuthorizeWithPermManager(wschannel &channel,
jsoncons::json response;
// Get Token from permission management daemon.
try {
response = getPermToken(client, clientSecret);
response = getPermToken(logger, client, clientSecret);
} catch (genException &exp) {
cout << exp.what() << endl;
logger->Log(LogLevel::ERROR, exp.what());
jsoncons::json result;
jsoncons::json error;
result["action"] = "kuksa-authorize";
Expand All @@ -332,7 +332,7 @@ string vsscommandprocessor::processAuthorizeWithPermManager(wschannel &channel,
tokenValidator->updatePubKey(response["pubkey"].as<string>());
ttl = tokenValidator->validate(channel, database, response["token"].as<string>());
} catch (exception &e) {
cout << e.what() << endl;
logger->Log(LogLevel::ERROR, e.what());
ttl = -1;
}
}
Expand Down Expand Up @@ -429,8 +429,8 @@ string vsscommandprocessor::processQuery(string req_json,
string clientSecret = root["secret"].as<string>();
uint32_t request_id = root["requestId"].as<int>();
#ifdef DEBUG
cout << "vsscommandprocessor::processQuery: kuksa authorize query with clientID = "
<< clientID << " with secret " << clientSecret << endl;
logger->Log(LogLevel::VERBOSE, "vsscommandprocessor::processQuery: kuksa authorize query with clientID = "
+ clientID + " with secret " + clientSecret);
#endif
response = processAuthorizeWithPermManager(channel, request_id, clientID, clientSecret);
} else {
Expand Down
23 changes: 4 additions & 19 deletions w3c-visserver-api/src/vssdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ void vssdatabase::setSignal(wschannel& channel, string path,
jsoncons::json item = setValues[i];
string jPath = item["path"].as<string>();
#ifdef DEBUG
cout << "vssdatabase::setSignal: path found = " << jPath << endl;
cout << "value to set asstring = " << item["value"].as<string>() << endl;
logger->Log(LogLevel::VERBOSE, "vssdatabase::setSignal: path found = " + jPath);
logger->Log(LogLevel::VERBOSE, "value to set asstring = " + item["value"].as<string>());
#endif
rwMutex.lock();
jsoncons::json resArray = json_query(data_tree, jPath);
Expand All @@ -530,8 +530,7 @@ void vssdatabase::setSignal(wschannel& channel, string path,
json_replace(data_tree, jPath, resJson);
rwMutex.unlock();
#ifdef DEBUG
cout << "vssdatabase::setSignal: new value set at path " << jPath
<< endl;
logger->Log(LogLevel::VERBOSE, "vssdatabase::setSignal: new value set at path " + jPath);
#endif

string uuid = resJson["uuid"].as<string>();
Expand All @@ -545,12 +544,10 @@ void vssdatabase::setSignal(wschannel& channel, string path,
}

} else if (resArray.is_array()) {
cout << "vssdatabase::setSignal : Path " << jPath << " has "
<< resArray.size() << " signals, the path needs refinement"
<< endl;
stringstream msg;
msg << "Path " << jPath << " has " << resArray.size()
<< " signals, the path needs refinement";
logger->Log(LogLevel::INFO, "vssdatabase::setSignal : " + msg.str());
throw genException(msg.str());
}
}
Expand Down Expand Up @@ -623,18 +620,6 @@ void vssdatabase::setSignal(string path,
}
}

// Utility method for setting values to JSON.
void setJsonValue(jsoncons::json& dest, jsoncons::json& source, string key) {
if (!source.has_key("type")) {
cout << "vssdatabase::setJsonValue : could not set value! type is not "
"present in source json!"
<< endl;
string msg = "Unknown type for signal found at " + key;
throw genException(msg);
}
dest[key] = source["value"];
}

// Returns response JSON for get request.
jsoncons::json vssdatabase::getSignal(class wschannel& channel, string path) {
bool isBranch = false;
Expand Down

0 comments on commit c25c338

Please sign in to comment.