Class: Underway::Settings::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



10
11
12
# File 'lib/underway/settings.rb', line 10

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/underway/settings.rb', line 8

def config
  @config
end

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/underway/settings.rb', line 8

def logger
  @logger
end

Instance Method Details

#app_issuerObject

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



47
48
49
# File 'lib/underway/settings.rb', line 47

def app_issuer
  @app_issuer ||= config["app_id"]
end

#app_root=(directory) ⇒ Object



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

def app_root=(directory)
  @app_root = Pathname.new(directory).dirname
end

#config_filename=(filename) ⇒ Object



29
30
31
# File 'lib/underway/settings.rb', line 29

def config_filename=(filename)
  @config_filename = filename
end

#dbObject



37
38
39
40
41
42
43
# File 'lib/underway/settings.rb', line 37

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

#load!Object



14
15
16
17
18
# File 'lib/underway/settings.rb', line 14

def load!
  @config = JSON.parse(
    @app_root.join(@config_filename).read
  )
end

#oauth_access_token_url(code) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/underway/settings.rb', line 84

def oauth_access_token_url(code)
  api_host = Addressable::URI.parse(config["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" => config["client_id"],
    "client_secret" => config["client_secret"]
  )
end

#oauth_authorize_urlObject



79
80
81
82
# File 'lib/underway/settings.rb', line 79

def oauth_authorize_url
  uri = Addressable::URI.parse(config["github_api_host"])
  "#{uri.scheme}://#{uri.domain}/login/oauth/authorize?client_id=#{config["client_id"]}"
end

#private_keyObject

Private Key for the App, generated based on the PEM file



67
68
69
# File 'lib/underway/settings.rb', line 67

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

#private_key_filenameObject



56
57
58
# File 'lib/underway/settings.rb', line 56

def private_key_filename
  @app_root.join(config["private_key_filename"])
end

#private_pemObject

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



62
63
64
# File 'lib/underway/settings.rb', line 62

def private_pem
  @private_pem ||= File.read(private_key_filename)
end

#rawObject

TODO: deprecate



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

def raw
  @config
end

#token_cacheObject



75
76
77
# File 'lib/underway/settings.rb', line 75

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

#verbose_loggingObject



71
72
73
# File 'lib/underway/settings.rb', line 71

def verbose_logging
  @verbose ||= config["verbose_logging"]
end

#webhook_secretObject

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



52
53
54
# File 'lib/underway/settings.rb', line 52

def webhook_secret
  @webhook_secret ||= config["webhook_secret"]
end