exvo_helpers 0.1.1 → 0.2.0
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.
- data/README.md +42 -29
- data/lib/exvo_helpers/helpers.rb +54 -6
- data/lib/exvo_helpers/version.rb +1 -1
- data/spec/exvo_helpers/helpers_spec.rb +20 -0
- metadata +16 -16
data/README.md
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
# Exvo Helpers
|
2
2
|
|
3
|
-
Ruby gem providing helper methods for various Exvo apps/services. It takes into account the Rails.env (or Merb.env). Also allows overwriting
|
3
|
+
Ruby gem providing helper methods for various Exvo apps/services. It takes into account the Rails.env (or Merb.env). Also allows overwriting the defaults by ENV variables (and directly too, see below).
|
4
|
+
|
5
|
+
This gem is used by both [omniauth-exvo](https://github.com/Exvo/omniauth-exvo/) and [exvo-auth](https://github.com/Exvo/Auth) gems as the authoritative source of **all auth related configuration**.
|
6
|
+
|
4
7
|
|
5
8
|
## Helpers
|
6
9
|
|
7
10
|
Results are from the 'development' Rails environment:
|
8
11
|
|
9
12
|
```ruby
|
13
|
+
Exvo::Helpers.auth_debug => false
|
14
|
+
Exvo::Helpers.auth_require_ssl => false
|
15
|
+
|
16
|
+
Exvo::Helpers.auth_client_id => nil
|
17
|
+
Exvo::Helpers.auth_client_secret => nil
|
18
|
+
|
10
19
|
Exvo::Helpers.auth_host => 'auth.exvo.local'
|
11
20
|
Exvo::Helpers.cdn_host => 'www.exvo.local'
|
12
21
|
Exvo::Helpers.cfs_host => 'cfs.exvo.local'
|
@@ -32,47 +41,51 @@ Exvo::Helpers.pics_uri => 'http://pics.exvo.local'
|
|
32
41
|
Exvo::Helpers.preview_uri => 'http://preview.exvo.local'
|
33
42
|
```
|
34
43
|
|
35
|
-
There is also an `auth_require_ssl` method, which takes true/false values and is used to construct `auth_uri`. It returns `true` in production and `false` in all other environments.
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
Exvo::Helpers.auth_require_ssl => false
|
39
|
-
```
|
40
|
-
|
41
44
|
|
42
45
|
### Overwriting the defaults
|
43
46
|
|
44
47
|
There are two ways to do it. One is by the means of ENV variables (the preferred method):
|
45
48
|
|
46
49
|
```ruby
|
50
|
+
ENV['AUTH_DEBUG'] = 'true'
|
47
51
|
ENV['AUTH_REQUIRE_SSL'] = 'true'
|
48
|
-
|
49
|
-
ENV['
|
50
|
-
ENV['
|
51
|
-
|
52
|
-
ENV['
|
53
|
-
ENV['
|
54
|
-
ENV['
|
55
|
-
ENV['
|
56
|
-
ENV['
|
57
|
-
ENV['
|
58
|
-
ENV['
|
52
|
+
|
53
|
+
ENV['AUTH_CLIENT_ID'] = '123'
|
54
|
+
ENV['AUTH_CLIENT_SECRET'] = 'abc'
|
55
|
+
|
56
|
+
ENV['AUTH_HOST'] = 'test.auth.exvo.com'
|
57
|
+
ENV['CDN_HOST'] = 'test.cdn.exvo.com'
|
58
|
+
ENV['CFS_HOST'] = 'test.cfs.exvo.com'
|
59
|
+
ENV['DESKTOP_HOST'] = 'test.exvo.com'
|
60
|
+
ENV['THEMES_HOST'] = 'test.themes.exvo.com'
|
61
|
+
ENV['BLOG_HOST'] = 'test.blog.exvo.local'
|
62
|
+
ENV['CONTACTS_HOST'] = 'test.contacts.exvo.local'
|
63
|
+
ENV['INBOX_HOST'] = 'test.inbox.exvo.local'
|
64
|
+
ENV['MUSIC_HOST'] = 'test.music.exvo.local'
|
65
|
+
ENV['PICS_HOST'] = 'test.pics.exvo.local'
|
66
|
+
ENV['PREVIEW_HOST'] = 'test.preview.exvo.local'
|
59
67
|
```
|
60
68
|
|
61
69
|
The other one is to set it in the application's config file:
|
62
70
|
|
63
71
|
```ruby
|
72
|
+
Exvo::Helpers.auth_debug = true
|
64
73
|
Exvo::Helpers.auth_require_ssl = true
|
65
|
-
|
66
|
-
Exvo::Helpers.
|
67
|
-
Exvo::Helpers.
|
68
|
-
|
69
|
-
Exvo::Helpers.
|
70
|
-
Exvo::Helpers.
|
71
|
-
Exvo::Helpers.
|
72
|
-
Exvo::Helpers.
|
73
|
-
Exvo::Helpers.
|
74
|
-
Exvo::Helpers.
|
75
|
-
Exvo::Helpers.
|
74
|
+
|
75
|
+
Exvo::Helpers.auth_client_id = '123'
|
76
|
+
Exvo::Helpers.auth_client_secret = 'abc'
|
77
|
+
|
78
|
+
Exvo::Helpers.auth_host = 'test.auth.exvo.com'
|
79
|
+
Exvo::Helpers.cdn_host = 'test.cdn.exvo.com'
|
80
|
+
Exvo::Helpers.cfs_host = 'test.cfs.exvo.com'
|
81
|
+
Exvo::Helpers.desktop_host = 'test.exvo.com'
|
82
|
+
Exvo::Helpers.themes_host = 'test.themes.exvo.com'
|
83
|
+
Exvo::Helpers.blog_host = 'test.blog.exvo.local'
|
84
|
+
Exvo::Helpers.contacts_host = 'test.contacts.exvo.local'
|
85
|
+
Exvo::Helpers.inbox_host = 'test.inbox.exvo.local'
|
86
|
+
Exvo::Helpers.music_host = 'test.music.exvo.local'
|
87
|
+
Exvo::Helpers.pics_host = 'test.pics.exvo.local'
|
88
|
+
Exvo::Helpers.preview_host = 'test.preview.exvo.local'
|
76
89
|
```
|
77
90
|
|
78
91
|
|
data/lib/exvo_helpers/helpers.rb
CHANGED
@@ -53,18 +53,62 @@ module Exvo
|
|
53
53
|
|
54
54
|
# AUTH
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
# Dynamically define class methods
|
57
|
+
class << self
|
58
|
+
|
59
|
+
%w(debug require_ssl).each do |option|
|
60
|
+
|
61
|
+
# def self.auth_debug
|
62
|
+
# return @@auth_debug if defined?(@@auth_debug) && !@@auth_debug.nil?
|
63
|
+
# @@auth_debug = (ENV['AUTH_DEBUG'] == 'true') || default_opts[env.to_sym][:auth_debug]
|
64
|
+
# end
|
65
|
+
define_method "auth_#{option}" do
|
66
|
+
if class_variable_defined?("@@auth_#{option}") and !class_variable_get("@@auth_#{option}").nil?
|
67
|
+
class_variable_get("@@auth_#{option}")
|
68
|
+
else
|
69
|
+
value = (ENV["AUTH_#{option.upcase}"] == 'true') || default_opts[env.to_sym]["auth_#{option}".to_sym]
|
70
|
+
class_variable_set("@@auth_#{option}", value)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# def self.auth_debug=(debug)
|
75
|
+
# @@auth_debug = debug
|
76
|
+
# end
|
77
|
+
define_method "auth_#{option}=" do |value|
|
78
|
+
class_variable_set("@@auth_#{option}", value)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
%w(client_id client_secret).each do |option|
|
84
|
+
|
85
|
+
# def self.auth_client_id
|
86
|
+
# @@auth_client_id ||= ENV['AUTH_CLIENT_ID']
|
87
|
+
# end
|
88
|
+
define_method "auth_#{option}" do
|
89
|
+
if class_variable_defined?("@@auth_#{option}") and !class_variable_get("@@auth_#{option}").nil?
|
90
|
+
class_variable_get("@@auth_#{option}")
|
91
|
+
else
|
92
|
+
value = ENV["AUTH_#{option.upcase}"]
|
93
|
+
class_variable_set("@@auth_#{option}", value)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# def self.auth_client_id=(auth_client_id)
|
98
|
+
# @@auth_client_id = auth_client_id
|
99
|
+
# end
|
100
|
+
define_method "auth_#{option}=" do |value|
|
101
|
+
class_variable_set("@@auth_#{option}", value)
|
102
|
+
end
|
103
|
+
end
|
60
104
|
|
61
|
-
def self.auth_require_ssl=(require_ssl)
|
62
|
-
@@auth_require_ssl = require_ssl
|
63
105
|
end
|
64
106
|
|
65
107
|
|
66
108
|
# ENV
|
67
109
|
|
110
|
+
# by default fall back to production; this way the omniauth-exvo's gem specs can pass
|
111
|
+
# (they depend on this gem and on env, but nor Rails nor Merb is undefined there)
|
68
112
|
def self.env
|
69
113
|
@@env ||= Rails.env if defined?(Rails)
|
70
114
|
@@env ||= Merb.env if defined?(Merb)
|
@@ -81,6 +125,7 @@ module Exvo
|
|
81
125
|
def self.default_opts
|
82
126
|
{
|
83
127
|
:production => {
|
128
|
+
:auth_debug => false,
|
84
129
|
:auth_host => 'auth.exvo.com',
|
85
130
|
:auth_require_ssl => true,
|
86
131
|
:cdn_host => 'd33gjlr95u9pgf.cloudfront.net', # cloudfront.net so we can use https (cdn.exvo.com via https does not work properly)
|
@@ -95,6 +140,7 @@ module Exvo
|
|
95
140
|
:preview_host => 'preview.exvo.com'
|
96
141
|
},
|
97
142
|
:staging => {
|
143
|
+
:auth_debug => false,
|
98
144
|
:auth_host => 'staging.auth.exvo.com',
|
99
145
|
:auth_require_ssl => false,
|
100
146
|
:cdn_host => 'd1by559a994699.cloudfront.net',
|
@@ -109,6 +155,7 @@ module Exvo
|
|
109
155
|
:preview_host => 'staging.preview.exvo.com'
|
110
156
|
},
|
111
157
|
:development => {
|
158
|
+
:auth_debug => false,
|
112
159
|
:auth_host => 'auth.exvo.local',
|
113
160
|
:auth_require_ssl => false,
|
114
161
|
:cdn_host => 'www.exvo.local',
|
@@ -123,6 +170,7 @@ module Exvo
|
|
123
170
|
:preview_host => 'preview.exvo.local'
|
124
171
|
},
|
125
172
|
:test => {
|
173
|
+
:auth_debug => false,
|
126
174
|
:auth_host => 'auth.exvo.local',
|
127
175
|
:auth_require_ssl => false,
|
128
176
|
:cdn_host => 'www.exvo.local',
|
data/lib/exvo_helpers/version.rb
CHANGED
@@ -52,6 +52,26 @@ describe Exvo::Helpers do
|
|
52
52
|
specify { Exvo::Helpers.preview_host.should eql('preview.exvo.com') }
|
53
53
|
end
|
54
54
|
|
55
|
+
describe "#auth_debug and #auth_require_ssl" do
|
56
|
+
specify { Exvo::Helpers.auth_debug.should be_false }
|
57
|
+
specify { Exvo::Helpers.auth_require_ssl.should be_true }
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "setting #auth_client_id and #auth_client_secret via ENV variables" do
|
61
|
+
before do
|
62
|
+
ENV["AUTH_CLIENT_ID"] = '123'
|
63
|
+
ENV["AUTH_CLIENT_SECRET"] = 'abc'
|
64
|
+
end
|
65
|
+
|
66
|
+
specify { Exvo::Helpers.auth_client_id.should eq('123') }
|
67
|
+
specify { Exvo::Helpers.auth_client_secret.should eq('abc') }
|
68
|
+
|
69
|
+
after do
|
70
|
+
ENV["AUTH_CLIENT_ID"] = nil
|
71
|
+
ENV["AUTH_CLIENT_SECRET"] = nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
55
75
|
describe "ENV setting overrides the defaults" do
|
56
76
|
# as all methods are defined the same using metaprogramming, only testing for 1 is enough
|
57
77
|
let(:cdn_host) { "test.cdn.exvo.com" }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exvo_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &82962000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.8'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *82962000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: guard
|
27
|
-
requirement: &
|
27
|
+
requirement: &82960500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.10.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *82960500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: guard-rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &82959420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.6.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *82959420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rb-fsevent
|
49
|
-
requirement: &
|
49
|
+
requirement: &82958790 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *82958790
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rb-inotify
|
60
|
-
requirement: &
|
60
|
+
requirement: &82958400 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *82958400
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &82944900 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *82944900
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: simplecov-rcov
|
82
|
-
requirement: &
|
82
|
+
requirement: &82943870 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *82943870
|
91
91
|
description: Ruby gem providing helper *_uri/*_host methods for Exvo services/apps
|
92
92
|
like DESKTOP/CFS/AUTH/THEMES.
|
93
93
|
email:
|