Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions C/plugins/common/include/http_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class HttpSender

virtual std::string getHostPort() = 0;
virtual std::string getHTTPResponse() = 0;
virtual unsigned int getMaxRetries() = 0;

virtual void setAuthMethod (std::string& authMethod) = 0;
virtual void setAuthBasicCredentials(std::string& authBasicCredentials) = 0;
virtual void setMaxRetries (unsigned int retries) = 0;

// OCS configurations
virtual void setOCSNamespace (std::string& OCSNamespace) = 0;
Expand Down
2 changes: 2 additions & 0 deletions C/plugins/common/include/libcurl_https.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class LibcurlHttps: public HttpSender

void setAuthMethod (std::string& authMethod) {m_authMethod = authMethod; }
void setAuthBasicCredentials(std::string& authBasicCredentials) {m_authBasicCredentials = authBasicCredentials; }
void setMaxRetries (unsigned int retries) {m_max_retry = retries; };

// OCS configurations
void setOCSNamespace (std::string& OCSNamespace) {m_OCSNamespace = OCSNamespace; }
Expand All @@ -61,6 +62,7 @@ class LibcurlHttps: public HttpSender

std::string getHostPort() { return m_host_port; };
std::string getHTTPResponse() { return m_HTTPResponse; };
unsigned int getMaxRetries() { return m_max_retry; };

private:
// Make private the copy constructor and operator=
Expand Down
2 changes: 1 addition & 1 deletion C/plugins/common/include/piwebapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class PIWebAPI
void setAuthBasicCredentials(std::string& authBasicCredentials) {m_authBasicCredentials = authBasicCredentials; }

int GetVersion(const string& host, string &version, bool logMessage = true);
string ExtractVersion(const string& response);
string errorMessageHandler(const string& msg);

private:
string ExtractVersion(const string& response);
string extractSection(const string& msg, const string& toSearch);
string extractMessageFromJSon(const string& json);

Expand Down
3 changes: 2 additions & 1 deletion C/plugins/common/include/simple_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ class SimpleHttp: public HttpSender

std::string getHostPort() { return m_host_port; };
std::string getHTTPResponse() { return m_HTTPResponse; };
unsigned int getMaxRetries() { return m_max_retry; };

// OCS configurations
void setOCSNamespace (std::string& OCSNamespace) {m_OCSNamespace = OCSNamespace; }
void setOCSTenantId (std::string& OCSTenantId) {m_OCSTenantId = OCSTenantId; }
void setOCSClientId (std::string& OCSClientId) {m_OCSClientId = OCSClientId; }
void setOCSClientSecret (std::string& OCSClientSecret) {m_OCSClientSecret = OCSClientSecret; }
void setOCSToken (std::string& OCSToken) {m_OCSToken = OCSToken; }

void setMaxRetries (unsigned int retries) {m_max_retry = retries; };

private:
// Make private the copy constructor and operator=
Expand Down
2 changes: 2 additions & 0 deletions C/plugins/common/include/simple_https.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class SimpleHttps: public HttpSender

void setAuthMethod (std::string& authMethod) {m_authMethod = authMethod; }
void setAuthBasicCredentials(std::string& authBasicCredentials) {m_authBasicCredentials = authBasicCredentials; }
void setMaxRetries (unsigned int retries) {m_max_retry = retries; };

// OCS configurations
void setOCSNamespace (std::string& OCSNamespace) {m_OCSNamespace = OCSNamespace; }
Expand All @@ -61,6 +62,7 @@ class SimpleHttps: public HttpSender

std::string getHTTPResponse() { return m_HTTPResponse; };
std::string getHostPort() { return m_host_port; };
unsigned int getMaxRetries() { return m_max_retry; };

private:
// Make private the copy constructor and operator=
Expand Down
2 changes: 1 addition & 1 deletion C/plugins/north/OMF/include/ocs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OCS
// Destructor
~OCS();

string retrieveToken(const string& clientId, const string& clientSecret);
string retrieveToken(const string& clientId, const string& clientSecret, bool logMessage = true);
string extractToken(const string& response);
private:
bool m_adh;
Expand Down
7 changes: 4 additions & 3 deletions C/plugins/north/OMF/include/omfinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ class OMFInformation {
void loadSentDataTypes(rapidjson::Document& JSONData);
long getMaxTypeId();
int PIWebAPIGetVersion(bool logMessage = true);
int EDSGetVersion();
int EDSGetVersion(bool logMessage = true);
int IsADHConnected(bool logMessage = true);
void SetOMFVersion();
void CheckDataActionCode();
std::string OCSRetrieveAuthToken();
std::string OCSRetrieveAuthToken(bool logMessage = true);
OMF_ENDPOINT identifyPIServerEndpoint();
std::string saveSentDataTypes();
unsigned long calcTypeShort(const std::string& dataTypes);
Expand All @@ -124,7 +125,7 @@ class OMFInformation {
std::string AuthBasicCredentialsGenerate(std::string& userId, std::string& password);
void AuthKerberosSetup(std::string& keytabEnv, std::string& keytabFileName);
double GetElapsedTime(struct timeval *startTime);
bool IsPIWebAPIConnected();
bool IsDataArchiveConnected();
void handleOMFTracing();

private:
Expand Down
30 changes: 19 additions & 11 deletions C/plugins/north/OMF/ocs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ std::string OCS::extractToken(const string& response)
}

/**
* Calls the OCS API to retrieve the authentication token related to the the clientId and clientSecret
* Calls the OCS/ADH API to retrieve the authentication token related to the the clientId and clientSecret
*
* @param clientId Client Id code assigned by OCS using its GUI to the specific connection
* @param clientSecret Client Secret code assigned by OCS using its gui to the specific connection
* @return The OCS token to be used for authentication in API calls
* @param clientId Client Id code assigned by OCS/ADH using its GUI to the specific connection
* @param clientSecret Client Secret code assigned by OCS/ADH using its GUI to the specific connection
* @param logMessage If true, log error messages (default: true)
* @return The OCS/ADH token to be used for authentication in API calls
*
*/
std::string OCS::retrieveToken(const string& clientId, const string& clientSecret)
std::string OCS::retrieveToken(const string& clientId, const string& clientSecret, bool logMessage)
{
string token;
string response;
Expand All @@ -86,7 +87,7 @@ std::string OCS::retrieveToken(const string& clientId, const string& clientSecre
TIMEOUT_CONNECT,
TIMEOUT_REQUEST,
RETRY_SLEEP_TIME,
MAX_RETRY);
0);

header.push_back( std::make_pair("Content-Type", "application/x-www-form-urlencoded"));
header.push_back( std::make_pair("Accept", " text/plain"));
Expand All @@ -112,17 +113,24 @@ std::string OCS::retrieveToken(const string& clientId, const string& clientSecre
if (httpCode >= 200 && httpCode <= 399)
{
token = extractToken(response);
Logger::getLogger()->debug("OCS authentication token :%s:" ,token.c_str() );
Logger::getLogger()->debug("ADH authentication token :%s:" ,token.c_str() );
}
else
else if (logMessage)
{
Logger::getLogger()->warn("Error in retrieving the authentication token from OCS - http :%d: :%s: ", httpCode, response.c_str());
Logger::getLogger()->warn("Error in retrieving the authentication token from ADH - http :%d: :%s: ", httpCode, response.c_str());
}

}
catch (const Unauthorized &e)
{
// Log authentication failures regardless of 'logMessage'
Logger::getLogger()->error("Unable to authenticate with AVEVA Data Hub");
}
catch (exception &ex)
{
Logger::getLogger()->warn("Error in retrieving the authentication token from OCS - error :%s: ", ex.what());
if (logMessage)
{
Logger::getLogger()->warn("Error in retrieving the authentication token from ADH - error :%s: ", ex.what());
}
}

delete endPoint;
Expand Down
Loading