enviroblyd 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/enviroblyd/command.rb +16 -7
- data/lib/enviroblyd/daemon.rb +25 -21
- data/lib/enviroblyd/imds.rb +2 -1
- data/lib/enviroblyd/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8467f960365419e9f02f14d3d3186a511787dff28798fd8883ac328a2443e9c
|
4
|
+
data.tar.gz: 2f39dbca93e49cf69ab2bb9aaed76fe89ed2ebd7867baebba640c8ea665082ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc3ea42ebc9125f88ec1828b4ebdf9032ba2482d1db359860b9b7c117ae0cb12eb57369531bd760cb54b2563f64c63e3afb89a304a574c23fa19bc7ff4334214
|
7
|
+
data.tar.gz: 3c9baed9045d458595627b186f5be800abe5da2df36beea47e22fd478bc28e25e984814de9731118040b4a65f16fabea10923d06daaa0f419639ace81f0be67f
|
data/lib/enviroblyd/command.rb
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "open3"
|
4
|
+
require "json"
|
4
5
|
|
5
6
|
class Enviroblyd::Command
|
6
7
|
DEFAULT_TIMEOUT_SECONDS = 5 * 60
|
7
8
|
DEFAULT_RUNTIME = "/bin/bash"
|
8
9
|
|
9
|
-
def
|
10
|
-
|
11
|
-
new(params).run
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(params)
|
10
|
+
def initialize(message)
|
11
|
+
params = parse_message message
|
16
12
|
@url = params.fetch "url"
|
17
13
|
@script = params.fetch "script"
|
18
14
|
@runtime = params.fetch "runtime", DEFAULT_RUNTIME
|
19
15
|
@timeout = params.fetch "timeout", DEFAULT_TIMEOUT_SECONDS
|
20
16
|
@stdout = @stderr = @exit_code = nil
|
17
|
+
@valid = true
|
18
|
+
rescue NoMethodError, KeyError
|
19
|
+
@valid = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid?
|
23
|
+
@valid
|
21
24
|
end
|
22
25
|
|
23
26
|
def run
|
@@ -45,4 +48,10 @@ class Enviroblyd::Command
|
|
45
48
|
}
|
46
49
|
}
|
47
50
|
end
|
51
|
+
|
52
|
+
def parse_message(message)
|
53
|
+
JSON.parse message
|
54
|
+
rescue
|
55
|
+
nil
|
56
|
+
end
|
48
57
|
end
|
data/lib/enviroblyd/daemon.rb
CHANGED
@@ -1,43 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "socket"
|
4
|
-
require "json"
|
5
4
|
|
6
5
|
class Enviroblyd::Daemon
|
7
6
|
MAX_MESSAGE_SIZE = 6000 # bytes
|
8
|
-
|
7
|
+
PORT = ENV.fetch("ENVIROBLYD_PORT", 63106).to_i
|
9
8
|
|
10
9
|
def self.start
|
11
10
|
imds = Enviroblyd::IMDS.new
|
12
11
|
host = imds.private_ipv4
|
13
|
-
new
|
14
|
-
|
15
|
-
end
|
12
|
+
daemon = new(host)
|
13
|
+
daemon.listen
|
16
14
|
end
|
17
15
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
16
|
+
def initialize(host)
|
17
|
+
@host = host
|
18
|
+
end
|
21
19
|
|
22
|
-
|
20
|
+
def listen
|
21
|
+
server = TCPServer.new @host, PORT
|
22
|
+
puts "Listening on #{@host}:#{PORT}"
|
23
|
+
Enviroblyd::Web.register
|
23
24
|
|
24
25
|
loop do
|
25
26
|
Thread.start(server.accept) do |client|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if params.nil?
|
34
|
-
client.puts "Error parsing JSON"
|
35
|
-
else
|
36
|
-
client.puts "OK"
|
27
|
+
message = client.recv(MAX_MESSAGE_SIZE)
|
28
|
+
command = Enviroblyd::Command.new message
|
29
|
+
|
30
|
+
unless command.valid?
|
31
|
+
$stderr.puts "Invalid message received: #{message}"
|
32
|
+
client.puts "Invalid message"
|
33
|
+
next
|
37
34
|
end
|
38
35
|
|
36
|
+
client.puts "OK"
|
37
|
+
client.close
|
38
|
+
command.run
|
39
|
+
ensure
|
39
40
|
client.close
|
40
|
-
|
41
|
+
command = nil
|
42
|
+
message = nil
|
43
|
+
client = nil
|
44
|
+
GC.start
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
data/lib/enviroblyd/imds.rb
CHANGED
@@ -6,7 +6,8 @@ class Enviroblyd::IMDS
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@token = Enviroblyd::Web.http("http://#{IMDS_HOST}/latest/api/token",
|
9
|
-
type: Net::HTTP::Put,
|
9
|
+
type: Net::HTTP::Put,
|
10
|
+
headers: { "X-aws-ec2-metadata-token-ttl-seconds" => TOKEN_TTL_SECONDS.to_s }).
|
10
11
|
body.strip
|
11
12
|
end
|
12
13
|
|
data/lib/enviroblyd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enviroblyd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Starsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|