Class: Underway::Settings::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/underway/settings.rb

Constant Summary collapse

SUPPORTED_SETTINGS =
[
  :app_id,
  :client_id,
  :client_secret,
  :database_url,
  :github_api_host,
  :logger,
  :private_key,
  :private_key_filename,
  :verbose_logging,
  :webhook_secret,
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



25
26
27
# File 'lib/underway/settings.rb', line 25

def initialize
  @logger = Underway::Logger.new
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



21
22
23
# File 'lib/underway/settings.rb', line 21

def app_id
  @app_id
end

#client_idObject

Returns the value of attribute client_id.



21
22
23
# File 'lib/underway/settings.rb', line 21

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



21
22
23
# File 'lib/underway/settings.rb', line 21

def client_secret
  @client_secret
end

#config_filenameObject

Returns the value of attribute config_filename.



21
22
23
# File 'lib/underway/settings.rb', line 21

def config_filename
  @config_filename
end

#database_urlObject

Returns the value of attribute database_url.



21
22
23
# File 'lib/underway/settings.rb', line 21

def database_url
  @database_url
end

#github_api_hostObject

Returns the value of attribute github_api_host.



21
22
23
# File 'lib/underway/settings.rb', line 21

def github_api_host
  @github_api_host
end

#loggerObject

Returns the value of attribute logger.



21
22
23
# File 'lib/underway/settings.rb', line 21

def logger
  @logger
end

#private_key_filenameObject

Returns the value of attribute private_key_filename.



21
22
23
# File 'lib/underway/settings.rb', line 21

def private_key_filename
  @private_key_filename
end

#verbose_loggingObject

Returns the value of attribute verbose_logging.



21
22
23
# File 'lib/underway/settings.rb', line 21

def verbose_logging
  @verbose_logging
end

#webhook_secretObject

Returns the value of attribute webhook_secret.



21
22
23
# File 'lib/underway/settings.rb', line 21

def webhook_secret
  @webhook_secret
end

Instance Method Details

#dbObject



55
56
57
58
59
60
61
# File 'lib/underway/settings.rb', line 55

def db
  @db ||=
    begin
      Underway::DB.configure(database_url)
      Underway::DB.instance.database
    end
end

#load!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# 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

#oauth_access_token_url(code) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
# 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_urlObject



118
119
120
121
# 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_keyObject

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



99
100
101
102
103
104
# 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) ⇒ Object



106
107
108
# File 'lib/underway/settings.rb', line 106

def private_key=(key)
  @private_key = OpenSSL::PKey::RSA.new(key)
end

#private_pemObject

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



92
93
94
# File 'lib/underway/settings.rb', line 92

def private_pem
  @private_pem ||= Pathname.new(private_key_filename).read
end

#token_cacheObject



114
115
116
# File 'lib/underway/settings.rb', line 114

def token_cache
  @token_cache ||= Underway::TokenCache.new(db)
end