add example websocket C++ server snake which supports basic cobra ops (publish and subscribe without stream sql
This commit is contained in:
52
ws/snake/IXAppConfig.cpp
Normal file
52
ws/snake/IXAppConfig.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* IXSnakeProtocol.cpp
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include "IXSnakeProtocol.h"
|
||||
#include "IXAppConfig.h"
|
||||
#include <iostream>
|
||||
#include <ixcrypto/IXUuid.h>
|
||||
|
||||
namespace snake
|
||||
{
|
||||
bool isAppKeyValid(
|
||||
const AppConfig& appConfig,
|
||||
std::string appkey)
|
||||
{
|
||||
return appConfig.apps.count(appkey) != 0;
|
||||
}
|
||||
|
||||
std::string getRoleSecret(
|
||||
const AppConfig& appConfig,
|
||||
std::string appkey,
|
||||
std::string role)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user