functions_framework 0.4.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +11 -11
- data/bin/functions-framework +4 -1
- data/bin/functions-framework-ruby +1 -1
- data/docs/deploying-functions.md +22 -13
- data/docs/overview.md +6 -6
- data/docs/testing-functions.md +59 -11
- data/docs/writing-functions.md +202 -13
- data/lib/functions_framework.rb +41 -10
- data/lib/functions_framework/cli.rb +97 -22
- data/lib/functions_framework/function.rb +142 -47
- data/lib/functions_framework/legacy_event_converter.rb +10 -11
- data/lib/functions_framework/registry.rb +36 -12
- data/lib/functions_framework/server.rb +27 -22
- data/lib/functions_framework/testing.rb +123 -24
- data/lib/functions_framework/version.rb +1 -1
- metadata +24 -16
- data/lib/functions_framework/cloud_events.rb +0 -45
- data/lib/functions_framework/cloud_events/content_type.rb +0 -222
- data/lib/functions_framework/cloud_events/errors.rb +0 -42
- data/lib/functions_framework/cloud_events/event.rb +0 -84
- data/lib/functions_framework/cloud_events/event/field_interpreter.rb +0 -150
- data/lib/functions_framework/cloud_events/event/v0.rb +0 -236
- data/lib/functions_framework/cloud_events/event/v1.rb +0 -223
- data/lib/functions_framework/cloud_events/http_binding.rb +0 -310
- data/lib/functions_framework/cloud_events/json_format.rb +0 -173
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: functions_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cloud_events
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: puma
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,7 +52,10 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '2.1'
|
41
|
-
description: The Functions Framework
|
55
|
+
description: The Functions Framework is an open source framework for writing lightweight,
|
56
|
+
portable Ruby functions that run in a serverless environment. Functions written
|
57
|
+
to this Framework will run on Google Cloud Functions, Google Cloud Run, or any other
|
58
|
+
Knative-based environment.
|
42
59
|
email:
|
43
60
|
- dazuma@google.com
|
44
61
|
executables:
|
@@ -60,15 +77,6 @@ files:
|
|
60
77
|
- docs/writing-functions.md
|
61
78
|
- lib/functions_framework.rb
|
62
79
|
- lib/functions_framework/cli.rb
|
63
|
-
- lib/functions_framework/cloud_events.rb
|
64
|
-
- lib/functions_framework/cloud_events/content_type.rb
|
65
|
-
- lib/functions_framework/cloud_events/errors.rb
|
66
|
-
- lib/functions_framework/cloud_events/event.rb
|
67
|
-
- lib/functions_framework/cloud_events/event/field_interpreter.rb
|
68
|
-
- lib/functions_framework/cloud_events/event/v0.rb
|
69
|
-
- lib/functions_framework/cloud_events/event/v1.rb
|
70
|
-
- lib/functions_framework/cloud_events/http_binding.rb
|
71
|
-
- lib/functions_framework/cloud_events/json_format.rb
|
72
80
|
- lib/functions_framework/function.rb
|
73
81
|
- lib/functions_framework/legacy_event_converter.rb
|
74
82
|
- lib/functions_framework/registry.rb
|
@@ -79,10 +87,10 @@ homepage: https://github.com/GoogleCloudPlatform/functions-framework-ruby
|
|
79
87
|
licenses:
|
80
88
|
- Apache-2.0
|
81
89
|
metadata:
|
82
|
-
changelog_uri: https://github.
|
90
|
+
changelog_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v0.7.0/file.CHANGELOG.html
|
83
91
|
source_code_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby
|
84
92
|
bug_tracker_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby/issues
|
85
|
-
documentation_uri: https://
|
93
|
+
documentation_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v0.7.0
|
86
94
|
post_install_message:
|
87
95
|
rdoc_options: []
|
88
96
|
require_paths:
|
@@ -91,14 +99,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
99
|
requirements:
|
92
100
|
- - ">="
|
93
101
|
- !ruby/object:Gem::Version
|
94
|
-
version: 2.
|
102
|
+
version: 2.5.0
|
95
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
104
|
requirements:
|
97
105
|
- - ">="
|
98
106
|
- !ruby/object:Gem::Version
|
99
107
|
version: '0'
|
100
108
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
109
|
+
rubygems_version: 3.0.3
|
102
110
|
signing_key:
|
103
111
|
specification_version: 4
|
104
112
|
summary: Functions Framework for Ruby
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# Copyright 2020 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require "functions_framework/cloud_events/content_type"
|
16
|
-
require "functions_framework/cloud_events/errors"
|
17
|
-
require "functions_framework/cloud_events/event"
|
18
|
-
require "functions_framework/cloud_events/http_binding"
|
19
|
-
require "functions_framework/cloud_events/json_format"
|
20
|
-
|
21
|
-
module FunctionsFramework
|
22
|
-
##
|
23
|
-
# CloudEvents implementation.
|
24
|
-
#
|
25
|
-
# This is a Ruby implementation of the [CloudEvents](https://cloudevents.io)
|
26
|
-
# specification. It supports both
|
27
|
-
# [CloudEvents 0.3](https://github.com/cloudevents/spec/blob/v0.3/spec.md) and
|
28
|
-
# [CloudEvents 1.0](https://github.com/cloudevents/spec/blob/v1.0/spec.md).
|
29
|
-
#
|
30
|
-
module CloudEvents
|
31
|
-
# @private
|
32
|
-
SUPPORTED_SPEC_VERSIONS = ["0.3", "1.0"].freeze
|
33
|
-
|
34
|
-
class << self
|
35
|
-
##
|
36
|
-
# The spec versions supported by this implementation.
|
37
|
-
#
|
38
|
-
# @return [Array<String>]
|
39
|
-
#
|
40
|
-
def supported_spec_versions
|
41
|
-
SUPPORTED_SPEC_VERSIONS
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,222 +0,0 @@
|
|
1
|
-
# Copyright 2020 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
module FunctionsFramework
|
16
|
-
module CloudEvents
|
17
|
-
##
|
18
|
-
# A parsed content-type header.
|
19
|
-
#
|
20
|
-
# This object represents the information contained in a Content-Type,
|
21
|
-
# obtained by parsing the header according to RFC 2045.
|
22
|
-
#
|
23
|
-
# Case-insensitive fields, such as media_type and subtype, are normalized
|
24
|
-
# to lower case.
|
25
|
-
#
|
26
|
-
# If parsing fails, this class will try to get as much information as it
|
27
|
-
# can, and fill the rest with defaults as recommended in RFC 2045 sec 5.2.
|
28
|
-
# In case of a parsing error, the {#error_message} field will be set.
|
29
|
-
#
|
30
|
-
class ContentType
|
31
|
-
##
|
32
|
-
# Parse the given header value.
|
33
|
-
#
|
34
|
-
# @param string [String] Content-Type header value in RFC 2045 format
|
35
|
-
#
|
36
|
-
def initialize string
|
37
|
-
@string = string
|
38
|
-
@media_type = "text"
|
39
|
-
@subtype_base = @subtype = "plain"
|
40
|
-
@subtype_format = nil
|
41
|
-
@params = []
|
42
|
-
@charset = "us-ascii"
|
43
|
-
@error_message = nil
|
44
|
-
parse consume_comments string.strip
|
45
|
-
@canonical_string = "#{@media_type}/#{@subtype}" +
|
46
|
-
@params.map { |k, v| "; #{k}=#{maybe_quote v}" }.join
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# The original header content string.
|
51
|
-
# @return [String]
|
52
|
-
#
|
53
|
-
attr_reader :string
|
54
|
-
alias to_s string
|
55
|
-
|
56
|
-
##
|
57
|
-
# A "canonical" header content string with spacing and capitalization
|
58
|
-
# normalized.
|
59
|
-
# @return [String]
|
60
|
-
#
|
61
|
-
attr_reader :canonical_string
|
62
|
-
|
63
|
-
##
|
64
|
-
# The media type.
|
65
|
-
# @return [String]
|
66
|
-
#
|
67
|
-
attr_reader :media_type
|
68
|
-
|
69
|
-
##
|
70
|
-
# The entire content subtype (which could include an extension delimited
|
71
|
-
# by a plus sign).
|
72
|
-
# @return [String]
|
73
|
-
#
|
74
|
-
attr_reader :subtype
|
75
|
-
|
76
|
-
##
|
77
|
-
# The portion of the content subtype before any plus sign.
|
78
|
-
# @return [String]
|
79
|
-
#
|
80
|
-
attr_reader :subtype_base
|
81
|
-
|
82
|
-
##
|
83
|
-
# The portion of the content subtype after any plus sign, or nil if there
|
84
|
-
# is no plus sign in the subtype.
|
85
|
-
# @return [String,nil]
|
86
|
-
#
|
87
|
-
attr_reader :subtype_format
|
88
|
-
|
89
|
-
##
|
90
|
-
# An array of parameters, each element as a two-element array of the
|
91
|
-
# parameter name and value.
|
92
|
-
# @return [Array<Array(String,String)>]
|
93
|
-
#
|
94
|
-
attr_reader :params
|
95
|
-
|
96
|
-
##
|
97
|
-
# The charset, defaulting to "us-ascii" if none is explicitly set.
|
98
|
-
# @return [String]
|
99
|
-
#
|
100
|
-
attr_reader :charset
|
101
|
-
|
102
|
-
##
|
103
|
-
# The error message when parsing, or `nil` if there was no error message.
|
104
|
-
# @return [String,nil]
|
105
|
-
#
|
106
|
-
attr_reader :error_message
|
107
|
-
|
108
|
-
##
|
109
|
-
# An array of values for the given parameter name
|
110
|
-
# @param key [String]
|
111
|
-
# @return [Array<String>]
|
112
|
-
#
|
113
|
-
def param_values key
|
114
|
-
key = key.downcase
|
115
|
-
@params.inject([]) { |a, (k, v)| key == k ? a << v : a }
|
116
|
-
end
|
117
|
-
|
118
|
-
## @private
|
119
|
-
def == other
|
120
|
-
other.is_a?(ContentType) && canonical_string == other.canonical_string
|
121
|
-
end
|
122
|
-
alias eql? ==
|
123
|
-
|
124
|
-
## @private
|
125
|
-
def hash
|
126
|
-
canonical_string.hash
|
127
|
-
end
|
128
|
-
|
129
|
-
## @private
|
130
|
-
class ParseError < ::StandardError
|
131
|
-
end
|
132
|
-
|
133
|
-
private
|
134
|
-
|
135
|
-
def parse str
|
136
|
-
@media_type, str = consume_token str, downcase: true, error_message: "Failed to parse media type"
|
137
|
-
str = consume_special str, "/"
|
138
|
-
@subtype, str = consume_token str, downcase: true, error_message: "Failed to parse subtype"
|
139
|
-
@subtype_base, @subtype_format = @subtype.split "+", 2
|
140
|
-
until str.empty?
|
141
|
-
str = consume_special str, ";"
|
142
|
-
name, str = consume_token str, downcase: true, error_message: "Faled to parse attribute name"
|
143
|
-
str = consume_special str, "=", error_message: "Failed to find value for attribute #{name}"
|
144
|
-
val, str = consume_token_or_quoted str, error_message: "Failed to parse value for attribute #{name}"
|
145
|
-
@params << [name, val]
|
146
|
-
@charset = val if name == "charset"
|
147
|
-
end
|
148
|
-
rescue ParseError => e
|
149
|
-
@error_message = e.message
|
150
|
-
end
|
151
|
-
|
152
|
-
def consume_token str, downcase: false, error_message: nil
|
153
|
-
match = /^([\w!#\$%&'\*\+\.\^`\{\|\}-]+)(.*)$/.match str
|
154
|
-
raise ParseError, error_message || "Expected token" unless match
|
155
|
-
token = match[1]
|
156
|
-
token.downcase! if downcase
|
157
|
-
str = consume_comments match[2].strip
|
158
|
-
[token, str]
|
159
|
-
end
|
160
|
-
|
161
|
-
def consume_special str, expected, error_message: nil
|
162
|
-
raise ParseError, error_message || "Expected #{expected.inspect}" unless str.start_with? expected
|
163
|
-
consume_comments str[1..-1].strip
|
164
|
-
end
|
165
|
-
|
166
|
-
def consume_token_or_quoted str, error_message: nil
|
167
|
-
return consume_token str unless str.start_with? '"'
|
168
|
-
arr = []
|
169
|
-
index = 1
|
170
|
-
loop do
|
171
|
-
char = str[index]
|
172
|
-
case char
|
173
|
-
when nil
|
174
|
-
raise ParseError, error_message || "Quoted-string never finished"
|
175
|
-
when "\""
|
176
|
-
break
|
177
|
-
when "\\"
|
178
|
-
char = str[index + 1]
|
179
|
-
raise ParseError, error_message || "Quoted-string never finished" unless char
|
180
|
-
arr << char
|
181
|
-
index += 2
|
182
|
-
else
|
183
|
-
arr << char
|
184
|
-
index += 1
|
185
|
-
end
|
186
|
-
end
|
187
|
-
index += 1
|
188
|
-
str = consume_comments str[index..-1].strip
|
189
|
-
[arr.join, str]
|
190
|
-
end
|
191
|
-
|
192
|
-
def consume_comments str
|
193
|
-
return str unless str.start_with? "("
|
194
|
-
index = 1
|
195
|
-
loop do
|
196
|
-
char = str[index]
|
197
|
-
case char
|
198
|
-
when nil
|
199
|
-
raise ParseError, "Comment never finished"
|
200
|
-
when ")"
|
201
|
-
break
|
202
|
-
when "\\"
|
203
|
-
index += 2
|
204
|
-
when "("
|
205
|
-
str = consume_comments str[index..-1]
|
206
|
-
index = 0
|
207
|
-
else
|
208
|
-
index += 1
|
209
|
-
end
|
210
|
-
end
|
211
|
-
index += 1
|
212
|
-
consume_comments str[index..-1].strip
|
213
|
-
end
|
214
|
-
|
215
|
-
def maybe_quote str
|
216
|
-
return str if /^[\w!#\$%&'\*\+\.\^`\{\|\}-]+$/ =~ str
|
217
|
-
str = str.gsub("\\", "\\\\\\\\").gsub("\"", "\\\\\"")
|
218
|
-
"\"#{str}\""
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# Copyright 2020 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
module FunctionsFramework
|
16
|
-
module CloudEvents
|
17
|
-
##
|
18
|
-
# Base class for all CloudEvents errors.
|
19
|
-
#
|
20
|
-
class CloudEventsError < ::StandardError
|
21
|
-
end
|
22
|
-
|
23
|
-
##
|
24
|
-
# Errors indicating unsupported or incorrectly formatted HTTP content or
|
25
|
-
# headers.
|
26
|
-
#
|
27
|
-
class HttpContentError < CloudEventsError
|
28
|
-
end
|
29
|
-
|
30
|
-
##
|
31
|
-
# Errors indicating an unsupported or incorrect spec version.
|
32
|
-
#
|
33
|
-
class SpecVersionError < CloudEventsError
|
34
|
-
end
|
35
|
-
|
36
|
-
##
|
37
|
-
# Errors related to CloudEvent attributes.
|
38
|
-
#
|
39
|
-
class AttributeError < CloudEventsError
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# Copyright 2020 Google LLC
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require "date"
|
16
|
-
require "uri"
|
17
|
-
|
18
|
-
require "functions_framework/cloud_events/event/field_interpreter"
|
19
|
-
require "functions_framework/cloud_events/event/v0"
|
20
|
-
require "functions_framework/cloud_events/event/v1"
|
21
|
-
|
22
|
-
module FunctionsFramework
|
23
|
-
module CloudEvents
|
24
|
-
##
|
25
|
-
# An Event object represents a complete CloudEvent, including both data and
|
26
|
-
# context attributes. The following are true of all event objects:
|
27
|
-
#
|
28
|
-
# * Event classes are defined within this module. For example, events
|
29
|
-
# conforming to the CloudEvents 1.0 specification are of type
|
30
|
-
# {FunctionsFramework::CloudEvents::Event::V1}.
|
31
|
-
# * All event classes include this module, so you can use
|
32
|
-
# `is_a? FunctionsFramework::CloudEvents::Event` to test whether an
|
33
|
-
# object is an event.
|
34
|
-
# * All event objects are immutable. Data and atribute values can be
|
35
|
-
# retrieved but not modified. To "modify" an event, make a copy with
|
36
|
-
# the desired changes. Generally, event classes will provide a helper
|
37
|
-
# method for this purpose.
|
38
|
-
# * All event objects have a `spec_version` method that returns the
|
39
|
-
# version of the CloudEvents spec implemented by that event. (Other
|
40
|
-
# methods may be different, depending on the spec version.)
|
41
|
-
#
|
42
|
-
# To create an event, you may either:
|
43
|
-
#
|
44
|
-
# * Construct an instance of the event class directly, for example by
|
45
|
-
# calling {Event::V1.new} and passing a set of attributes.
|
46
|
-
# * Call {Event.create} and pass a spec version and a set of attributes.
|
47
|
-
# This will choose the appropriate event class based on the version.
|
48
|
-
# * Decode an event from another representation. For example, use
|
49
|
-
# {CloudEvents::JsonFormat} to decode an event from JSON, or use
|
50
|
-
# {CloudEvents::HttpBinding} to decode an event from an HTTP request.
|
51
|
-
#
|
52
|
-
# See https://github.com/cloudevents/spec for more information about
|
53
|
-
# CloudEvents. The documentation for the individual event classes
|
54
|
-
# {FunctionsFramework::CloudEvents::Event::V0} and
|
55
|
-
# {FunctionsFramework::CloudEvents::Event::V1} also include links to their
|
56
|
-
# respective specifications.
|
57
|
-
#
|
58
|
-
module Event
|
59
|
-
class << self
|
60
|
-
##
|
61
|
-
# Create a new cloud event object with the given version. Generally,
|
62
|
-
# you must also pass additional keyword arguments providing the event's
|
63
|
-
# data and attributes. For example, if you pass `1.0` as the
|
64
|
-
# `spec_version`, the remaining keyword arguments will be passed
|
65
|
-
# through to the {Event::V1.new} constructor.
|
66
|
-
#
|
67
|
-
# @param spec_version [String] The required `specversion` field.
|
68
|
-
# @param kwargs [keywords] Additional parameters for the event.
|
69
|
-
#
|
70
|
-
def create spec_version:, **kwargs
|
71
|
-
case spec_version
|
72
|
-
when "0.3"
|
73
|
-
V0.new spec_version: spec_version, **kwargs
|
74
|
-
when /^1(\.|$)/
|
75
|
-
V1.new spec_version: spec_version, **kwargs
|
76
|
-
else
|
77
|
-
raise SpecVersionError, "Unrecognized specversion: #{spec_version}"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
alias new create
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|