enviroblyd 0.4.4 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45118408246d815ecd5132ae18a22cc3fa33f4106b1a825984285c58d1c0129e
4
- data.tar.gz: a948c9c4ffd8f1bbda57a92d3acf63b4abdf653d737fa36ddb4f3c7775301244
3
+ metadata.gz: a8467f960365419e9f02f14d3d3186a511787dff28798fd8883ac328a2443e9c
4
+ data.tar.gz: 2f39dbca93e49cf69ab2bb9aaed76fe89ed2ebd7867baebba640c8ea665082ae
5
5
  SHA512:
6
- metadata.gz: c0016f127f30a58c53052664526b1b7a5da5cd28c7a539e7e36a559c2f0ab530d9bf48ab1340986e671547c89d2c38e03d901264340c4f7825b15edf611d753c
7
- data.tar.gz: 57cf14b9e65ccaeb7a84a2681488815fe7ba0f7332edb3186dfdddf66bc6ec80e3a35b6287e48846e439e833ea578963ced5c1693a6856e7db394a5fabf94c5c
6
+ metadata.gz: dc3ea42ebc9125f88ec1828b4ebdf9032ba2482d1db359860b9b7c117ae0cb12eb57369531bd760cb54b2563f64c63e3afb89a304a574c23fa19bc7ff4334214
7
+ data.tar.gz: 3c9baed9045d458595627b186f5be800abe5da2df36beea47e22fd478bc28e25e984814de9731118040b4a65f16fabea10923d06daaa0f419639ace81f0be67f
data/bin/enviroblyd CHANGED
File without changes
@@ -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 self.run(params)
10
- Thread.new do
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
@@ -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
- LISTEN_PORT = ENV.fetch("ENVIROBLYD_PORT", 63106).to_i
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.listen(host) do
14
- Enviroblyd::Web.register
15
- end
12
+ daemon = new(host)
13
+ daemon.listen
16
14
  end
17
15
 
18
- def listen(host)
19
- server = TCPServer.new host, LISTEN_PORT
20
- puts "Listening on #{host}:#{LISTEN_PORT}"
16
+ def initialize(host)
17
+ @host = host
18
+ end
21
19
 
22
- yield
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
- params =
27
- begin
28
- JSON.parse client.recv(MAX_MESSAGE_SIZE)
29
- rescue
30
- :invalid_json
31
- end
32
-
33
- if params == :invalid_json
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
- Enviroblyd::Command.run(params)
41
+ command = nil
42
+ message = nil
43
+ client = nil
44
+ GC.start
41
45
  end
42
46
  end
43
47
  end
@@ -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, headers: { "X-aws-ec2-metadata-token-ttl-seconds" => TOKEN_TTL_SECONDS.to_s }).
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enviroblyd
4
- VERSION = "0.4.4"
4
+ VERSION = "0.4.6"
5
5
  end
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
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-05 00:00:00.000000000 Z
11
+ date: 2024-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor