Class: MongoVpn

Inherits:
Object
  • Object
show all
Defined in:
lib/imperituroard/projects/autovpn/mongo_vpn.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMongoVpn

Returns a new instance of MongoVpn.



14
15
16
17
18
19
20
21
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 14

def initialize
  @mongo_vpn_database = Imperituroard::AUTOVPN_MONGO_VPN_DATABASE
  @mongo_vpn_ip = Imperituroard::AUTOVPN_MONGO_IP
  @mongo_vpn_port = Imperituroard::AUTOVPN_MONGO_VPN_PORT
  client_vpn_host = [mongo_vpn_ip + ':' + @mongo_vpn_port]
  @client_vpn = Mongo::Client.new(client_vpn_host, :database => @mongo_vpn_database)
  @logger_any = LogAddFunctions_2.new
end

Instance Attribute Details

#client_vpnObject

Returns the value of attribute client_vpn.



12
13
14
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 12

def client_vpn
  @client_vpn
end

#internal_vpn_funcObject

Returns the value of attribute internal_vpn_func.



12
13
14
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 12

def internal_vpn_func
  @internal_vpn_func
end

#logger_anyObject

Returns the value of attribute logger_any.



12
13
14
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 12

def logger_any
  @logger_any
end

#mongo_vpn_databaseObject

Returns the value of attribute mongo_vpn_database.



12
13
14
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 12

def mongo_vpn_database
  @mongo_vpn_database
end

#mongo_vpn_ipObject

Returns the value of attribute mongo_vpn_ip.



12
13
14
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 12

def mongo_vpn_ip
  @mongo_vpn_ip
end

#mongo_vpn_portObject

Returns the value of attribute mongo_vpn_port.



12
13
14
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 12

def mongo_vpn_port
  @mongo_vpn_port
end

Instance Method Details

#get_mongo_msisdn(msisdn) ⇒ Object

get data by msisdn. Validate data from collection msisdn_list



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 24

def get_mongo_msisdn(msisdn)
  out_resp = {}
  begin
    msisdn_data = []
    collection = client_vpn[:sdp_msisdn_list]
    collection.find({'msisdn': msisdn.to_s}).each {|row|
      msisdn_data = row
    }
    if msisdn_data != [] && msisdn_data['msisdn'] != nil && msisdn_data['msisdn'] != ''
      if msisdn_data['group_id'] != [] && msisdn_data['group_id'] != nil && msisdn_data['group_id'] != ''
        if msisdn_data['profile_id'] != [] && msisdn_data['profile_id'] != nil && msisdn_data['profile_id'] != ''
          out_resp = {:code => 200, :result => 'get_mongo_msisdn: Request completed successfully', :body => msisdn_data}
        else
          out_resp = {:code => 406, :result => 'get_mongo_msisdn: invalid data. profile_id not found'}
        end
      else
        out_resp = {:code => 405, :result => 'get_mongo_msisdn: invalid data. organization_id not found'}
      end
    else
      out_resp = {:code => 404, :result => 'get_mongo_msisdn: login not found in database'}
    end
  rescue
    out_resp = {:code => 507, :result => 'get_mongo_msisdn: Unknown SDK error'}
  end
  logger_any.printer_texter(out_resp, 'debug')
  out_resp
end

#get_mongo_organization_id(id) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 52

def get_mongo_organization_id(id)
  out_resp = {}
  begin
    mongo_data = []
    collection = client_vpn[:attr_organizations]
    collection.find({'organization_id': id.to_s}).each {|row|
      mongo_data = row
    }
    if mongo_data != [] && mongo_data['organization_id'] != nil && mongo_data['organization_id'] != ''
      if mongo_data['customer_id'] != [] && mongo_data['customer_id'] != nil && mongo_data['customer_id'] != ''
          out_resp = {:code => 200, :result => 'get_mongo_organization_id: Request completed successfully', :body => mongo_data}
      else
        out_resp = {:code => 405, :result => 'get_mongo_organization_id: invalid data. customer_id not found'}
      end
    else
      out_resp = {:code => 404, :result => 'get_mongo_organization_id: organization_id not found in database'}
    end
  rescue
    out_resp = {:code => 507, :result => 'get_mongo_organization_id: Unknown SDK error'}
  end
  logger_any.printer_texter(out_resp, 'debug')
  out_resp
end

#get_mongo_profile_id(id) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/imperituroard/projects/autovpn/mongo_vpn.rb', line 77

def get_mongo_profile_id(id)
  out_resp = {}
  begin
    mongo_data = []
    collection = client_vpn[:attr_profiles]
    collection.find({'profile_id': id.to_s}).each {|row|
      mongo_data = row
    }
    if mongo_data != [] && mongo_data['profile_id'] != nil && mongo_data['profile_id'] != ''
      if mongo_data['attribute_list'] != [] && mongo_data['attribute_list'] != nil && mongo_data['attribute_list'] != ''
        out_resp = {:code => 200, :result => 'get_mongo_profile_id: Request completed successfully', :body => mongo_data}
      else
        out_resp = {:code => 405, :result => 'get_mongo_profile_id: invalid data. customer_id not found'}
      end
    else
      out_resp = {:code => 404, :result => 'get_mongo_profile_id: organization_id not found in database'}
    end
  rescue
    out_resp = {:code => 507, :result => 'get_mongo_profile_id: Unknown SDK error'}
  end
  logger_any.printer_texter(out_resp, 'debug')
  out_resp
end