fdk 0.0.18 → 0.0.25

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: 7202ae9a894c4f8441a14d462347e378a5a2a7b7bbfe491ab63422c18fd53220
4
- data.tar.gz: 0b206f459aff8f18ccd90369f8f1d5817546bfd158f25c556d071af0dd481e1e
3
+ metadata.gz: 2e3bbd08c2801e8b98ab2a0ed065ec4833c1c76aa9557b80e789518b7536ebe9
4
+ data.tar.gz: aaad97f4e9a0ce65fca6ca275b65566cc080bfa71c727c3c801b95b7254518b4
5
5
  SHA512:
6
- metadata.gz: a7166a00ed4d2132a545bb563ad4714836dee8c66bd7cc7f30b54f142054195f20f84f632c1bb7d591a77cf9bf8a4003ec39c013bc77f5f70f8c5f4f1b29cc2d
7
- data.tar.gz: 7d01f662675303828e27365aa5d87cdc66543749a932a295e957132e47c648725576b6f0d568ade13e3dd7619bbdb6bd11e45a84b7037a86e3b54f166fe8b857
6
+ metadata.gz: 044ec13b6a88dd96f261a669171fbc9e86c7fbe414b76c32b01580387709c3b5b0ec18c0dfc242114207a61c401c0403c205da4c8d243cff11f6a073a254f0e2
7
+ data.tar.gz: 876ddbff791b328e57985b1147caa5e1c4fca063e2ef89d60f7d71595f1c209086e37109caee4ed3bfeb41a3e6aca830de8b6aa1449abbe6d8a00bc838848396
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
@@ -46,16 +67,23 @@ 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)
75
+ resp["Connection"] = "close" # we're not using keep alives sadly
54
76
  resp.send_response(local_socket)
55
77
  FDK.debug "sending resp #{resp.status}, #{resp.header}"
56
78
  local_socket.close
57
79
  end
58
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
+
59
87
  def socket_path
60
88
  @socket_path ||= url[5..url.length]
61
89
  end
@@ -63,5 +91,26 @@ module FDK
63
91
  def private_socket_path
64
92
  socket_path + ".private"
65
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
66
115
  end
67
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.18".freeze
20
+ VERSION = "0.0.25"
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.18
4
+ version: 0.0.25
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-01-30 00:00:00.000000000 Z
13
+ date: 2021-08-20 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.1
128
+ rubygems_version: 3.1.6
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Ruby FDK for Fn Project