restpack_web 0.0.4 → 0.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: 25954423a62ed8ae97a753a3539b4cda465db466
4
- data.tar.gz: a8a938e5e341161eaf9e34d086dad5a146e65f07
3
+ metadata.gz: 8830af231f1d83fb48ceae33fd6e664421a7decd
4
+ data.tar.gz: f6a3bfb0fc99b289934bc476abb95c0b0b573663
5
5
  SHA512:
6
- metadata.gz: c32739ff72b3d94ccd2eb867faa7d6b9d09344f3cc6b6ad84d4a6c9e1df038d1b7a3baea89bcd6b2fe5a11a14784ec6e68d2f5779ddf421c7ffbdb4877f0232b
7
- data.tar.gz: 49860fdc65c8660e76f53ec6f1fe07a0c6a28eec472ae6de6ba7342a32d2f4f7d7bfa4643273f76c4aab801396b0df80f06af173699d5b90245a9e7b16af147f
6
+ metadata.gz: fda6cf1ebece0df58b0b0aeadb91b4680c905686bd6d5fc86466c89a605b9f23c7c373cddd302eb7e97d7b69a0a2b344defda1157359f41629d9f8c2b32d3dda
7
+ data.tar.gz: 66f2cd98d722c66ab32b4c59ed5a5fc2b1b12553b1b29455b963e343d7a0178bad5071af552b830640cbc16dc551a9d9d86b942d5ac7a155c49e4dfd145a95fb
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'encrypted_cookie', path: '../encrypted_cookie'
@@ -0,0 +1,16 @@
1
+ module RestPack::Web
2
+ class Configuration
3
+ attr_accessor :authentication_port
4
+
5
+ def initialize
6
+ @authentication_port = nil
7
+ end
8
+ end
9
+
10
+ mattr_accessor :config
11
+ @@config = Configuration.new
12
+
13
+ def self.setup
14
+ yield @@config
15
+ end
16
+ end
@@ -0,0 +1,70 @@
1
+ module RestPack::Web
2
+ class Context
3
+ attr_accessor :domain, :application, :user, :account
4
+
5
+ def initialize(env)
6
+ restpack = env['restpack']
7
+
8
+ if restpack
9
+ @domain = restpack[:domain]
10
+ @application = restpack[:application]
11
+ @user = restpack[:user]
12
+ @account = restpack[:account]
13
+ end
14
+ end
15
+
16
+ def authenticated?
17
+ !@user.nil?
18
+ end
19
+
20
+ def user_id
21
+ authenticated? ? @user[:id] : nil
22
+ end
23
+
24
+ def account_id
25
+ authenticated? ? @account[:id] : nil
26
+ end
27
+
28
+ def application_id
29
+ @application[:id]
30
+ end
31
+
32
+ def domain_id
33
+ @domain[:id]
34
+ end
35
+
36
+ def home_domain
37
+ "www.#{@domain[:identifier]}"
38
+ end
39
+
40
+ def auth_domain
41
+ "auth.#{@domain[:identifier]}"
42
+ end
43
+
44
+ def logout_url(next_url = nil)
45
+ next_url ||= "http://#{home_domain}/"
46
+ auth_url('/auth/logout', next_url)
47
+ end
48
+
49
+ def login_url(provider = :twitter, next_url = nil)
50
+ auth_url("/auth/#{provider}", next_url)
51
+ end
52
+
53
+ def debug_info
54
+ "todo"
55
+ end
56
+
57
+ private
58
+
59
+ def auth_url(path, next_url = nil)
60
+ #TODO: GJ: whitelist the next_url?
61
+ #TODO: GJ: URI encode next_url?
62
+ port = RestPack::Web.config.authentication_port
63
+
64
+ port_part = port ? ":#{port}" : ""
65
+ next_part = next_url ? "?next=#{next_url}" : ""
66
+
67
+ "http://#{auth_domain}#{port_part}#{path}#{next_part}"
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,36 @@
1
+ module RestPack::Web::Rack
2
+ class Domain
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ identifier = Rack::Request.new(env).host
9
+
10
+ response = Commands::Core::Domain::ByIdentifier.run({
11
+ identifier: identifier,
12
+ include: 'applications'
13
+ })
14
+
15
+ if response.status == :ok
16
+ domain = response.result[:domains][0]
17
+ application = response.result[:applications][0]
18
+
19
+ env['restpack'] ||= {}
20
+ env['restpack'][:domain] = domain
21
+ env['restpack'][:application] = application
22
+ env['restpack'][:application_id] = application[:id]
23
+
24
+ env['restpack.session.options'] ||= {}
25
+ env['restpack.session.options'][:key] = 'restpack.session'
26
+ env['restpack.session.options'][:secret] = domain[:session_secret]
27
+ env['restpack.session.options'][:domain] = domain[:identifier]
28
+ else
29
+ #TODO: GJ: better exceptions based on response status
30
+ raise "[#{identifier}] is not a RestPack domain"
31
+ end
32
+
33
+ @app.call(env)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require 'encrypted_cookie'
2
+
3
+ module RestPack::Web::Rack
4
+ class Session < Rack::Session::EncryptedCookie
5
+
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ require 'restpack_user_service'
2
+ require 'restpack_account_service'
3
+
4
+ module RestPack::Web::Rack
5
+ class User
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ session = env["restpack.session"]
12
+ user_id = session[:user_id]
13
+ account_id = session[:account_id]
14
+
15
+ if user_id && account_id
16
+ response = Commands::Users::User::Get.run({
17
+ id: user_id,
18
+ application_id: env['restpack'][:application_id]
19
+ })
20
+
21
+ raise "Error getting user" unless response.success?
22
+ env['restpack'][:user] = response.result[:users][0]
23
+
24
+ response = Commands::Accounts::Account::Get.run({
25
+ id: account_id,
26
+ application_id: env['restpack'][:application_id]
27
+ })
28
+ raise "Error getting account" unless response.success?
29
+ env['restpack'][:account] = response.result[:accounts][0]
30
+ end
31
+
32
+ @app.call(env)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ module RestPack::Web::Rails
2
+ module Controller
3
+ def self.included(base)
4
+ base.send(:before_filter, :setup_restpack_context)
5
+ end
6
+
7
+ def setup_restpack_context
8
+ @restpack = RestPack::Web::Context.new(request.env)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module RestPack::Web::Sinatra
2
+ module App
3
+ def self.included(base)
4
+ base.use RestPack::Web::Rack::Domain
5
+ base.use RestPack::Web::Rack::Session
6
+ base.use RestPack::Web::Rack::User
7
+
8
+ base.before do
9
+ @restpack = RestPack::Web::Context.new(env)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Web
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
data/lib/restpack_web.rb CHANGED
@@ -1,5 +1,11 @@
1
- require "restpack_web/version"
1
+ require 'restpack_web/version'
2
2
 
3
- module RestPack::Web
3
+ require 'restpack_web/configuration'
4
+ require 'restpack_web/context'
4
5
 
5
- end
6
+ require 'restpack_web/rack/domain'
7
+ require 'restpack_web/rack/user'
8
+ require 'restpack_web/rack/session'
9
+
10
+ require 'restpack_web/rails/controller'
11
+ require 'restpack_web/sinatra/app'
data/restpack_web.gemspec CHANGED
@@ -19,6 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "restpack_gem"
22
+ spec.add_dependency "restpack_core_service"
23
+ spec.add_dependency "restpack_user_service"
24
+ spec.add_dependency "restpack_account_service"
25
+ spec.add_dependency "restpack_group_service"
22
26
 
23
27
  spec.add_development_dependency "bundler", "~> 1.3"
24
28
  spec.add_development_dependency "rake"
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.0.4
4
+ version: 0.0.5
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-09-16 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: restpack_gem
@@ -24,6 +24,62 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: restpack_core_service
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: restpack_user_service
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: restpack_account_service
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: restpack_group_service
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
27
83
  - !ruby/object:Gem::Dependency
28
84
  name: bundler
29
85
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +149,13 @@ files:
93
149
  - README.md
94
150
  - Rakefile
95
151
  - lib/restpack_web.rb
152
+ - lib/restpack_web/configuration.rb
153
+ - lib/restpack_web/context.rb
154
+ - lib/restpack_web/rack/domain.rb
155
+ - lib/restpack_web/rack/session.rb
156
+ - lib/restpack_web/rack/user.rb
157
+ - lib/restpack_web/rails/controller.rb
158
+ - lib/restpack_web/sinatra/app.rb
96
159
  - lib/restpack_web/version.rb
97
160
  - restpack_web.gemspec
98
161
  homepage: http://restpack.org/