Class: Authn::Tokens::RunnerAuthenticationToken

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plaintext, source) ⇒ RunnerAuthenticationToken

Returns a new instance of RunnerAuthenticationToken.



17
18
19
20
21
22
# File 'lib/authn/tokens/runner_authentication_token.rb', line 17

def initialize(plaintext, source)
  return unless self.class.prefix?(plaintext)

  @revocable = ::Ci::Runner.find_by_token(plaintext)
  @source = source
end

Instance Attribute Details

#revocableObject (readonly)

Returns the value of attribute revocable.



15
16
17
# File 'lib/authn/tokens/runner_authentication_token.rb', line 15

def revocable
  @revocable
end

#sourceObject (readonly)

Returns the value of attribute source.



15
16
17
# File 'lib/authn/tokens/runner_authentication_token.rb', line 15

def source
  @source
end

Class Method Details

.prefix?(plaintext) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
# File 'lib/authn/tokens/runner_authentication_token.rb', line 6

def self.prefix?(plaintext)
  prefixes = [
    ::Ci::Runner.created_runner_prefix,
    ::Ci::Runner::CREATED_RUNNER_TOKEN_PREFIX
  ]

  plaintext.start_with?(*prefixes)
end

Instance Method Details

#present_withObject



24
25
26
# File 'lib/authn/tokens/runner_authentication_token.rb', line 24

def present_with
  ::API::Entities::Ci::Runner
end

#revoke!(current_user) ⇒ Object



28
29
30
31
32
33
# File 'lib/authn/tokens/runner_authentication_token.rb', line 28

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

  service = ::Ci::Runners::ResetAuthenticationTokenService.new(runner: revocable, current_user: current_user)
  service.execute!
end