Class: Authn::Tokens::CiTriggerToken

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plaintext, source) ⇒ CiTriggerToken

Returns a new instance of CiTriggerToken.



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

def initialize(plaintext, source)
  @revocable = ::Ci::Trigger.find_by_token(plaintext)
  @source = source
end

Instance Attribute Details

#revocableObject (readonly)

Returns the value of attribute revocable.



12
13
14
# File 'lib/authn/tokens/ci_trigger_token.rb', line 12

def revocable
  @revocable
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/authn/tokens/ci_trigger_token.rb', line 12

def source
  @source
end

Class Method Details

.prefix?(plaintext) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.prefix?(plaintext)
  prefixes = [::Ci::Trigger::TRIGGER_TOKEN_PREFIX, ::Ci::Trigger.prefix_for_trigger_token].uniq

  plaintext.start_with?(*prefixes)
end

Instance Method Details

#present_withObject



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

def present_with
  ::API::Entities::Trigger
end

#revoke!(current_user) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/authn/tokens/ci_trigger_token.rb', line 23

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

  unless Feature.enabled?(:token_api_expire_pipeline_triggers, revocable.project)
    raise ::Authn::AgnosticTokenIdentifier::UnsupportedTokenError, 'Unsupported token type'
  end

  ::Ci::PipelineTriggers::ExpireService.new(user: current_user, trigger: revocable).execute
end