Class: Underway::Settings::Configuration
- Inherits:
-
Object
- Object
- Underway::Settings::Configuration
- 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
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#config_filename ⇒ Object
Returns the value of attribute config_filename.
-
#database_url ⇒ Object
Returns the value of attribute database_url.
-
#github_api_host ⇒ Object
Returns the value of attribute github_api_host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#private_key_filename ⇒ Object
Returns the value of attribute private_key_filename.
-
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
-
#webhook_secret ⇒ Object
Returns the value of attribute webhook_secret.
Instance Method Summary collapse
- #db ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load! ⇒ Object
- #oauth_access_token_url(code) ⇒ Object
- #oauth_authorize_url ⇒ Object
-
#private_key ⇒ Object
Private Key for the App.
- #private_key=(key) ⇒ Object
-
#private_pem ⇒ Object
PEM file for request signing (PKCS#1 RSAPrivateKey format) (Download from github.com/settings/apps/<app-name> “Private key”).
- #token_cache ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_id ⇒ Object
Returns the value of attribute app_id.
21 22 23 |
# File 'lib/underway/settings.rb', line 21 def app_id @app_id end |
#client_id ⇒ Object
Returns the value of attribute client_id.
21 22 23 |
# File 'lib/underway/settings.rb', line 21 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
21 22 23 |
# File 'lib/underway/settings.rb', line 21 def client_secret @client_secret end |
#config_filename ⇒ Object
Returns the value of attribute config_filename.
21 22 23 |
# File 'lib/underway/settings.rb', line 21 def config_filename @config_filename end |
#database_url ⇒ Object
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_host ⇒ Object
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 |
#logger ⇒ Object
Returns the value of attribute logger.
21 22 23 |
# File 'lib/underway/settings.rb', line 21 def logger @logger end |
#private_key_filename ⇒ Object
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_logging ⇒ Object
Returns the value of attribute verbose_logging.
21 22 23 |
# File 'lib/underway/settings.rb', line 21 def verbose_logging @verbose_logging end |
#webhook_secret ⇒ Object
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
#db ⇒ Object
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.( "scheme" => api_host.scheme, "host" => api_host.domain, "code" => code, "client_id" => client_id, "client_secret" => client_secret ) end |
#oauth_authorize_url ⇒ Object
118 119 120 121 |
# File 'lib/underway/settings.rb', line 118 def uri = Addressable::URI.parse(github_api_host) "#{uri.scheme}://#{uri.domain}/login/oauth/authorize?client_id=#{client_id}" end |
#private_key ⇒ Object
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_pem ⇒ Object
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_cache ⇒ Object
114 115 116 |
# File 'lib/underway/settings.rb', line 114 def token_cache @token_cache ||= Underway::TokenCache.new(db) end |