当前位置: 首页>>代码示例>>C++>>正文


C++ PluginResponse类代码示例

本文整理汇总了C++中PluginResponse的典型用法代码示例。如果您正苦于以下问题:C++ PluginResponse类的具体用法?C++ PluginResponse怎么用?C++ PluginResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PluginResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getDatabaseValue

Status getDatabaseValue(const std::string& domain,
                        const std::string& key,
                        std::string& value) {
  if (domain.empty()) {
    return Status(1, "Missing domain");
  }

  if (RegistryFactory::get().external()) {
    // External registries (extensions) do not have databases active.
    // It is not possible to use an extension-based database.
    PluginRequest request = {
        {"action", "get"}, {"domain", domain}, {"key", key}};
    PluginResponse response;
    auto status = Registry::call("database", request, response);
    if (status.ok()) {
      // Set value from the internally-known "v" key.
      if (response.size() > 0 && response[0].count("v") > 0) {
        value = response[0].at("v");
      }
    }
    return status;
  }

  ReadLock lock(kDatabaseReset);
  if (!DatabasePlugin::kDBInitialized) {
    throw std::runtime_error("Cannot get database value: " + key);
  } else {
    auto plugin = getDatabasePlugin();
    return plugin->get(domain, key, value);
  }
}
开发者ID:wxsBSD,项目名称:osquery,代码行数:31,代码来源:database.cpp

示例2: TEST_F

TEST_F(TLSConfigTests, test_retrieve_config) {
  TLSServerRunner::start();
  TLSServerRunner::setClientConfig();

  // Trigger the enroll.
  auto endpoint = Flag::getValue("config_tls_endpoint");
  Flag::updateValue("config_tls_endpoint", "/config");
  Registry::setActive("config", "tls");

  // Expect a POST to the /config endpoint.
  // A GET will return different results.
  Config c;
  c.load();

  const auto& hashes = c.hash_;
  EXPECT_EQ("c109cd4fc0a928dba787384a89f9d03d", hashes.at("tls_plugin"));

  // Configure the plugin to use the node API.
  Flag::updateValue("tls_node_api", "1");
  Registry::setActive("config", "tls");

  PluginResponse response;
  auto status = Registry::call("config", {{"action", "genConfig"}}, response);
  ASSERT_TRUE(status.ok());
  ASSERT_EQ(1U, response.size());

  // The GET and POST results are slightly different.
  EXPECT_EQ("baz", response[0]["tls_plugin"]);

  // Clean up.
  Flag::updateValue("tls_node_api", "0");
  Flag::updateValue("config_tls_endpoint", endpoint);
  TLSServerRunner::unsetClientConfig();
  TLSServerRunner::stop();
}
开发者ID:hackgnar,项目名称:osquery,代码行数:35,代码来源:tls_config_tests.cpp

示例3: Status

Status Config::load() {
  valid_ = false;
  auto& config_plugin = Registry::getActive("config");
  if (!Registry::exists("config", config_plugin)) {
    return Status(1, "Missing config plugin " + config_plugin);
  }

  PluginResponse response;
  auto status = Registry::call("config", {{"action", "genConfig"}}, response);
  if (!status.ok()) {
    loaded_ = true;
    return status;
  }

  // if there was a response, parse it and update internal state
  valid_ = true;
  if (response.size() > 0) {
    if (FLAGS_config_dump) {
      // If config checking is enabled, debug-write the raw config data.
      for (const auto& content : response[0]) {
        fprintf(stdout,
                "{\"%s\": %s}\n",
                content.first.c_str(),
                content.second.c_str());
      }
      // Instead of forcing the shutdown, request one since the config plugin
      // may have started services.
      Initializer::requestShutdown();
    }
    status = update(response[0]);
  }

  loaded_ = true;
  return status;
}
开发者ID:friedbutter,项目名称:osquery,代码行数:35,代码来源:config.cpp

示例4: genPack

Status Config::genPack(const std::string& name,
                       const std::string& source,
                       const std::string& target) {
  // If the pack value is a string (and not a JSON object) then it is a
  // resource to be handled by the config plugin.
  PluginResponse response;
  PluginRequest request = {
      {"action", "genPack"}, {"name", name}, {"value", target}};
  Registry::call("config", request, response);

  if (response.size() == 0 || response[0].count(name) == 0) {
    return Status(1, "Invalid plugin response");
  }

  try {
    pt::ptree pack_tree;
    std::stringstream pack_stream;
    pack_stream << response[0][name];
    pt::read_json(pack_stream, pack_tree);
    addPack(name, source, pack_tree);
  } catch (const pt::json_parser::json_parser_error& /* e */) {
    LOG(WARNING) << "Error parsing the pack JSON: " << name;
  }
  return Status(0);
}
开发者ID:friedbutter,项目名称:osquery,代码行数:25,代码来源:config.cpp

