dc_tunnel 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dc_tunnel.rb +20 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ae87fc147d8f974581db286011e1cfa29a8efc548ea89ee200bea1a16f19bc4
|
4
|
+
data.tar.gz: 22e14c328c6ba2cff433f97f821c4eea63839558aa921dcdc4bc10c49614dbfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
15
|
-
|
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
|
-
|
24
|
+
self.logger "--- Tunnel : got parsed response #{res} "
|
19
25
|
res = res.symbolize_keys(true)
|
20
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
74
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
101
|
+
self.logger "update_attributes is #{update_attributes}"
|
96
102
|
user.update(update_attributes)
|
97
103
|
end
|
98
104
|
end
|
99
105
|
# 子系统内同步删除
|
100
|
-
|
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
|