class Dradis::Plugins::Settings::Adapters::EncryptedConfiguration

Attributes

config_path[W]

Public Class Methods

new(namespace) click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 5
def initialize(namespace)
  @namespace = namespace
end

Public Instance Methods

delete(key) click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 9
def delete(key)
  if exists?(key)
    configuration.config[@namespace].delete(key)
    configuration.write(configuration.config.to_yaml)
  end
end
exists?(key) click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 16
def exists?(key)
  !!configuration.config[@namespace]&.key?(key)
end
key_path=(string_or_pathname) click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 30
def key_path=(string_or_pathname)
  @key_path = Pathname.new(string_or_pathname)
end
read(key) click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 20
def read(key)
  configuration.config.fetch(@namespace, {}).fetch(key, nil)
end
write(key, value) click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 24
def write(key, value)
  configuration.config[@namespace] ||= {}
  configuration.config[@namespace][key] = value
  configuration.write(configuration.config.to_yaml)
end

Private Instance Methods

config_path() click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 35
def config_path
  @config_path ||= Rails.root.join('config', 'shared', 'dradis-plugins.yml.enc')
end
configuration() click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 39
def configuration
  @configuration ||= begin
      create_key unless key_path.exist?

      ActiveSupport::EncryptedConfiguration.new(
        config_path: config_path, key_path: key_path,
        env_key: 'RAILS_MASTER_KEY', raise_if_missing_key: true
      )
    end
end
create_key() click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 50
def create_key
  File.write(key_path, ActiveSupport::EncryptedConfiguration.generate_key)
end
key_path() click to toggle source
# File lib/dradis/plugins/settings/adapters/encrypted_configuration.rb, line 54
def key_path
  @key_path ||= Rails.root.join('config', 'shared', 'dradis-plugins.key')
end