Skip to content

Commit 221f8ad

Browse files
adding --path-temp argument
1 parent 8c8539f commit 221f8ad

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/k8s-vault.cr

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ module K8sVault
7878
CLI Options:
7979
-h | --help | --usage displays usage
8080
-d | --debug enabled debug output
81+
--temp-path path of generated temp file
8182
example-config outputs example config
8283
completion outputs bash completion code
8384
exec executes K8s-Vault
@@ -183,14 +184,15 @@ module K8sVault
183184
# Return `nil`
184185
def self.cleanup : Nil
185186
K8sVault::Log.debug "cleaning up"
186-
File.delete(K8sVault::KUBECONFIG_TEMP) rescue nil
187+
File.delete(ENV["KUBECONFIG"]) rescue nil
187188
end
188189

189190
# Runs everything
190191
def self.run(options : Array(String))
191192
kubecontext = "_unset_"
192193
spawn_shell = false
193-
194+
kubeconfigTemp = K8sVault::KUBECONFIG_TEMP;
195+
194196
while options.size > 0
195197
case options.first
196198
when "-v", "--version"
@@ -202,6 +204,10 @@ module K8sVault
202204
when "-d", "--debug"
203205
K8sVault::Log.debug = true
204206
options.shift
207+
when "--temp-path"
208+
options.shift
209+
kubeconfigTemp = options.first
210+
options.shift
205211
when "example-config"
206212
K8sVault.example_config
207213
exit 0
@@ -271,7 +277,7 @@ module K8sVault
271277
begin
272278
config = K8sVault.config(kubecontext: kubecontext)
273279
# write temp KUBECONFIG
274-
File.write(K8sVault::KUBECONFIG_TEMP, config.kubeconfig, perm = 0o0600)
280+
File.write(kubeconfigTemp, config.kubeconfig, perm = 0o0600)
275281
rescue K8sVault::UnconfiguredContextError
276282
K8sVault::Log.error "\"#{kubecontext}\" context is not found in #{K8sVault::K8SVAULT_CONFIG}"
277283
cleanup
@@ -319,9 +325,9 @@ module K8sVault
319325
end
320326

321327
ENV["K8SVAULT"] = "1"
322-
ENV["KUBECONFIG"] = K8sVault::KUBECONFIG_TEMP
328+
ENV["KUBECONFIG"] = kubeconfigTemp
323329
ENV["K8SVAULT_CONTEXT"] = kubecontext
324-
K8sVault::Log.debug "using KUBECONFIG: #{K8sVault::KUBECONFIG_TEMP}"
330+
K8sVault::Log.debug "using KUBECONFIG: #{kubeconfigTemp}"
325331

326332
if spawn_shell
327333
K8sVault::Log.info "k8s-vault session started"
@@ -332,7 +338,7 @@ module K8sVault
332338
sleep 3
333339
cmd = options.first
334340
options.shift
335-
Process.run(cmd, options, {"KUBECONFIG" => K8sVault::KUBECONFIG_TEMP}, output: STDOUT, error: STDERR)
341+
Process.run(cmd, options, {"KUBECONFIG" => kubeconfigTemp}, output: STDOUT, error: STDERR)
336342
end
337343

338344
forwarder.signal(Signal::TERM) rescue nil

0 commit comments

Comments
 (0)