Class: Gitlab::Ci::Jwt

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

Constant Summary collapse

NOT_BEFORE_TIME =
5
DEFAULT_EXPIRE_TIME =
60 * 5

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build, ttl: nil) ⇒ Jwt

Returns a new instance of Jwt.


13
14
15
16
# File 'lib/gitlab/ci/jwt.rb', line 13

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

Class Method Details

.for_build(build) ⇒ Object


9
10
11
# File 'lib/gitlab/ci/jwt.rb', line 9

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

Instance Method Details

#encodedObject


22
23
24
25
26
# File 'lib/gitlab/ci/jwt.rb', line 22

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

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

#payloadObject


18
19
20
# File 'lib/gitlab/ci/jwt.rb', line 18

def payload
  custom_claims.merge(reserved_claims)
end