Class: Authn::Tokens::DeployToken

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plaintext, source) ⇒ DeployToken

Returns a new instance of DeployToken.



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

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

Instance Attribute Details

#revocableObject (readonly)

Returns the value of attribute revocable.



10
11
12
# File 'lib/authn/tokens/deploy_token.rb', line 10

def revocable
  @revocable
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/authn/tokens/deploy_token.rb', line 10

def source
  @source
end

Class Method Details

.prefix?(plaintext) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.prefix?(plaintext)
  plaintext.start_with?(::DeployToken::DEPLOY_TOKEN_PREFIX)
end

Instance Method Details

#present_withObject



17
18
19
# File 'lib/authn/tokens/deploy_token.rb', line 17

def present_with
  ::API::Entities::DeployToken
end

#revoke!(current_user) ⇒ Object



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

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

  service = ::Groups::DeployTokens::RevokeService.new(
    revocable.group,
    current_user,
    { id: revocable.id }
  )
  service.source = source
  service.execute
end