aptible-rails 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/aptible/rails/controller.rb +46 -64
- data/lib/aptible/rails/railtie.rb +0 -15
- data/lib/aptible/rails/version.rb +1 -1
- metadata +23 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c901ab9e1415711648f097b854423a3949efb7a4
|
4
|
+
data.tar.gz: 329150e1e681f530ab6222290382f8fbd85b54fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cca7efae246d50448f00daefbaa8c3ca882564cdf4d5526715584234948e723beac9c0be7db52e651ef8910ed10b11bbb2f45bea8df62547776dec3c15a3519d
|
7
|
+
data.tar.gz: 1ae028627e055174b384b27dc2c9cc1920b6184c5fe7c123a32b213ef06638a2a31ab7345426b2a0cd1b156cc2449413c596409a689d93c33aaf5a814dff37e1
|
data/Gemfile
CHANGED
@@ -7,73 +7,36 @@ module Aptible
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
included do
|
10
|
-
helper_method :
|
11
|
-
:current_organization, :subscribed?, :has_acccount?,
|
12
|
-
:email_verified?, :subscribed_and_verified?, :user_url,
|
10
|
+
helper_method :current_user, :current_organization, :user_url,
|
13
11
|
:organization_url
|
14
12
|
end
|
15
13
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@api ||= Aptible::Api::Agent.new(token: service_token).get
|
22
|
-
end
|
23
|
-
|
24
|
-
def current_aptible_user
|
25
|
-
@current_user ||= auth.find_by_url(aptible_subject)
|
26
|
-
rescue
|
14
|
+
def current_user
|
15
|
+
return unless current_user_url
|
16
|
+
@current_user ||= Aptible::Auth::User.find_by_url(current_user_url,
|
17
|
+
token: session_token)
|
18
|
+
rescue => e
|
27
19
|
clear_session_cookie
|
20
|
+
raise e
|
28
21
|
end
|
29
22
|
|
30
23
|
def current_organization
|
31
|
-
session[:organization_url] ||=
|
24
|
+
session[:organization_url] ||= Aptible::Auth::Organization.all(
|
25
|
+
token: session_token
|
26
|
+
).first.href
|
32
27
|
url = [session[:organization_url], token: service_token]
|
33
28
|
@current_organization ||= Aptible::Auth::Organization.find_by_url(*url)
|
34
29
|
rescue
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
# rubocop:disable PredicateName
|
39
|
-
def has_account?
|
40
|
-
current_organization && current_organization.accounts.any?
|
41
|
-
end
|
42
|
-
# rubocop:enable PredicateName
|
43
|
-
|
44
|
-
def subscribed?
|
45
|
-
@has_subscription ||= has_account? &&
|
46
|
-
current_organization.accounts.any?(&:has_subscription?)
|
47
|
-
end
|
48
|
-
|
49
|
-
def email_verified?
|
50
|
-
current_aptible_user && current_aptible_user.verified?
|
51
|
-
end
|
52
|
-
|
53
|
-
def subscribed_and_verified?
|
54
|
-
has_account? && subscribed? && email_verified?
|
55
|
-
end
|
56
|
-
|
57
|
-
def service_token
|
58
|
-
return unless aptible_token && aptible_token.session
|
59
|
-
@service_token ||= service_token_for(aptible_token)
|
60
|
-
end
|
61
|
-
|
62
|
-
def aptible_login_url
|
63
|
-
Aptible::Rails.configuration.login_url
|
30
|
+
nil
|
64
31
|
end
|
65
32
|
|
66
|
-
def
|
33
|
+
def current_user_url
|
67
34
|
token_subject || session_subject
|
68
35
|
end
|
69
36
|
|
70
|
-
def aptible_token
|
71
|
-
current_token || session_token
|
72
|
-
end
|
73
|
-
|
74
37
|
# before_action :authenticate_user
|
75
|
-
def
|
76
|
-
redirect_to
|
38
|
+
def authenticate_user
|
39
|
+
redirect_to Aptible::Rails.configuration.login_url unless current_user
|
77
40
|
end
|
78
41
|
|
79
42
|
# before_action :ensure_service_token
|
@@ -81,37 +44,56 @@ module Aptible
|
|
81
44
|
redirect_to aptible_login_url unless service_token
|
82
45
|
end
|
83
46
|
|
84
|
-
|
85
|
-
|
47
|
+
# before_action :ensure_auth_key
|
48
|
+
def ensure_auth_key
|
49
|
+
return if Fridge.configuration.public_key
|
50
|
+
Fridge.configure do |config|
|
51
|
+
config.public_key = Aptible::Auth.public_key unless ::Rails.env.test?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def service_token
|
56
|
+
return unless session_token && session_token.session
|
57
|
+
return @service_token if @service_token
|
58
|
+
|
59
|
+
@service_token = cached_service_token(session_token)
|
86
60
|
if Fridge::AccessToken.new(service_token).valid?
|
87
|
-
service_token
|
61
|
+
@service_token
|
88
62
|
else
|
89
|
-
|
63
|
+
@service_token = cached_service_token(session_token,
|
64
|
+
force: true) || session_token
|
90
65
|
end
|
91
66
|
end
|
92
67
|
|
93
|
-
def
|
94
|
-
fail 'Token must be a service token' unless
|
95
|
-
|
96
|
-
|
68
|
+
def cached_service_token(session_token, options = {})
|
69
|
+
fail 'Token must be a service token' unless session_token.session
|
70
|
+
cache_key = "service_token:#{session_token.session}"
|
71
|
+
::Rails.cache.fetch(cache_key, options) do
|
72
|
+
swap_session_token(session_token)
|
97
73
|
end
|
98
74
|
end
|
99
75
|
|
100
|
-
|
76
|
+
# rubocop:disable MethodLength
|
77
|
+
def swap_session_token(session_token)
|
101
78
|
Aptible::Auth::Token.create(
|
102
79
|
client_id: Aptible::Rails.configuration.client_id,
|
103
80
|
client_secret: Aptible::Rails.configuration.client_secret,
|
104
|
-
subject:
|
81
|
+
subject: session_token.serialize
|
105
82
|
).access_token
|
106
|
-
rescue
|
107
|
-
|
83
|
+
rescue OAuth2::Error => e
|
84
|
+
if e.code == 'unauthorized'
|
85
|
+
nil
|
86
|
+
else
|
87
|
+
raise 'Could not swap session token, check Client#privileged?'
|
88
|
+
end
|
108
89
|
end
|
90
|
+
# rubocop:enable MethodLength
|
109
91
|
|
110
92
|
def organization_url(id)
|
111
93
|
"#{dashboard_url}/organizations/#{id}"
|
112
94
|
end
|
113
95
|
|
114
|
-
def user_url(id =
|
96
|
+
def user_url(id = current_user.id)
|
115
97
|
"#{dashboard_url}/users/#{id}"
|
116
98
|
end
|
117
99
|
end
|
@@ -5,21 +5,6 @@ require 'aptible/rails/view_helper'
|
|
5
5
|
module Aptible
|
6
6
|
module Rails
|
7
7
|
class Railtie < ::Rails::Railtie
|
8
|
-
initializer 'fridge.configure' do
|
9
|
-
require 'fridge'
|
10
|
-
require 'aptible/auth'
|
11
|
-
|
12
|
-
Fridge.configure do |config|
|
13
|
-
begin
|
14
|
-
unless ::Rails.env.test?
|
15
|
-
config.public_key = Aptible::Auth.public_key
|
16
|
-
end
|
17
|
-
rescue
|
18
|
-
raise 'Could not retrieve auth server public key'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
8
|
initializer 'aptible.rails.controller' do
|
24
9
|
ActionController::Base.send :include, Aptible::Rails::Controller
|
25
10
|
end
|
metadata
CHANGED
@@ -1,125 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aptible-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Macreery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_config
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: aptible-auth
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.5.0
|
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
40
|
version: 0.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aptible-api
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.5.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.5.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: fridge
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: aptible-tasks
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '2.0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ~>
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '2.0'
|
125
125
|
description: Rails helpers for Aptible service applications
|
@@ -129,9 +129,9 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
-
-
|
133
|
-
-
|
134
|
-
-
|
132
|
+
- .gitignore
|
133
|
+
- .rspec
|
134
|
+
- .travis.yml
|
135
135
|
- Gemfile
|
136
136
|
- LICENSE.md
|
137
137
|
- README.md
|
@@ -154,12 +154,12 @@ require_paths:
|
|
154
154
|
- lib
|
155
155
|
required_ruby_version: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - '>='
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
|
-
- -
|
162
|
+
- - '>='
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|