Class: Rack::Auth::Travis
- Inherits:
-
AbstractHandler
- Object
- AbstractHandler
- Rack::Auth::Travis
show all
- Defined in:
- lib/rack/auth/travis.rb
Defined Under Namespace
Classes: DIYAuthenticator, ENVAuthenticator, Request
Constant Summary
collapse
- VERSION =
'0.1.0'
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(app, config = {}, &authenticator) ⇒ Travis
Returns a new instance of Travis.
31
32
33
34
35
36
|
# File 'lib/rack/auth/travis.rb', line 31
def initialize(app, config = {}, &authenticator)
@config = config
@config[:sources] ||= [:env]
super(app, config[:realm], &authenticator)
configure_authenticators
end
|
Class Method Details
.authz(owner_name, name, token) ⇒ Object
13
14
15
|
# File 'lib/rack/auth/travis.rb', line 13
def self.authz(owner_name, name, token)
::Digest::SHA256.hexdigest([owner_name, name].join('/') + token)
end
|
.default_authenticators ⇒ Object
.repo_env_key(repo_slug) ⇒ Object
17
18
19
|
# File 'lib/rack/auth/travis.rb', line 17
def self.repo_env_key(repo_slug)
"TRAVIS_AUTH_#{repo_slug.gsub(/[^\p{Alnum}]/, '_').upcase}"
end
|
Instance Method Details
#build_env_authenticator ⇒ Object
46
47
48
|
# File 'lib/rack/auth/travis.rb', line 46
def build_env_authenticator
ENVAuthenticator.new
end
|
#call(env) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/rack/auth/travis.rb', line 38
def call(env)
auth_req = Travis::Request.new(env, @authenticators)
return unauthorized unless auth_req.provided?
return bad_request unless auth_req.travis? && auth_req.json?
return @app.call(env) if auth_req.valid?
unauthorized
end
|
#challenge ⇒ Object
61
62
63
|
# File 'lib/rack/auth/travis.rb', line 61
def challenge
%Q(Travis realm="#{realm}")
end
|
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/rack/auth/travis.rb', line 50
def configure_authenticators
@authenticators = []
@config[:sources].each do |source|
method_name = "build_#{source}_authenticator"
@authenticators << send(method_name) if respond_to?(method_name)
end
if @authenticator
@authenticators << DIYAuthenticator.new(@authenticator)
end
end
|