Module: Dapp::Kube::Dapp::Command::Common
- Included in:
- Dapp
- Defined in:
- lib/dapp/kube/dapp/command/common.rb
Instance Method Summary collapse
- #kube_chart_path(*path) ⇒ Object
- #kube_chart_secret_dir_name ⇒ Object
- #kube_chart_secret_path(*path) ⇒ Object
- #kube_check_helm! ⇒ Object
- #kube_helm_decode_json(secret, json) ⇒ Object
- #kube_helm_encode_json(secret, json) ⇒ Object
- #kube_namespace ⇒ Object
- #kube_release_name ⇒ Object
- #kube_tmp_chart_path(*path) ⇒ Object
- #kubernetes ⇒ Object
- #secret ⇒ Object
- #secret_key_not_found_in ⇒ Object
- #secret_key_should_exist! ⇒ Object
- #with_kube_tmp_chart_dir ⇒ Object
Instance Method Details
#kube_chart_path(*path) ⇒ Object
57 58 59 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 57 def kube_chart_path(*path) self.path('.helm', *path). end |
#kube_chart_secret_dir_name ⇒ Object
53 54 55 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 53 def kube_chart_secret_dir_name 'secret' end |
#kube_chart_secret_path(*path) ⇒ Object
49 50 51 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 49 def kube_chart_secret_path(*path) kube_chart_path(kube_chart_secret_dir_name, *path). end |
#kube_check_helm! ⇒ Object
6 7 8 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 6 def kube_check_helm! raise Error::Command, code: :helm_not_found if shellout('which helm').exitstatus == 1 end |
#kube_helm_decode_json(secret, json) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 30 def kube_helm_decode_json(secret, json) decode_value = proc do |value| case value when Array then value.map { |v| decode_value.call(v) } when Hash then kube_helm_decode_json(secret,value) else secret.nil? ? '' : secret.extract(value) end end json.each { |k, v| json[k] = decode_value.call(v) } end |
#kube_helm_encode_json(secret, json) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 18 def kube_helm_encode_json(secret, json) encode_json = proc do |value| case value when Array then value.map { |v| encode_json.call(v) } when Hash then kube_helm_encode_json(secret,value) else secret.nil? ? '' : secret.generate(value) end end json.each { |k, v| json[k] = encode_json.call(v) } end |
#kube_namespace ⇒ Object
14 15 16 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 14 def kube_namespace kubernetes.namespace end |
#kube_release_name ⇒ Object
10 11 12 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 10 def kube_release_name "#{name}-#{kube_namespace}" end |
#kube_tmp_chart_path(*path) ⇒ Object
67 68 69 70 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 67 def kube_tmp_chart_path(*path) @kube_tmp_path ||= Dir.mktmpdir('dapp-helm-chart-', tmp_base_dir) make_path(@kube_tmp_path, *path)..tap { |p| p.parent.mkpath } end |
#kubernetes ⇒ Object
95 96 97 98 99 100 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 95 def kubernetes @kubernetes ||= begin namespace = [:namespace].nil? ? nil : [:namespace].tr('_', '-') Kubernetes::Client.new(namespace: namespace) end end |
#secret ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 72 def secret @secret ||= begin unless (secret_key = ENV['DAPP_SECRET_KEY']) secret_key_not_found_in << '`DAPP_SECRET_KEY`' if dappfile_exists? file_path = path('.dapp_secret_key') if file_path.file? secret_key = path('.dapp_secret_key').read.chomp else secret_key_not_found_in << "`#{file_path}`" end end end Secret.new(secret_key) if secret_key end end |
#secret_key_not_found_in ⇒ Object
91 92 93 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 91 def secret_key_not_found_in @secret_key_not_found_in ||= [] end |
#secret_key_should_exist! ⇒ Object
42 43 44 45 46 47 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 42 def secret_key_should_exist! raise(Error::Command, code: :secret_key_not_found, data: {not_found_in: secret_key_not_found_in.join(', ')} ) if secret.nil? end |
#with_kube_tmp_chart_dir ⇒ Object
61 62 63 64 65 |
# File 'lib/dapp/kube/dapp/command/common.rb', line 61 def with_kube_tmp_chart_dir yield if block_given? ensure FileUtils.rm_rf(kube_tmp_chart_path) end |