示例5: call

Status ConfigPlugin::call(const PluginRequest& request,
                          PluginResponse& response) {
  if (request.count("action") == 0) {
    return Status(1, "Config plugins require an action in PluginRequest");
  }

  if (request.at("action") == "genConfig") {
    std::map<std::string, std::string> config;
    auto stat = genConfig(config);
    response.push_back(config);
    return stat;
  } else if (request.at("action") == "genPack") {
    if (request.count("name") == 0 || request.count("value") == 0) {
      return Status(1, "Missing name or value");
    }
    std::string pack;
    auto stat = genPack(request.at("name"), request.at("value"), pack);
    response.push_back({{request.at("name"), pack}});
    return stat;
  } else if (request.at("action") == "update") {
    if (request.count("source") == 0 || request.count("data") == 0) {
      return Status(1, "Missing source or data");
    }
    return Config::getInstance().update(
        {{request.at("source"), request.at("data")}});
  }
  return Status(1, "Config plugin action unknown: " + request.at("action"));
}
开发者ID:friedbutter,项目名称:osquery,代码行数:28,代码来源:config.cpp

示例6: TEST_F

TEST_F(RemoteEnrollmentTests, test_enroll) {
  // Set the enrollment URI to the server we created.
  FLAGS_enrollment_uri = "http://127.0.0.1:" + port_;
  FLAGS_enrollment_app_id = "just_a_test_id";

  // Call enroll
  PluginRequest request = {
      {"enroll", "1"},
      // 0 enroll if needed, 1 force re-enroll
  };
  PluginResponse resp;
  Status stat = Registry::call("enrollment", "get_key", request, resp);

  // The enrollment server test mostly stresses workflow and code coverage.
  // Occasionally, like with the transports testing, the non-mocked netlib
  // server failed to bind.
  if (stat.ok()) {
    // Verify get key contains the string
    if (resp.size() == 1) {
      EXPECT_EQ(resp[0]["key"], "potatoes");
    } else {
      EXPECT_EQ(resp.size(), 1);
    }
  }
}
开发者ID:aayn,项目名称:osquery,代码行数:25,代码来源:http_enrollment_tests.cpp

示例7: call

Status DatabasePlugin::call(const PluginRequest& request,
                            PluginResponse& response) {
  if (request.count("action") == 0) {
    return Status(1, "Database plugin must include a request action");
  }

  // Get a domain/key, which are used for most database plugin actions.
  auto domain = (request.count("domain") > 0) ? request.at("domain") : "";
  auto key = (request.count("key") > 0) ? request.at("key") : "";

  // Switch over the possible database plugin actions.
  if (request.at("action") == "get") {
    std::string value;
    auto status = this->get(domain, key, value);
    response.push_back({{"v", value}});
    return status;
  } else if (request.at("action") == "put") {
    if (request.count("value") == 0) {
      return Status(1, "Database plugin put action requires a value");
    }
    return this->put(domain, key, request.at("value"));
  } else if (request.at("action") == "remove") {
    return this->remove(domain, key);
  } else if (request.at("action") == "scan") {
    std::vector<std::string> keys;
    auto status = this->scan(domain, keys);
    for (const auto& key : keys) {
      response.push_back({{"k", key}});
    }
    return status;
  }

  return Status(1, "Unknown database plugin action");
}
开发者ID:tburgin,项目名称:osquery,代码行数:34,代码来源:database.cpp

示例8: call

Status TablePlugin::call(const PluginRequest& request,
                         PluginResponse& response) {
  response.clear();
  // TablePlugin API calling requires an action.
  if (request.count("action") == 0) {
    return Status(1, "Table plugins must include a request action");
  }

  if (request.at("action") == "generate") {
    // "generate" runs the table implementation using a PluginRequest with
    // optional serialized QueryContext and returns the QueryData results as
    // the PluginRequest data.
    QueryContext context;
    if (request.count("context") > 0) {
      setContextFromRequest(request, context);
    }
    response = generate(context);
  } else if (request.at("action") == "columns") {
    // "columns" returns a PluginRequest filled with column information
    // such as name and type.
    const auto& column_list = columns();
    for (const auto& column : column_list) {
      response.push_back(
          {{"name", column.first}, {"type", columnTypeName(column.second)}});
    }
  } else if (request.at("action") == "definition") {
    response.push_back({{"definition", columnDefinition()}});
  } else {
    return Status(1, "Unknown table plugin action: " + request.at("action"));
  }

  return Status(0, "OK");
}
开发者ID:tburgin,项目名称:osquery,代码行数:33,代码来源:tables.cpp

示例9: routeInfo

PluginResponse TablePlugin::routeInfo() const {
  // Route info consists of only the serialized column information.
  PluginResponse response;
  for (const auto& column : columns()) {
    response.push_back({{"name", column.first}, {"type", column.second}});
  }
  return response;
}
开发者ID:JessicaWhite17,项目名称:osquery,代码行数:8,代码来源:tables.cpp

示例10: genConfig

Status Config::genConfig() {
  PluginResponse response;
  auto status = Registry::call("config", {{"action", "genConfig"}}, response);
  if (!status.ok()) {
    return status;
  }

  if (response.size() > 0) {
    return update(response[0]);
  }
  return Status(0, "OK");
}
开发者ID:eastebry,项目名称:osquery,代码行数:12,代码来源:config.cpp

示例11: runEnrollment

Status runEnrollment(bool force = false) {
  PluginResponse response;
  PluginRequest request = {{"enroll", (force) ? "1" : "0"}};
  auto status = Registry::call("enrollment", "get_key", request, response);
  if (!status.ok()) {
    return status;
  }

  if (response.size() > 0 && response[0]["key"].size() == 0) {
    return Status(1, "Enrollment Error: No Key");
  }
  return Status(0, "OK");
}
开发者ID:aayn,项目名称:osquery,代码行数:13,代码来源:http.cpp

示例12: call

Status SpecialWidget::call(const PluginRequest& request,
                           PluginResponse& response) {
  response.push_back(request);
  response[0]["from"] = name_;
  response[0]["secret_power"] = secretPower(request);
  return Status(0, "OK");
}
开发者ID:1514louluo,项目名称:osquery,代码行数:7,代码来源:registry_tests.cpp

示例13: setResponse

void Plugin::setResponse(const std::string& key,
                         const boost::property_tree::ptree& tree,
                         PluginResponse& response) {
  std::ostringstream output;
  boost::property_tree::write_json(output, tree, false);
  response.push_back({{key, output.str()}});
}
开发者ID:AndrewKahn,项目名称:osquery,代码行数:7,代码来源:registry.cpp

示例14: getDatabaseValue

Status getDatabaseValue(const std::string& domain,
                        const std::string& key,
                        std::string& value) {
  PluginRequest request = {{"action", "get"}, {"domain", domain}, {"key", key}};
  PluginResponse response;
  auto status = Registry::call("database", "rocks", request, response);
  if (!status.ok()) {
    return status;
  }

  // Set value from the internally-known "v" key.
  if (response.size() > 0 && response[0].count("v") > 0) {
    value = response[0].at("v");
  }
  return status;
}
开发者ID:AidHamza,项目名称:osquery,代码行数:16,代码来源:database.cpp

示例15: callExtension

Status callExtension(const std::string& extension_path,
                     const std::string& registry,
                     const std::string& item,
                     const PluginRequest& request,
                     PluginResponse& response) {
  // Make sure the extension manager path exists, and is writable.
  auto status = extensionPathActive(extension_path);
  if (!status.ok()) {
    return status;
  }

  ExtensionResponse ext_response;
  try {
    auto client = EXClient(extension_path);
    client.get()->call(ext_response, registry, item, request);
  } catch (const std::exception& e) {
    return Status(1, "Extension call failed: " + std::string(e.what()));
  }

  // Convert from Thrift-internal list type to PluginResponse type.
  if (ext_response.status.code == ExtensionCode::EXT_SUCCESS) {
    for (const auto& item : ext_response.response) {
      response.push_back(item);
    }
  }
  return Status(ext_response.status.code, ext_response.status.message);
}
开发者ID:1514louluo,项目名称:osquery,代码行数:27,代码来源:extensions.cpp


注:本文中的PluginResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。