stoor 0.1.7 → 0.1.8

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/config.ru CHANGED
@@ -53,6 +53,15 @@ use Rack::Session::Cookie, :domain => domain, :key => 'rack.session', :secret =>
53
53
  use Rack::CommonLogger, access_logger
54
54
  use Stoor::Logger, log_stream, Logger::INFO
55
55
  if repo_exists
56
+ Stoor::GithubAuth.set :github_options, {
57
+ scopes: 'user:email',
58
+ client_id: ENV['STOOR_GITHUB_CLIENT_ID'],
59
+ secret: ENV['STOOR_GITHUB_CLIENT_SECRET']
60
+ }
61
+ Stoor::GithubAuth.set :stoor_options, {
62
+ github_team_id: ENV['STOOR_GITHUB_TEAM_ID'],
63
+ github_email_domain: ENV['STOOR_GITHUB_EMAIL_DOMAIN']
64
+ }
56
65
  use Stoor::GithubAuth
57
66
  use Stoor::GitConfig, gollum_path
58
67
  use Stoor::TransformContent,
@@ -1,15 +1,15 @@
1
1
  module Stoor
2
2
  class GithubAuth < Sinatra::Base
3
3
 
4
- set :github_options, {
5
- :scopes => "user,user:email",
6
- :client_id => ENV['STOOR_GITHUB_CLIENT_ID'],
7
- :secret => ENV['STOOR_GITHUB_CLIENT_SECRET']
8
- }
9
-
10
4
  register Sinatra::Auth::Github
11
5
  register Mustache::Sinatra
12
6
 
7
+ # def initialize(*)
8
+ # @github_options = {}
9
+ # @stoor_options = {}
10
+ # super
11
+ # end
12
+
13
13
  get '/logout' do
14
14
  logout!
15
15
  mustache :logout
@@ -18,25 +18,35 @@ module Stoor
18
18
  get '/*' do
19
19
  session['stoor.github.authorized'] = nil
20
20
 
21
- pass unless ENV['STOOR_GITHUB_CLIENT_ID'] && ENV['STOOR_GITHUB_CLIENT_SECRET']
21
+ pass unless github_options[:client_id] && github_options[:secret]
22
22
 
23
23
  pass if request.path_info =~ /\./
24
24
 
25
25
  authenticate!
26
- if ENV['STOOR_GITHUB_TEAM_ID']
27
- github_team_authenticate!(ENV['STOOR_GITHUB_TEAM_ID'])
26
+ if stoor_options[:github_team_id]
27
+ github_team_authenticate!(stoor_options[:github_team_id])
28
28
  end
29
29
 
30
30
  session['stoor.github.authorized'] = 'yes'
31
31
 
32
32
  email = nil
33
33
  emails = github_user.api.emails
34
- if ENV['STOOR_GITHUB_EMAIL_DOMAIN']
35
- email = emails.find { |e| e =~ /#{ENV['STOOR_GITHUB_EMAIL_DOMAIN']}/ }
34
+ if stoor_options[:github_email_domain]
35
+ email = emails.find { |e| e =~ /#{stoor_options[:github_email_domain]}/ }
36
36
  end
37
37
  email ||= emails.first
38
38
  session['gollum.author'] = { :name => github_user.name, :email => email }
39
39
  pass
40
40
  end
41
+
42
+ private
43
+
44
+ def github_options
45
+ @github_options ||= settings.github_options || {}
46
+ end
47
+
48
+ def stoor_options
49
+ @stoor_options ||= settings.stoor_options || {}
50
+ end
41
51
  end
42
52
  end
data/lib/stoor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stoor
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -22,6 +22,15 @@ module Stoor
22
22
  ENV['STOOR_WIKI_PATH'] = './repo'
23
23
 
24
24
  before do
25
+ Stoor::GithubAuth.set :github_options, {
26
+ scopes: 'user:email',
27
+ client_id: ENV['STOOR_GITHUB_CLIENT_ID'],
28
+ secret: ENV['STOOR_GITHUB_CLIENT_SECRET']
29
+ }
30
+ Stoor::GithubAuth.set :stoor_options, {
31
+ github_team_id: ENV['STOOR_GITHUB_TEAM_ID'],
32
+ github_email_domain: ENV['STOOR_GITHUB_EMAIL_DOMAIN']
33
+ }
25
34
  Stoor::GithubAuth.send(:enable, :sessions)
26
35
  @user = make_user(ENV['STOOR_TESTING_USER'], [ 'effie@example.com', 'effie@7fff.com', 'john@7fff.com' ])
27
36
  login_as @user
@@ -38,11 +47,12 @@ module Stoor
38
47
  end
39
48
 
40
49
  it 'Sets the gollum.user according to domain if specified' do
41
- save = ENV['STOOR_GITHUB_EMAIL_DOMAIN']
42
- ENV['STOOR_GITHUB_EMAIL_DOMAIN'] = '7fff.com'
50
+ Stoor::GithubAuth.set :stoor_options, {
51
+ github_team_id: ENV['STOOR_GITHUB_TEAM_ID'],
52
+ github_email_domain: '7fff.com'
53
+ }
43
54
  get '/'
44
55
  expect(last_request.env['rack.session']['gollum.author']).to eq(name: 'Effie Klinker', email: 'effie@7fff.com')
45
- ENV['STOOR_GITHUB_EMAIL_DOMAIN'] = save
46
56
  end
47
57
 
48
58
  it 'logs the user out' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-02 00:00:00.000000000 Z
12
+ date: 2013-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin