mirror of
				https://github.com/Telecominfraproject/wlan-cloud-owprov.git
				synced 2025-10-30 18:18:03 +00:00 
			
		
		
		
	Adding configuration block management.
This commit is contained in:
		| @@ -89,6 +89,42 @@ namespace OpenWifi{ | |||||||
|         BadRequest(Request, Response, "Internal error. Consult documentation and try again."); |         BadRequest(Request, Response, "Internal error. Consult documentation and try again."); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     //      interfaces | ||||||
|  |     //      metrics | ||||||
|  |     //      radios | ||||||
|  |     //      services | ||||||
|  |     //      globals | ||||||
|  |     //      unit | ||||||
|  |     bool RESTAPI_configurations_handler::ValidateConfigBlock(const ProvObjects::DeviceConfiguration &Config, | ||||||
|  |                                                                      Poco::Net::HTTPServerRequest &Request, | ||||||
|  |                                                                      Poco::Net::HTTPServerResponse &Response) { | ||||||
|  |         static const std::vector<std::string> SectionNames{ "globals", "interfaces", "metrics", "radios", "services", "unit" }; | ||||||
|  |  | ||||||
|  |         try { | ||||||
|  |             for(const auto &i:Config.configuration) { | ||||||
|  |                 Poco::JSON::Parser  P; | ||||||
|  |  | ||||||
|  |                 if(i.name.empty()) { | ||||||
|  |                     BadRequest(Request, Response, "The configuration block name must be included."); | ||||||
|  |                     return false; | ||||||
|  |                 } | ||||||
|  |                 auto Blocks = P.parse(i.configuration).extract<Poco::JSON::Object::Ptr>(); | ||||||
|  |                 auto N = Blocks->getNames(); | ||||||
|  |  | ||||||
|  |                 for(const auto &j:N) { | ||||||
|  |                     if(std::find(SectionNames.cbegin(),SectionNames.cend(),j)==SectionNames.cend()) { | ||||||
|  |                         BadRequest(Request, Response, "Configuration block type invalid."); | ||||||
|  |                         return false; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } catch (const Poco::Exception &E) { | ||||||
|  |             BadRequest(Request, Response, "Invalid configuration portion."); | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     void RESTAPI_configurations_handler::DoPost(Poco::Net::HTTPServerRequest &Request, |     void RESTAPI_configurations_handler::DoPost(Poco::Net::HTTPServerRequest &Request, | ||||||
|                                                Poco::Net::HTTPServerResponse &Response) { |                                                Poco::Net::HTTPServerResponse &Response) { | ||||||
|         try { |         try { | ||||||
| @@ -127,20 +163,8 @@ namespace OpenWifi{ | |||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             try { |             if(!ValidateConfigBlock(C, Request, Response)) | ||||||
|                 for(const auto &i:C.configuration) { |  | ||||||
|                     Poco::JSON::Parser  P; |  | ||||||
|                     // std::cout << "Config:>>>" << std::endl << i.configuration << std::endl << "<<<" << std::endl; |  | ||||||
|                     if(i.name.empty()) { |  | ||||||
|                         BadRequest(Request, Response, "The configuration block name must be included."); |  | ||||||
|                 return; |                 return; | ||||||
|                     } |  | ||||||
|                     P.parse(i.configuration).extract<Poco::JSON::Object::Ptr>(); |  | ||||||
|                 } |  | ||||||
|             } catch (const Poco::Exception &E) { |  | ||||||
|                 BadRequest(Request, Response, "Invalid configuration portion."); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if(Storage()->ConfigurationDB().CreateRecord(C)) { |             if(Storage()->ConfigurationDB().CreateRecord(C)) { | ||||||
|                 Storage()->ConfigurationDB().GetRecord("id", C.info.id, C); |                 Storage()->ConfigurationDB().GetRecord("id", C.info.id, C); | ||||||
| @@ -208,23 +232,8 @@ namespace OpenWifi{ | |||||||
|  |  | ||||||
|             NewConfig.info.modified = std::time(nullptr); |             NewConfig.info.modified = std::time(nullptr); | ||||||
|  |  | ||||||
|             if(!NewConfig.configuration.empty()) { |             if(!ValidateConfigBlock(NewConfig, Request, Response)) | ||||||
|                 try { |  | ||||||
|                     for(const auto &i:NewConfig.configuration) { |  | ||||||
|                         if(i.name.empty()) { |  | ||||||
|                             BadRequest(Request, Response, "The configuration block name must be included."); |  | ||||||
|                 return; |                 return; | ||||||
|                         } |  | ||||||
|                         Poco::JSON::Parser  P; |  | ||||||
|                         auto T = P.parse(i.configuration).extract<Poco::JSON::Object>(); |  | ||||||
|                     } |  | ||||||
|                 } catch (const Poco::Exception &E) { |  | ||||||
|                     BadRequest(Request, Response, "Invalid configuration portion."); |  | ||||||
|                     return; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 Existing.configuration = NewConfig.configuration; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if(!NewConfig.variables.empty()) |             if(!NewConfig.variables.empty()) | ||||||
|                 Existing.variables = NewConfig.variables; |                 Existing.variables = NewConfig.variables; | ||||||
|   | |||||||
| @@ -11,6 +11,7 @@ | |||||||
| #include "RESTAPI_handler.h" | #include "RESTAPI_handler.h" | ||||||
| #include "Poco/Net/HTTPServerRequest.h" | #include "Poco/Net/HTTPServerRequest.h" | ||||||
| #include "Poco/Net/HTTPServerResponse.h" | #include "Poco/Net/HTTPServerResponse.h" | ||||||
|  | #include "RESTAPI_ProvObjects.h" | ||||||
|  |  | ||||||
| namespace OpenWifi { | namespace OpenWifi { | ||||||
|     class RESTAPI_configurations_handler : public RESTAPIHandler { |     class RESTAPI_configurations_handler : public RESTAPIHandler { | ||||||
| @@ -34,6 +35,10 @@ namespace OpenWifi { | |||||||
|                    Poco::Net::HTTPServerResponse &Response); |                    Poco::Net::HTTPServerResponse &Response); | ||||||
|         void DoDelete(Poco::Net::HTTPServerRequest &Request, |         void DoDelete(Poco::Net::HTTPServerRequest &Request, | ||||||
|                       Poco::Net::HTTPServerResponse &Response); |                       Poco::Net::HTTPServerResponse &Response); | ||||||
|  |     private: | ||||||
|  |         bool ValidateConfigBlock(const      ProvObjects::DeviceConfiguration &Config, | ||||||
|  |                                             Poco::Net::HTTPServerRequest &Request, | ||||||
|  |                                             Poco::Net::HTTPServerResponse &Response); | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,53 +1,71 @@ | |||||||
| { | { | ||||||
|                 "type" : "entity", | 	"type": "entity", | ||||||
|                 "name" : "world", | 	"name": "world", | ||||||
|                 "children" : [{ | 	"children": [{ | ||||||
|                                 "type" : "entity", | 			"type": "entity", | ||||||
|                                 "name" : "root" , | 			"name": "Canada", | ||||||
|                                 "children" : [ { | 			"children": [{ | ||||||
|                                                     "type" : "entity" , | 				"type": "entity", | ||||||
|                                                     "name" : "sub-root1" , | 				"name": "Provinces", | ||||||
|                                                     "children" : [{ | 				"children": [{ | ||||||
|                                                                         "type" : "entity" , | 						"type": "entity", | ||||||
|                                                                         "name" : "sub-1.1" , | 						"name": "Quebec", | ||||||
|                                                                         "children" : [] , | 						"children": [], | ||||||
|                                                                         "venues" : [] | 						"venues": [{ | ||||||
|  | 								"type": "venue", | ||||||
|  | 								"name": "Bell Center", | ||||||
|  | 								"venues": [] | ||||||
| 							}, | 							}, | ||||||
| 							{ | 							{ | ||||||
|                                                                         "type" : "entity" , | 								"type": "venue", | ||||||
|                                                                         "name" : "sub-1.2" , | 								"name": "Olymic Statium", | ||||||
|                                                                         "children" : [] , | 								"venues": [] | ||||||
|                                                                         "venues" : [] |  | ||||||
| 							} | 							} | ||||||
|                                                                 ] , | 						] | ||||||
|                                                     "venues" : [{ |  | ||||||
|                                                                 "type" : "venue" , |  | ||||||
|                                                                 "name" : "sub-r1-v1" , |  | ||||||
|                                                                 "venues" : [] |  | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
|                                                                 "type" : "venue" , | 						"type": "entity", | ||||||
|                                                                 "name" : "sub-r1-v2" , | 						"name": "Ontario", | ||||||
|                                                                 "venues" : [] | 						"children": [], | ||||||
|                                                         }] | 						"venues": [{ | ||||||
|  | 								"type": "venue", | ||||||
|  | 								"name": "CN Tower", | ||||||
|  | 								"venues": [] | ||||||
| 							}, | 							}, | ||||||
| 							{ | 							{ | ||||||
|                                                     "type" : "entity" , | 								"type": "venue", | ||||||
|                                                     "name" : "sub-root2" , | 								"name": "Rogers Center", | ||||||
|                                                     "children" : [] , | 								"venues": [] | ||||||
|                                                     "venues" : [] |  | ||||||
| 							} | 							} | ||||||
|                                                 ] , | 						] | ||||||
|                                 "venues" : [ { |  | ||||||
|                                                     "type" : "venue" , |  | ||||||
|                                                     "name" : "sub-v1" , |  | ||||||
|                                                     "venues" : [] |  | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
|                                                     "type" : "venue" , | 						"type": "entity", | ||||||
|                                                     "name" : "sub-v2" , | 						"name": "BC", | ||||||
|                                                     "venues" : [] | 						"children": [], | ||||||
|                                             }] | 						"venues": [{ | ||||||
|  | 								"type": "venue", | ||||||
|  | 								"name": "BC Place", | ||||||
|  | 								"venues": [] | ||||||
|  | 							}, | ||||||
|  | 							{ | ||||||
|  | 								"type": "venue", | ||||||
|  | 								"name": "Stanley Park", | ||||||
|  | 								"venues": [] | ||||||
|  | 							} | ||||||
|  | 						] | ||||||
|  | 					} | ||||||
|  | 				], | ||||||
|  | 				"venues": [] | ||||||
| 			}], | 			}], | ||||||
|                 "venues" : [] | 			"venues": [] | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			"type": "entity", | ||||||
|  | 			"name": "Mexico", | ||||||
|  | 			"children": [], | ||||||
|  | 			"venues": [] | ||||||
| 		} | 		} | ||||||
|  | 	], | ||||||
|  | 	"venues": [] | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 stephb9959
					stephb9959