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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# 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
kube_secret_file_validate!(file_path)
if options[:values]
(file_path)
else
(file_path)
end
end
tmp_file_path = kube_chart_path_for_helm(File.basename(file_path))
tmp_file_path.binwrite(decoded_data)
loop do
begin
system(kube_secret_editor, tmp_file_path.to_s)
encoded_data = begin
if options[:values]
encoded_values = yaml_load_file(file_path)
decoded_values = kube_helm_decode_json(secret, yaml_load_file(file_path))
updated_decoded_values = yaml_load_file(tmp_file_path)
deep_delete_if_key_not_exist(encoded_values, updated_decoded_values)
modified_decoded_values = deep_select_modified_keys(updated_decoded_values, decoded_values)
updated_encoded_values = deep_merge(encoded_values, kube_helm_encode_json(secret, modified_decoded_values))
deep_sort_by_same_structure(updated_encoded_values, updated_decoded_values).to_yaml
else
kube_secret_file(tmp_file_path)
end
end
IO.binwrite(file_path, "#{encoded_data}\n")
break
rescue ::Dapp::Error::Base => e
log_warning(Helper::NetStatus.message(e))
print 'Do you want to change file (Y/n)?'
response = $stdin.getch.tap { print "\n" }
return if response.strip == 'n'
end
end
end
end
|