-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
92 lines (69 loc) · 2.51 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// CodeJam.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <mordor/config.h>
#include <mordor/main.h>
using namespace Mordor;
#include "sync_worker.h"
#include "sync_config.h"
#include "logger.h"
using namespace dpc;
const int DPC_CONFIG_FAILED = -1;
const int DPC_SYNC_FAILED = -2;
const int DPC_SUCCESS = 0;
int do_config(Settings& setting);
int do_sync(dpc::Settings& setting);
REGISTER_LOGGER("dpc:connector:main");
MORDOR_MAIN(int argc, char* argv[])
{
Config::loadFromEnvironment();
#ifdef WINDOWS
g_log->addSink(Mordor::LogSink::ptr(new dpc::EventLogSink(ComponentName, SourceName)));
#endif
Config::lookup("log.file")->fromString("z.log");
Config::lookup("log.stdout")->fromString("1");
std::stringstream temp_stream;
for (int i=0; i<argc; i++)
temp_stream << argv[i] << ' ';
std::string all_args = temp_stream.str(); // it has an additional space char at the end.
MORDOR_LOG_INFO(g_log) << "Full Command Line: "<< all_args.substr(0, all_args.size() -1);
Settings mysetting;
mysetting.ParseCLI(argc, argv);
if (mysetting.IsConfigMode())
do_config(mysetting);
else
do_sync(mysetting);
MORDOR_LOG_ERROR(g_log)<<"can you see this?";
return 0;
}
int do_config(Settings& setting)
{
BifrostClient bifrost(setting);
MORDOR_LOG_INFO(g_log) << bifrost.SvcAuthenticate();
if (bifrost.CheckApiKey() == false) {
MORDOR_LOG_ERROR(g_log) << "API KEY is invalid for this partner";
return DPC_CONFIG_FAILED;
}
MORDOR_LOG_INFO(g_log) << "API KEY is valid";
// bifrost instance is valid from now on.
// it can be used to do version report/check
bifrost.ReportVersion(setting.CurrentVersion());
bifrost.CheckLatestClientVersion(setting.CurrentVersion());
return setting.PersistToRegistry();
}
int do_sync(dpc::Settings& setting)
{
BifrostClient::ptr bifrost(new BifrostClient(setting));
bifrost->SvcAuthenticate();
bifrost->ReportVersion(setting.CurrentVersion());
bifrost->CheckLatestClientVersion(setting.CurrentVersion());
SyncConfig sync_config(bifrost->SvcGetSyncConfigJson());
//bifrost is pointing to a usable instance to talk with endpoint
LdapClient::ptr ldap(new LdapClient(sync_config.LdapSetting(), setting));
if (ldap->ConnectLdap()) {
MORDOR_LOG_INFO(g_log) << "ldap is pointing to a usable instance from now on";
//SyncWorker worker(bifrost, ldap, sync_config);
//worker.run();
}
return 0;
}