aptible-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ad4008fd7624c45bf1d61e66a72dade04080f92
4
+ data.tar.gz: 568c0b9d1c2b8eefb3a6fc8680a9f80fe520c02f
5
+ SHA512:
6
+ metadata.gz: c40e9aa89eb1b61e850b578300f106d07b8598e5532998691a2874ac4d8f16404a581e3ec942b03a31144700d13ce084f2bd59c72033e895815103b169a96931
7
+ data.tar.gz: da05cd829cbc5fd9c28ae5375aeb50636d95c31067ca3e11cf193f540756cae0444bb4cb85cb11b0dd3725673170fc7a2e92e5995adc370cf93942aa5d320b98
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'oauth2', github: 'fancyremarker/oauth2', branch: 'aptible'
4
+ gem 'hyperresource', github: 'fancyremarker/hyperresource', branch: 'aptible'
5
+
6
+ # Specify your gem's dependencies in aptible-rails.gemspec
7
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Aptible, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # ![](https://raw.github.com/aptible/straptible/master/lib/straptible/rails/templates/public.api/icon-60px.png) Aptible::Rails
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/aptible-rails.png)](https://rubygems.org/gems/aptible-rails)
4
+ [![Build Status](https://travis-ci.org/aptible/aptible-rails.png?branch=master)](https://travis-ci.org/aptible/aptible-rails)
5
+ [![Dependency Status](https://gemnasium.com/aptible/aptible-rails.png)](https://gemnasium.com/aptible/aptible-rails)
6
+
7
+ Rails helpers for Aptible service applications.
8
+
9
+ ## Installation
10
+
11
+ Add the following line to your application's Gemfile.
12
+
13
+ gem 'aptible-rails'
14
+
15
+ And then run `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ TODO: Add usage notes.
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork the project.
24
+ 1. Commit your changes, with specs.
25
+ 1. Ensure that your code passes specs (`rake spec`) and meets Aptible's Ruby style guide (`rake rubocop`).
26
+ 1. Create a new pull request on GitHub.
27
+
28
+ ## Copyright and License
29
+
30
+ MIT License, see [LICENSE](LICENSE.md) for details.
31
+
32
+ Copyright (c) 2014 [Aptible](https://www.aptible.com), Frank Macreery, and contributors.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'aptible/tasks'
4
+ Aptible::Tasks.load_tasks
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'English'
6
+ require 'aptible/rails/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'aptible-rails'
10
+ spec.version = Aptible::Rails::VERSION
11
+ spec.authors = ['Frank Macreery']
12
+ spec.email = ['frank@macreery.com']
13
+ spec.description = %q{Rails helpers for Aptible service applications}
14
+ spec.summary = %q{Rails helpers for Aptible service applications}
15
+ spec.homepage = 'https://github.com/aptible/aptible-rails'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($RS)
19
+ spec.test_files = spec.files.grep(/^spec\//)
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'gem_config'
23
+ spec.add_dependency 'aptible-auth'
24
+ spec.add_dependency 'aptible-api'
25
+ spec.add_dependency 'fridge'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.5'
28
+ spec.add_development_dependency 'aptible-tasks'
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'rspec', '~> 2.0'
31
+ end
@@ -0,0 +1,20 @@
1
+ require 'aptible/rails/version'
2
+ require 'aptible/rails/railtie' if defined?(::Rails)
3
+
4
+ require 'gem_config'
5
+
6
+ module Aptible
7
+ module Rails
8
+ include GemConfig::Base
9
+
10
+ with_configuration do
11
+ # Where users will be redirected on
12
+ has :login_url, classes: [String], default: '/login'
13
+
14
+ has :client_id, classes: [String, NilClass],
15
+ default: ENV['CLIENT_ID']
16
+ has :client_secret, classes: [String, NilClass],
17
+ default: ENV['CLIENT_SECRET']
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,73 @@
1
+ require 'aptible/auth'
2
+ require 'aptible/api'
3
+
4
+ module Aptible
5
+ module Rails
6
+ module Controller
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ helper_method :auth, :api, :current_aptible_user
11
+ end
12
+
13
+ def auth
14
+ @auth ||= Aptible::Auth::Client.new(token: service_token).get
15
+ end
16
+
17
+ def api
18
+ @api ||= Aptible::Api::Client.new(token: service_token).get
19
+ end
20
+
21
+ def current_aptible_user
22
+ @current_user ||= auth.find_by_url(session_subject)
23
+ rescue
24
+ clear_session_cookie
25
+ end
26
+
27
+ def service_token
28
+ return unless session_token && session_token.session
29
+ @service_token ||= service_token_for(session_token)
30
+ end
31
+
32
+ def aptible_login_url
33
+ Aptible::Rails.configuration.login_url
34
+ end
35
+
36
+ # before_action :authenticate_user
37
+ def authenticate_aptible_user
38
+ redirect_to aptible_login_url unless current_aptible_user
39
+ end
40
+
41
+ # before_action :ensure_service_token
42
+ def ensure_service_token
43
+ redirect_to aptible_login_url unless service_token
44
+ end
45
+
46
+ def service_token_for(token)
47
+ service_token = fetch_service_token(token)
48
+ if Fridge::AccessToken.new(service_token).valid?
49
+ service_token
50
+ else
51
+ fetch_service_token(token, force: true)
52
+ end
53
+ end
54
+
55
+ def fetch_service_token(token, options = {})
56
+ fail 'Token must be a service token' unless token.session
57
+ ::Rails.cache.fetch "service_token:#{token.session}", options do
58
+ swap_session_token(token)
59
+ end
60
+ end
61
+
62
+ def swap_session_token(token)
63
+ Aptible::Auth::Token.create(
64
+ client_id: Aptible::Rails.configuration.client_id,
65
+ client_secret: Aptible::Rails.configuration.client_secret,
66
+ subject: token.serialize
67
+ ).access_token
68
+ rescue
69
+ token.serialize
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,20 @@
1
+ require 'aptible/rails/controller'
2
+
3
+ module Aptible
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ initializer 'fridge.configure' do
7
+ require 'fridge'
8
+ require 'aptible/auth'
9
+
10
+ Fridge.configure do |config|
11
+ config.public_key = Aptible::Auth.public_key unless ::Rails.env.test?
12
+ end
13
+ end
14
+
15
+ initializer 'aptible.rails.controller' do
16
+ ActionController::Base.send :include, Aptible::Rails::Controller
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Aptible
2
+ module Rails
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ # Load shared spec files
5
+ Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
6
+ require file
7
+ end
8
+
9
+ # Require library up front
10
+ require 'aptible/rails'
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aptible-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Frank Macreery
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gem_config
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aptible-auth
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: aptible-api
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: fridge
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: aptible-tasks
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ description: Rails helpers for Aptible service applications
126
+ email:
127
+ - frank@macreery.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .travis.yml
135
+ - Gemfile
136
+ - LICENSE.md
137
+ - README.md
138
+ - Rakefile
139
+ - aptible-rails.gemspec
140
+ - lib/aptible/rails.rb
141
+ - lib/aptible/rails/controller.rb
142
+ - lib/aptible/rails/railtie.rb
143
+ - lib/aptible/rails/version.rb
144
+ - spec/spec_helper.rb
145
+ homepage: https://github.com/aptible/aptible-rails
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.2.1
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Rails helpers for Aptible service applications
169
+ test_files:
170
+ - spec/spec_helper.rb