Module: Dapp::Kube::Dapp::Command::SecretEdit

Included in:
Dapp
Defined in:
lib/dapp/kube/dapp/command/secret_edit.rb

Instance Method Summary collapse

Instance Method Details

#kube_secret_edit(file_path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dapp/kube/dapp/command/secret_edit.rb', line 6

def kube_secret_edit(file_path)
  secret_key_should_exist!

  with_kube_tmp_chart_dir do
    decoded_data = begin
      raise Error::Command, code: :file_not_exist, data: { path: File.expand_path(file_path) } unless File.exist?(file_path)

      if options[:values]
        kube_extract_secret_values(file_path)
      else
        kube_extract_secret_file(file_path)
      end
    end

    tmp_file_path = kube_tmp_chart_path(file_path)
    tmp_file_path.binwrite(decoded_data)
    system(kube_secret_editor, tmp_file_path.to_s)

    encoded_data = begin
      if options[:values]
        kube_secret_values(tmp_file_path)
      else
        kube_secret_file(tmp_file_path)
      end
    end

    IO.binwrite(file_path, "#{encoded_data}\n")
  end
end

#kube_secret_editorObject

Raises:



36
37
38
39
40
# File 'lib/dapp/kube/dapp/command/secret_edit.rb', line 36

def kube_secret_editor
  return ENV['EDITOR'] unless ENV['EDITOR'].nil?
  %w(vim vi nano).each { |editor| return editor unless shellout("which #{editor}").exitstatus.nonzero? }
  raise Error::Command, code: :editor_not_found
end