class Underway::Settings::Configuration

Constants

SUPPORTED_SETTINGS

Attributes

app_id[R]
client_id[R]
client_secret[R]
config_filename[R]
database_url[R]
github_api_host[R]
logger[R]
private_key_filename[R]
verbose_logging[R]
webhook_secret[R]

Public Class Methods

new() click to toggle source
# File lib/underway/settings.rb, line 25
def initialize
  @logger = Underway::Logger.new
end

Public Instance Methods

app_id=(id) click to toggle source

The Integration ID From “About -> ID” at github.com/settings/apps/<app-name>

# File lib/underway/settings.rb, line 69
def app_id=(id)
  @app_id = id
end
client_id=(id) click to toggle source
# File lib/underway/settings.rb, line 73
def client_id=(id)
  @client_id = id
end
client_secret=(secret) click to toggle source
# File lib/underway/settings.rb, line 77
def client_secret=(secret)
  @client_secret = secret
end
config_filename=(filename) click to toggle source
# File lib/underway/settings.rb, line 43
def config_filename=(filename)
  @config_filename = filename
end
database_url=(url) click to toggle source
# File lib/underway/settings.rb, line 51
def database_url=(url)
  @database_url = url
end
db() click to toggle source
# File lib/underway/settings.rb, line 55
def db
  @db ||=
    begin
      Underway::DB.configure(database_url)
      Underway::DB.instance.database
    end
end
github_api_host=(host) click to toggle source
# File lib/underway/settings.rb, line 63
def github_api_host=(host)
  @github_api_host = host
end
load!() click to toggle source
# File lib/underway/settings.rb, line 29
def load!
  if config_filename
    config = JSON.parse(
      Pathname.new(config_filename).read
    )

    SUPPORTED_SETTINGS.map(&:to_s).each do |setting|
      if config[setting]
        send("#{setting}=", config[setting])
      end
    end
  end
end
logger=(logger) click to toggle source
# File lib/underway/settings.rb, line 47
def logger=(logger)
  @logger = logger
end
oauth_access_token_url(code) click to toggle source
# File lib/underway/settings.rb, line 123
def oauth_access_token_url(code)
  api_host = Addressable::URI.parse(github_api_host)
  template = Addressable::Template.new(
    "{scheme}://{host}/login/oauth/access_token{?code,client_id,client_secret}"
  )
  template.expand(
    "scheme" => api_host.scheme,
    "host" => api_host.domain,
    "code" => code,
    "client_id" => client_id,
    "client_secret" => client_secret
  )
end
oauth_authorize_url() click to toggle source
# File lib/underway/settings.rb, line 118
def oauth_authorize_url
  uri = Addressable::URI.parse(github_api_host)
  "#{uri.scheme}://#{uri.domain}/login/oauth/authorize?client_id=#{client_id}"
end
private_key() click to toggle source

Private Key for the App. Either the explicitly configured private_key value or the contents of the configured private_key_filename.

# File lib/underway/settings.rb, line 99
def private_key
  @private_key ||=
    unless private_key_filename.nil?
      OpenSSL::PKey::RSA.new(private_pem)
    end
end
private_key=(key) click to toggle source
# File lib/underway/settings.rb, line 106
def private_key=(key)
  @private_key = OpenSSL::PKey::RSA.new(key)
end
private_key_filename=(filename) click to toggle source
# File lib/underway/settings.rb, line 86
def private_key_filename=(filename)
  @private_key_filename = filename
end
private_pem() click to toggle source

PEM file for request signing (PKCS#1 RSAPrivateKey format) (Download from github.com/settings/apps/<app-name> “Private key”)

# File lib/underway/settings.rb, line 92
def private_pem
  @private_pem ||= Pathname.new(private_key_filename).read
end
token_cache() click to toggle source
# File lib/underway/settings.rb, line 114
def token_cache
  @token_cache ||= Underway::TokenCache.new(db)
end
verbose_logging=(verbose) click to toggle source
# File lib/underway/settings.rb, line 110
def verbose_logging=(verbose)
  @verbose_logging = !!verbose
end
webhook_secret=(secret) click to toggle source

Integration webhook secret (for validating that webhooks come from GitHub)

# File lib/underway/settings.rb, line 82
def webhook_secret=(secret)
  @webhook_secret = secret
end