fdk 0.0.16 → 0.0.24

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
- SHA1:
3
- metadata.gz: 65e2394fdcb3ded2289d375557641ce03ad38781
4
- data.tar.gz: 6587cea06ad9da035c853218d52ffc6af9733fae
2
+ SHA256:
3
+ metadata.gz: 82337a2e0152a4b8e145e5b7e14f4ec76cbbbf64a4f698ddf0b5b87ca0c329e0
4
+ data.tar.gz: 36ec9f76404c426a30f81732709aee3bc2b55beebea4fd67ec4fc3c9724ff968
5
5
  SHA512:
6
- metadata.gz: 85cf5dd30e50be0b4301ceda4954f2fce48c978c69584d10d0e282f5036da583a2ff49bc5610d2b676b511fd929f1410f9e882fa81aac6cad7862cfb7a8855c1
7
- data.tar.gz: 89d8e019779503fd53d00026dfa412fccc87b4c75eae36f11ff1568b124e287a331338b0a192ed2de62f5e322f96779798c58363f43152a488fba4a4e0048c2a
6
+ metadata.gz: 4657ece9b952b4f3a15c5e0e26ccf0e36991def60f94c0255fa7b8aef4e00b6e06580653396df32c8b8d534fb31d728dea794bff9a18009b956f6b58162f426c
7
+ data.tar.gz: 9a4a9eb7ec981dbaa009c1d5d919255f4fd5439309e9fa0fd2fd1be2d8c9f00084677c45676d582461272f115475b854e8060f89e904e476a98a1f07a3f03ef8
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.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"
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
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
@@ -32,29 +53,35 @@ module FDK
32
53
  end
33
54
 
34
55
  def listen(&block)
35
- local_socket = socket.accept
36
- begin
37
- raise StandardError("No block given") unless block_given?
56
+ raise StandardError("No block given") unless block_given?
38
57
 
39
- handle_requests(socket: local_socket, fn_block: block)
58
+ begin
59
+ loop do
60
+ handle_request(fn_block: block)
61
+ end
40
62
  rescue StandardError => e
41
63
  FDK.log(entry: "Error in request handling #{e}")
42
64
  FDK.log(entry: e.backtrace)
43
65
  end
66
+ end
67
+
68
+ def handle_request(fn_block:)
69
+ local_socket = socket.accept
70
+ req, resp = new_req_resp
71
+ req.parse(local_socket)
72
+ FDK.debug "got request #{req}"
73
+ log_frame_header(req.header)
74
+ fn_block.call(req, resp)
75
+ resp["Connection"] = "close" # we're not using keep alives sadly
76
+ resp.send_response(local_socket)
77
+ FDK.debug "sending resp #{resp.status}, #{resp.header}"
44
78
  local_socket.close
45
79
  end
46
80
 
47
- def handle_requests(socket:, fn_block:)
48
- loop do
49
- req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
50
- resp = WEBrick::HTTPResponse.new(WEBrick::Config::HTTP)
51
- req.parse(socket)
52
- FDK.debug "got request #{req}"
53
- fn_block.call(req, resp)
54
- resp.send_response(socket)
55
- FDK.debug "sending resp #{resp.status}, #{resp.header}"
56
- break unless req.keep_alive?
57
- end
81
+ def new_req_resp
82
+ req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
83
+ resp = WEBrick::HTTPResponse.new(WEBrick::Config::HTTP)
84
+ [req, resp]
58
85
  end
59
86
 
60
87
  def socket_path
@@ -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
 
@@ -18,7 +36,7 @@ module FDK
18
36
  # Writes the entry to STDERR if the log_level >= log_threshold
19
37
  # If no log level is specified, 1 is assumed.
20
38
  def self.log(entry:, log_level: FDK_LOG_DEFAULT)
21
- STDERR.puts(entry) if log_level >= log_threshold
39
+ warn(entry) if log_level >= log_threshold
22
40
  end
23
41
 
24
42
  def self.log_error(error:)
@@ -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.16".freeze
20
+ VERSION = "0.0.24"
3
21
  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.16
4
+ version: 0.0.24
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: 2018-11-01 00:00:00.000000000 Z
13
+ date: 2021-06-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -32,6 +32,26 @@ dependencies:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 2.1.0
35
+ - !ruby/object:Gem::Dependency
36
+ name: webrick
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.4'
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 1.4.2
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '1.4'
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.4.2
35
55
  - !ruby/object:Gem::Dependency
36
56
  name: net_http_unix
37
57
  requirement: !ruby/object:Gem::Requirement
@@ -98,15 +118,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
118
  requirements:
99
119
  - - ">="
100
120
  - !ruby/object:Gem::Version
101
- version: '2.4'
121
+ version: '2.5'
102
122
  required_rubygems_version: !ruby/object:Gem::Requirement
103
123
  requirements:
104
124
  - - ">="
105
125
  - !ruby/object:Gem::Version
106
126
  version: '0'
107
127
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.6.14.1
128
+ rubygems_version: 3.1.6
110
129
  signing_key:
111
130
  specification_version: 4
112
131
  summary: Ruby FDK for Fn Project