imperituroard 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64ac99c5a41209df78fa5f319ec47a51cb28b05b
4
- data.tar.gz: 004ea48aa310c5d3159ffa8f93b6451f6105fe0a
3
+ metadata.gz: 4f3be6181f0232b7cf9ffcbc83e64b250c193ba8
4
+ data.tar.gz: 1bec083ea1a987aa71a5387f01ee66d414c82fc2
5
5
  SHA512:
6
- metadata.gz: 97de046b4032c0751a046c4e1f57cbaffafd63936e53bfa08bcca6dc7216b6a5f73dcf1a68715c9a0a21b4f4ff5e1c116b3fabe0f450a264962543e68b6055b3
7
- data.tar.gz: 62ad29d69a43d0b0574c5249ac6777bc153a10472b9cce01298a80e27c8c956b6776aa86eef9d558d87acd1d260d5f7ca66428fa12ac8cfead71aab7fb0a7383
6
+ metadata.gz: 3e2c3e4efb2ae8069803ddafaa4fcf55dda9b9cf6759444fe21ba829927d3c1067003df4a5c0ab51338e43cf2fb831035fee1c64a0b384869610078ad2c15842
7
+ data.tar.gz: 0b4e145d35a75cbc40f75fe84fb1d72b6ae3fd749ab8a47ad6ecc405c50fee1e2972b03a2f1ca1e270107a645a72f9bc47f10e18c1e97c8121214528fa72b5e5
@@ -33,6 +33,7 @@ require 'net/http'
33
33
  require 'uri'
34
34
 
35
35
  module Imperituroard
36
+
36
37
  class Error < StandardError;
37
38
  end
38
39
 
@@ -42,6 +43,7 @@ module Imperituroard
42
43
  def hhh(jjj)
43
44
  p jjj
44
45
  end
46
+
45
47
  # Your code goes here...
46
48
  end
47
49
 
@@ -239,6 +241,11 @@ class Iot
239
241
  iot_connector.get_available_types_2(login, real_ip, remote_ip)
240
242
  end
241
243
 
244
+ #9-1 get available types for login and profile
245
+ def get_available_types2(login, profile, real_ip, remote_ip)
246
+ iot_connector.get_available_types2_2(login, profile, real_ip, remote_ip)
247
+ end
248
+
242
249
  #10 get info for device type
243
250
  def get_info_data_type(type, real_ip, remote_ip)
244
251
  iot_connector.get_info_data_type_2(type, real_ip, remote_ip)
@@ -115,10 +115,9 @@ class IotFunctions_2
115
115
  end
116
116
  end
117
117
 
118
-
119
118
  begin
120
119
  added_on_iot_platf = []
121
- if for_insert!=[]
120
+ if for_insert != []
122
121
  ##Logic for IOT Platform connection###
123
122
 
124
123
 
@@ -141,7 +140,7 @@ class IotFunctions_2
141
140
 
142
141
  #get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
143
142
  #from database
144
- model_data = mongo_client.get_device_type_info_by_model(aaa["device_type"])
143
+ model_data = mongo_client.get_device_type_info_universal(aaa["device_type"])
145
144
  resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
146
145
  credentials[:body][:secret],
147
146
  aaa["imei"],
@@ -160,7 +159,6 @@ class IotFunctions_2
160
159
  s1 = aaa
161
160
  s1[:huadata] = resss
162
161
  s1[:created] = DateTime.now
163
- s1[:type] = s1["device_type"]
164
162
  added_on_iot_platf.append(s1)
165
163
  end
166
164
  else
@@ -199,9 +197,7 @@ class IotFunctions_2
199
197
  end
200
198
  thr1.join
201
199
 
202
-
203
200
  resp_out[:body][:tosoapgw] = internal_func.iot_create_dev_soapgw_answer(input_json, resp_out)
204
-
205
201
  mongo_client.audit_logger("add_device_to_profile", remote_ip, input_json, resp_out, real_ip)
206
202
  resp_out
207
203
  end
@@ -221,16 +217,16 @@ class IotFunctions_2
221
217
  resp_out = {}
222
218
  begin
223
219
  thr2 = Thread.new do
224
- if add_functions_connector.check_input_2(login, imei_list)[:code]==200
220
+ if add_functions_connector.check_input_2(login, imei_list)[:code] == 200
225
221
 
226
222
  for t in imei_list
