imperituroard 1.1.0 → 1.1.5
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 +192 -13
- data/lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb +23 -13
- data/lib/imperituroard/projects/iot/internal_functions.rb +8 -3
- 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: fa09dfb75a266256aa4c5d30389bfd7abe4a2fe0
|
4
|
+
data.tar.gz: 205e98e1d6d25442861f0bf5fec36d8085684570
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5559c3bd1563437fe219df60d4466633ba26e913d467898faf48c6c75646d5f0493e7b737715f2ecda6cde3e9ff2064350181927d7c7748ca0cfbbe6004eb77f
|
7
|
+
data.tar.gz: e6b3fbf12f8852ad4ac2e5679fcef7c0f98d207decb34e47bfcad6e493644e30d337243055b37660e03d8ed39974433415dea3f0c3c47a6ece208809dd388922
|
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
|
|
@@ -209,7 +209,167 @@ class IotFunctions_2
|
|
209
209
|
thr1.join
|
210
210
|
|
211
211
|
resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
|
212
|
-
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
|
+
input_json22 = {:login => login, :imei_list => imei_list}
|
232
|
+
resp_out = {}
|
233
|
+
begin
|
234
|
+
|
235
|
+
thr1 = Thread.new do
|
236
|
+
if add_functions_connector.check_input_1(login, imei_list)[:code]==200
|
237
|
+
|
238
|
+
imei = []
|
239
|
+
list1 = {}
|
240
|
+
for_insert = []
|
241
|
+
not_processed_list = []
|
242
|
+
processed_list = []
|
243
|
+
|
244
|
+
for ii in imei_list
|
245
|
+
valid_resp = internal_func.imei_validate(ii["imei"])
|
246
|
+
if valid_resp[:checked]
|
247
|
+
list1[ii["imei"]] = ii
|
248
|
+
imei.append(ii["imei"])
|
249
|
+
else
|
250
|
+
not_processed_list.append({:imei => ii["imei"], :error => valid_resp[:result]})
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
if imei != []
|
255
|
+
list_checked = mongo_client.check_imei_exists(imei)
|
256
|
+
|
257
|
+
for ss in list_checked[:body][:exists]
|
258
|
+
not_processed_list.append({:imei => ss, :error => "Device exists in database"})
|
259
|
+
p ss
|
260
|
+
p "ss"
|
261
|
+
p list_checked
|
262
|
+
end
|
263
|
+
|
264
|
+
for jj in list_checked[:body][:not_exists]
|
265
|
+
begin
|
266
|
+
get_login_info = mongo_client.check_login_prof_perm_id_one(login, list1[jj]["profile"])[:code]
|
267
|
+
if get_login_info==200
|
268
|
+
for_insert.append(list1[jj])
|
269
|
+
else
|
270
|
+
not_processed_list.append({:imei => list1[jj], :error => "Permission denied for this profile"})
|
271
|
+
end
|
272
|
+
rescue
|
273
|
+
not_processed_list.append({:imei => list1[jj], :error => "Unknown error"})
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
begin
|
279
|
+
added_on_iot_platf = []
|
280
|
+
if for_insert != []
|
281
|
+
##Logic for IOT Platform connection###
|
282
|
+
|
283
|
+
|
284
|
+
for aaa in for_insert
|
285
|
+
|
286
|
+
#########change 2020.05.11. imperituroard
|
287
|
+
#########replace process for get iot app_id and password from users to profile
|
288
|
+
|
289
|
+
#credentials = mongo_client.get_iot_oceanconnect_credent(login)
|
290
|
+
credentials = mongo_client.get_iot_oceanconn_credent_2(aaa["profile"])
|
291
|
+
|
292
|
+
#########
|
293
|
+
|
294
|
+
if aaa.key?("type") && !aaa.key?("device_type")
|
295
|
+
aaa["device_type"] = aaa["type"]
|
296
|
+
aaa = internal_func.delete_key_hash(aaa, "type")
|
297
|
+
end
|
298
|
+
|
299
|
+
aaa = internal_func.hash_val_to_string(aaa)
|
300
|
+
|
301
|
+
if credentials[:code] == 200
|
302
|
+
|
303
|
+
begin
|
304
|
+
dev_name = aaa["imei"].to_s
|
305
|
+
|
306
|
+
#get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
|
307
|
+
#from database
|
308
|
+
model_data = mongo_client.get_device_type_info_universal(aaa["device_type"])
|
309
|
+
profile_data = mongo_client.get_profile_universal(aaa["profile"])
|
310
|
+
p profile_data
|
311
|
+
p model_data
|
312
|
+
p "model_data"
|
313
|
+
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
|
314
|
+
credentials[:body][:secret],
|
315
|
+
aaa["imei"],
|
316
|
+
dev_name,
|
317
|
+
aaa["description"],
|
318
|
+
model_data[:body]["device_type"],
|
319
|
+
aaa["profile"],
|
320
|
+
model_data[:body]["ManufacturerID"],
|
321
|
+
model_data[:body]["ManufacturerNAME"],
|
322
|
+
model_data[:body]["model"]
|
323
|
+
)
|
324
|
+
if resss[:code]=="200"
|
325
|
+
if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
|
326
|
+
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
327
|
+
else
|
328
|
+
s1 = aaa
|
329
|
+
s1[:huadata] = resss
|
330
|
+
s1[:created] = DateTime.now
|
331
|
+
s1["device_type"] = model_data[:body]["model"]
|
332
|
+
s1["profile"] = profile_data["profile_id"]
|
333
|
+
added_on_iot_platf.append(s1)
|
334
|
+
end
|
335
|
+
else
|
336
|
+
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
337
|
+
end
|
338
|
+
rescue
|
339
|
+
not_processed_list.append({:imei => aaa["imei"], :error => "Unknown error with insertion imei on IOT platform"})
|
340
|
+
end
|
341
|
+
#########end iot platform logic#######
|
342
|
+
|
343
|
+
else
|
344
|
+
resss_err = {:code => 400, :result => "IOT platform credentials not found"}
|
345
|
+
not_processed_list.append({:imei => aaa["imei"], :error => resss_err})
|
346
|
+
end
|
347
|
+
|
348
|
+
end
|
349
|
+
|
350
|
+
if added_on_iot_platf.length != 0
|
351
|
+
mongo_client.imei_insert_list(added_on_iot_platf)
|
352
|
+
resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
353
|
+
else
|
354
|
+
resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
355
|
+
end
|
356
|
+
else
|
357
|
+
resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
|
358
|
+
end
|
359
|
+
rescue
|
360
|
+
resp_out = {:code => 505, :result => "Error with database communication"}
|
361
|
+
end
|
362
|
+
else
|
363
|
+
resp_out = {:code => 509, :result => "Input data invalid"}
|
364
|
+
end
|
365
|
+
end
|
366
|
+
rescue
|
367
|
+
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
368
|
+
end
|
369
|
+
thr1.join
|
370
|
+
|
371
|
+
resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json22, resp_out)
|
372
|
+
mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip, {})
|
213
373
|
resp_out
|
214
374
|
end
|
215
375
|
|
@@ -272,7 +432,7 @@ class IotFunctions_2
|
|
272
432
|
|
273
433
|
resp_out[:data][:tosoapgw] = add_functions_connector.iot_query_dev_soapgw_answer(input_json, resp_out)
|
274
434
|
|
275
|
-
mongo_client.audit_logger("device_find", remote_ip, input_json, resp_out, real_ip)
|
435
|
+
mongo_client.audit_logger("device_find", remote_ip, input_json, resp_out, real_ip, {})
|
276
436
|
resp_out
|
277
437
|
|
278
438
|
end
|
@@ -444,7 +604,7 @@ class IotFunctions_2
|
|
444
604
|
end
|
445
605
|
|
446
606
|
thr3.join
|
447
|
-
mongo_client.audit_logger("imei_replace", remote_ip, input_json, resp_out, real_ip)
|
607
|
+
mongo_client.audit_logger("imei_replace", remote_ip, input_json, resp_out, real_ip, {})
|
448
608
|
|
449
609
|
resp_out
|
450
610
|
|
@@ -531,7 +691,7 @@ class IotFunctions_2
|
|
531
691
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
532
692
|
end
|
533
693
|
thr4.join
|
534
|
-
mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip)
|
694
|
+
mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip, {})
|
535
695
|
resp_out
|
536
696
|
end
|
537
697
|
|
@@ -611,7 +771,7 @@ class IotFunctions_2
|
|
611
771
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
612
772
|
end
|
613
773
|
thr5.join
|
614
|
-
mongo_client.audit_logger("device_add_address", remote_ip, input_json, resp_out, real_ip)
|
774
|
+
mongo_client.audit_logger("device_add_address", remote_ip, input_json, resp_out, real_ip, {})
|
615
775
|
resp_out
|
616
776
|
end
|
617
777
|
|
@@ -689,7 +849,7 @@ class IotFunctions_2
|
|
689
849
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
690
850
|
end
|
691
851
|
thr6.join
|
692
|
-
mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip)
|
852
|
+
mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out, real_ip, {})
|
693
853
|
resp_out
|
694
854
|
end
|
695
855
|
|
@@ -717,7 +877,7 @@ class IotFunctions_2
|
|
717
877
|
end
|
718
878
|
end
|
719
879
|
thr7.join
|
720
|
-
mongo_client.audit_logger("autorize_subscriber", remote_ip, input_json, resp_out, real_ip)
|
880
|
+
mongo_client.audit_logger("autorize_subscriber", remote_ip, input_json, resp_out, real_ip, {})
|
721
881
|
resp_out
|
722
882
|
end
|
723
883
|
|
@@ -775,7 +935,7 @@ class IotFunctions_2
|
|
775
935
|
}
|
776
936
|
resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
|
777
937
|
end
|
778
|
-
mongo_client.audit_logger("get_available_prof_2", remote_ip, input_params, resp_out, real_ip)
|
938
|
+
mongo_client.audit_logger("get_available_prof_2", remote_ip, input_params, resp_out, real_ip, {})
|
779
939
|
resp_out
|
780
940
|
end
|
781
941
|
|
@@ -831,7 +991,7 @@ class IotFunctions_2
|
|
831
991
|
}
|
832
992
|
resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
|
833
993
|
end
|
834
|
-
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip)
|
994
|
+
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip, {})
|
835
995
|
resp_out
|
836
996
|
end
|
837
997
|
|
@@ -902,7 +1062,7 @@ class IotFunctions_2
|
|
902
1062
|
}
|
903
1063
|
resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
|
904
1064
|
end
|
905
|
-
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip)
|
1065
|
+
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip, {})
|
906
1066
|
resp_out
|
907
1067
|
end
|
908
1068
|
|
@@ -932,7 +1092,7 @@ class IotFunctions_2
|
|
932
1092
|
rescue
|
933
1093
|
output_answ = {:code => 507, :result => "Unknown SDK error"}
|
934
1094
|
end
|
935
|
-
mongo_client.audit_logger("get_info_data_type_2", remote_ip, input_params, output_answ, real_ip)
|
1095
|
+
mongo_client.audit_logger("get_info_data_type_2", remote_ip, input_params, output_answ, real_ip, {})
|
936
1096
|
output_answ
|
937
1097
|
end
|
938
1098
|
|
@@ -963,7 +1123,7 @@ class IotFunctions_2
|
|
963
1123
|
rescue
|
964
1124
|
output_answ = {:code => 507, :result => "Unknown SDK error"}
|
965
1125
|
end
|
966
|
-
mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip)
|
1126
|
+
mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip, {})
|
967
1127
|
output_answ
|
968
1128
|
end
|
969
1129
|
|
@@ -1139,7 +1299,7 @@ class IotFunctions_2
|
|
1139
1299
|
thr13set.join
|
1140
1300
|
|
1141
1301
|
output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => answ_to_soapgw, :not_processed_list => not_processed_list, :processed_list => processed_list}}
|
1142
|
-
mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
|
1302
|
+
mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip, {})
|
1143
1303
|
output_answ
|
1144
1304
|
end
|
1145
1305
|
|
@@ -1221,6 +1381,25 @@ class IotFunctions_2
|
|
1221
1381
|
end
|
1222
1382
|
|
1223
1383
|
|
1384
|
+
################################################
|
1385
|
+
############technology procedures###############
|
1386
|
+
################################################
|
1387
|
+
|
1388
|
+
def delete_all_devices_in_database
|
1389
|
+
|
1390
|
+
imei_list = []
|
1391
|
+
all_imei = mongo_client.get_all_imei_from_db
|
1392
|
+
all_imei[:body].each do |immm|
|
1393
|
+
imei_list.append(immm["imei"])
|
1394
|
+
end
|
1395
|
+
|
1396
|
+
imei_list.each do |del_imei|
|
1397
|
+
p del_imei
|
1398
|
+
self.device_remove_2("test", del_imei, "localhost", "localhost")
|
1399
|
+
end
|
1400
|
+
end
|
1401
|
+
|
1402
|
+
|
1224
1403
|
#for internal use. Add new device model
|
1225
1404
|
def add_model_to_mongo(model, manufacture_id, manufacture_name, device_type, description, note)
|
1226
1405
|
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
|
|
@@ -166,13 +166,18 @@ class InternalFunc
|
|
166
166
|
|
167
167
|
#delete one key from hash
|
168
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 = {}
|
169
172
|
res = {}
|
170
173
|
hash_f.each do |ggg|
|
171
174
|
if ggg[0].to_s != delete_key.to_s
|
172
175
|
res[ggg[0]] = ggg[1]
|
173
176
|
end
|
174
177
|
end
|
175
|
-
res
|
178
|
+
out_data = res
|
179
|
+
printer_texter({:out_data => out_data, :inp_fun => inp_fun, :fun => "delete_key_hash" }, "debug")
|
180
|
+
out_data
|
176
181
|
end
|
177
182
|
|
178
183
|
|
@@ -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.1.
|
4
|
+
version: 1.1.5
|
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
|