Class: Configuration::CredentialsConfiguration

Inherits:
Configuration show all
Defined in:
lib/configuration/credentials_configuration.rb

Overview

Configuration for credentials.

Instance Attribute Summary

Attributes inherited from Configuration

#data, #manager

Instance Method Summary collapse

Methods inherited from Configuration

#initialize

Constructor Details

This class inherits a constructor from Configuration::Configuration

Instance Method Details

#decrypted_passwordObject



43
44
45
46
# File 'lib/configuration/credentials_configuration.rb', line 43

def decrypted_password
  decrypt(data[:credentials][:password][:cipher],
          data[:credentials][:password][:iv])
end

#login_credentialsAccountCredentials

Read credentials from configuration file

Returns:

  • (AccountCredentials)

    An AccountCredentials instance with username, password and is_stored properties.



26
27
28
29
30
31
32
33
34
35
# File 'lib/configuration/credentials_configuration.rb', line 26

def 
  if 
    raise LogworkException::ConfigurationValueNotFound.new,
          "Cannot read username/password from configuration file at '#{manager.configuration_path}'."
  end

  AccountCredentials.new(username: data[:credentials][:username],
                         password: decrypted_password,
                         is_stored: true)
end

#login_credentials_empty?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/configuration/credentials_configuration.rb', line 37

def 
  data[:credentials].nil? ||
    data[:credentials][:username].nil? ||
    data[:credentials][:password].nil?
end

#update_login_credentials(username, password) ⇒ Object

Update login credentials in configuration file

Parameters:

  • username (String)

    Jira username

  • password (String)

    Jira password



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/configuration/credentials_configuration.rb', line 52

def (username, password)
  if !username.nil? && !password.nil?
    encrypted_password = encrypt(password)
    data[:credentials] = {
      username: username,
      password: encrypted_password
    }
  else
    data.delete(:credentials)
  end

  manager.save_configuration
end