imperituroard 1.0.9 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/imperituroard.rb +13 -0
- data/lib/imperituroard/projects/iot.rb +198 -15
- data/lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb +23 -13
- data/lib/imperituroard/projects/iot/internal_functions.rb +31 -2
- data/lib/imperituroard/projects/iot/mongoconnector.rb +34 -5
- data/lib/imperituroard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0217c1cc75b261d264e0bda7b844973fa538e72a
|
4
|
+
data.tar.gz: 153d87dad8e3241911d7dfc6fe8deb5a589c4062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6deca94580b39be517b6f7a258712c26ba081aa41f899c5ba204195706262652590a2de6747d26131e7650e48c55ef49a21e5cc606bffa1d5059277851154b7f
|
7
|
+
data.tar.gz: aac3ba712d125edea747bccddc7fa6c81b8c016f35752acf5f5e49f841ada625959a51a061c45c2d4854f1494abc3efea615e73273f61071c4e09fd463d5d48f
|
data/lib/imperituroard.rb
CHANGED
@@ -168,6 +168,10 @@ class Iot
|
|
168
168
|
iot_connector.add_device_to_prof_2(login, imei_list, real_ip, remote_ip)
|
169
169
|
end
|
170
170
|
|
171
|
+
def add_device_to_profile2(request_f, real_ip, remote_ip)
|
172
|
+
iot_connector.add_device_to_prof2_2(request_f, real_ip, remote_ip)
|
173
|
+
end
|
174
|
+
|
171
175
|
|
172
176
|
#!!2 Find device (only mongo datebase. IOT platform not need)
|
173
177
|
# procedure for data selection from mongo database.
|
@@ -270,10 +274,19 @@ class Iot
|
|
270
274
|
mongo_client.audit_logger(proc_name, src_ip, input_json, output_json, real_ip)
|
271
275
|
end
|
272
276
|
|
277
|
+
|
278
|
+
####################################################################
|
279
|
+
#######technological procedures
|
280
|
+
####################################################################
|
281
|
+
def delete_all_iot_device_in_db
|
282
|
+
iot_connector.delete_all_devices_in_database
|
283
|
+
end
|
284
|
+
|
273
285
|
def test111
|
274
286
|
iot_connector.test1278493
|
275
287
|
end
|
276
288
|
|
289
|
+
|
277
290
|
end
|
278
291
|
|
279
292
|
|
@@ -133,10 +133,11 @@ class IotFunctions_2
|
|
133
133
|
|
134
134
|
if aaa.key?("type") && !aaa.key?("device_type")
|
135
135
|
aaa["device_type"] = aaa["type"]
|
136
|
-
|
137
|
-
aaa["type"] = aaa["device_type"]
|
136
|
+
aaa = internal_func.delete_key_hash(aaa, "type")
|
138
137
|
end
|
139
138
|
|
139
|
+
aaa = internal_func.hash_val_to_string(aaa)
|
140
|
+
|
140
141
|
if credentials[:code] == 200
|
141
142
|
|
142
143
|
begin
|
@@ -145,6 +146,8 @@ class IotFunctions_2
|
|
145
146
|
#get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
|
146
147
|
#from database
|
147
148
|
model_data = mongo_client.get_device_type_info_universal(aaa["device_type"])
|
149
|
+
profile_data = mongo_client.get_profile_universal(aaa["profile"])
|
150
|
+
p profile_data
|
148
151
|
p model_data
|
149
152
|
p "model_data"
|
150
153
|
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
|
@@ -165,6 +168,8 @@ class IotFunctions_2
|
|
165
168
|
s1 = aaa
|
166
169
|
s1[:huadata] = resss
|
167
170
|
s1[:created] = DateTime.now
|
171
|
+
s1["device_type"] = model_data[:body]["model"]
|
172
|
+
s1["profile"] = profile_data["profile_id"]
|
168
173
|
added_on_iot_platf.append(s1)
|
169
174
|
end
|
170
175
|
else
|
@@ -204,7 +209,166 @@ class IotFunctions_2
|
|
204
209
|
thr1.join
|
205
210
|
|
206
211
|
resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
|
207
|
-
mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip)
|
212
|
+
mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip, {})
|
213
|
+
resp_out
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
def add_device_to_prof2_2(request_full, real_ip, remote_ip)
|
218
|
+
|
219
|
+
#{"autorization"=>{"login"=>"test", "token"=>"tE3aFvs27"}, "devlist"=>[{"devices"=>{"imei"=>123419520034999, "type"=>"1000002", "profile"=>0}}]}
|
220
|
+
|
221
|
+
login = request_full["autorization"]["login"]
|
222
|
+
|
223
|
+
im_li =[]
|
224
|
+
|
225
|
+
for sd in request_full["devlist"]
|
226
|
+
im_li.append(sd["devices"])
|
227
|
+
end
|
228
|
+
imei_list = im_li
|
229
|
+
|
230
|
+
input_json = {:request_full => request_full}
|
231
|
+
resp_out = {}
|
232
|
+
begin
|
233
|
+
|
234
|
+
thr1 = Thread.new do
|
235
|
+
if add_functions_connector.check_input_1(login, imei_list)[:code]==200
|
236
|
+
|
237
|
+
imei = []
|
238
|
+
list1 = {}
|
239
|
+
for_insert = []
|
240
|
+
not_processed_list = []
|
241
|
+
processed_list = []
|
242
|
+
|
243
|
+
for ii in imei_list
|
244
|
+
valid_resp = internal_func.imei_validate(ii["imei"])
|
245
|
+
if valid_resp[:checked]
|
246
|
+
list1[ii["imei"]] = ii
|
247
|
+
imei.append(ii["imei"])
|
248
|
+
else
|
249
|
+
not_processed_list.append({:imei => ii["imei"], :error => valid_resp[:result]})
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
if imei != []
|
254
|
+
list_checked = mongo_client.check_imei_exists(imei)
|
255
|
+
|
256
|
+
for ss in list_checked[:body][:exists]
|
257
|
+
not_processed_list.append({:imei => ss, :error => "Device exists in database"})
|
258
|
+
p ss
|
259
|
+
p "ss"
|
260
|
+
p list_checked
|
261
|
+
end
|
262
|
+
|
263
|
+
for jj in list_checked[:body][:not_exists]
|
264
|
+
begin
|
265
|
+
get_login_info = mongo_client.check_login_prof_perm_id_one(login, list1[jj]["profile"])[:code]
|
266
|
+
if get_login_info==200
|
267
|
+
for_insert.append(list1[jj])
|
268
|
+
else
|
269
|
+
not_processed_list.append({:imei => list1[jj], :error => "Permission denied for this profile"})
|
270
|
+
end
|
271
|
+
rescue
|
272
|
+
not_processed_list.append({:imei => list1[jj], :error => "Unknown error"})
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
begin
|
278
|
+
added_on_iot_platf = []
|
279
|
+
if for_insert != []
|
280
|
+
##Logic for IOT Platform connection###
|
281
|
+
|
282
|
+
|
283
|
+
for aaa in for_insert
|
284
|
+
|
285
|
+
#########change 2020.05.11. imperituroard
|
286
|
+
#########replace process for get iot app_id and password from users to profile
|
287
|
+
|
288
|
+
#credentials = mongo_client.get_iot_oceanconnect_credent(login)
|
289
|
+
credentials = mongo_client.get_iot_oceanconn_credent_2(aaa["profile"])
|
290
|
+
|
291
|
+
#########
|
292
|
+
|
293
|
+
if aaa.key?("type") && !aaa.key?("device_type")
|
294
|
+
aaa["device_type"] = aaa["type"]
|
295
|
+
aaa = internal_func.delete_key_hash(aaa, "type")
|
296
|
+
end
|
297
|
+
|
298
|
+
aaa = internal_func.hash_val_to_string(aaa)
|
299
|
+
|
300
|
+
if credentials[:code] == 200
|
301
|
+
|
302
|
+
begin
|
303
|
+
dev_name = aaa["imei"].to_s
|
304
|
+
|
305
|
+
#get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
|
306
|
+
#from database
|
307
|
+
model_data = mongo_client.get_device_type_info_universal(aaa["device_type"])
|
308
|
+
profile_data = mongo_client.get_profile_universal(aaa["profile"])
|
309
|
+
p profile_data
|
310
|
+
p model_data
|
311
|
+
p "model_data"
|
312
|
+
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
|
313
|
+
credentials[:body][:secret],
|
314
|
+
aaa["imei"],
|
315
|
+
dev_name,
|
316
|
+
aaa["description"],
|
317
|
+
model_data[:body]["device_type"],
|
318
|
+
aaa["profile"],
|
319
|
+
model_data[:body]["ManufacturerID"],
|
320
|
+
model_data[:body]["ManufacturerNAME"],
|
321
|
+
model_data[:body]["model"]
|
322
|
+
)
|
323
|
+
if resss[:code]=="200"
|
324
|
+
if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
|
325
|
+
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
326
|
+
else
|
327
|
+
s1 = aaa
|
328
|
+
s1[:huadata] = resss
|
329
|
+
s1[:created] = DateTime.now
|
330
|
+
s1["device_type"] = model_data[:body]["model"]
|
331
|
+
s1["profile"] = profile_data["profile_id"]
|
332
|
+
added_on_iot_platf.append(s1)
|
333
|
+
end
|
334
|
+
else
|
335
|
+
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
336
|
+
end
|
337
|
+
rescue
|
338
|
+
not_processed_list.append({:imei => aaa["imei"], :error => "Unknown error with insertion imei on IOT platform"})
|
339
|
+
end
|
340
|
+
#########end iot platform logic#######
|
341
|
+
|
342
|
+
else
|
343
|
+
resss_err = {:code => 400, :result => "IOT platform credentials not found"}
|
344
|
+
not_processed_list.append({:imei => aaa["imei"], :error => resss_err})
|
345
|
+
end
|
346
|
+
|
347
|
+
end
|
348
|
+
|
349
|
+
if added_on_iot_platf.length != 0
|
350
|
+
mongo_client.imei_insert_list(added_on_iot_platf)
|
351
|
+
resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
352
|
+
else
|
353
|
+
resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
354
|
+
end
|
355
|
+
else
|
356
|
+
resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
357
|
+
end
|
358
|
+
rescue
|
359
|
+
resp_out = {:code => 505, :result => "Error with database communication"}
|
360
|
+
end
|
361
|
+
else
|
362
|
+
resp_out = {:code => 509, :result => "Input data invalid"}
|
363
|
+
end
|
364
|
+
end
|
365
|
+
rescue
|
366
|
+
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
367
|
+
end
|
368
|
+
thr1.join
|
369
|
+
|
370
|
+
resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
|
371
|
+
mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip, {})
|
208
372
|
resp_out
|
209
373
|
end
|
210
374
|
|
@@ -267,7 +431,7 @@ class IotFunctions_2
|
|
267
431
|
|
268
432
|
resp_out[:data][:tosoapgw] = add_functions_connector.iot_query_dev_soapgw_answer(input_json, resp_out)
|
269
433
|
|
270
|
-
mongo_client.audit_logger("device_find", remote_ip, input_json, resp_out, real_ip)
|
434
|
+
mongo_client.audit_logger("device_find", remote_ip, input_json, resp_out, real_ip, {})
|
271
435
|
resp_out
|
272
436
|
|
273
437
|
end
|
@@ -439,7 +603,7 @@ class IotFunctions_2
|
|
439
603
|
end
|
440
604
|
|
441
605
|
thr3.join
|
442
|
-
mongo_client.audit_logger("imei_replace", remote_ip, input_json, resp_out, real_ip)
|
606
|
+
mongo_client.audit_logger("imei_replace", remote_ip, input_json, resp_out, real_ip, {})
|
443
607
|
|
444
608
|
resp_out
|
445
609
|
|
@@ -526,7 +690,7 @@ class IotFunctions_2
|
|
526
690
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
527
691
|
end
|
528
692
|
thr4.join
|
529
|
-
mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip)
|
693
|
+
mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip, {})
|
530
694
|
resp_out
|
531
695
|
end
|
532
696
|
|
@@ -606,7 +770,7 @@ class IotFunctions_2
|
|
606
770
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
607
771
|
end
|
608
772
|
thr5.join
|
609
|
-
mongo_client.audit_logger("device_add_address", remote_ip, input_json, resp_out, real_ip)
|
773
|
+
mongo_client.audit_logger("device_add_address", remote_ip, input_json, resp_out, real_ip, {})
|
610
774
|
resp_out
|
611
775
|
end
|
612
776
|
|
@@ -684,7 +848,7 @@ class IotFunctions_2
|
|
684
848
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
685
849
|
end
|
686
850
|
thr6.join
|
687
|
-
mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip)
|
851
|
+
mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip, {})
|
688
852
|
resp_out
|
689
853
|
end
|
690
854
|
|
@@ -712,7 +876,7 @@ class IotFunctions_2
|
|
712
876
|
end
|
713
877
|
end
|
714
878
|
thr7.join
|
715
|
-
mongo_client.audit_logger("autorize_subscriber", remote_ip, input_json, resp_out, real_ip)
|
879
|
+
mongo_client.audit_logger("autorize_subscriber", remote_ip, input_json, resp_out, real_ip, {})
|
716
880
|
resp_out
|
717
881
|
end
|
718
882
|
|
@@ -770,7 +934,7 @@ class IotFunctions_2
|
|
770
934
|
}
|
771
935
|
resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
|
772
936
|
end
|
773
|
-
mongo_client.audit_logger("get_available_prof_2", remote_ip, input_params, resp_out, real_ip)
|
937
|
+
mongo_client.audit_logger("get_available_prof_2", remote_ip, input_params, resp_out, real_ip, {})
|
774
938
|
resp_out
|
775
939
|
end
|
776
940
|
|
@@ -826,7 +990,7 @@ class IotFunctions_2
|
|
826
990
|
}
|
827
991
|
resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
|
828
992
|
end
|
829
|
-
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip)
|
993
|
+
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip, {})
|
830
994
|
resp_out
|
831
995
|
end
|
832
996
|
|
@@ -897,7 +1061,7 @@ class IotFunctions_2
|
|
897
1061
|
}
|
898
1062
|
resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
|
899
1063
|
end
|
900
|
-
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip)
|
1064
|
+
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip, {})
|
901
1065
|
resp_out
|
902
1066
|
end
|
903
1067
|
|
@@ -927,7 +1091,7 @@ class IotFunctions_2
|
|
927
1091
|
rescue
|
928
1092
|
output_answ = {:code => 507, :result => "Unknown SDK error"}
|
929
1093
|
end
|
930
|
-
mongo_client.audit_logger("get_info_data_type_2", remote_ip, input_params, output_answ, real_ip)
|
1094
|
+
mongo_client.audit_logger("get_info_data_type_2", remote_ip, input_params, output_answ, real_ip, {})
|
931
1095
|
output_answ
|
932
1096
|
end
|
933
1097
|
|
@@ -958,7 +1122,7 @@ class IotFunctions_2
|
|
958
1122
|
rescue
|
959
1123
|
output_answ = {:code => 507, :result => "Unknown SDK error"}
|
960
1124
|
end
|
961
|
-
mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip)
|
1125
|
+
mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip, {})
|
962
1126
|
output_answ
|
963
1127
|
end
|
964
1128
|
|
@@ -1134,7 +1298,7 @@ class IotFunctions_2
|
|
1134
1298
|
thr13set.join
|
1135
1299
|
|
1136
1300
|
output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => answ_to_soapgw, :not_processed_list => not_processed_list, :processed_list => processed_list}}
|
1137
|
-
mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
|
1301
|
+
mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip, {})
|
1138
1302
|
output_answ
|
1139
1303
|
end
|
1140
1304
|
|
@@ -1216,6 +1380,25 @@ class IotFunctions_2
|
|
1216
1380
|
end
|
1217
1381
|
|
1218
1382
|
|
1383
|
+
################################################
|
1384
|
+
############technology procedures###############
|
1385
|
+
################################################
|
1386
|
+
|
1387
|
+
def delete_all_devices_in_database
|
1388
|
+
|
1389
|
+
imei_list = []
|
1390
|
+
all_imei = mongo_client.get_all_imei_from_db
|
1391
|
+
all_imei[:body].each do |immm|
|
1392
|
+
imei_list.append(immm["imei"])
|
1393
|
+
end
|
1394
|
+
|
1395
|
+
imei_list.each do |del_imei|
|
1396
|
+
p del_imei
|
1397
|
+
self.device_remove_2("test", del_imei, "localhost", "localhost")
|
1398
|
+
end
|
1399
|
+
end
|
1400
|
+
|
1401
|
+
|
1219
1402
|
#for internal use. Add new device model
|
1220
1403
|
def add_model_to_mongo(model, manufacture_id, manufacture_name, device_type, description, note)
|
1221
1404
|
model = {
|
@@ -25,6 +25,12 @@ class HuaIot
|
|
25
25
|
@client_iot_mongo = MongoIot.new(mongo_ip, mongo_port, mongo_database)
|
26
26
|
end
|
27
27
|
|
28
|
+
def valid_json?(json)
|
29
|
+
JSON.parse(json)
|
30
|
+
rescue JSON::ParserError => e
|
31
|
+
json
|
32
|
+
end
|
33
|
+
|
28
34
|
def parse_token(str)
|
29
35
|
begin
|
30
36
|
dd = str.split(",")
|
@@ -79,7 +85,9 @@ class HuaIot
|
|
79
85
|
p res.code
|
80
86
|
p res.message
|
81
87
|
p res.body.to_s
|
82
|
-
|
88
|
+
|
89
|
+
out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
90
|
+
|
83
91
|
fff = {:func => "get_token",
|
84
92
|
:iot_fun => "",
|
85
93
|
:req_header => {:content_type => 'application/x-www-form-urlencoded',
|
@@ -120,7 +128,9 @@ class HuaIot
|
|
120
128
|
request.content_type = 'application/json'
|
121
129
|
request.body = URI.encode_www_form(data)
|
122
130
|
res = https.request(request)
|
123
|
-
|
131
|
+
#JSON.parse(res.body.to_s)
|
132
|
+
out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s) }
|
133
|
+
|
124
134
|
fff = {:func => "token_logout",
|
125
135
|
:iot_fun => "logout",
|
126
136
|
:platform => "Huawei oceanconnect"
|
@@ -157,7 +167,7 @@ class HuaIot
|
|
157
167
|
data = {nodeId: node_id}
|
158
168
|
request.body = data.to_json
|
159
169
|
res = https.request(request)
|
160
|
-
out_resp = {:code => res.code, :message => res.message, :body =>
|
170
|
+
out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
161
171
|
fff = {:func => "dev_register_verif_code_mode",
|
162
172
|
:iot_fun => "Registering a Directly Connected Device (Verification Code Mode) (V2)",
|
163
173
|
:req_header => {:content_type => 'application/json',
|
@@ -195,7 +205,7 @@ class HuaIot
|
|
195
205
|
internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
|
196
206
|
request.body = data_out.to_json
|
197
207
|
res = https.request(request)
|
198
|
-
out_resp = {:code => res.code, :message => res.message, :body =>
|
208
|
+
out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
199
209
|
fff = {:func => "dev_register_passw_code_mode2",
|
200
210
|
:iot_fun => "2.2.4",
|
201
211
|
:req_header => {:authorization => 'Bearer ' + token,
|
@@ -230,7 +240,7 @@ class HuaIot
|
|
230
240
|
request.body = data_out
|
231
241
|
res = https.request(request)
|
232
242
|
p res.body.to_s
|
233
|
-
out_resp = {:code => res.code, :message => res.message, :body =>
|
243
|
+
out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
234
244
|
fff = {:func => "dev_reg_passw_code_mode2_2",
|
235
245
|
:iot_fun => "2.2.4",
|
236
246
|
:req_header => {:content_type => 'application/json',
|
@@ -262,7 +272,7 @@ class HuaIot
|
|
262
272
|
request['app_key'] = app_id
|
263
273
|
res = https.request(request)
|
264
274
|
if res.body != nil
|
265
|
-
out_resp = {:code => res.code, :message => res.message, :body => {:answ =>
|
275
|
+
out_resp = {:code => res.code, :message => res.message, :body => {:answ => valid_json?(res.body.to_s)}}
|
266
276
|
else
|
267
277
|
out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
|
268
278
|
end
|
@@ -303,7 +313,7 @@ class HuaIot
|
|
303
313
|
res = https.request(request)
|
304
314
|
p res.body.to_s
|
305
315
|
p res.code
|
306
|
-
{:code => res.code, :message => res.message, :body =>
|
316
|
+
{:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
307
317
|
end
|
308
318
|
|
309
319
|
#2.2.14 Querying Device Activation Status
|
@@ -323,7 +333,7 @@ class HuaIot
|
|
323
333
|
request['Authorization'] = 'Bearer ' + token
|
324
334
|
request['app_key'] = app_id
|
325
335
|
res = https.request(request)
|
326
|
-
output_ans = {:code => res.code, :message => res.message, :body =>
|
336
|
+
output_ans = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
327
337
|
fff = {:func => "querying_device_activ_status",
|
328
338
|
:iot_fun => "2.2.14",
|
329
339
|
:req_header => {:content_type => 'application/json',
|
@@ -353,7 +363,7 @@ class HuaIot
|
|
353
363
|
request['Authorization'] = 'Bearer ' + token
|
354
364
|
request['app_key'] = app_id
|
355
365
|
res = https.request(request)
|
356
|
-
out_resp = {:code => res.code, :message => res.message, :body =>
|
366
|
+
out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
357
367
|
fff = {:func => "querying_device_info",
|
358
368
|
:iot_fun => "2.9.1",
|
359
369
|
:req_header => {:authorization => 'Bearer ' + token,
|
@@ -384,7 +394,7 @@ class HuaIot
|
|
384
394
|
req_body = {deviceIds: dev_list}
|
385
395
|
request.body = req_body.to_json
|
386
396
|
res = https.request(request)
|
387
|
-
output_str = {:code => res.code, :message => res.message, :body =>
|
397
|
+
output_str = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
388
398
|
fff = {:func => "querying_device_direct_conn",
|
389
399
|
:iot_fun => "2.9.6",
|
390
400
|
:req_header => {:authorization => 'Bearer ' + token,
|
@@ -414,7 +424,7 @@ class HuaIot
|
|
414
424
|
request['Authorization'] = 'Bearer ' + token
|
415
425
|
request['app_key'] = app_id
|
416
426
|
res = https.request(request)
|
417
|
-
output_ans = {:code => res.code, :message => res.message, :body =>
|
427
|
+
output_ans = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
418
428
|
|
419
429
|
fff = {:func => "querying_device_type_list",
|
420
430
|
:iot_fun => "2.9.19",
|
@@ -448,7 +458,7 @@ class HuaIot
|
|
448
458
|
data = {deviceIds: dev_list}
|
449
459
|
request.body = data.to_json
|
450
460
|
res = https.request(request)
|
451
|
-
output_ans = {:code => res.code, :message => res.message, :body =>
|
461
|
+
output_ans = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
|
452
462
|
fff = {:func => "quer_dev_direct_conn_batches",
|
453
463
|
:iot_fun => "2.9.6",
|
454
464
|
:req_header => {:content_type => 'application/json',
|
@@ -485,7 +495,7 @@ class HuaIot
|
|
485
495
|
p res.code
|
486
496
|
p res.body
|
487
497
|
if res.body != nil
|
488
|
-
out_resp = {:code => res.code, :message => res.message, :body => {:answ =>
|
498
|
+
out_resp = {:code => res.code, :message => res.message, :body => {:answ => valid_json?(res.body.to_s)}}
|
489
499
|
else
|
490
500
|
out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
|
491
501
|
end
|
@@ -65,6 +65,7 @@ class InternalFunc
|
|
65
65
|
else
|
66
66
|
output_params = {:code => 200, :result => "if_digit_or_string: Request processed. Its string", :body => {:string => true}}
|
67
67
|
end
|
68
|
+
printer_texter({:input_params => input_params, :output_params => output_params}, "debug")
|
68
69
|
output_params
|
69
70
|
|
70
71
|
end
|
@@ -76,7 +77,6 @@ class InternalFunc
|
|
76
77
|
|
77
78
|
output_info = {}
|
78
79
|
begin
|
79
|
-
|
80
80
|
if output_answer[:code] != 200
|
81
81
|
deviceserr = []
|
82
82
|
failednum = input_params[:imei_list].length
|
@@ -151,7 +151,7 @@ class InternalFunc
|
|
151
151
|
else
|
152
152
|
answer = {:code => 400, :result => "Invalid IMEI. Data is not integer", :checked => false}
|
153
153
|
end
|
154
|
-
printer_texter({:answer => answer, :input => input}, "debug")
|
154
|
+
printer_texter({:answer => answer, :input => input, :fun => "imei_validate"}, "debug")
|
155
155
|
answer
|
156
156
|
end
|
157
157
|
|
@@ -163,6 +163,35 @@ class InternalFunc
|
|
163
163
|
v3.uniq - v2.uniq - v1.uniq
|
164
164
|
end
|
165
165
|
|
166
|
+
|
167
|
+
#delete one key from hash
|
168
|
+
def delete_key_hash(hash_f, delete_key)
|
169
|
+
inp_fun = {:hash_f => hash_f, :delete_key => delete_key}
|
170
|
+
hash_f = hash_f.to_h
|
171
|
+
out_data = {}
|
172
|
+
res = {}
|
173
|
+
hash_f.each do |ggg|
|
174
|
+
if ggg[0].to_s != delete_key.to_s
|
175
|
+
res[ggg[0]] = ggg[1]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
out_data = res
|
179
|
+
printer_texter({:out_data => out_data, :inp_fun => inp_fun, :fun => "delete_key_hash" }, "debug")
|
180
|
+
out_data
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
#process hash array. Transform keys to string keys
|
185
|
+
def hash_val_to_string(hash_full)
|
186
|
+
resp = {}
|
187
|
+
hash_full.each do |hsh|
|
188
|
+
resp[hsh[0].to_s] = hsh[1]
|
189
|
+
end
|
190
|
+
resp
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
|
166
195
|
def test()
|
167
196
|
p "eeeeeeeeeeeeeeeeeeeeeeee"
|
168
197
|
end
|
@@ -20,7 +20,7 @@ class MongoIot
|
|
20
20
|
@internal_func = InternalFunc.new
|
21
21
|
end
|
22
22
|
|
23
|
-
def audit_logger(proc_name, src_ip, input_json, output_json, real_ip)
|
23
|
+
def audit_logger(proc_name, src_ip, input_json, output_json, real_ip, add_params)
|
24
24
|
out_resp = {}
|
25
25
|
begin
|
26
26
|
current = internal_func.datetimenow
|
@@ -30,7 +30,8 @@ class MongoIot
|
|
30
30
|
:date => current,
|
31
31
|
:sender => {:src_ip => src_ip, :real_ip => real_ip},
|
32
32
|
:input_params => input_json,
|
33
|
-
:output_params => output_json
|
33
|
+
:output_params => output_json,
|
34
|
+
:add_params => add_params
|
34
35
|
}
|
35
36
|
result = collection.insert_one(doc)
|
36
37
|
out_resp = {:code => 200, :result => "audit_logger: Request completed successfully", :body => result}
|
@@ -506,6 +507,7 @@ class MongoIot
|
|
506
507
|
#function for get iot platform credentials from profile
|
507
508
|
#universal procedure. use profile or profile id
|
508
509
|
def get_iot_oceanconn_credent_2(profile)
|
510
|
+
input_in = {:profile => profile}
|
509
511
|
out_resp = {}
|
510
512
|
begin
|
511
513
|
result_ps = []
|
@@ -527,7 +529,7 @@ class MongoIot
|
|
527
529
|
rescue
|
528
530
|
out_resp = {:code => 500, :result => "get_iot_oceanconn_credent_2: Process failed"}
|
529
531
|
end
|
530
|
-
internal_func.printer_texter(out_resp, "debug")
|
532
|
+
internal_func.printer_texter({:input_in => input_in, :out_resp => out_resp, :fun => "get_iot_oceanconn_credent_2"}, "debug")
|
531
533
|
out_resp
|
532
534
|
end
|
533
535
|
|
@@ -554,6 +556,7 @@ class MongoIot
|
|
554
556
|
|
555
557
|
#universal procedure. Use id or name
|
556
558
|
def get_device_type_info_universal(device_model)
|
559
|
+
input_fun = {:device_model => device_model}
|
557
560
|
out_resp = {}
|
558
561
|
begin
|
559
562
|
as = internal_func.if_digit_or_string(device_model)
|
@@ -587,13 +590,14 @@ class MongoIot
|
|
587
590
|
rescue
|
588
591
|
out_resp = {:code => 500, :result => "get_device_type_info_universal: procedure error", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
|
589
592
|
end
|
590
|
-
internal_func.printer_texter(out_resp, "debug")
|
593
|
+
internal_func.printer_texter({:input_fun => input_fun, :out_resp => out_resp, :fun => "get_device_type_info_universal"}, "debug")
|
591
594
|
out_resp
|
592
595
|
end
|
593
596
|
|
594
597
|
|
595
598
|
|
596
599
|
def compare_profiles(profile1, profile2)
|
600
|
+
input_inf = {:profile1 => profile1, :profile2 => profile2}
|
597
601
|
out_answ = {}
|
598
602
|
ch1 = internal_func.if_digit_or_string(profile1)
|
599
603
|
ch2 = internal_func.if_digit_or_string(profile2)
|
@@ -630,10 +634,12 @@ class MongoIot
|
|
630
634
|
out_answ = {:code => 200, :result => "compare_profiles: profiles are different", :is_the_same => false, :data_type => "different"}
|
631
635
|
end
|
632
636
|
end
|
637
|
+
internal_func.printer_texter({:input_inf => input_inf, :out => out_answ, :fun => "compare_profiles"}, "debug")
|
633
638
|
out_answ
|
634
639
|
end
|
635
640
|
|
636
641
|
def compare_device_types(type1, type2)
|
642
|
+
input_inf = {:type1 => type1, :type2 => type2}
|
637
643
|
out_answ = {}
|
638
644
|
tp1 = internal_func.if_digit_or_string(type1)
|
639
645
|
tp2 = internal_func.if_digit_or_string(type2)
|
@@ -680,12 +686,15 @@ class MongoIot
|
|
680
686
|
out_answ = {:code => 200, :result => "compare_device_types: profiles are different", :is_the_same => false, :data_type => "different"}
|
681
687
|
end
|
682
688
|
end
|
689
|
+
internal_func.printer_texter({:input_inf => input_inf, :out => out_answ, :fun => "compare_device_types"}, "debug")
|
683
690
|
out_answ
|
684
691
|
end
|
685
692
|
|
686
693
|
|
687
694
|
#universal procedure. put there profile name or id in string or int
|
688
695
|
def get_profile_universal(profile)
|
696
|
+
input_inf = {:profile => profile}
|
697
|
+
out = {}
|
689
698
|
inn = internal_func.if_digit_or_string(profile)
|
690
699
|
out = {}
|
691
700
|
if inn[:body][:string]
|
@@ -693,10 +702,12 @@ class MongoIot
|
|
693
702
|
else
|
694
703
|
out = self.get_profile_name_by_id(profile.to_i)
|
695
704
|
end
|
705
|
+
internal_func.printer_texter({:input_inf => input_inf, :out => out, :fun => "get_profile_universal"}, "debug")
|
696
706
|
out
|
697
707
|
end
|
698
708
|
|
699
709
|
def modify_attr_mongo_universal(imei, attribute)
|
710
|
+
input_add = {:imei => imei, :attribute => attribute}
|
700
711
|
out_resp = {}
|
701
712
|
begin
|
702
713
|
collection = client[:device_imei]
|
@@ -709,7 +720,25 @@ class MongoIot
|
|
709
720
|
rescue
|
710
721
|
out_resp = {:code => 507, :result => "modify_attr_mongo_universal: Unknown SDK error"}
|
711
722
|
end
|
712
|
-
internal_func.printer_texter(out_resp, "debug")
|
723
|
+
internal_func.printer_texter({:input_add => input_add, :out_resp => out_resp, :fun => "modify_attr_mongo_universal"}, "debug")
|
724
|
+
out_resp
|
725
|
+
end
|
726
|
+
|
727
|
+
|
728
|
+
def get_all_imei_from_db
|
729
|
+
out_resp = {}
|
730
|
+
begin
|
731
|
+
req2 = []
|
732
|
+
result_ps = []
|
733
|
+
collection = client[:device_imei]
|
734
|
+
collection.find({}, {:_id => 0}).each {|row|
|
735
|
+
result_ps.append(row)
|
736
|
+
}
|
737
|
+
out_resp = {:code => 200, :result => "get_all_imei_from_db: Request completed successfully", :body => result_ps}
|
738
|
+
rescue
|
739
|
+
out_resp = {:code => 507, :result => "get_all_imei_from_db: Unknown SDK error"}
|
740
|
+
end
|
741
|
+
#internal_func.printer_texter(out_resp, "debug")
|
713
742
|
out_resp
|
714
743
|
end
|
715
744
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imperituroard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dzmitry Buynovskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|