Skip to content

Commit 66cb707

Browse files
committed
WIP: action to download a remote file to the local computer
1 parent c6bca74 commit 66cb707

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

app/turbulence/gcloud/actions.rb

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Actions
99
TailLogsSingleContainer,
1010
TailLogsAllContainers,
1111
ForwardPort,
12+
DownloadFile,
1213
RestartDeployment,
1314
DestroyNamespace
1415
].freeze
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
module Turbulence
4+
module GCloud
5+
module Actions
6+
# Access a command line / console for a container
7+
class DownloadFile
8+
ID = :download_file
9+
NAME = 'Download a file from a Pod to your computer'
10+
11+
include ActionResources
12+
13+
def run
14+
project
15+
cluster
16+
namespace
17+
pod
18+
container
19+
remote_file_name
20+
download_destination
21+
22+
PROMPT.ok("\nConnecting...\n")
23+
download && \
24+
PROMPT.ok("\nThe file is now in the Downloads folder of your Turbulence installation.")
25+
end
26+
27+
private
28+
29+
def remote_file_name
30+
return @remote_file_name if defined?(@remote_file_name)
31+
32+
remote_file = PROMPT.ask('Full path and filename of remote file: (e.g. /tmp/my-file)', required: true)
33+
34+
@remote_file_path = File.dirname(remote_file)
35+
@remote_file_name = File.basename(remote_file)
36+
end
37+
38+
def download_destination
39+
system('[ -d ./Downloads ] || mkdir Downloads')
40+
end
41+
42+
def command
43+
"kubectl cp -n #{namespace.name} -c #{container.name} #{pod.id}:#{remote_file_name} ./Downloads/#{remote_file_name}".tap { puts _1 }
44+
end
45+
46+
def download
47+
system(command)
48+
end
49+
end
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)