excursion 0.1.2 → 0.1.3
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/config/routes.rb +3 -0
- data/lib/excursion/configuration.rb +8 -1
- data/lib/excursion/cors.rb +35 -0
- data/lib/excursion/pool.rb +11 -3
- data/lib/excursion/railtie.rb +5 -4
- data/lib/excursion/version.rb +1 -1
- data/lib/excursion.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab8132a7eecf4dbcd15c02be1910a80ff4f99251
|
4
|
+
data.tar.gz: 09b7d1bb9d3c3df27b13943717da2fc425d1b173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96cbfb48309e2b4e238b9ec4fb07c9e8ce6832f29001b6b2869ef1ee2d75466b20867245510d44c8b3598e35ae797c0c078cd892f80a65294f5b43d2ae599054
|
7
|
+
data.tar.gz: 56e54a5963c2ef247b8ba511613c98bb1967ca33acf05689bbbba088a2757497ac37d0c1831db47569a3c73345a1ef7245b11628778412aa67de1ad2cc5d967d
|
data/config/routes.rb
ADDED
@@ -6,7 +6,14 @@ module Excursion
|
|
6
6
|
# include_pattern: to only include certain routes
|
7
7
|
register_app: true, # whether or not to register the app automatically on init
|
8
8
|
default_url_options: {}, # default_url_options used when building routes for this app
|
9
|
-
retry_limit: 3 # retry limit for datastores that user remote servers
|
9
|
+
retry_limit: 3, # retry limit for datastores that user remote servers
|
10
|
+
enable_cors: false, # enables cross-origin resource sharing for this app
|
11
|
+
cors_whitelist: :pool, # whitelist for allowing cors for specific domains - defaults to only allow registered excursion apps
|
12
|
+
cors_blacklist: nil, # blacklist for denying cors for specific domains
|
13
|
+
cors_allow_methods: %w(POST PUT PATCH GET DELETE), # list of allowed cors request methods (Access-Control-Allow-Methods)
|
14
|
+
cors_allow_headers: %w(origin content-type accept x-requested-with x-csrf-token), # list of allowed cors request headers (Access-Control-Allow-Headers)
|
15
|
+
cors_allow_credentials: true, # allow credentials with cors requests (Access-Control-Allow-Credentials)
|
16
|
+
cors_max_age: 1728000 # cors max age (Access-Control-Max-Age)
|
10
17
|
}
|
11
18
|
|
12
19
|
#attr_reader *DEFAULT_CONFIGURATION_OPTIONS.keys
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Excursion
|
2
|
+
module CORS
|
3
|
+
def self.included(base)
|
4
|
+
base.send :before_filter, :cors_headers if Excursion.configuration.enable_cors
|
5
|
+
end
|
6
|
+
|
7
|
+
def cors_match?(origin, host)
|
8
|
+
host.is_a?(Regexp) ? origin.match(host) : origin.downcase == host.downcase
|
9
|
+
end
|
10
|
+
|
11
|
+
def cors_whitelisted?(origin)
|
12
|
+
return Excursion::Pool.all_applications.values.map { |app| app.default_url_options[:host] }.any? { |cw| cors_match? origin, cw } if Excursion.configuration.cors_whitelist == :pool
|
13
|
+
Excursion.configuration.cors_whitelist.nil? || Excursion.configuration.cors_whitelist.any? { |cw| cors_match? origin, cw }
|
14
|
+
end
|
15
|
+
|
16
|
+
def cors_blacklisted?(origin)
|
17
|
+
!Excursion.configuration.cors_blacklist.nil? && !Excursion.configuration.cors_blacklist.any? { |cb| cors_match? origin, cb }
|
18
|
+
end
|
19
|
+
|
20
|
+
def cors_headers
|
21
|
+
if !request.headers['Origin'].nil? && cors_whitelisted?(request.headers['Origin']) && !cors_blacklisted?(request.headers['Origin'])
|
22
|
+
headers['Access-Control-Allow-Origin'] = request.headers['Origin']
|
23
|
+
headers['Access-Control-Allow-Methods'] = Excursion.configuration.cors_allow_methods.join(',')
|
24
|
+
headers['Access-Control-Allow-Headers'] = Excursion.configuration.cors_allow_headers.join(', ')
|
25
|
+
headers['Access-Control-Allow-Credentials'] = Excursion.configuration.cors_allow_credentials.to_s
|
26
|
+
headers['Access-Control-Max-Age'] = Excursion.configuration.cors_max_age.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def cors_preflight
|
31
|
+
cors_headers
|
32
|
+
render :text => '', :content_type => 'text/plain'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/excursion/pool.rb
CHANGED
@@ -16,10 +16,10 @@ module Excursion
|
|
16
16
|
|
17
17
|
def self.application(name)
|
18
18
|
check_local_cache
|
19
|
-
return @@applications[name] if @@applications.has_key?(name) && !@@applications[name].nil?
|
19
|
+
return @@applications[name.to_s] if @@applications.has_key?(name.to_s) && !@@applications[name.to_s].nil?
|
20
20
|
|
21
21
|
app = datastore.app(name)
|
22
|
-
@@applications[name] = app unless app.nil?
|
22
|
+
@@applications[name.to_s] = app unless app.nil?
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.register_application(app=nil, opts={}, &block)
|
@@ -61,7 +61,7 @@ module Excursion
|
|
61
61
|
datastore.set(name, app_hash)
|
62
62
|
datastore.set('_pool_updated', Time.now.to_i)
|
63
63
|
end
|
64
|
-
@@applications[name] = datastore.app(name)
|
64
|
+
@@applications[name.to_s] = datastore.app(name)
|
65
65
|
end
|
66
66
|
|
67
67
|
def self.remove_application(app)
|
@@ -107,5 +107,13 @@ module Excursion
|
|
107
107
|
def self.check_local_cache
|
108
108
|
(@@refreshed = Time.now.to_i) && (@@applications = {}) if pool_updated > pool_refreshed
|
109
109
|
end
|
110
|
+
|
111
|
+
def self.set_secret_key_base
|
112
|
+
datastore.set('_secret_key_base', Digest::MD5.hexdigest(SecureRandom.base64(32)))
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.secret_key_base
|
116
|
+
key = datastore.get('_secret_key_base') || set_secret_key_base
|
117
|
+
end
|
110
118
|
end
|
111
119
|
end
|
data/lib/excursion/railtie.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Excursion
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
config.after_initialize do |app|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
File.basename($0) != "rake" # Do not register on init when running a rake task
|
4
|
+
# Do not register on init when running a generator (is there a better way to detect this? Maybe $0 == 'rails' && ARGV.include?('generate') or 'g')
|
5
|
+
# Do not register on init when running a rake task
|
6
|
+
if Excursion.configuration.register_app == true && !Excursion.configuration.datastore.nil? && !defined?(Rails::Generators::Base) && File.basename($0) != "rake"
|
8
7
|
app.reload_routes!
|
9
8
|
Excursion::Pool.register_application(app)
|
10
9
|
end
|
10
|
+
|
11
|
+
ApplicationController.send :include, Excursion::CORS if Excursion.configuration.enable_cors
|
11
12
|
end
|
12
13
|
|
13
14
|
rake_tasks do
|
data/lib/excursion/version.rb
CHANGED
data/lib/excursion.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excursion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -99,10 +99,12 @@ files:
|
|
99
99
|
- lib/excursion/helpers.rb
|
100
100
|
- lib/excursion/route_pool.rb
|
101
101
|
- lib/excursion/version.rb
|
102
|
+
- lib/excursion/cors.rb
|
102
103
|
- lib/generators/excursion/active_record_generator.rb
|
103
104
|
- lib/generators/excursion/templates/migration.rb
|
104
105
|
- lib/excursion.rb
|
105
106
|
- app/assets/javascripts/excursion.js
|
107
|
+
- config/routes.rb
|
106
108
|
- spec/excursion_spec.rb
|
107
109
|
- spec/dummy/public/500.html
|
108
110
|
- spec/dummy/public/index.html
|