Class: Authn::Tokens::ClusterAgentToken

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plaintext, source) ⇒ ClusterAgentToken

Returns a new instance of ClusterAgentToken.



15
16
17
18
19
20
# File 'lib/authn/tokens/cluster_agent_token.rb', line 15

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

  @revocable = ::Clusters::AgentToken.find_by_token(plaintext)
  @source = source
end

Instance Attribute Details

#revocableObject (readonly)

Returns the value of attribute revocable.



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

def revocable
  @revocable
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Class Method Details

.prefix?(plaintext) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.prefix?(plaintext)
  prefixes = [::Clusters::AgentToken.glagent_prefix,
    ::Clusters::AgentToken::TOKEN_PREFIX].uniq

  plaintext.start_with?(*prefixes)
end

Instance Method Details

#present_withObject



22
23
24
# File 'lib/authn/tokens/cluster_agent_token.rb', line 22

def present_with
  ::API::Entities::Clusters::AgentToken
end

#revoke!(current_user) ⇒ Object



26
27
28
29
30
31
# File 'lib/authn/tokens/cluster_agent_token.rb', line 26

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

  service = ::Clusters::AgentTokens::RevokeService.new(token: revocable, current_user: current_user)
  service.execute
end