227
223
  prof_name1 = mongo_client.get_profile_name_from_imei(t)
228
- if prof_name1[:code]==200
224
+ if prof_name1[:code] == 200
229
225
  begin
230
226
  permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1[:body]["profile"])
231
227
  p "permiss1"
232
228
  p permiss1
233
- if permiss1[:code]==200
229
+ if permiss1[:code] == 200
234
230
  ime_list_approved.append(t)
235
231
  else
236
232
  ime_list_notapproved.append({:imei => t, :error => permiss1})
@@ -460,12 +456,12 @@ class IotFunctions_2
460
456
  begin
461
457
  thr4 = Thread.new do
462
458
 
463
- if add_functions_connector.check_input_4(login, imei)[:code]==200
459
+ if add_functions_connector.check_input_4(login, imei)[:code] == 200
464
460
 
465
461
  prof_name = mongo_client.get_profile_name_from_imei(imei)
466
- if prof_name[:code]==200
462
+ if prof_name[:code] == 200
467
463
  permiss = mongo_client.check_login_profile_permiss(login, prof_name[:body]["profile"])
468
- if permiss[:code]==200
464
+ if permiss[:code] == 200
469
465
 
470
466
  ##Logic for IOT Platform connection###
471
467
 
@@ -479,17 +475,17 @@ class IotFunctions_2
479
475
 
480
476
  resp = {}
481
477
 
482
- if credentials[:code]==200
478
+ if credentials[:code] == 200
483
479
 
484
480
  imei_data = mongo_client.get_imei_info_from_db([imei])
485
- if imei_data[:body]!=[]
481
+ if imei_data[:body] != []
486
482
  ans = {}
487
483
  if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
488
484
  ans = hua_aceanconnect_connector.remove_one_device_from_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
489
485
  else
490
486
  ans = {:code => "204", :result => "Not processed by iot platform. deviceId not found in mongoDB"}
491
487
  end
492
- if ans[:code]=="204" or ans[:code]=="200"
488
+ if ans[:code] == "204" or ans[:code] == "200"
493
489
  resp = mongo_client.device_remove_single_mongo(imei)
494
490
  else
495
491
  resp = {:code => 500, :result => "Unknown IOT platform error", :body => ans}
@@ -573,10 +569,8 @@ class IotFunctions_2
573
569
  imei_data = mongo_client.get_imei_info_from_db([p[:imei]])
574
570
  if imei_data[:body]!=[]
575
571
  ans = hua_aceanconnect_connector.modify_location_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"], p[:address])
576
-
577
572
  internal_func.printer_texter({:function => "device_add_address Step2", :ans => ans, :descrition => "answer from hua IOT", :input => {:did => imei_data[:body][0]["huadata"]["body"]["deviceId"], :appid => credentials[:body][:app_id], :secret => credentials[:body][:secret], :address => p[:address]}}, "debug")
578
573
  end
579
-
580
574
  end
581
575
 
582
576
  #########end iot platform logic#######
@@ -651,7 +645,7 @@ class IotFunctions_2
651
645
  if attr["profile"].is_a? Integer
652
646
  p "Ok"
653
647
  else
654
- p new = mongo_client.get_profile_id_by_name(attr["profile"])
648
+ p new = mongo_client.get_profile_universal(attr["profile"])
655
649
  attr["profile"] = new["profile_id"]
656
650
  end
657
651
  end
@@ -736,6 +730,7 @@ class IotFunctions_2
736
730
  permit_profiles = login_info[:body]["permit_profiles"]
737
731
  permit_types = login_info[:body]["permit_types"]
738
732
  data_from_mongo = mongo_client.get_profile_list_by_id(permit_profiles)
733
+ p data_from_mongo
739
734
 
740
735
  for ff in data_from_mongo
