class Rack::Auth::Travis

Constants

VERSION

Public Class Methods

authz(owner_name, name, token) click to toggle source
# 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() click to toggle source
# File lib/rack/auth/travis.rb, line 25
def self.default_authenticators
  [
    ::Rack::Auth::Travis::ENVAuthenticator.new
  ]
end
new(app, config = {}, &authenticator) click to toggle source
Calls superclass method
# 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
repo_env_key(repo_slug) click to toggle source
# File lib/rack/auth/travis.rb, line 17
def self.repo_env_key(repo_slug)
  "TRAVIS_AUTH_#{repo_slug.gsub(/[^\p{Alnum}]/, '_').upcase}"
end
valid?(env) click to toggle source
# File lib/rack/auth/travis.rb, line 21
def self.valid?(env)
  ::Rack::Auth::Travis::Request.new(env).valid?
end

Public Instance Methods

build_env_authenticator() click to toggle source
# File lib/rack/auth/travis.rb, line 46
def build_env_authenticator
  ENVAuthenticator.new
end
call(env) click to toggle source
# 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() click to toggle source
# File lib/rack/auth/travis.rb, line 61
def challenge
  %Q(Travis realm="#{realm}")
end
configure_authenticators() click to toggle source
# 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