Committing updates.
This commit is contained in:
@@ -320,9 +320,9 @@ namespace Apostol {
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CCustomModule::CreateAccessToken(const CProvider &Provider, const CString &Application, CContext &Context) {
|
||||
void CCustomModule::CreateAccessToken(CContext &Context, CProvider &Provider, const CString &Application) {
|
||||
|
||||
auto OnDone = [this, &Context](CTCPConnection *Sender) {
|
||||
auto OnDone = [this, &Context, &Provider](CTCPConnection *Sender) {
|
||||
|
||||
auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender);
|
||||
auto pReply = pConnection->Reply();
|
||||
@@ -337,18 +337,24 @@ namespace Apostol {
|
||||
|
||||
Context.Tokens().Values("access_token", Json["access_token"].AsString());
|
||||
|
||||
Provider.KeyStatus(ksSuccess);
|
||||
|
||||
ModuleStatus(Context);
|
||||
} else {
|
||||
Provider.KeyStatus(ksFailed);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
auto OnFail = [&Context](CTCPConnection *Sender, const Delphi::Exception::Exception &E) {
|
||||
auto OnFail = [&Context, &Provider](CTCPConnection *Sender, const Delphi::Exception::Exception &E) {
|
||||
Context.SetStatus(csInitialized);
|
||||
|
||||
auto pConnection = dynamic_cast<CHTTPClientConnection *> (Sender);
|
||||
auto pClient = dynamic_cast<CHTTPClient *> (pConnection->Client());
|
||||
|
||||
Provider.KeyStatus(ksFailed);
|
||||
|
||||
DebugReply(pConnection->Reply());
|
||||
|
||||
Log()->Error(APP_LOG_ERR, 0, "[%s:%d] %s", pClient->Host().c_str(), pClient->Port(), E.what());
|
||||
@@ -371,16 +377,16 @@ namespace Apostol {
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CCustomModule::FetchProviders(CDateTime Now, CContext &Context) {
|
||||
void CCustomModule::CheckProviders(CContext &Context, CDateTime Now) {
|
||||
for (int i = 0; i < Context.Providers().Count(); i++) {
|
||||
auto &Provider = Context.Providers()[i].Value();
|
||||
for (int j = 0; j < Provider.Applications().Count(); ++j) {
|
||||
const auto &app = Provider.Applications().Members(j);
|
||||
if (app["type"].AsString() == "service_account") {
|
||||
if (Provider.KeyStatus() == ksUnknown) {
|
||||
CreateAccessToken(Provider, app.String(), Context);
|
||||
const auto &caApplication = Provider.Applications().Members(j);
|
||||
if (caApplication["type"].AsString() == "service_account") {
|
||||
if (Provider.KeyStatus() != ksFetching) {
|
||||
Provider.KeyStatusTime(Now);
|
||||
Provider.KeyStatus(ksSuccess);
|
||||
Provider.KeyStatus(ksFetching);
|
||||
CreateAccessToken(Context, Provider, caApplication.String());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -388,24 +394,13 @@ namespace Apostol {
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CCustomModule::CheckProviders(CDateTime Now, CContext &Context) {
|
||||
for (int i = 0; i < Context.Providers().Count(); i++) {
|
||||
auto& Provider = Context.Providers()[i].Value();
|
||||
if (Provider.KeyStatus() != ksUnknown) {
|
||||
Provider.KeyStatusTime(Now);
|
||||
Provider.KeyStatus(ksUnknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CCustomModule::CheckDeal(const CDeal &Deal) {
|
||||
|
||||
const auto &Data = Deal.Data();
|
||||
|
||||
const auto DateTime = UTC();
|
||||
const auto Date = StringToDate(Data.Date);
|
||||
const auto Sum = BTCToDouble(Data.Payment.Sum);
|
||||
//const auto Sum = BTCToDouble(Data.Payment.Sum);
|
||||
|
||||
if (Data.Order == doCreate) {
|
||||
if (DateTime < Date)
|
||||
|
||||
@@ -95,10 +95,9 @@ namespace Apostol {
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------
|
||||
|
||||
void FetchProviders(CDateTime Now, CContext &Context);
|
||||
static void CheckProviders(CDateTime Now, CContext &Context);
|
||||
void CheckProviders(CContext &Context, CDateTime Now);
|
||||
|
||||
void CreateAccessToken(const CProvider &Provider, const CString &Application, CContext &Context);
|
||||
void CreateAccessToken(CContext &Context, CProvider &Provider, const CString &Application);
|
||||
void ParsePGPKey(const CString &Key, CStringPairs &ServerList, CStringList &BTCKeys);
|
||||
|
||||
void ModuleService(CContext &Context);
|
||||
|
||||
@@ -93,7 +93,6 @@ namespace Apostol {
|
||||
|
||||
const auto &caFormat = pServerRequest->Params["payload"];
|
||||
if (!caFormat.IsEmpty()) {
|
||||
|
||||
if (caFormat == "html") {
|
||||
pServerReply->ContentType = CHTTPReply::html;
|
||||
} else if (caFormat == "json") {
|
||||
@@ -111,11 +110,12 @@ namespace Apostol {
|
||||
}
|
||||
pProxyConnection->SendReply(pProxyReply->Status, nullptr, true);
|
||||
} else {
|
||||
pServerReply->Content = pProxyReply->Content;
|
||||
pProxyConnection->SendStockReply(pProxyReply->Status, true);
|
||||
}
|
||||
} else {
|
||||
if (pProxyReply->Status == CHTTPReply::ok) {
|
||||
pServerReply->Content = pProxyReply->Content;
|
||||
if (pProxyReply->Status == CHTTPReply::ok) {
|
||||
pProxyConnection->SendReply(pProxyReply->Status, nullptr, true);
|
||||
} else {
|
||||
pProxyConnection->SendStockReply(pProxyReply->Status, true);
|
||||
@@ -1103,8 +1103,7 @@ namespace Apostol {
|
||||
}
|
||||
|
||||
if (Context.Status() >= Context::csInitialized) {
|
||||
CheckProviders(Now, Context);
|
||||
FetchProviders(Now, Context);
|
||||
CheckProviders(Context, Now);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1053,8 +1053,7 @@ namespace Apostol {
|
||||
}
|
||||
|
||||
if (Context.Status() >= Context::csInitialized) {
|
||||
CheckProviders(Now, Context);
|
||||
FetchProviders(Now, Context);
|
||||
CheckProviders(Context, Now);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user