Class: Helpers::BusbarConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/busbar_cli/helpers/busbar_config.rb

Constant Summary collapse

CONFIG_OPTIONS =
{
  default_git_branch: {
    text: 'Please provide the default git branch',
    default: 'master'
  },
  kubectl_config_url: {
    text: 'Please provide the kubectl remote configuration URL',
    default: nil
  },
  kubectl_config_version_url: {
    text: 'Please provide the kubectl configuration version URL',
    default: nil
  },
  busbar_profile: {
    text: 'Please provide the Busbar profile',
    default: nil
  }
}.freeze

Class Method Summary collapse

Class Method Details

.create_empty_config_fileObject



29
30
31
32
33
34
35
36
# File 'lib/busbar_cli/helpers/busbar_config.rb', line 29

def create_empty_config_file
  busbar_config_hash = {}
  ensure_dependencies
  CONFIG_OPTIONS.each do |k, _|
    busbar_config_hash[k.to_s] = nil
  end
  File.open(BUSBAR_CONFIG_FILE_PATH, 'w') { |f| f.write(busbar_config_hash.to_yaml) }
end

.ensure_dependenciesObject



25
26
27
# File 'lib/busbar_cli/helpers/busbar_config.rb', line 25

def ensure_dependencies
  FileUtils.mkdir_p(BUSBAR_LOCAL_FOLDER) unless Dir.exist?(BUSBAR_LOCAL_FOLDER)
end

.write_from_hash(busbar_config_hash, first_run) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/busbar_cli/helpers/busbar_config.rb', line 38

def write_from_hash(busbar_config_hash, first_run)
  # Pre-Validate
  busbar_config_hash.each do |k, v|
    Services::Kube.validate_profile(v) if k == 'busbar_profile' unless first_run
  end
  # Write
  busbar_config_hash.each do |k, v|
    Services::BusbarConfig.set(k.to_s, v)
  end
end