Changeset - 42b653a23ffc
[Not reviewed]
0 3 0
Jan Kaluza - 9 years ago 2016-01-26 19:24:14
jkaluza@redhat.com
Spectrum2_manager: add method to detect frontend type
3 files changed with 42 insertions and 0 deletions:
0 comments (0 inline, 0 general)
spectrum_manager/src/methods.cpp
Show inline comments
 
@@ -498,12 +498,51 @@ static void handleConnected(boost::shared_ptr<Swift::Connection> m_conn, const s
 
		
 
		// send header together with wrapper message
 
		m_conn->write(Swift::createSafeByteArray(std::string(header, 4) + message));
 
	}
 
}
 

	
 
bool is_slack(ManagerConfig *config, const std::string &jid) {
 
	path p(CONFIG_STRING(config, "service.config_directory"));
 

	
 
	try {
 
		if (!exists(p)) {
 
			std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
 
			exit(6);
 
		}
 

	
 
		if (!is_directory(p)) {
 
			std::cerr << "Config directory " << CONFIG_STRING(config, "service.config_directory") << " does not exist\n";
 
			exit(7);
 
		}
 

	
 
		directory_iterator end_itr;
 
		for (directory_iterator itr(p); itr != end_itr; ++itr) {
 
			if (is_regular(itr->path()) && extension(itr->path()) == ".cfg") {
 
				Config cfg;
 
				if (cfg.load(itr->path().string()) == false) {
 
					std::cerr << "Can't load config file " << itr->path().string() << ". Skipping...\n";
 
					continue;
 
				}
 

	
 
				if (CONFIG_STRING(&cfg, "service.jid") != jid) {
 
					continue;
 
				}
 

	
 
				return CONFIG_STRING(&cfg, "service.frontend") == "slack";
 
			}
 
		}
 

	
 
	}
 
	catch (const filesystem_error& ex) {
 
		return false;
 
	}
 

	
 
	return false;
 
}
 

	
 
void ask_local_server(ManagerConfig *config, Swift::BoostNetworkFactories &networkFactories, const std::string &jid, const std::string &message) {
 
	response = "";
 
	path p(CONFIG_STRING(config, "service.config_directory"));
 

	
 
	try {
 
		if (!exists(p)) {
spectrum_manager/src/methods.h
Show inline comments
 
@@ -48,10 +48,11 @@ int start_instances(ManagerConfig *config, const std::string &_jid = "");
 
int restart_instances(ManagerConfig *config, const std::string &_jid = "");
 
void stop_instances(ManagerConfig *config, const std::string &_jid = "");
 

	
 
int show_status(ManagerConfig *config);
 

	
 
void ask_local_server(ManagerConfig *config, Swift::BoostNetworkFactories &networkFactories, const std::string &jid, const std::string &message);
 
bool is_slack(ManagerConfig *config, const std::string &jid);
 

	
 
std::vector<std::string> show_list(ManagerConfig *config, bool show = true);
 

	
 
std::string get_response();
spectrum_manager/src/server.cpp
Show inline comments
 
@@ -394,15 +394,17 @@ void Server::serve_oauth2(struct mg_connection *conn, struct http_message *hm) {
 
	std::string uri(hm->uri.p, hm->uri.len);
 
	std::string instance = uri.substr(uri.rfind("/") + 1);
 
	std::string code = get_http_var(hm, "code");
 
	std::string state = get_http_var(hm, "state");
 

	
 
	std::string response = send_command(instance, "set_oauth2_code " + code + " " + state);
 
	std::cerr << "set_oauth2_code response: '" << response << "'\n";
 
	if (response.find("Registered as ") == 0) {
 
		std::vector<std::string> args;
 
		boost::split(args, response, boost::is_any_of(" "));
 
		std::cerr << "set_oauth2_code response size " << args.size() << "\n";
 
		if (args.size() == 3) {
 
			Server:session *session = get_session(hm);
 
			UserInfo info;
 
			m_storage->getUser(session->user, info);
 
			std::string username = "";
 
			int type = (int) TYPE_STRING;
0 comments (0 inline, 0 general)