Module: Vault::Rails::Configurable

Includes:
Configurable
Defined in:
lib/vault/rails/configurable.rb

Instance Method Summary collapse

Instance Method Details

#applicationString

The name of the Vault::Rails application.

Returns:

  • (String)

Raises:

  • (RuntimeError)

    if the application has not been set



15
16
17
18
19
20
21
22
23
# File 'lib/vault/rails/configurable.rb', line 15

def application
  if defined?(@application) && !@application.nil?
    return @application
  end
  if ENV.has_key?("VAULT_RAILS_APPLICATION")
    return ENV["VAULT_RAILS_APPLICATION"]
  end
  raise RuntimeError, "Must set `Vault::Rails#application'!"
end

#application=(val) ⇒ Object

Set the name of the application.

Parameters:

  • val (String)


28
29
30
# File 'lib/vault/rails/configurable.rb', line 28

def application=(val)
  @application = val
end

#default_role_nameString

Gets the default role name.

Returns:

  • (String)


135
136
137
# File 'lib/vault/rails/configurable.rb', line 135

def default_role_name
  @default_role_name
end

#default_role_name=(val) ⇒ Object

Sets the default role to use with various plugins.

Parameters:

  • val (String)


142
143
144
# File 'lib/vault/rails/configurable.rb', line 142

def default_role_name=(val)
  @default_role_name = val
end

#enabled=(val) ⇒ true, false

Sets whether Vault is enabled. Users can set this in an initializer depending on their Rails environment.

Examples:

Vault.configure do |vault|
  vault.enabled = Rails.env.production?
end

Returns:

  • (true, false)


57
58
59
# File 'lib/vault/rails/configurable.rb', line 57

def enabled=(val)
  @enabled = !!val
end

#enabled?true, false

Whether the connection to Vault is enabled. The default value is ‘false`, which means vault-rails will perform in-memory encryption/decryption and not attempt to talk to a real Vault server. This is useful for development and testing.

Returns:

  • (true, false)


38
39
40
41
42
43
44
45
46
# File 'lib/vault/rails/configurable.rb', line 38

def enabled?
  if defined?(@enabled) && !@enabled.nil?
    return @enabled
  end
  if ENV.has_key?("VAULT_RAILS_ENABLED")
    return (ENV["VAULT_RAILS_ENABLED"] == "true")
  end
  return false
end

#in_memory_warnings_enabled=(val) ⇒ true, false

Sets whether warnings about in-memory ciphers are enabled. Users can set this in an initializer depending on their Rails environment.

Examples:

Vault.configure do |vault|
  vault.in_memory_warnings_enabled = !Rails.env.test?
end

Returns:

  • (true, false)


83
84
85
# File 'lib/vault/rails/configurable.rb', line 83

def in_memory_warnings_enabled=(val)
  @in_memory_warnings_enabled = val
end

#in_memory_warnings_enabled?true, false

Whether warnings about in-memory ciphers are enabled. The default value is ‘true`, which means vault-rails will log a warning for every attempt to encrypt or decrypt using an in-memory cipher. This is useful for development and testing.

Returns:

  • (true, false)


67
68
69
70
71
72
# File 'lib/vault/rails/configurable.rb', line 67

def in_memory_warnings_enabled?
  if !defined?(@in_memory_warnings_enabled) || @in_memory_warnings_enabled.nil?
    return true
  end
  return @in_memory_warnings_enabled
end

#retry_attemptsFixnum

Gets the number of retry attempts.

Returns:

  • (Fixnum)


90
91
92
# File 'lib/vault/rails/configurable.rb', line 90

def retry_attempts
  @retry_attempts ||= 0
end

#retry_attempts=(val) ⇒ Object

Sets the number of retry attempts. Please see the Vault documentation for more information.

Parameters:

  • val (Fixnum)


98
99
100
# File 'lib/vault/rails/configurable.rb', line 98

def retry_attempts=(val)
  @retry_attempts = val
end

#retry_baseFixnum

Gets the number of retry attempts.

Returns:

  • (Fixnum)


105
106
107
# File 'lib/vault/rails/configurable.rb', line 105

def retry_base
  @retry_base ||= Vault::Defaults::RETRY_BASE
end

#retry_base=(val) ⇒ Object

Sets the retry interval. Please see the Vault documentation for more information.

Parameters:

  • val (Fixnum)


113
114
115
# File 'lib/vault/rails/configurable.rb', line 113

def retry_base=(val)
  @retry_base = val
end

#retry_max_waitFixnum

Gets the retry maximum wait.

Returns:

  • (Fixnum)


120
121
122
# File 'lib/vault/rails/configurable.rb', line 120

def retry_max_wait
  @retry_max_wait ||= Vault::Defaults::RETRY_MAX_WAIT
end

#retry_max_wait=(val) ⇒ Object

Sets the maximum amount of time for a single retry. Please see the Vault documentation for more information.

Parameters:

  • val (Fixnum)


128
129
130
# File 'lib/vault/rails/configurable.rb', line 128

def retry_max_wait=(val)
  @retry_max_wait = val
end