restpack_web 0.2.19 → 0.2.20
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 +8 -8
- data/lib/restpack_web/app.rb +13 -26
- data/lib/restpack_web/context.rb +24 -13
- data/lib/restpack_web/version.rb +1 -1
- data/restpack_web.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2Y1Y2U5NjY1MjFmZWY0NjUyZTk0NmJjNzMwNGQ3Y2I3ODQzNWY3Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjQxZGU0NDE0MDQ2YTU1MWZiZDk1ZDBhMzA5MmE0NjE2NGRhNGU1YQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTcyNmQwM2Y1NjQwZTI4MDBjZDM2MmQ4ODJjNTQ3MWZiMmQ1NDQ3MTkxMTNk
|
10
|
+
MTVjNzQ4M2ZiMDE4N2YyMGE3MjMyM2NkZjEzMzFmMDlkMTdlNWM1MTg1NDlj
|
11
|
+
NDljMzJjOTE3MWVhNTY2MTY2ZjgzZDQwOTUzZGY3ZWQxMDZjNmY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjNmMzhiOTM1NjA1NzlhYjE3YWE4MjkyOWVkN2ZiOGJkNjQyODYwMzZmY2Zl
|
14
|
+
ZmNmMjlkYjEzMzIxNWQ2YTAzODEzYTIwMDU4MGUyNTYwNzVmNzFjMTg5NmQ2
|
15
|
+
ZmJkMzRjOWRlNTk3YjA5NDJhNDI4NzBhNDliZmE4OWU3NDc5MzU=
|
data/lib/restpack_web/app.rb
CHANGED
@@ -4,7 +4,6 @@ module RestPack
|
|
4
4
|
module Web
|
5
5
|
class App
|
6
6
|
def initialize(app, options = {})
|
7
|
-
p "RestPack::Web::App.initialize"
|
8
7
|
@app = app
|
9
8
|
|
10
9
|
options[:core_domain] ||= ENV['RESTPACK_CORE_SERVICE']
|
@@ -18,29 +17,17 @@ module RestPack
|
|
18
17
|
def call(env)
|
19
18
|
env[:restpack] ||= {}
|
20
19
|
|
21
|
-
|
22
|
-
request = Rack::Request.new(env)
|
20
|
+
request = Rack::Request.new(env)
|
23
21
|
|
24
|
-
|
25
|
-
domain = channel.get_domain_by_host(request.host)
|
22
|
+
domain = @core_cache.get_domain(request.host)
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
env[:restpack][:configurations] = @core_cache.configurations
|
33
|
-
env[:restpack][:services] = @core_cache.get_configuration_value('services', [])
|
24
|
+
env[:restpack][:host] = request.host
|
25
|
+
env[:restpack][:channel] = domain.channel
|
26
|
+
env[:restpack][:application] = domain.application
|
27
|
+
env[:restpack][:domain] = domain
|
28
|
+
env[:restpack][:configurations] = @core_cache.configurations
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
rescue Exception => e
|
38
|
-
p "---"
|
39
|
-
p e.message
|
40
|
-
p "===="
|
41
|
-
p e.backtrace.inspect
|
42
|
-
p "---"
|
43
|
-
end
|
30
|
+
add_user env
|
44
31
|
|
45
32
|
@app.call(env)
|
46
33
|
end
|
@@ -53,11 +40,11 @@ module RestPack
|
|
53
40
|
user_id = env['rack.session'][:user_id]
|
54
41
|
|
55
42
|
if user_id
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
json = RestClient.get("
|
60
|
-
env[:restpack][:user] = Yajl::Parser.parse(json)[
|
43
|
+
context = RestPack::Web::Context.new(env)
|
44
|
+
|
45
|
+
user_service_domain = context.get_service_domain('restpack-user-service')
|
46
|
+
json = RestClient.get("http://:#{ENV['RESTPACK_ACCESS_KEY']}@#{user_service_domain}/api/v1/users/#{user_id}.json")
|
47
|
+
env[:restpack][:user] = Yajl::Parser.parse(json, :symbolize_keys => true)[:user]
|
61
48
|
end
|
62
49
|
|
63
50
|
env[:restpack][:user_id] = user_id
|
data/lib/restpack_web/context.rb
CHANGED
@@ -3,18 +3,16 @@ require 'public_suffix'
|
|
3
3
|
module RestPack
|
4
4
|
module Web
|
5
5
|
class Context
|
6
|
-
attr_accessor :domain, :application, :channel, :configurations, :
|
7
|
-
|
8
|
-
def initialize(env)
|
6
|
+
attr_accessor :domain, :application, :channel, :configurations, :user, :user_id
|
7
|
+
|
8
|
+
def initialize(env)
|
9
9
|
restpack = env[:restpack]
|
10
10
|
|
11
11
|
if restpack
|
12
|
-
@request = restpack[:request]
|
13
12
|
@domain = restpack[:domain]
|
14
13
|
@application = restpack[:application]
|
15
14
|
@channel = restpack[:channel]
|
16
15
|
@configurations = restpack[:configurations]
|
17
|
-
@services = restpack[:services]
|
18
16
|
@user = restpack[:user]
|
19
17
|
@user_id = @user[:id] if @user
|
20
18
|
end
|
@@ -24,8 +22,20 @@ module RestPack
|
|
24
22
|
!@user.nil?
|
25
23
|
end
|
26
24
|
|
25
|
+
def get_configuration(key)
|
26
|
+
@configurations.find { |c| c.key == key }
|
27
|
+
end
|
28
|
+
|
29
|
+
def services
|
30
|
+
get_configuration('services').value
|
31
|
+
end
|
32
|
+
|
27
33
|
def get_service(name)
|
28
|
-
|
34
|
+
services.find { |s| s[:name] == name }
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_service_domain(name)
|
38
|
+
get_service(name)[:domain]
|
29
39
|
end
|
30
40
|
|
31
41
|
def home_domain
|
@@ -54,14 +64,14 @@ module RestPack
|
|
54
64
|
user_debug_info = ""
|
55
65
|
if is_authenticated?
|
56
66
|
image_debug_info = ""
|
57
|
-
image_debug_info = " * **image** : #{@user[
|
67
|
+
image_debug_info = " * **image** : #{@user[:image]} 
|
66
76
|
}
|
67
77
|
end
|
@@ -94,6 +104,7 @@ module RestPack
|
|
94
104
|
#### Configuration:
|
95
105
|
|
96
106
|
* **keys**: #{@configurations.map { |c| c.key }.join(', ')}
|
107
|
+
* **services**: #{services.map { |s| s[:name] + ': ' + s[:domain] }.join(', ')}
|
97
108
|
|
98
109
|
#### Authentication:
|
99
110
|
|
@@ -104,4 +115,4 @@ module RestPack
|
|
104
115
|
end
|
105
116
|
end
|
106
117
|
end
|
107
|
-
end
|
118
|
+
end
|
data/lib/restpack_web/version.rb
CHANGED
data/restpack_web.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
gem.add_dependency 'rack-auto-session-domain', '~> 0.1.1'
|
21
|
-
gem.add_dependency 'restpack_core_client', '~> 0.2.
|
21
|
+
gem.add_dependency 'restpack_core_client', '~> 0.2.6'
|
22
22
|
gem.add_dependency 'public_suffix', '~> 1.3.0'
|
23
23
|
gem.add_dependency 'yajl-ruby', '~> 1.1.0'
|
24
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restpack_web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Joyce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack-auto-session-domain
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.2.
|
33
|
+
version: 0.2.6
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.2.
|
40
|
+
version: 0.2.6
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: public_suffix
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|