Sha256: 744738768ceee18cb3c03a95c49829ce628f48361f8c554269102f3a9c846af7

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 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-from=.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

5 entries across 5 versions & 1 rubygems

Version Path
chamber-2.12.3 lib/chamber/commands/securable.rb
chamber-2.12.2 lib/chamber/commands/securable.rb
chamber-2.12.1 lib/chamber/commands/securable.rb
chamber-2.12.0 lib/chamber/commands/securable.rb
chamber-2.11.0 lib/chamber/commands/securable.rb