Line data Source code
1 : /*
2 : ___________________________________________
3 : | _ ___ _ |
4 : | | | |__ \ | | |
5 : | | |__ ) |__ _ __ _ ___ _ __ | |_ |
6 : | | '_ \ / // _` |/ _` |/ _ \ '_ \| __| | HTTP/2 AGENT FOR MOCK TESTING
7 : | | | | |/ /| (_| | (_| | __/ | | | |_ | Version 0.0.z
8 : | |_| |_|____\__,_|\__, |\___|_| |_|\__| | https://github.com/testillano/h2agent
9 : | __/ | |
10 : | |___/ |
11 : |___________________________________________|
12 :
13 : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
14 : SPDX-License-Identifier: MIT
15 : Copyright (c) 2021 Eduardo Ramos
16 :
17 : Permission is hereby granted, free of charge, to any person obtaining a copy
18 : of this software and associated documentation files (the "Software"), to deal
19 : in the Software without restriction, including without limitation the rights
20 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 : copies of the Software, and to permit persons to whom the Software is
22 : furnished to do so, subject to the following conditions:
23 :
24 : The above copyright notice and this permission notice shall be included in all
25 : copies or substantial portions of the Software.
26 :
27 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 : SOFTWARE.
34 : */
35 :
36 : #pragma once
37 :
38 : #include <nlohmann/json.hpp>
39 :
40 : #include <AdminServerMatchingData.hpp>
41 : #include <AdminServerProvisionData.hpp>
42 : #include <AdminClientEndpointData.hpp>
43 : #include <AdminClientProvisionData.hpp>
44 : #include <AdminSchemaData.hpp>
45 : #include <common.hpp>
46 :
47 : namespace h2agent
48 : {
49 : namespace model
50 : {
51 :
52 : class AdminData
53 : {
54 : AdminServerMatchingData server_matching_data_{};
55 : AdminServerProvisionData server_provision_data_{};
56 : AdminClientEndpointData client_endpoint_data_{};
57 : AdminClientProvisionData client_provision_data_{};
58 : AdminSchemaData schema_data_{};
59 :
60 : public:
61 :
62 : /** Empty constructor */
63 173 : AdminData() {;}
64 :
65 : /**
66 : * Loads admin matching operation data
67 : *
68 : * @param j json document from operation body request
69 : *
70 : * @return Boolean about success operation
71 : */
72 142 : AdminServerMatchingData::LoadResult loadServerMatching(const nlohmann::json &j) {
73 142 : return server_matching_data_.load(j);
74 : }
75 :
76 : /**
77 : * Loads admin server provision operation data
78 : *
79 : * @param j json document from operation body request
80 : * @param cr common resources references (general configuration, global variables, file manager, mock server events data)
81 : *
82 : * @return Boolean about success operation
83 : */
84 123 : AdminServerProvisionData::LoadResult loadServerProvision(const nlohmann::json &j, const common_resources_t &cr) {
85 123 : return server_provision_data_.load(j, (server_matching_data_.getAlgorithm() == AdminServerMatchingData::AlgorithmType::RegexMatching), cr);
86 : }
87 :
88 : /**
89 : * Loads admin client endpoint operation data
90 : *
91 : * @param j json document from operation body request
92 : * @param cr common resources references (general configuration, global variables, file manager, mock client events data)
93 : *
94 : * @return Boolean about success operation
95 : */
96 20 : AdminClientEndpointData::LoadResult loadClientEndpoint(const nlohmann::json &j, const common_resources_t &cr) {
97 20 : return client_endpoint_data_.load(j, cr);
98 : }
99 :
100 : /**
101 : * Loads admin client provision operation data
102 : *
103 : * @param j json document from operation body request
104 : * @param cr common resources references (general configuration, global variables, file manager, mock client events data)
105 : *
106 : * @return Boolean about success operation
107 : */
108 0 : AdminClientProvisionData::LoadResult loadClientProvision(const nlohmann::json &j, const common_resources_t &cr) {
109 0 : return client_provision_data_.load(j, cr);
110 : }
111 :
112 : /**
113 : * Loads admin schema operation data
114 : *
115 : * @param j json document from operation body request
116 : *
117 : * @return Boolean about success operation
118 : */
119 336 : AdminSchemaData::LoadResult loadSchema(const nlohmann::json &j) {
120 336 : return schema_data_.load(j);
121 : }
122 :
123 : /**
124 : * Clears admin server provisions data
125 : *
126 : * @return True if something was removed, false if already empty
127 : */
128 10 : bool clearServerProvisions() {
129 10 : return server_provision_data_.clear();
130 : }
131 :
132 : /**
133 : * Clears admin client endpoints data
134 : *
135 : * @return True if something was removed, false if already empty
136 : */
137 9 : bool clearClientEndpoints() {
138 9 : return client_endpoint_data_.clear();
139 : }
140 :
141 : /**
142 : * Clears admin client provisions data
143 : *
144 : * @return True if something was removed, false if already empty
145 : */
146 0 : bool clearClientProvisions() {
147 0 : return client_provision_data_.clear();
148 : }
149 :
150 : /**
151 : * Clears admin schemas data
152 : *
153 : * @return True if something was removed, false if already empty
154 : */
155 5 : bool clearSchemas() {
156 5 : return schema_data_.clear();
157 : }
158 :
159 : /**
160 : * Gets admin matching data
161 : */
162 51 : const AdminServerMatchingData& getServerMatchingData() const {
163 51 : return server_matching_data_;
164 : }
165 :
166 : /**
167 : * Gets admin server provision data
168 : */
169 334 : const AdminServerProvisionData& getServerProvisionData() const {
170 334 : return server_provision_data_;
171 : }
172 :
173 : /**
174 : * Gets admin client endpoint data
175 : */
176 6 : const AdminClientEndpointData& getClientEndpointData() const {
177 6 : return client_endpoint_data_;
178 : }
179 :
180 : /**
181 : * Gets admin client provision data
182 : */
183 0 : const AdminClientProvisionData& getClientProvisionData() const {
184 0 : return client_provision_data_;
185 : }
186 :
187 : /**
188 : * Gets admin schema data
189 : */
190 31 : const AdminSchemaData& getSchemaData() const {
191 31 : return schema_data_;
192 : }
193 : };
194 :
195 : }
196 : }
197 :
|