741
736
  data_processed.append({:profile_id => ff["profile_id"],
@@ -840,33 +835,47 @@ class IotFunctions_2
840
835
  data_processed = []
841
836
  data_soapgw = []
842
837
  login_info = mongo_client.get_login_inf2_select(login)
838
+ prof_data = mongo_client.get_profile_universal(profile)
843
839
  if login_info[:code]==200
844
840
 
845
841
  permit_profiles = login_info[:body]["permit_profiles"]
846
842
  permit_types = login_info[:body]["permit_types"]
843
+ perm_tp_prof = prof_data["permit_types"]
844
+
845
+ if permit_profiles.include?(prof_data["profile_id"])
846
+ res_types_permitted = internal_func.compare_dict(permit_types, perm_tp_prof)
847
+ data_from_mongo = mongo_client.get_type_list_by_id(res_types_permitted)
848
+
849
+ for ff in data_from_mongo
850
+ data_processed.append({:type_id => ff["type_id"],
851
+ :description => ff["description"],
852
+ :note => ff["note"],
853
+ :form => ff["form"],
854
+ :ManufacturerID => ff["ManufacturerID"],
855
+ :ManufacturerNAME => ff["ManufacturerNAME"],
856
+ :device_type => ff["device_type"],
857
+ :model => ff["model"],
858
+ :info => ff["info"]
859
+ })
860
+ data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
861
+ end
847
862
 
848
- data_from_mongo = mongo_client.get_type_list_by_id(permit_types)
863
+ tosoapgw = {:code => 200,
864
+ :result => "Request completed successfully",
865
+ :types => data_soapgw
866
+ }
849
867
 
850
- for ff in data_from_mongo
851
- data_processed.append({:type_id => ff["type_id"],
852
- :description => ff["description"],
853
- :note => ff["note"],
854
- :form => ff["form"],
855
- :ManufacturerID => ff["ManufacturerID"],
856
- :ManufacturerNAME => ff["ManufacturerNAME"],
857
- :device_type => ff["device_type"],
858
- :model => ff["model"],
859
- :info => ff["info"]
860
- })
861
- data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
868
+ resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
869
+
870
+ else
871
+ tosoapgw = {:code => 700,
872
+ :result => "Profile not permitted",
873
+ :types => data_soapgw
874
+ }
875
+ resp_out = {:code => 700, :result => "Profile not permitted", :body => {:tosoapgw => tosoapgw}}
862
876
  end
863
877
 
864
- tosoapgw = {:code => 200,
865
- :result => "Request completed successfully",
866
- :types => data_soapgw
867
- }
868
878
 
869
- resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
870
879
  else
871
880
  tosoapgw = {:code => login_info[:code],
872
881
  :result => login_info[:result],
@@ -930,6 +939,8 @@ class IotFunctions_2
930
939
  mon_answer = mongo_client.get_profile_name_by_id(profile)
931
940
  end
932
941
 
942
+ p mon_answer
943
+
933
944
  if mon_answer != {} && mon_answer != []
934
945
  output_answ = {:code => 200, :result => "Request completed successfully", :body => {:data => {:info => mon_answer["info"],
935
946
  :profile => mon_answer["profile"],
@@ -943,7 +954,6 @@ class IotFunctions_2
943
954
  end
944
955
  mongo_client.audit_logger("get_info_data_profile_2", remote_ip, input_params, output_answ, real_ip)
945
956
  output_answ
946
-
947
957
  end
948
958
 
949
959
 
@@ -1002,7 +1012,7 @@ class IotFunctions_2
1002
1012
  cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
1003
1013
  p cur_comp1
1004
1014
  p "cur_comp1"
1005
- cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["type"], type_new_pr)
1015
+ cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["device_type"], type_new_pr)
1006
1016
 
1007
1017
 
1008
1018
  p cur_comp2
@@ -1053,7 +1063,7 @@ class IotFunctions_2
1053
1063
  new_profile_id = prof_new_id
1054
1064
  now_date = DateTime.now
1055
1065
  #finished success. update database
1056
- attribute = {profile: new_profile_id, type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1066
+ attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1057
1067
  answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
1058
1068
  if answ_mongo[:code] != 200
1059
1069
  not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
@@ -76,7 +76,8 @@ class HuaIot
76
76
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
77
77
  fff = {:func => "get_token",
78
78
  :iot_fun => "",
79
- :req_header => {:content_type => 'application/x-www-form-urlencoded'
79
+ :req_header => {:content_type => 'application/x-www-form-urlencoded',
80
+ :platform => "Huawei oceanconnect"
80
81
  }}
81
82
  client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
82
83
  rescue
@@ -112,7 +113,8 @@ class HuaIot
112
113
  res = https.request(request)
113
114
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
114
115
  fff = {:func => "token_logout",
115
- :iot_fun => "logout"
116
+ :iot_fun => "logout",
117
+ :platform => "Huawei oceanconnect"
116
118
  }
117
119
  client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
118
120
  rescue
@@ -125,6 +127,7 @@ class HuaIot
125
127
 
126
128
  #Registering a Directly Connected Device (Verification Code Mode) (V2)
127
129
  def dev_register_verif_code_mode(app_id, secret, node_id)
130
+ out_resp = {}
128
131
  token = get_token(app_id, secret)[:body]["accessToken"]
129
132
  path = "/iocm/app/reg/v1.1.0/deviceCredentials?appId=" + app_id
130
133
  url_string = "https://" + platformip + ":" + platformport + path
@@ -138,9 +141,17 @@ class HuaIot
138
141
  request.content_type = 'application/json'
139
142
  request['Authorization'] = 'Bearer ' + token
140
143
  request['app_key'] = app_id
141
- request.body = {nodeId: node_id}.to_json
144
+ data = {nodeId: node_id}
145
+ request.body = data.to_json
142
146
  res = https.request(request)
143
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
147
+ out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
148
+ fff = {:func => "dev_register_verif_code_mode",
149
+ :iot_fun => "Registering a Directly Connected Device (Verification Code Mode) (V2)",
150
+ :req_header => {:content_type => 'application/json',
151
+ :platform => "Huawei oceanconnect"
152
+ }}
153
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
154
+ out_resp
144
155
  end
145
156
 
146
157
  #2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
@@ -176,7 +187,8 @@ class HuaIot
176
187
  :iot_fun => "2.2.4",
177
188
  :req_header => {:authorization => 'Bearer ' + token,
178
189
  :content_type => 'application/json',
179
- :app_key => app_id
190
+ :app_key => app_id,
191
+ :platform => "Huawei oceanconnect"
180
192
  }}
181
193
  client_iot_mongo.audit_iot_logger(fff, url_string, data_out, out_resp)
182
194
  out_resp
@@ -199,13 +211,21 @@ class HuaIot
199
211
  request.content_type = 'application/json'
200
212
  request['Authorization'] = 'Bearer ' + token
201
213
  request['app_key'] = app_id
202
- data_out = {deviceInfo: attr_list}.to_json
214
+ data = {deviceInfo: attr_list}
215
+ data_out = data.to_json
203
216
  internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
204
217
  request.body = data_out
205
218
  res = https.request(request)
206
219
  p res.body.to_s
207
220
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
208
- p out_resp
221
+ fff = {:func => "dev_reg_passw_code_mode2_2",
222
+ :iot_fun => "2.2.4",
223
+ :req_header => {:content_type => 'application/json',
224
+ :authorization => 'Bearer ' + token,
225
+ :app_key => app_id,
226
+ :platform => "Huawei oceanconnect"
227
+ }}
228
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
209
229
  out_resp
210
230
  end
211
231
 
@@ -237,7 +257,8 @@ class HuaIot
237
257
  :iot_fun => "2.2.12",
238
258
  :req_header => {:authorization => 'Bearer ' + token,
239
259
  :content_type => 'application/json',
240
- :app_key => app_id
260
+ :app_key => app_id,
261
+ :platform => "Huawei oceanconnect"
241
262
  }}
242
263
  client_iot_mongo.audit_iot_logger(fff, url_string, "Delete", out_resp)
243
264
  rescue
@@ -274,6 +295,7 @@ class HuaIot
274
295
 
275
296
  #2.2.14 Querying Device Activation Status
276
297
  def querying_device_activ_status(app_id, secret, device_id)
298
+ output_ans = {}
277
299
  token = get_token(app_id, secret)[:body]["accessToken"]
278
300
  path = "/iocm/app/reg/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
279
301
  url_string = "https://" + platformip + ":" + platformport + path
@@ -288,12 +310,22 @@ class HuaIot
288
310
  request['Authorization'] = 'Bearer ' + token
289
311
  request['app_key'] = app_id
290
312
  res = https.request(request)
291
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
313
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
314
+ fff = {:func => "querying_device_activ_status",
315
+ :iot_fun => "2.2.14",
316
+ :req_header => {:content_type => 'application/json',
317
+ :authorization => 'Bearer ' + token,
318
+ :app_key => app_id,
319
+ :platform => "Huawei oceanconnect"
320
+ }}
321
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
322
+ output_ans
292
323
  end
293
324
 
294
325
 
295
326
  #2.9.1 Querying Information About a Device
296
327
  def querying_device_info(app_id, secret, device_id)
328
+ out_resp = {}
297
329
  token = get_token(app_id, secret)[:body]["accessToken"]
298
330
  path = "/iocm/app/dm/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
299
331
  url_string = "https://" + platformip + ":" + platformport + path
@@ -308,7 +340,16 @@ class HuaIot
308
340
  request['Authorization'] = 'Bearer ' + token
309
341
  request['app_key'] = app_id
310
342
  res = https.request(request)
311
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
343
+ out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
344
+ fff = {:func => "querying_device_info",
345
+ :iot_fun => "2.9.1",
346
+ :req_header => {:authorization => 'Bearer ' + token,
347
+ :content_type => 'application/json',
348
+ :app_key => app_id,
349
+ :platform => "Huawei oceanconnect"
350
+ }}
351
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Get", out_resp)
352
+ out_resp
312
353
  end
313
354
 
314
355
  #2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
@@ -335,7 +376,8 @@ class HuaIot
335
376
  :iot_fun => "2.9.6",
336
377
  :req_header => {:authorization => 'Bearer ' + token,
337
378
  :content_type => 'application/json',
338
- :app_key => app_id
379
+ :app_key => app_id,
380
+ :platform => "Huawei oceanconnect"
339
381
  }}
340
382
  client_iot_mongo.audit_iot_logger(fff, url_string, req_body, output_str)
341
383
  output_str
@@ -344,6 +386,7 @@ class HuaIot
344
386
 
345
387
  #2.9.19 Querying the Complete Device Type List of All Device Capabilities
346
388
  def querying_device_type_list(app_id, secret)
389
+ output_ans = {}
347
390
  token = get_token(app_id, secret)[:body]["accessToken"]
348
391
  path = "/iocm/app/profile/v1.1.0/allDeviceTypes"
349
392
  url_string = "https://" + platformip + ":" + platformport + path
@@ -358,13 +401,24 @@ class HuaIot
358
401
  request['Authorization'] = 'Bearer ' + token
359
402
  request['app_key'] = app_id
360
403
  res = https.request(request)
361
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
404
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
405
+
406
+ fff = {:func => "querying_device_type_list",
407
+ :iot_fun => "2.9.19",
408
+ :req_header => {:content_type => 'application/json',
409
+ :authorization => 'Bearer ' + token,
410
+ :app_key => app_id,
411
+ :platform => "Huawei oceanconnect"
412
+ }}
413
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Get", output_ans)
414
+ output_ans
415
+
362
416
  end
363
417
 
364
418
 
365
419
  #2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
366
420
  def quer_dev_direct_conn_batches(app_id, dev_list, token)
367
-
421
+ output_ans = {}
368
422
  path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
369
423
  url_string = "https://" + platformip + ":" + platformport + path
370
424
  p url_string
@@ -378,10 +432,19 @@ class HuaIot
378
432
  request.content_type = 'application/json'
379
433
  request['Authorization'] = 'Bearer ' + token
380
434
  request['app_key'] = app_id
381
- request.body = {deviceIds: dev_list}.to_json
435
+ data = {deviceIds: dev_list}
436
+ request.body = data.to_json
382
437
  res = https.request(request)
383
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
384
-
438
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
439
+ fff = {:func => "quer_dev_direct_conn_batches",
440
+ :iot_fun => "2.9.6",
441
+ :req_header => {:content_type => 'application/json',
442
+ :authorization => 'Bearer ' + token,
443
+ :app_key => app_id,
444
+ :platform => "Huawei oceanconnect"
445
+ }}
446
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
447
+ output_ans
385
448
  end
386
449
 
387
450
 
@@ -417,7 +480,8 @@ class HuaIot
417
480
  :iot_fun => "2.2.11",
418
481
  :req_header => {:authorization => 'Bearer ' + token,
419
482
  :content_type => 'application/json',
420
- :app_key => app_id
483
+ :app_key => app_id,
484
+ :platform => "Huawei oceanconnect"
421
485
  }}
422
486
  client_iot_mongo.audit_iot_logger(fff, url_string, req_b, out_resp)
423
487
  rescue
@@ -155,6 +155,14 @@ class InternalFunc
155
155
  answer
156
156
  end
157
157
 
158
+ #compare dictionaries
159
+ def compare_dict(dict1, dict2)
160
+ v1 = dict1 - dict2
161
+ v2 = dict2 - dict1
162
+ v3 = dict2 + dict1
163
+ v3.uniq - v2.uniq - v1.uniq
164
+ end
165
+
158
166
  def test()
159
167
  p "eeeeeeeeeeeeeeeeeeeeeeee"
160
168
  end
@@ -194,7 +194,7 @@ class MongoIot
194
194
  begin
195
195
  result_ps = []
196
196
  collection = client[:device_profiles]
197
- collection.find({"profile_id" => profile_id}).each {|row|
197
+ collection.find({"profile_id" => profile_id.to_i}).each {|row|
198
198
  result_ps.append(row)
199
199
  }
200
200
  result_ps[0]
@@ -238,7 +238,7 @@ class MongoIot
238
238
  begin
239
239
  result_ps = []
240
240
  collection = client[:device_types]
241
- collection.find({"type_id" => type_id}).each {|row|
241
+ collection.find({"type_id" => type_id.to_i}).each {|row|
242
242
  result_ps.append(row)
243
243
  }
244
244
  result_ps[0]
@@ -260,19 +260,20 @@ class MongoIot
260
260
  end
261
261
  end
262
262
 
263
+ #universal procedure. might be profile id or name
263
264
  def check_login_profile_permiss(login, profile)
264
265
  out_resp = {}
265
266
  get_login_info = get_profiles_by_login(login)
266
- if get_login_info[:code]==200
267
- dst_profile = get_profile_id_by_name(profile)
268
- access=1
269
- if get_login_info[:body]!=[]
270
- if dst_profile!=[]
267
+ if get_login_info[:code] == 200
268
+ dst_profile = get_profile_universal(profile)
269
+ access = 1
270
+ if get_login_info[:body] != []
271
+ if dst_profile != []
271
272
  for j in get_login_info[:body]
272
- if j["profile_id"].to_i==dst_profile["profile_id"].to_i
273
- access=0
273
+ if j["profile_id"].to_i == dst_profile["profile_id"].to_i
274
+ access = 0
274
275
  end
275
- if access==0
276
+ if access == 0
276
277
  out_resp = {:code => 200, :result => "check_login_profile_permiss: Permission granted"}
277
278
  else
278
279
  out_resp = {:code => 400, :result => "check_login_profile_permiss: Access denied. This incident will be reported."}
@@ -292,13 +293,15 @@ class MongoIot
292
293
  end
293
294
 
294
295
 
296
+ #universal procedure. You can use profile id or profile name as profile_id (string or int)
295
297
  def check_login_prof_perm_id_one(login, profile_id)
296
298
  out_resp = {}
297
299
  get_login_info = get_profiles_by_login(login)
300
+ profile_data = self.get_profile_universal(profile_id)
298
301
  access=1
299
302
  if get_login_info[:body]!=[]
300
303
  for j in get_login_info[:body]
301
- if j["profile_id"].to_i==profile_id.to_i
304
+ if j["profile_id"].to_i==profile_data["profile_id"]
302
305
  access=0
303
306
  end
304
307
  if access==0
@@ -340,7 +343,6 @@ class MongoIot
340
343
  description: "test imei",
341
344
  note: "second description",
342
345
  profile: 0,
343
- type: 0,
344
346
  device_type: 0,
345
347
  address: "unknown"
346
348
  }
@@ -364,7 +366,6 @@ class MongoIot
364
366
  description: "test imei",
365
367
  note: "second description",
366
368
  profile: 0,
367
- type: 0,
368
369
  device_type: 0,
369
370
  address: "unknown"
370
371
  }
@@ -503,6 +504,7 @@ class MongoIot
503
504
 
504
505
 
505
506
  #function for get iot platform credentials from profile
507
+ #universal procedure. use profile or profile id
506
508
  def get_iot_oceanconn_credent_2(profile)
507
509
  out_resp = {}
508
510
  begin
@@ -550,6 +552,7 @@ class MongoIot
550
552
  out_resp
551
553
  end
552
554
 
555
+ #universal procedure. Use id or name
553
556
  def get_device_type_info_universal(device_model)
554
557
  out_resp = {}
555
558
  begin
@@ -681,6 +684,7 @@ class MongoIot
681
684
  end
682
685
 
683
686
 
687
+ #universal procedure. put there profile name or id in string or int
684
688
  def get_profile_universal(profile)
685
689
  inn = internal_func.if_digit_or_string(profile)
686
690
  out = {}
@@ -1,4 +1,4 @@
1
1
  module Imperituroard
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imperituroard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy