Sha256: 3ac162b062698b0cc005b97fe41f640159eb83b734137f1e648fb37f3655f9cc

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require 'shellwords'
require 'chamber/instance'

module  Chamber
module  Commands
module  Securable
  def initialize(options = {})
    super

    ignored_settings_options        = options.
                                        merge(files: ignored_settings_filepaths).
                                        reject { |k, _v| k == 'basepath' }
    self.ignored_settings_instance  = Chamber::Instance.new(ignored_settings_options)
    self.current_settings_instance  = Chamber::Instance.new(options)
    self.only_sensitive             = options[:only_sensitive]
  end

  protected

  attr_accessor :only_sensitive,
                :ignored_settings_instance,
                :current_settings_instance

  def securable_environment_variables
    if only_sensitive
      securable_settings.to_environment
    else
      current_settings.to_environment
    end
  end

  def insecure_environment_variables
    securable_settings.insecure.to_environment
  end

  def securable_settings
    ignored_settings.merge(current_settings.securable)
  end

  def current_settings
    current_settings_instance.settings
  end

  def ignored_settings
    ignored_settings_instance.settings
  end

  def ignored_settings_filepaths
    shell_escaped_chamber_filenames = chamber.filenames.map do |filename|
      Shellwords.escape(filename)
    end

    `
      git ls-files --other --ignored --exclude-per-directory=.gitignore |
      sed -e "s|^|#{Shellwords.escape(rootpath.to_s)}/|" |
      grep --colour=never -E '#{shell_escaped_chamber_filenames.join('|')}'
    `.split("\n")
  end
end
end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chamber-2.13.1 lib/chamber/commands/securable.rb
chamber-2.13.0 lib/chamber/commands/securable.rb
chamber-2.12.5 lib/chamber/commands/securable.rb