fdk 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fdk.rb +2 -0
- data/lib/fdk/call.rb +2 -0
- data/lib/fdk/context.rb +2 -0
- data/lib/fdk/function.rb +2 -0
- data/lib/fdk/listener.rb +35 -3
- data/lib/fdk/runner.rb +3 -1
- data/lib/fdk/support_classes.rb +2 -0
- data/lib/fdk/version.rb +3 -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: bf44c78f30f73ef02883f583ed7d3d1718a5f32e58fb04cbcf5e61730a8a0792
|
4
|
+
data.tar.gz: 4c997f610e8d1b6a654fba5ce0362a05abe70bd1fab035e7a007b063c47fac56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3212288e1ede41978bd0489b5a4ee95371cbcfa04e0514103b80819ed43e9abd1126e0325babf0294eb01c392b3d994e1151449eac190dcd988623f8d342522
|
7
|
+
data.tar.gz: 22224118f8a1be06f74c16f4c85a09a7033c2d3aced3e41e6b39ff64b900b56180054f452cd8683944f4390180c967a8dd87649954c176225729a4de98b2a94f
|
data/lib/fdk.rb
CHANGED
data/lib/fdk/call.rb
CHANGED
data/lib/fdk/context.rb
CHANGED
data/lib/fdk/function.rb
CHANGED
data/lib/fdk/listener.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module FDK
|
2
4
|
# Represents the socket that Fn uses to communicate
|
3
5
|
# with the FDK (and thence the function)
|
@@ -9,13 +11,16 @@ module FDK
|
|
9
11
|
#
|
10
12
|
# Fn waits for the socket_path to be created and then connects
|
11
13
|
class Listener
|
12
|
-
attr_reader :url, :private_socket
|
14
|
+
attr_reader :url, :private_socket, :fn_logframe_name, :fn_logframe_hdr
|
13
15
|
|
14
16
|
def initialize(url:)
|
15
17
|
if url.nil? || !url.start_with?("unix:/")
|
16
18
|
raise "Missing or invalid socket URL in FN_LISTENER."
|
17
19
|
end
|
18
20
|
|
21
|
+
@fn_logframe_name = ENV["FN_LOGFRAME_NAME"]
|
22
|
+
@fn_logframe_hdr = ENV["FN_LOGFRAME_HDR"]
|
23
|
+
|
19
24
|
@url = url
|
20
25
|
@private_socket = UNIXServer.open(private_socket_path)
|
21
26
|
end
|
@@ -46,10 +51,10 @@ module FDK
|
|
46
51
|
|
47
52
|
def handle_request(fn_block:)
|
48
53
|
local_socket = socket.accept
|
49
|
-
req =
|
50
|
-
resp = WEBrick::HTTPResponse.new(WEBrick::Config::HTTP)
|
54
|
+
req, resp = new_req_resp
|
51
55
|
req.parse(local_socket)
|
52
56
|
FDK.debug "got request #{req}"
|
57
|
+
log_frame_header(req.header)
|
53
58
|
fn_block.call(req, resp)
|
54
59
|
resp["Connection"] = "close" # we're not using keep alives sadly
|
55
60
|
resp.send_response(local_socket)
|
@@ -57,6 +62,12 @@ module FDK
|
|
57
62
|
local_socket.close
|
58
63
|
end
|
59
64
|
|
65
|
+
def new_req_resp
|
66
|
+
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
|
67
|
+
resp = WEBrick::HTTPResponse.new(WEBrick::Config::HTTP)
|
68
|
+
[req, resp]
|
69
|
+
end
|
70
|
+
|
60
71
|
def socket_path
|
61
72
|
@socket_path ||= url[5..url.length]
|
62
73
|
end
|
@@ -64,5 +75,26 @@ module FDK
|
|
64
75
|
def private_socket_path
|
65
76
|
socket_path + ".private"
|
66
77
|
end
|
78
|
+
|
79
|
+
def log_frame_header(headers)
|
80
|
+
return unless logframe_vars_exist
|
81
|
+
|
82
|
+
k = @fn_logframe_hdr.downcase
|
83
|
+
v = headers[k]
|
84
|
+
return if v.nil? || v.empty?
|
85
|
+
|
86
|
+
frm = "\n#{@fn_logframe_name}=#{v[0]}\n"
|
87
|
+
$stderr.print frm
|
88
|
+
$stderr.flush
|
89
|
+
$stdout.print frm
|
90
|
+
$stdout.flush
|
91
|
+
end
|
92
|
+
|
93
|
+
def logframe_vars_exist
|
94
|
+
return false if @fn_logframe_name.nil? || @fn_logframe_name.empty? ||
|
95
|
+
@fn_logframe_hdr.nil? || @fn_logframe_hdr.empty?
|
96
|
+
|
97
|
+
true
|
98
|
+
end
|
67
99
|
end
|
68
100
|
end
|
data/lib/fdk/runner.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "webrick"
|
2
4
|
require "fileutils"
|
3
5
|
require "json"
|
@@ -7,7 +9,7 @@ require "set"
|
|
7
9
|
# Executes it with input
|
8
10
|
# Responds with output
|
9
11
|
module FDK
|
10
|
-
FDK_LOG_THRESHOLD = "FDK_LOG_THRESHOLD"
|
12
|
+
FDK_LOG_THRESHOLD = "FDK_LOG_THRESHOLD"
|
11
13
|
FDK_LOG_DEBUG = 0
|
12
14
|
FDK_LOG_DEFAULT = 1
|
13
15
|
|
data/lib/fdk/support_classes.rb
CHANGED
data/lib/fdk/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-05-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|