-admission::admission (std::string policy_schema_file, std::string samples_file, std::string metrics_schema_file, unsigned int num_instances, bool report_only){
- bool res;
-
- if (num_instances == 0){
- throw std::runtime_error("Error ! Number of instances of admission_policy protector pluging must be > 0");
- }
-
- std::string response;
- std::string buffer;
- std::string error_string;
-
- std::vector<TrieNode> config_schema_path;
-
- config_schema_path.clear();
-
- // path to node in schema to process policy request
- config_schema_path.emplace_back("controls");
- config_schema_path.emplace_back((int)0);
- config_schema_path.emplace_back("message_receives_payload_schema");
- config_schema_path[0].add_child(&config_schema_path[1]);
- config_schema_path[1].add_child(&config_schema_path[2]);
-
- set_policy_req_obj.load_schema(policy_schema_file, &config_schema_path[0]);
- // mdclog_write(MDCLOG_INFO, "Loaded schema for set Policy request");
-
- //path to node in schema to process policy response
- config_schema_path.clear();
- config_schema_path.emplace_back("controls");
- config_schema_path.emplace_back(0);
- config_schema_path.emplace_back("message_sends_payload_schema");
- config_schema_path[0].add_child(&config_schema_path[1]);
- config_schema_path[1].add_child(&config_schema_path[2]);
-
- set_policy_resp_obj.load_schema(policy_schema_file, &config_schema_path[0]);
- mdclog_write(MDCLOG_INFO, "Loaded schema for set Policy response");
-
- // load sample response
- config_schema_path.clear();
- config_schema_path.emplace_back("message_sends_example");
-
- set_policy_resp_obj.load_buffer(samples_file, &config_schema_path[0]);
-
- // verify that our sample conforms to the schema ...
- buffer = set_policy_resp_obj.get_buffer();
- if (! set_policy_resp_obj.is_valid(buffer.c_str(), buffer.length(), response)){
- std::stringstream ss;
- ss << "Error ! Sample loaded for SET policy response = " << buffer << " from file " << samples_file << " not valid. Reason = " << response;
- throw std::runtime_error(ss.str());
- }
- mdclog_write(MDCLOG_INFO, "Verified sample for set Policy response");
-
- // path to node in schema to respond to get policy (current same as set policy)
- config_schema_path.clear();
- config_schema_path.emplace_back("controls");
- config_schema_path.emplace_back(0);
- config_schema_path.emplace_back("message_receives_payload_schema");
- config_schema_path[0].add_child(&config_schema_path[1]);
- config_schema_path[1].add_child(&config_schema_path[2]);
-
- get_policy_resp_obj.load_schema(policy_schema_file, &config_schema_path[0]);
- mdclog_write(MDCLOG_INFO, "Loaded schema for get Policy response");
-