Class: Gitlab::Ci::Jwt

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/jwt.rb

Direct Known Subclasses

JwtV2

Constant Summary collapse

NOT_BEFORE_TIME =
5
DEFAULT_EXPIRE_TIME =
60 * 5
NoSigningKeyError =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build, ttl: nil) ⇒ Jwt

Returns a new instance of Jwt.


15
16
17
18
# File 'lib/gitlab/ci/jwt.rb', line 15

def initialize(build, ttl: nil)
  @build = build
  @ttl = ttl
end

Class Method Details

.for_build(build) ⇒ Object


11
12
13
# File 'lib/gitlab/ci/jwt.rb', line 11

def self.for_build(build)
  self.new(build, ttl: build.).encoded
end

Instance Method Details

#encodedObject


24
25
26
27
28
# File 'lib/gitlab/ci/jwt.rb', line 24

def encoded
  headers = { kid: kid, typ: 'JWT' }

  JWT.encode(payload, key, 'RS256', headers)
end

#payloadObject


20
21
22
# File 'lib/gitlab/ci/jwt.rb', line 20

def payload
  custom_claims.merge(reserved_claims)
end