Class: Authn::Tokens::CiJobToken

Inherits:
Object
  • Object
show all
Defined in:
lib/authn/tokens/ci_job_token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plaintext, source) ⇒ CiJobToken

Returns a new instance of CiJobToken.



13
14
15
16
17
# File 'lib/authn/tokens/ci_job_token.rb', line 13

def initialize(plaintext, source)
  @revocable = ::Ci::AuthJobFinder.new(token: plaintext).execute

  @source = source
end

Instance Attribute Details

#revocableObject (readonly)

Returns the value of attribute revocable.



11
12
13
# File 'lib/authn/tokens/ci_job_token.rb', line 11

def revocable
  @revocable
end

#sourceObject (readonly)

Returns the value of attribute source.



11
12
13
# File 'lib/authn/tokens/ci_job_token.rb', line 11

def source
  @source
end

Class Method Details

.prefix?(plaintext) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
# File 'lib/authn/tokens/ci_job_token.rb', line 6

def self.prefix?(plaintext)
  prefixes = [::Ci::JobToken::Jwt.token_prefix, ::Ci::Build::TOKEN_PREFIX].uniq
  plaintext.start_with?(*prefixes)
end

Instance Method Details

#present_withObject



19
20
21
# File 'lib/authn/tokens/ci_job_token.rb', line 19

def present_with
  ::API::Entities::Ci::JobToken
end

#revoke!(_current_user) ⇒ Object



23
24
25
26
27
# File 'lib/authn/tokens/ci_job_token.rb', line 23

def revoke!(_current_user)
  raise ::Authn::AgnosticTokenIdentifier::NotFoundError, 'Not Found' if revocable.blank?

  raise ::Authn::AgnosticTokenIdentifier::UnsupportedTokenError, 'Unsupported token type'
end