dc_tunnel 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dc_tunnel.rb +20 -14
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 425fd14241af543d80b93019524dceb331d720d9f4ff41f9a9227325cbccb967
4
- data.tar.gz: f1815dfad14be6208d829d75a05ae615dc6988ece8354b71c409cec50bb72448
3
+ metadata.gz: 1ae87fc147d8f974581db286011e1cfa29a8efc548ea89ee200bea1a16f19bc4
4
+ data.tar.gz: 22e14c328c6ba2cff433f97f821c4eea63839558aa921dcdc4bc10c49614dbfe
5
5
  SHA512:
6
- metadata.gz: 735164e698903c298d1024a4957d9324729526990e9629b7e7c5a181dff1ce54362e6bb2571b4a5614f3d24ee774f9a95e094538b3a42d9e1754921c4cc44c17
7
- data.tar.gz: 7e455ff8163296ac563f9b030a67aedcb740ea96281107a9170ee1c9cc9abbeaa94d79fd9dd31c629fa6aace0484152557e80de271492776770452c0e093681f
6
+ metadata.gz: df51fc273700496490edee089bd8e787061c420c122cf2484c46b742ac1556dbce5c238e4dda0677e92d954d23d8de8ad3e525043b10415f5c2fd353eed58f62
7
+ data.tar.gz: fa2f65f35d2016ba36f2c163269dee053a3240c7d7a52608e35fe32dc2f145306b689fc64deacda2629697464b82a0cbb45c4dd7c5f59a4f6b378f0dedf82f12
data/lib/dc_tunnel.rb CHANGED
@@ -10,33 +10,39 @@ class DcTunnel
10
10
  @settings
11
11
  end
12
12
 
13
+ def logger(content)
14
+ unless self.get_settings[:silence]
15
+ puts content
16
+ end
17
+ end
18
+
13
19
  def http_get(url)
14
- puts '0.6'
15
- puts "--- Tunnel : start get #{url} "
20
+ self.logger '0.9'
21
+ self.logger "--- Tunnel : start get #{url} "
16
22
  res = Net::HTTP.get(URI(url))
17
23
  res = JSON.parse(res)
18
- puts "--- Tunnel : got parsed response #{res} "
24
+ self.logger "--- Tunnel : got parsed response #{res} "
19
25
  res = res.symbolize_keys(true)
20
- puts "--- Tunnel : got symbolize_keys! response #{res} "
26
+ self.logger "--- Tunnel : got symbolize_keys! response #{res} "
21
27
  res
22
28
  end
23
29
 
24
30
  def http_post(url, postdata={})
25
- puts "--- Tunnel : start get #{url} "
31
+ self.logger "--- Tunnel : start get #{url} "
26
32
  res = Net::HTTP.post_form(URI(url), postdata).body
27
33
  res = JSON.parse(res).symbolize_keys(true)
28
- puts "--- Tunnel : got response #{res} "
34
+ self.logger "--- Tunnel : got response #{res} "
29
35
  res
30
36
  end
31
37
 
32
38
  def sso_path(path, params = {})
33
39
  settings = self.get_settings
34
- puts "--- Tunnel : sso_path set to #{settings[:sso_host]} "
40
+ self.logger "--- Tunnel : sso_path set to #{settings[:sso_host]} "
35
41
  auth = {
36
42
  system_id: settings[:system_id],
37
43
  system_token: settings[:system_token]
38
44
  }
39
- puts "--- Auth : #{auth}"
45
+ self.logger "--- Auth : #{auth}"
40
46
  "#{settings[:sso_host]}#{path}.json?#{params.to_param}&#{auth.to_param}"
41
47
  end
42
48
 
@@ -70,10 +76,10 @@ class DcTunnel
70
76
  res = self.http_get self.sso_path('/users', {:system_ids => [self.get_settings[:system_id]]})
71
77
  allowed_ids = []
72
78
  res[:users].each do |sso_user|
73
- puts "sso_user is #{sso_user}"
74
- puts "sso_user_id is #{sso_user[:id]}"
79
+ self.logger "sso_user is #{sso_user}"
80
+ self.logger "sso_user_id is #{sso_user[:id]}"
75
81
  user = User.find_by_sso_id sso_user[:id]
76
- puts "user is #{user}"
82
+ self.logger "user is #{user}"
77
83
  allowed_ids.push sso_user[:id]
78
84
  if user.nil?
79
85
  create_attributes = {
@@ -84,7 +90,7 @@ class DcTunnel
84
90
  value = item[1]
85
91
  create_attributes[name] = sso_user[name].present? ? sso_user[name] : value
86
92
  end
87
- puts "create_attributes is #{create_attributes}"
93
+ self.logger "create_attributes is #{create_attributes}"
88
94
  User.create create_attributes
89
95
  else
90
96
  update_attributes = {
@@ -92,12 +98,12 @@ class DcTunnel
92
98
  phone: sso_user[:phone],
93
99
  sso_id: sso_user[:id]
94
100
  }
95
- puts "update_attributes is #{update_attributes}"
101
+ self.logger "update_attributes is #{update_attributes}"
96
102
  user.update(update_attributes)
97
103
  end
98
104
  end
99
105
  # 子系统内同步删除
100
- puts "allowed sso ids is #{allowed_ids}"
106
+ self.logger "allowed sso ids is #{allowed_ids}"
101
107
  User.where.not(:sso_id => allowed_ids).destroy_all
102
108
  User.where(:sso_id => nil).destroy_all
103
109
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dc_tunnel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qxchen