Class: CiToolkit::GithubBot::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_toolkit/github_bot.rb

Overview

Provides a jwt token for authentication. Sores the private key and app id for the bot

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id = ENV.fetch("CRVSH_BOT_GITHUB_APP_ID", nil), private_key = ENV.fetch("CRVSH_BOT_GITHUB_APP_PRIVATE_KEY", nil)) ⇒ Credentials

Returns a new instance of Credentials.



13
14
15
16
17
# File 'lib/ci_toolkit/github_bot.rb', line 13

def initialize(app_id = ENV.fetch("CRVSH_BOT_GITHUB_APP_ID", nil),
               private_key = ENV.fetch("CRVSH_BOT_GITHUB_APP_PRIVATE_KEY", nil))
  @app_id = app_id.to_i
  @private_key = private_key
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



11
12
13
# File 'lib/ci_toolkit/github_bot.rb', line 11

def app_id
  @app_id
end

Instance Method Details

#jwt_tokenObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ci_toolkit/github_bot.rb', line 19

def jwt_token
  return if @private_key.nil?

  JWT.encode(
    {
      iat: Time.now.to_i,
      exp: Time.now.to_i + (9 * 60),
      iss: @app_id
    },
    OpenSSL::PKey::RSA.new(@private_key),
    "RS256"
  )
end