2019-04-22 17:24:01 -07:00
|
|
|
/*
|
|
|
|
* IXSnakeProtocol.cpp
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "IXAppConfig.h"
|
2019-09-23 10:25:23 -07:00
|
|
|
|
|
|
|
#include "IXSnakeProtocol.h"
|
2019-04-22 17:24:01 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <ixcrypto/IXUuid.h>
|
|
|
|
|
|
|
|
namespace snake
|
|
|
|
{
|
2019-09-23 10:25:23 -07:00
|
|
|
bool isAppKeyValid(const AppConfig& appConfig, std::string appkey)
|
2019-04-22 17:24:01 -07:00
|
|
|
{
|
|
|
|
return appConfig.apps.count(appkey) != 0;
|
|
|
|
}
|
|
|
|
|
2019-09-23 10:25:23 -07:00
|
|
|
std::string getRoleSecret(const AppConfig& appConfig, std::string appkey, std::string role)
|
2019-04-22 17:24:01 -07:00
|
|
|
{
|
|
|
|
if (!isAppKeyValid(appConfig, appkey))
|
|
|
|
{
|
|
|
|
std::cerr << "Missing appkey " << appkey << std::endl;
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto roles = appConfig.apps[appkey]["roles"];
|
|
|
|
auto channel = roles[role]["secret"];
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string generateNonce()
|
|
|
|
{
|
|
|
|
return ix::uuid4();
|
|
|
|
}
|
|
|
|
|
|
|
|
void dumpConfig(const AppConfig& appConfig)
|
|
|
|
{
|
|
|
|
for (auto&& host : appConfig.redisHosts)
|
|
|
|
{
|
|
|
|
std::cout << "redis host: " << host << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "redis password: " << appConfig.redisPassword << std::endl;
|
|
|
|
std::cout << "redis port: " << appConfig.redisPort << std::endl;
|
|
|
|
}
|
2019-09-23 10:25:23 -07:00
|
|
|
} // namespace snake
|