putpaws 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5383c31d8b2b94dcb948e565f9ab5784137a0b946aa53e2ade93fc5e1bf3152
|
4
|
+
data.tar.gz: 30babace1c15c9675752567795e4c43414be155cc0f9affccfdb8bd8907a215d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f506cafed6700e2fc5bff6334e7e3374e528652740de99c03a36e89a031603b891b77133b5264fff51f8d1d3bc7db22f8549c88a32658f87883249c8cfe9d331
|
7
|
+
data.tar.gz: 941ceaa13526fd71c3a37d5d6541490950472dea6bff75aff2b495acc10adb41f46b270e14a6c279d542863792594896443aeca882655321b856a745c38306e0
|
@@ -12,9 +12,9 @@ module Putpaws::CloudWatch
|
|
12
12
|
|
13
13
|
def self.config(config, type: "default")
|
14
14
|
if type == "build"
|
15
|
-
new(config.build_log_command_params)
|
15
|
+
new(**config.build_log_command_params)
|
16
16
|
else
|
17
|
-
new(config.log_command_params)
|
17
|
+
new(**config.log_command_params)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'aws-sdk-ecs'
|
2
|
+
require 'aws-sdk-ssm'
|
2
3
|
|
3
4
|
module Putpaws::Ecs
|
4
5
|
class TaskCommand
|
5
6
|
def self.config(config)
|
6
|
-
new(config.ecs_command_params)
|
7
|
+
new(**config.ecs_command_params)
|
7
8
|
end
|
8
9
|
|
9
10
|
attr_reader :ecs_client
|
@@ -27,11 +28,35 @@ module Putpaws::Ecs
|
|
27
28
|
}
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
+
def get_session_target(container: 'app')
|
31
32
|
raise "ECS Task Not Set" unless ecs_task
|
32
33
|
ctn = ecs_task.containers.detect{|c| c.name == container}
|
33
34
|
task_id = ecs_task.task_arn.split('/').last
|
34
35
|
raise "Container: #{container} not found" unless ctn
|
36
|
+
"ecs:#{cluster}_#{task_id}_#{ctn.runtime_id}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_port_forwarding_command(container: nil, remote_port:, remote_host:, local_port: nil)
|
40
|
+
container ||= 'app'
|
41
|
+
target = get_session_target(container: container)
|
42
|
+
ssm_client = Aws::SSM::Client.new({region: region})
|
43
|
+
local_port ||= (1050..1079).map(&:to_s).shuffle.first
|
44
|
+
puts "Starting to use local port: #{local_port}"
|
45
|
+
res = ssm_client.start_session({
|
46
|
+
target: target,
|
47
|
+
document_name: "AWS-StartPortForwardingSessionToRemoteHost",
|
48
|
+
parameters: {
|
49
|
+
portNumber: [remote_port],
|
50
|
+
localPortNumber: [local_port],
|
51
|
+
host: [remote_host]
|
52
|
+
}
|
53
|
+
})
|
54
|
+
build_session_manager_plugin_command(session: res, target: target)
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_attach_command(container: nil)
|
58
|
+
container ||= 'app'
|
59
|
+
target = get_session_target(container: container)
|
35
60
|
res = ecs_client.execute_command({
|
36
61
|
cluster: cluster,
|
37
62
|
container: container,
|
@@ -39,17 +64,26 @@ module Putpaws::Ecs
|
|
39
64
|
interactive: true,
|
40
65
|
task: ecs_task.task_arn,
|
41
66
|
})
|
67
|
+
build_session_manager_plugin_command(session: res.session, target: target)
|
68
|
+
end
|
42
69
|
|
70
|
+
def build_session_manager_plugin_command(session:, target:)
|
43
71
|
ssm_region = ENV['AWS_REGION_SSM'] || @region
|
44
|
-
|
72
|
+
|
45
73
|
# https://github.com/aws/aws-cli/blob/2a6136010d8656a605d41d1e7b5fdab3c2930cad/awscli/customizations/ecs/executecommand.py#L105
|
46
|
-
session_json =
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
74
|
+
session_json = if session.respond_to?(:session_id)
|
75
|
+
{
|
76
|
+
"SessionId" => session.session_id,
|
77
|
+
"StreamUrl" => session.stream_url,
|
78
|
+
"TokenValue" => session.token_value,
|
79
|
+
}.to_json
|
80
|
+
elsif session.is_a?(Hash)
|
81
|
+
session.to_json
|
82
|
+
else
|
83
|
+
session
|
84
|
+
end
|
51
85
|
target_json = {
|
52
|
-
"Target" =>
|
86
|
+
"Target" => target
|
53
87
|
}.to_json
|
54
88
|
cmd = [
|
55
89
|
"session-manager-plugin",
|
@@ -22,7 +22,28 @@ namespace :ecs do
|
|
22
22
|
ecs_task = fetch(:ecs_task)
|
23
23
|
aws = Putpaws::Ecs::TaskCommand.config(fetch(:app))
|
24
24
|
aws.ecs_task = ecs_task
|
25
|
-
cmd = aws.get_attach_command
|
25
|
+
cmd = aws.get_attach_command(container: ENV['container'])
|
26
|
+
puts cmd
|
27
|
+
system(cmd)
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Run port forwarding session. You need to enable ECS Exec on a specified task and also install session-manager-plugin."
|
31
|
+
task forward: :set_task do
|
32
|
+
ecs_task = fetch(:ecs_task)
|
33
|
+
aws = Putpaws::Ecs::TaskCommand.config(fetch(:app))
|
34
|
+
aws.ecs_task = ecs_task
|
35
|
+
|
36
|
+
remote_host, remote_port = (ENV['remote'] || '').split(':').map(&:strip)
|
37
|
+
_, local_port = (ENV['local'] || '').split(':').map(&:strip)
|
38
|
+
if remote_host.nil? or remote_port.nil?
|
39
|
+
raise "Remote Host, Port is required: (Ex) remote=192.168.1.1:80"
|
40
|
+
end
|
41
|
+
cmd = aws.get_port_forwarding_command(
|
42
|
+
container: ENV['container'],
|
43
|
+
remote_host: remote_host,
|
44
|
+
remote_port: remote_port,
|
45
|
+
local_port: local_port
|
46
|
+
)
|
26
47
|
puts cmd
|
27
48
|
system(cmd)
|
28
49
|
end
|
data/lib/putpaws/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: putpaws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- metheglin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aws-sdk-ssm
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: aws-sdk-ecs
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,7 +131,7 @@ homepage: https://rubygems.org/gems/putpaws
|
|
117
131
|
licenses:
|
118
132
|
- MIT
|
119
133
|
metadata: {}
|
120
|
-
post_install_message:
|
134
|
+
post_install_message:
|
121
135
|
rdoc_options: []
|
122
136
|
require_paths:
|
123
137
|
- lib
|
@@ -132,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
146
|
- !ruby/object:Gem::Version
|
133
147
|
version: '0'
|
134
148
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
136
|
-
signing_key:
|
149
|
+
rubygems_version: 3.4.10
|
150
|
+
signing_key:
|
137
151
|
specification_version: 4
|
138
152
|
summary: Put your paws up!!
|
139
153
|
test_files: []
|