fdk 0.0.19 → 0.0.26

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: 78e0e2f31ccc1881218c6a3ecfe5fc8a98bab525c4710ffb8e63ffec58bcaaa0
4
- data.tar.gz: ed342e0ba43d13b0cced1488bb111a9de258fedf77df2105f3ea4ef9bfd59aaf
3
+ metadata.gz: 11bde0cbeae6808c95696bc9068aa90c4fe1cdd191878ac72a1560688f01064c
4
+ data.tar.gz: e3265d7ef4e04cbd6a5f91bed6091d96c29fb3eebd052fb8bda161f0f2026c96
5
5
  SHA512:
6
- metadata.gz: eb1b8a8c907a33fd5d40ff70e8346c52352ccebcda056923707285bf8a13127664b7bb6cbb3e6170503beb7d479262053b6fb043e3000fef81cec410d5d7d021
7
- data.tar.gz: 401cdd0d0e13ffba1155e4a54c61281c0d8f07d7d8754395df92807f596595cd599eb0aa43c3224ee33ac8a2d40527b16cd777a0968debc722647933c6ae9632
6
+ metadata.gz: 0577ca1a919505807e9c1662b96bba8238eee65e26042541b93160039dd898501cbfb137e09e291d86bbb050a4d4619b7e9b2ed518f4c4119943bf3de3ced33b
7
+ data.tar.gz: 356dc9aa5da12d54e18603c6a7ffed2ff798902b2e7940e22320718e34d5d759c79c944a1e4ecb5d6ede8b0537bd49b7f7e59cce54987429358b537ce86d71f2
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # Ruby Function Developer Kit (FDK)
2
- This provides a Ruby framework for developing functions for use with [Fn](https://fnproject.github.io).
1
+ # Function Development Kit for Ruby
2
+ The Function Development Kit for Ruby (FDK for Ruby) provides a Ruby framework for developing functions for use with [Fn](https://fnproject.github.io).
3
3
 
4
4
  [![CircleCI](https://circleci.com/gh/fnproject/fdk-ruby.svg?style=svg)](https://circleci.com/gh/fnproject/fdk-ruby)
5
5
 
data/lib/fdk/call.rb CHANGED
@@ -1,8 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  module FDK
2
20
  # Call represents a call to the target function or lambda
3
21
  class Call
4
- FILTER_HEADERS = ["content-length", "te", "transfer-encoding",
5
- "upgrade", "trailer"].freeze
22
+ FILTER_HEADERS = %w[content-length te transfer-encoding upgrade trailer].freeze
6
23
 
7
24
  attr_reader :request, :response
8
25
  attr_accessor :error
data/lib/fdk/context.rb CHANGED
@@ -1,3 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require "date"
2
20
 
3
21
  module FDK
@@ -33,6 +51,8 @@ module FDK
33
51
  # Represents outbound HTTP headers
34
52
  class OutHeaders < InHeaders
35
53
  def initialize(headers, key_in_fn)
54
+ headers["Fn-Fdk-Version"] = ["fdk-ruby/#{FDK::VERSION}"]
55
+ headers["Fn-Fdk-Runtime"] = ["ruby/#{RUBY_VERSION}"]
36
56
  super(headers, key_in_fn)
37
57
  end
38
58
 
data/lib/fdk/function.rb CHANGED
@@ -1,3 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  module FDK
2
20
  # Function represents a function function or lambda
3
21
  class Function
data/lib/fdk/listener.rb CHANGED
@@ -1,3 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  module FDK
2
20
  # Represents the socket that Fn uses to communicate
3
21
  # with the FDK (and thence the function)
@@ -9,13 +27,16 @@ module FDK
9
27
  #
10
28
  # Fn waits for the socket_path to be created and then connects
11
29
  class Listener
12
- attr_reader :url, :private_socket
30
+ attr_reader :url, :private_socket, :fn_logframe_name, :fn_logframe_hdr
13
31
 
14
32
  def initialize(url:)
15
33
  if url.nil? || !url.start_with?("unix:/")
16
34
  raise "Missing or invalid socket URL in FN_LISTENER."
17
35
  end
18
36
 
37
+ @fn_logframe_name = ENV["FN_LOGFRAME_NAME"]
38
+ @fn_logframe_hdr = ENV["FN_LOGFRAME_HDR"]
39
+
19
40
  @url = url
20
41
  @private_socket = UNIXServer.open(private_socket_path)
21
42
  end
@@ -46,10 +67,10 @@ module FDK
46
67
 
47
68
  def handle_request(fn_block:)
48
69
  local_socket = socket.accept
49
- req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
50
- resp = WEBrick::HTTPResponse.new(WEBrick::Config::HTTP)
70
+ req, resp = new_req_resp
51
71
  req.parse(local_socket)
52
72
  FDK.debug "got request #{req}"
73
+ log_frame_header(req.header)
53
74
  fn_block.call(req, resp)
54
75
  resp["Connection"] = "close" # we're not using keep alives sadly
55
76
  resp.send_response(local_socket)
@@ -57,6 +78,12 @@ module FDK
57
78
  local_socket.close
58
79
  end
59
80
 
81
+ def new_req_resp
82
+ req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
83
+ resp = WEBrick::HTTPResponse.new(WEBrick::Config::HTTP)
84
+ [req, resp]
85
+ end
86
+
60
87
  def socket_path
61
88
  @socket_path ||= url[5..url.length]
62
89
  end
@@ -64,5 +91,26 @@ module FDK
64
91
  def private_socket_path
65
92
  socket_path + ".private"
66
93
  end
94
+
95
+ def log_frame_header(headers)
96
+ return unless logframe_vars_exist
97
+
98
+ k = @fn_logframe_hdr.downcase
99
+ v = headers[k]
100
+ return if v.nil? || v.empty?
101
+
102
+ frm = "\n#{@fn_logframe_name}=#{v[0]}\n"
103
+ $stderr.print frm
104
+ $stderr.flush
105
+ $stdout.print frm
106
+ $stdout.flush
107
+ end
108
+
109
+ def logframe_vars_exist
110
+ return false if @fn_logframe_name.nil? || @fn_logframe_name.empty? ||
111
+ @fn_logframe_hdr.nil? || @fn_logframe_hdr.empty?
112
+
113
+ true
114
+ end
67
115
  end
68
116
  end
data/lib/fdk/runner.rb CHANGED
@@ -1,3 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require "webrick"
2
20
  require "fileutils"
3
21
  require "json"
@@ -7,7 +25,7 @@ require "set"
7
25
  # Executes it with input
8
26
  # Responds with output
9
27
  module FDK
10
- FDK_LOG_THRESHOLD = "FDK_LOG_THRESHOLD".freeze
28
+ FDK_LOG_THRESHOLD = "FDK_LOG_THRESHOLD"
11
29
  FDK_LOG_DEBUG = 0
12
30
  FDK_LOG_DEFAULT = 1
13
31
 
@@ -1,3 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  module FDK
2
20
  # ParsedInput stores raw input and can parse it as
3
21
  # JSON (add extra formats as required)
data/lib/fdk/version.rb CHANGED
@@ -1,3 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  module FDK
2
- VERSION = "0.0.19".freeze
20
+ VERSION = "0.0.26"
3
21
  end
data/lib/fdk.rb CHANGED
@@ -1,3 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require_relative "fdk/version"
2
20
  require_relative "fdk/runner"
3
21
  require_relative "fdk/context"
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.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
@@ -10,28 +10,28 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-04-26 00:00:00.000000000 Z
13
+ date: 2021-08-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: 2.1.0
22
19
  - - "~>"
23
20
  - !ruby/object:Gem::Version
24
21
  version: '2.1'
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.1.0
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- version: 2.1.0
32
29
  - - "~>"
33
30
  - !ruby/object:Gem::Version
34
31
  version: '2.1'
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.1.0
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: webrick
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -118,14 +118,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - ">="
120
120
  - !ruby/object:Gem::Version
121
- version: '2.4'
121
+ version: '2.5'
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 3.0.3
128
+ rubygems_version: 3.1.6
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Ruby FDK for Fn Project