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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78e0e2f31ccc1881218c6a3ecfe5fc8a98bab525c4710ffb8e63ffec58bcaaa0
4
- data.tar.gz: ed342e0ba43d13b0cced1488bb111a9de258fedf77df2105f3ea4ef9bfd59aaf
3
+ metadata.gz: bf44c78f30f73ef02883f583ed7d3d1718a5f32e58fb04cbcf5e61730a8a0792
4
+ data.tar.gz: 4c997f610e8d1b6a654fba5ce0362a05abe70bd1fab035e7a007b063c47fac56
5
5
  SHA512:
6
- metadata.gz: eb1b8a8c907a33fd5d40ff70e8346c52352ccebcda056923707285bf8a13127664b7bb6cbb3e6170503beb7d479262053b6fb043e3000fef81cec410d5d7d021
7
- data.tar.gz: 401cdd0d0e13ffba1155e4a54c61281c0d8f07d7d8754395df92807f596595cd599eb0aa43c3224ee33ac8a2d40527b16cd777a0968debc722647933c6ae9632
6
+ metadata.gz: b3212288e1ede41978bd0489b5a4ee95371cbcfa04e0514103b80819ed43e9abd1126e0325babf0294eb01c392b3d994e1151449eac190dcd988623f8d342522
7
+ data.tar.gz: 22224118f8a1be06f74c16f4c85a09a7033c2d3aced3e41e6b39ff64b900b56180054f452cd8683944f4390180c967a8dd87649954c176225729a4de98b2a94f
data/lib/fdk.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "fdk/version"
2
4
  require_relative "fdk/runner"
3
5
  require_relative "fdk/context"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FDK
2
4
  # Call represents a call to the target function or lambda
3
5
  class Call
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "date"
2
4
 
3
5
  module FDK
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FDK
2
4
  # Function represents a function function or lambda
3
5
  class Function
@@ -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 = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
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
@@ -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".freeze
12
+ FDK_LOG_THRESHOLD = "FDK_LOG_THRESHOLD"
11
13
  FDK_LOG_DEBUG = 0
12
14
  FDK_LOG_DEFAULT = 1
13
15
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FDK
2
4
  # ParsedInput stores raw input and can parse it as
3
5
  # JSON (add extra formats as required)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FDK
2
- VERSION = "0.0.19".freeze
4
+ VERSION = "0.0.20"
3
5
  end
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.19
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-04-26 00:00:00.000000000 Z
13
+ date: 2019-05-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json