Class: LogStash::Outputs::Keystone::Token

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/logstash/outputs/keystone/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToken

Returns a new instance of Token.



45
46
47
# File 'lib/logstash/outputs/keystone/token.rb', line 45

def initialize
  @logger = Cabin::Channel.get(LogStash)
end

Instance Attribute Details

#expires_atObject

Returns the value of attribute expires_at.



25
26
27
# File 'lib/logstash/outputs/keystone/token.rb', line 25

def expires_at
  @expires_at
end

#idObject

Returns the value of attribute id.



25
26
27
# File 'lib/logstash/outputs/keystone/token.rb', line 25

def id
  @id
end

#keystone_clientObject

Returns the value of attribute keystone_client.



25
26
27
# File 'lib/logstash/outputs/keystone/token.rb', line 25

def keystone_client
  @keystone_client
end

Instance Method Details

#request_new_token(username, user_domain_name, password, project_name, project_domain_name) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/logstash/outputs/keystone/token.rb', line 27

def request_new_token(username, user_domain_name, password, project_name, project_domain_name)
  token = @keystone_client
    .authenticate(username, user_domain_name, password, project_name, project_domain_name)
  set_token(token[:token], token[:expires_at])
  @logger.info("New token requested")
  @logger.debug("token=#{@id}, expire_at=#{@expires_at}")
end

#set_keystone_client(keystone_api, insecure) ⇒ Object



40
41
42
43
# File 'lib/logstash/outputs/keystone/token.rb', line 40

def set_keystone_client(keystone_api, insecure)
  @keystone_client = LogStash::Outputs::Keystone::KeystoneClient
    .new(keystone_api, insecure)
end

#set_token(id, expires_at) ⇒ Object



35
36
37
38
# File 'lib/logstash/outputs/keystone/token.rb', line 35

def set_token id, expires_at
  @id = id
  @expires_at = expires_at
end

#valid?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'lib/logstash/outputs/keystone/token.rb', line 49

def valid?
  token_valid = true
  now = DateTime.now + Rational(1, 1440)
  if @id.nil? or now >= @expires_at
    token_valid = false
  end
  token_valid
end