chairman 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chairman.rb +4 -29
- data/lib/chairman/holmes.rb +93 -0
- data/lib/chairman/routes.rb +29 -0
- data/lib/version.rb +1 -1
- metadata +21 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff20b3104c603e43fc597006def2aec2e11e2934
|
4
|
+
data.tar.gz: 4c1d6f1964604534e8320256241f01a7ebf83b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c7ed4e1d570f628cba20cafc7b0ff34436a62e3fd85e38dc3f94680dafafabef59d0b97101afbfb875313b3a9935b2b222a535ea728513bd7d46e1cc9305abb
|
7
|
+
data.tar.gz: b89bff4b46f9c405f349e32b5cb5ea9066e46443f4a4c139bea9219cadddc37b2f9cbb13630edec0f2b27b5eba6a4a73e19a953c8121657e061ff7983002f8c4
|
data/lib/chairman.rb
CHANGED
@@ -6,6 +6,7 @@ require 'logger'
|
|
6
6
|
require 'oj'
|
7
7
|
require 'dalli'
|
8
8
|
require 'memcachier'
|
9
|
+
require 'chairman/routes'
|
9
10
|
|
10
11
|
module Chairman
|
11
12
|
class << self
|
@@ -14,8 +15,8 @@ module Chairman
|
|
14
15
|
def config(client_id, client_secret, scope)
|
15
16
|
memcache_host = ENV['MEMCACHIER_SERVERS'] || 'localhost:11211'
|
16
17
|
|
17
|
-
stack = Faraday::
|
18
|
-
builder.use Faraday::HttpCache, logger: Logger.new(STDOUT), store: :mem_cache_store, store_options: [memcache_host], serializer: Oj
|
18
|
+
stack = Faraday::RackBuilder.new do |builder|
|
19
|
+
builder.use Faraday::HttpCache, shared_cache: false, logger: Logger.new(STDOUT), store: :mem_cache_store, store_options: [memcache_host], serializer: Oj
|
19
20
|
builder.adapter Faraday.default_adapter
|
20
21
|
end
|
21
22
|
Octokit.middleware = stack
|
@@ -29,31 +30,5 @@ module Chairman
|
|
29
30
|
@session = Octokit::Client.new :access_token => auth_token, :client_id => @client_id, :client_secret => @client_secret
|
30
31
|
end
|
31
32
|
end
|
32
|
-
|
33
|
-
class Routes < Sinatra::Base
|
34
|
-
set :protection, :except => :frame_options
|
35
|
-
|
36
|
-
get '/authorize' do
|
37
|
-
redirect to Chairman.session.authorize_url(Chairman.client_id, '', :scope => Chairman.scope.join(','))
|
38
|
-
end
|
39
|
-
|
40
|
-
get '/authorize/return' do
|
41
|
-
halt if params[:error] == 'access_denied'
|
42
|
-
|
43
|
-
token = Chairman.session.exchange_code_for_token(params[:code], Chairman.client_id, Chairman.client_secret, {:accept => 'application/json'})
|
44
|
-
|
45
|
-
# TODO: Verify that returned scope is the same as we requested
|
46
|
-
# See: http://developer.github.com/changes/2013-10-04-oauth-changes-coming/
|
47
|
-
|
48
|
-
@user = Chairman.session(token.access_token).user
|
49
|
-
|
50
|
-
session[:github_token] = token.access_token
|
51
|
-
session[:github_id] = @user.login
|
52
|
-
end
|
53
|
-
|
54
|
-
get '/logout' do
|
55
|
-
session[:github_token] = nil
|
56
|
-
session[:github_id] = nil
|
57
|
-
end
|
58
|
-
end
|
59
33
|
end
|
34
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'sawyer'
|
3
|
+
|
4
|
+
module Chairman
|
5
|
+
module Holmes
|
6
|
+
class Client
|
7
|
+
attr_accessor :headers, :body
|
8
|
+
|
9
|
+
def initialize(host)
|
10
|
+
@api_client = Sawyer::Agent.new(host, {serializer: Sawyer::Serializer.yajl}) do |http|
|
11
|
+
http.headers['content-type'] = 'application/json'
|
12
|
+
end
|
13
|
+
|
14
|
+
@headers = {}
|
15
|
+
@body = ''
|
16
|
+
end
|
17
|
+
|
18
|
+
def root
|
19
|
+
get '/'
|
20
|
+
end
|
21
|
+
|
22
|
+
def extensions
|
23
|
+
get '/extensions'
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def passthrough_headers
|
29
|
+
[
|
30
|
+
'content-type',
|
31
|
+
'last-modified',
|
32
|
+
'cache-control'
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
def get(path, params = {})
|
37
|
+
call @api_client.call :get, path, params
|
38
|
+
end
|
39
|
+
|
40
|
+
def post(path, params = {})
|
41
|
+
call @api_client.call :post, path, params
|
42
|
+
end
|
43
|
+
|
44
|
+
def call(api_response)
|
45
|
+
api_response.headers.each do |key, value|
|
46
|
+
if passthrough_headers.include? key
|
47
|
+
@headers[key] = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if api_response.data.respond_to? :to_hash
|
52
|
+
@body = api_response.data.to_attrs.to_json
|
53
|
+
else
|
54
|
+
@body = api_response.data
|
55
|
+
end
|
56
|
+
|
57
|
+
return api_response.status
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
class Routes < Sinatra::Base
|
64
|
+
set :protection, except: :frame_options
|
65
|
+
|
66
|
+
get '/authorize' do
|
67
|
+
|
68
|
+
redirect to Chairman.session.authorize_url(Chairman.client_id, scope: Chairman.scope.join(','))
|
69
|
+
end
|
70
|
+
|
71
|
+
get '/authorize/return' do
|
72
|
+
halt if params[:error] == 'access_denied'
|
73
|
+
|
74
|
+
token = Chairman.session.exchange_code_for_token(params[:code], Chairman.client_id, Chairman.client_secret, {accept: 'application/json'})
|
75
|
+
|
76
|
+
# TODO: Verify that returned scope is the same as we requested
|
77
|
+
# See: http://developer.github.com/changes/2013-10-04-oauth-changes-coming/
|
78
|
+
|
79
|
+
@user = Chairman.session(token.access_token).user
|
80
|
+
|
81
|
+
session[:github_token] = token.access_token
|
82
|
+
session[:github_id] = @user.login
|
83
|
+
end
|
84
|
+
|
85
|
+
get '/logout' do
|
86
|
+
session[:github_token] = nil
|
87
|
+
session[:github_id] = nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Chairman
|
2
|
+
class Routes < Sinatra::Base
|
3
|
+
set :protection, except: :frame_options
|
4
|
+
|
5
|
+
get '/authorize' do
|
6
|
+
redirect to Chairman.session.authorize_url(Chairman.client_id, scope: Chairman.scope.join(','))
|
7
|
+
end
|
8
|
+
|
9
|
+
get '/authorize/return' do
|
10
|
+
halt if params[:error] == 'access_denied'
|
11
|
+
|
12
|
+
token = Chairman.session.exchange_code_for_token(params[:code], Chairman.client_id, Chairman.client_secret, {accept: 'application/json'})
|
13
|
+
|
14
|
+
# TODO: Verify that returned scope is the same as we requested
|
15
|
+
# See: http://developer.github.com/changes/2013-10-04-oauth-changes-coming/
|
16
|
+
|
17
|
+
@user = Chairman.session(token.access_token).user
|
18
|
+
|
19
|
+
session[:github_token] = token.access_token
|
20
|
+
session[:github_id] = @user.login
|
21
|
+
end
|
22
|
+
|
23
|
+
get '/logout' do
|
24
|
+
session[:github_token] = nil
|
25
|
+
session[:github_id] = nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chairman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jed Foster
|
@@ -14,84 +14,84 @@ dependencies:
|
|
14
14
|
name: sinatra
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.4.3
|
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: 1.4.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: octokit
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.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
|
-
version: '
|
40
|
+
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday-http-cache
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.4.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.4.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: dalli
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 2.6.4
|
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: 2.6.4
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: memcachier
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.0.2
|
76
76
|
type: :runtime
|
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: 0.0.2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: oj
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 2.4.0
|
90
90
|
type: :runtime
|
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: 2.4.0
|
97
97
|
description: GitHub authentication routes and tools for Sinatra apps
|
@@ -100,8 +100,10 @@ executables: []
|
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
|
-
- LICENSE
|
104
103
|
- README.md
|
104
|
+
- LICENSE
|
105
|
+
- lib/chairman/holmes.rb
|
106
|
+
- lib/chairman/routes.rb
|
105
107
|
- lib/chairman.rb
|
106
108
|
- lib/http_cache/response.rb
|
107
109
|
- lib/version.rb
|
@@ -114,17 +116,17 @@ require_paths:
|
|
114
116
|
- lib
|
115
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
118
|
requirements:
|
117
|
-
- -
|
119
|
+
- - '>='
|
118
120
|
- !ruby/object:Gem::Version
|
119
121
|
version: '0'
|
120
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
123
|
requirements:
|
122
|
-
- -
|
124
|
+
- - '>='
|
123
125
|
- !ruby/object:Gem::Version
|
124
126
|
version: '0'
|
125
127
|
requirements: []
|
126
128
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.0.14
|
128
130
|
signing_key:
|
129
131
|
specification_version: 4
|
130
132
|
summary: GitHub authentication for Sinatra
|