Module: Dapp::Kube::Dapp::Command::SecretGenerate

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

Instance Method Summary collapse

Instance Method Details

#kube_secretObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dapp/kube/dapp/command/secret_generate.rb', line 31

def kube_secret
  data = begin
    if $stdin.tty?
      print 'Enter secret: '
      $stdin.noecho(&:gets).tap { print "\n" }
    else
      $stdin.read
    end.to_s.chomp
  end

  if data.empty?
    exit 0
  else
    secret.generate(data)
  end
end

#kube_secret_file(file_path) ⇒ Object



52
53
54
# File 'lib/dapp/kube/dapp/command/secret_generate.rb', line 52

def kube_secret_file(file_path)
  secret.generate(IO.binread(file_path))
end

#kube_secret_generate(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
# File 'lib/dapp/kube/dapp/command/secret_generate.rb', line 6

def kube_secret_generate(file_path)
  secret_key_should_exist!

  data = begin
    if file_path
      kube_secret_file_validate!(file_path)

      if options[:values]
        kube_secret_values(file_path)
      else
        kube_secret_file(file_path)
      end
    else
      kube_secret
    end
  end

  if (output_file_path = options[:output_file_path])
    FileUtils.mkpath File.dirname(output_file_path)
    IO.binwrite(output_file_path, "#{data}\n")
  else
    puts data
  end
end

#kube_secret_values(file_path) ⇒ Object



48
49
50
# File 'lib/dapp/kube/dapp/command/secret_generate.rb', line 48

def kube_secret_values(file_path)
  kube_helm_encode_json(secret, yaml_load_file(file_path)).to_yaml
end