functions_framework 0.9.0 → 1.0.1
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 +4 -4
- data/CHANGELOG.md +36 -16
- data/README.md +2 -2
- data/docs/overview.md +2 -2
- data/docs/writing-functions.md +3 -3
- data/lib/functions_framework/legacy_event_converter.rb +65 -13
- data/lib/functions_framework/server.rb +20 -9
- data/lib/functions_framework/testing.rb +11 -4
- data/lib/functions_framework/version.rb +1 -1
- metadata +25 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eca52587c3a84a8fdfc58792bc87fb6908e5bbf1c65b265b12ccdc1eb943848d
|
|
4
|
+
data.tar.gz: 2226f0ba38007a22bbd046093a9d726aadcb25feaf18a7c6b24d780b5bdfc749
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '08d533e4c06749aeee4feb6988a775186a392a18b3c50a79bc93700b99c56ea6a16da7195c89afd44e4313770e620e3071a7d6207d568a3dd9aed4a9339da71d'
|
|
7
|
+
data.tar.gz: 1c145d4178b2d86bdde76c38340c3ea51f2b54bb9897304eb84ce1f3586467f7e205a4007d06a98dcfa8d78c5b8dbdb8afc919b8e0801bdf5c2420266e3b4dff
|
data/CHANGELOG.md
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 1.0.1 (2021-09-10)
|
|
4
|
+
|
|
5
|
+
* FIXED: Update legacy event conversion to set the correct types for firebase database events
|
|
6
|
+
|
|
7
|
+
## 1.0.0 (2021-07-07)
|
|
8
|
+
|
|
9
|
+
* Bumped the version to 1.0.
|
|
10
|
+
* Removed the "preview" notices for Google Cloud Functions since the Ruby runtime is now GA.
|
|
11
|
+
|
|
12
|
+
## v0.11.0 / 2021-06-28
|
|
13
|
+
|
|
14
|
+
* UPDATED: Update CloudEvents dependency to 0.5 to get fixes for JSON formatting cases
|
|
15
|
+
* FIXED: Updated Pub/Sub and Firebase event conversion logic to better align to Eventarc
|
|
16
|
+
|
|
17
|
+
## v0.10.0 / 2021-06-01
|
|
18
|
+
|
|
19
|
+
* ADDED: Support raw pubsub events sent by the pubsub emulator
|
|
20
|
+
* FIXED: Set proper response content-type charset when a function returns a string (plain text) or hash (JSON)
|
|
21
|
+
* FIXED: Properly handle conversion of non-ascii characters in legacy event strings
|
|
22
|
+
|
|
23
|
+
## v0.9.0 / 2021-03-18
|
|
4
24
|
|
|
5
25
|
* BREAKING CHANGE: Servers are configured as single-threaded in production by default, matching the current behavior of Google Cloud Functions.
|
|
6
26
|
* FIXED: Fixed conversion of Firebase events to CloudEvents to conform to the specs used by Cloud Functions and Cloud Run.
|
|
7
27
|
* FIXED: Fixed an error when reading a global set to a Minitest::Mock. This will make it easier to write tests that use mocks for global resources.
|
|
8
28
|
|
|
9
|
-
|
|
29
|
+
## v0.8.0 / 2021-03-02
|
|
10
30
|
|
|
11
31
|
* ADDED: Support for lazily-initialized globals
|
|
12
32
|
|
|
13
|
-
|
|
33
|
+
## v0.7.1 / 2021-01-26
|
|
14
34
|
|
|
15
35
|
* DOCS: Fixed several errors in the writing-functions doc samples
|
|
16
36
|
* DOCS: Updated documentation to note public release of GCF support
|
|
17
37
|
|
|
18
|
-
|
|
38
|
+
## v0.7.0 / 2020-09-25
|
|
19
39
|
|
|
20
40
|
* Now requires Ruby 2.5 or later.
|
|
21
41
|
* BREAKING CHANGE: Renamed "context" hash to "globals" and made it read-only for normal functions.
|
|
@@ -29,33 +49,33 @@
|
|
|
29
49
|
* DOCS: Expanded documentation on initialization, execution context, and shared resources.
|
|
30
50
|
* DEPRECATED: The functions-framework executable is deprecated. Use functions-framework-ruby instead.
|
|
31
51
|
|
|
32
|
-
|
|
52
|
+
## v0.6.0 / 2020-09-17
|
|
33
53
|
|
|
34
54
|
* ADDED: You can use the --version flag to print the framework version
|
|
35
55
|
* ADDED: You can use the --verify flag to verify that a given function is defined
|
|
36
56
|
* ADDED: You can now define blocks that are executed at server startup
|
|
37
57
|
|
|
38
|
-
|
|
58
|
+
## v0.5.2 / 2020-09-06
|
|
39
59
|
|
|
40
60
|
* FIXED: Use global $stderr rather than STDERR for logger
|
|
41
61
|
* DOCS: Fix instructions for deployment to Google Cloud Functions
|
|
42
62
|
|
|
43
|
-
|
|
63
|
+
## v0.5.1 / 2020-07-20
|
|
44
64
|
|
|
45
65
|
* Updated some documentation links. No functional changes.
|
|
46
66
|
|
|
47
|
-
|
|
67
|
+
## v0.5.0 / 2020-07-09
|
|
48
68
|
|
|
49
69
|
* Removed embedded CloudEvents classes and added the official CloudEvents SDK as a dependency. A `FunctionsFramework::CloudEvents` alias provides backward compatibility.
|
|
50
70
|
|
|
51
|
-
|
|
71
|
+
## v0.4.1 / 2020-07-08
|
|
52
72
|
|
|
53
73
|
* Fixed unsupported signal error on Windows.
|
|
54
74
|
* Fixed several edge case errors in legacy event conversion.
|
|
55
75
|
* Generated Content-Type headers now properly quote param values if needed.
|
|
56
76
|
* Minor documentation updates.
|
|
57
77
|
|
|
58
|
-
|
|
78
|
+
## v0.4.0 / 2020-06-29
|
|
59
79
|
|
|
60
80
|
* Dropped the legacy and largely unsupported `:event` function type. All event functions should be of type `:cloud_event`.
|
|
61
81
|
* Define the object context for function execution, and include an extensible context helper.
|
|
@@ -66,21 +86,21 @@
|
|
|
66
86
|
* Removed redundant `_string` accessors from event classes since raw forms are already available via `[]`.
|
|
67
87
|
* A variety of corrections to event-related class documentation.
|
|
68
88
|
|
|
69
|
-
|
|
89
|
+
## v0.3.1 / 2020-06-27
|
|
70
90
|
|
|
71
91
|
* Fixed crash when using "return" directly in a function block.
|
|
72
92
|
* Added a more flexible request generation helper in the testing module.
|
|
73
93
|
* Fixed several typos in the documentation.
|
|
74
94
|
|
|
75
|
-
|
|
95
|
+
## v0.3.0 / 2020-06-26
|
|
76
96
|
|
|
77
97
|
* Updated the CloudEvent data format for converted pubsub events to conform to Cloud Run's conversion.
|
|
78
98
|
|
|
79
|
-
|
|
99
|
+
## v0.2.1 / 2020-06-25
|
|
80
100
|
|
|
81
101
|
* The `--signature-type` check recognizes the legacy `event` type for `:cloud_event` functions.
|
|
82
102
|
|
|
83
|
-
|
|
103
|
+
## v0.2.0 / 2020-06-24
|
|
84
104
|
|
|
85
105
|
Significant changes:
|
|
86
106
|
|
|
@@ -99,11 +119,11 @@ Minor changes:
|
|
|
99
119
|
* Renamed a few undocumented environment variables, and added support for a logging level environment variable. All CLI flags now have associated environment variables.
|
|
100
120
|
* Several fixes to the example code, and added a new Sinatra example.
|
|
101
121
|
|
|
102
|
-
|
|
122
|
+
## v0.1.1 / 2020-02-27
|
|
103
123
|
|
|
104
124
|
* Server returns 404 when receiving a /favicon.ico or /robots.txt request.
|
|
105
125
|
* Correct a rack constant name in Testing#make_post_request
|
|
106
126
|
|
|
107
|
-
|
|
127
|
+
## v0.1.0 / 2020-01-30
|
|
108
128
|
|
|
109
129
|
* Initial release
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@ An open source framework for writing lightweight, portable Ruby functions that
|
|
|
4
4
|
run in a serverless environment. Functions written to this Framework will run
|
|
5
5
|
in many different environments, including:
|
|
6
6
|
|
|
7
|
-
* [Google Cloud Functions](https://cloud.google.com/functions)
|
|
7
|
+
* [Google Cloud Functions](https://cloud.google.com/functions)
|
|
8
8
|
* [Google Cloud Run](https://cloud.google.com/run)
|
|
9
9
|
* Any other [Knative](https://github.com/knative)-based environment
|
|
10
10
|
* Your local development machine
|
|
@@ -60,7 +60,7 @@ Create a `Gemfile` listing the Functions Framework as a dependency:
|
|
|
60
60
|
```ruby
|
|
61
61
|
# Gemfile
|
|
62
62
|
source "https://rubygems.org"
|
|
63
|
-
gem "functions_framework", "~> 0
|
|
63
|
+
gem "functions_framework", "~> 1.0"
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
Create a file called `app.rb` and include the following code. This defines a
|
data/docs/overview.md
CHANGED
|
@@ -8,7 +8,7 @@ The Functions Framework is an open source framework for writing lightweight,
|
|
|
8
8
|
portable Ruby functions that run in a serverless environment. Functions written
|
|
9
9
|
to this Framework will run in many different environments, including:
|
|
10
10
|
|
|
11
|
-
* [Google Cloud Functions](https://cloud.google.com/functions)
|
|
11
|
+
* [Google Cloud Functions](https://cloud.google.com/functions)
|
|
12
12
|
* [Google Cloud Run](https://cloud.google.com/run)
|
|
13
13
|
* Any other [Knative](https://github.com/knative)-based environment
|
|
14
14
|
* Your local development machine
|
|
@@ -64,7 +64,7 @@ Create a `Gemfile` listing the Functions Framework as a dependency:
|
|
|
64
64
|
```ruby
|
|
65
65
|
# Gemfile
|
|
66
66
|
source "https://rubygems.org"
|
|
67
|
-
gem "functions_framework", "~> 0
|
|
67
|
+
gem "functions_framework", "~> 1.0"
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Create a file called `app.rb` and include the following code. This defines a
|
data/docs/writing-functions.md
CHANGED
|
@@ -111,7 +111,7 @@ dependency on Sinatra in your `Gemfile`:
|
|
|
111
111
|
|
|
112
112
|
```ruby
|
|
113
113
|
source "https://rubygems.org"
|
|
114
|
-
gem "functions_framework", "~> 0
|
|
114
|
+
gem "functions_framework", "~> 1.0"
|
|
115
115
|
gem "sinatra", "~> 2.0"
|
|
116
116
|
```
|
|
117
117
|
|
|
@@ -152,7 +152,7 @@ information about it:
|
|
|
152
152
|
require "functions_framework"
|
|
153
153
|
|
|
154
154
|
FunctionsFramework.cloud_event "hello" do |event|
|
|
155
|
-
|
|
155
|
+
logger.info "I received an event of type #{event.type}!"
|
|
156
156
|
end
|
|
157
157
|
```
|
|
158
158
|
|
|
@@ -470,7 +470,7 @@ Following is a typical layout for a Functions Framework based project.
|
|
|
470
470
|
```ruby
|
|
471
471
|
# Gemfile
|
|
472
472
|
source "https://rubygems.org"
|
|
473
|
-
gem "functions_framework", "~> 0
|
|
473
|
+
gem "functions_framework", "~> 1.0"
|
|
474
474
|
```
|
|
475
475
|
|
|
476
476
|
```ruby
|
|
@@ -27,10 +27,11 @@ module FunctionsFramework
|
|
|
27
27
|
# @return [nil] if the event format was not recognized.
|
|
28
28
|
#
|
|
29
29
|
def decode_rack_env env
|
|
30
|
-
content_type = ::CloudEvents::ContentType.new env["CONTENT_TYPE"]
|
|
30
|
+
content_type = ::CloudEvents::ContentType.new env["CONTENT_TYPE"], default_charset: "utf-8"
|
|
31
31
|
return nil unless content_type.media_type == "application" && content_type.subtype_base == "json"
|
|
32
32
|
input = read_input_json env["rack.input"], content_type.charset
|
|
33
33
|
return nil unless input
|
|
34
|
+
input = convert_raw_pubsub_event input, env if raw_pubsub_payload? input
|
|
34
35
|
context = normalized_context input
|
|
35
36
|
return nil unless context
|
|
36
37
|
construct_cloud_event context, input["data"]
|
|
@@ -40,7 +41,7 @@ module FunctionsFramework
|
|
|
40
41
|
|
|
41
42
|
def read_input_json input, charset
|
|
42
43
|
input = input.read if input.respond_to? :read
|
|
43
|
-
input
|
|
44
|
+
input.force_encoding charset if charset
|
|
44
45
|
content = ::JSON.parse input
|
|
45
46
|
content = nil unless content.is_a? ::Hash
|
|
46
47
|
content
|
|
@@ -48,14 +49,46 @@ module FunctionsFramework
|
|
|
48
49
|
nil
|
|
49
50
|
end
|
|
50
51
|
|
|
52
|
+
def raw_pubsub_payload? input
|
|
53
|
+
return false if input.include?("context") || !input.include?("subscription")
|
|
54
|
+
message = input["message"]
|
|
55
|
+
message.is_a?(::Hash) && message.include?("data") && message.include?("messageId")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def convert_raw_pubsub_event input, env
|
|
59
|
+
message = input["message"]
|
|
60
|
+
path = "#{env['SCRIPT_NAME']}#{env['PATH_INFO']}"
|
|
61
|
+
path_match = %r{projects/[^/?]+/topics/[^/?]+}.match path
|
|
62
|
+
topic = path_match ? path_match[0] : "UNKNOWN_PUBSUB_TOPIC"
|
|
63
|
+
timestamp = message["publishTime"] || ::Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%6NZ")
|
|
64
|
+
{
|
|
65
|
+
"context" => {
|
|
66
|
+
"eventId" => message["messageId"],
|
|
67
|
+
"timestamp" => timestamp,
|
|
68
|
+
"eventType" => "google.pubsub.topic.publish",
|
|
69
|
+
"resource" => {
|
|
70
|
+
"service" => "pubsub.googleapis.com",
|
|
71
|
+
"type" => "type.googleapis.com/google.pubsub.v1.PubsubMessage",
|
|
72
|
+
"name" => topic
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"data" => {
|
|
76
|
+
"@type" => "type.googleapis.com/google.pubsub.v1.PubsubMessage",
|
|
77
|
+
"data" => message["data"],
|
|
78
|
+
"attributes" => message["attributes"]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
end
|
|
82
|
+
|
|
51
83
|
def normalized_context input
|
|
52
84
|
id = normalized_context_field input, "eventId"
|
|
53
85
|
timestamp = normalized_context_field input, "timestamp"
|
|
54
86
|
type = normalized_context_field input, "eventType"
|
|
87
|
+
domain = normalized_context_field input, "domain"
|
|
55
88
|
service, resource = analyze_resource normalized_context_field input, "resource"
|
|
56
89
|
service ||= service_from_type type
|
|
57
90
|
return nil unless id && timestamp && type && service && resource
|
|
58
|
-
{ id: id, timestamp: timestamp, type: type, service: service, resource: resource }
|
|
91
|
+
{ id: id, timestamp: timestamp, type: type, service: service, resource: resource, domain: domain }
|
|
59
92
|
end
|
|
60
93
|
|
|
61
94
|
def normalized_context_field input, field
|
|
@@ -82,10 +115,10 @@ module FunctionsFramework
|
|
|
82
115
|
end
|
|
83
116
|
|
|
84
117
|
def construct_cloud_event context, data
|
|
85
|
-
source, subject = convert_source context[:service], context[:resource]
|
|
118
|
+
source, subject = convert_source context[:service], context[:resource], context[:domain]
|
|
86
119
|
type = LEGACY_TYPE_TO_CE_TYPE[context[:type]]
|
|
87
120
|
return nil unless type && source
|
|
88
|
-
ce_data, data_subject = convert_data context
|
|
121
|
+
ce_data, data_subject = convert_data context, data
|
|
89
122
|
content_type = "application/json"
|
|
90
123
|
::CloudEvents::Event.new id: context[:id],
|
|
91
124
|
source: source,
|
|
@@ -97,17 +130,36 @@ module FunctionsFramework
|
|
|
97
130
|
time: context[:timestamp]
|
|
98
131
|
end
|
|
99
132
|
|
|
100
|
-
def convert_source service, resource
|
|
133
|
+
def convert_source service, resource, domain
|
|
101
134
|
return ["//#{service}/#{resource}", nil] unless CE_SERVICE_TO_RESOURCE_RE.key? service
|
|
102
135
|
|
|
103
136
|
match = CE_SERVICE_TO_RESOURCE_RE[service].match resource
|
|
104
137
|
return [nil, nil] unless match
|
|
105
|
-
|
|
138
|
+
resource_fragment = match[1]
|
|
139
|
+
subject = match[2]
|
|
140
|
+
|
|
141
|
+
if service == "firebasedatabase.googleapis.com"
|
|
142
|
+
location =
|
|
143
|
+
case domain
|
|
144
|
+
when "firebaseio.com"
|
|
145
|
+
"us-central1"
|
|
146
|
+
when /^([\w-]+)\./
|
|
147
|
+
Regexp.last_match[1]
|
|
148
|
+
else
|
|
149
|
+
return [nil, nil]
|
|
150
|
+
end
|
|
151
|
+
["//#{service}/projects/_/locations/#{location}/#{resource_fragment}", subject]
|
|
152
|
+
else
|
|
153
|
+
["//#{service}/#{resource_fragment}", subject]
|
|
154
|
+
end
|
|
106
155
|
end
|
|
107
156
|
|
|
108
|
-
def convert_data
|
|
157
|
+
def convert_data context, data
|
|
158
|
+
service = context[:service]
|
|
109
159
|
case service
|
|
110
160
|
when "pubsub.googleapis.com"
|
|
161
|
+
data["messageId"] = context[:id]
|
|
162
|
+
data["publishTime"] = context[:timestamp]
|
|
111
163
|
[{ "message" => data }, nil]
|
|
112
164
|
when "firebaseauth.googleapis.com"
|
|
113
165
|
if data.key? "metadata"
|
|
@@ -148,16 +200,16 @@ module FunctionsFramework
|
|
|
148
200
|
"providers/firebase.auth/eventTypes/user.create" => "google.firebase.auth.user.v1.created",
|
|
149
201
|
"providers/firebase.auth/eventTypes/user.delete" => "google.firebase.auth.user.v1.deleted",
|
|
150
202
|
"providers/google.firebase.analytics/eventTypes/event.log" => "google.firebase.analytics.log.v1.written",
|
|
151
|
-
"providers/google.firebase.database/eventTypes/ref.create" => "google.firebase.database.
|
|
152
|
-
"providers/google.firebase.database/eventTypes/ref.write" => "google.firebase.database.
|
|
153
|
-
"providers/google.firebase.database/eventTypes/ref.update" => "google.firebase.database.
|
|
154
|
-
"providers/google.firebase.database/eventTypes/ref.delete" => "google.firebase.database.
|
|
203
|
+
"providers/google.firebase.database/eventTypes/ref.create" => "google.firebase.database.ref.v1.created",
|
|
204
|
+
"providers/google.firebase.database/eventTypes/ref.write" => "google.firebase.database.ref.v1.written",
|
|
205
|
+
"providers/google.firebase.database/eventTypes/ref.update" => "google.firebase.database.ref.v1.updated",
|
|
206
|
+
"providers/google.firebase.database/eventTypes/ref.delete" => "google.firebase.database.ref.v1.deleted",
|
|
155
207
|
"providers/cloud.storage/eventTypes/object.change" => "google.cloud.storage.object.v1.finalized"
|
|
156
208
|
}.freeze
|
|
157
209
|
|
|
158
210
|
CE_SERVICE_TO_RESOURCE_RE = {
|
|
159
211
|
"firebase.googleapis.com" => %r{^(projects/[^/]+)/(events/[^/]+)$},
|
|
160
|
-
"firebasedatabase.googleapis.com" => %r{^
|
|
212
|
+
"firebasedatabase.googleapis.com" => %r{^projects/_/(instances/[^/]+)/(refs/.+)$},
|
|
161
213
|
"firestore.googleapis.com" => %r{^(projects/[^/]+/databases/\(default\))/(documents/.+)$},
|
|
162
214
|
"storage.googleapis.com" => %r{^(projects/[^/]+/buckets/[^/]+)/([^#]+)(?:#.*)?$}
|
|
163
215
|
}.freeze
|
|
@@ -346,9 +346,9 @@ module FunctionsFramework
|
|
|
346
346
|
when ::Rack::Response
|
|
347
347
|
response.finish
|
|
348
348
|
when ::String
|
|
349
|
-
string_response response,
|
|
349
|
+
string_response response, 200
|
|
350
350
|
when ::Hash
|
|
351
|
-
string_response ::JSON.dump(response), "application/json"
|
|
351
|
+
string_response ::JSON.dump(response), 200, content_type: "application/json"
|
|
352
352
|
when ::CloudEvents::CloudEventsError
|
|
353
353
|
cloud_events_error_response response
|
|
354
354
|
when ::StandardError
|
|
@@ -359,10 +359,17 @@ module FunctionsFramework
|
|
|
359
359
|
end
|
|
360
360
|
|
|
361
361
|
def notfound_response
|
|
362
|
-
string_response "Not found",
|
|
362
|
+
string_response "Not found", 404
|
|
363
363
|
end
|
|
364
364
|
|
|
365
|
-
def string_response string,
|
|
365
|
+
def string_response string, status, content_type: nil
|
|
366
|
+
string.force_encoding ::Encoding::ASCII_8BIT unless string.valid_encoding?
|
|
367
|
+
if string.encoding == ::Encoding::ASCII_8BIT
|
|
368
|
+
content_type ||= "application/octet-stream"
|
|
369
|
+
else
|
|
370
|
+
content_type ||= "text/plain"
|
|
371
|
+
content_type = "#{content_type}; charset=#{string.encoding.name.downcase}"
|
|
372
|
+
end
|
|
366
373
|
headers = {
|
|
367
374
|
"Content-Type" => content_type,
|
|
368
375
|
"Content-Length" => string.bytesize
|
|
@@ -372,13 +379,13 @@ module FunctionsFramework
|
|
|
372
379
|
|
|
373
380
|
def cloud_events_error_response error
|
|
374
381
|
@config.logger.warn error
|
|
375
|
-
string_response "#{error.class}: #{error.message}",
|
|
382
|
+
string_response "#{error.class}: #{error.message}", 400
|
|
376
383
|
end
|
|
377
384
|
|
|
378
385
|
def error_response message
|
|
379
386
|
@config.logger.error message
|
|
380
387
|
message = "Unexpected internal error" unless @config.show_error_details?
|
|
381
|
-
string_response message,
|
|
388
|
+
string_response message, 500
|
|
382
389
|
end
|
|
383
390
|
end
|
|
384
391
|
|
|
@@ -424,7 +431,7 @@ module FunctionsFramework
|
|
|
424
431
|
when ::CloudEvents::Event
|
|
425
432
|
handle_cloud_event event, logger
|
|
426
433
|
when ::Array
|
|
427
|
-
::CloudEvents::
|
|
434
|
+
::CloudEvents::CloudEventsError.new "Batched CloudEvents are not supported"
|
|
428
435
|
when ::CloudEvents::CloudEventsError
|
|
429
436
|
event
|
|
430
437
|
else
|
|
@@ -436,9 +443,13 @@ module FunctionsFramework
|
|
|
436
443
|
private
|
|
437
444
|
|
|
438
445
|
def decode_event env
|
|
439
|
-
|
|
446
|
+
begin
|
|
447
|
+
@cloud_events.decode_event env
|
|
448
|
+
rescue ::CloudEvents::NotCloudEventError
|
|
449
|
+
env["rack.input"].rewind rescue nil
|
|
440
450
|
@legacy_events.decode_rack_env(env) ||
|
|
441
|
-
|
|
451
|
+
raise(::CloudEvents::CloudEventsError, "Unrecognized event format")
|
|
452
|
+
end
|
|
442
453
|
rescue ::CloudEvents::CloudEventsError => e
|
|
443
454
|
e
|
|
444
455
|
end
|
|
@@ -330,20 +330,27 @@ module FunctionsFramework
|
|
|
330
330
|
when ::Array
|
|
331
331
|
::Rack::Response.new response[2], response[0], response[1]
|
|
332
332
|
when ::String
|
|
333
|
-
string_response response,
|
|
333
|
+
string_response response, 200
|
|
334
334
|
when ::Hash
|
|
335
335
|
json = ::JSON.dump response
|
|
336
|
-
string_response json, "application/json"
|
|
336
|
+
string_response json, 200, content_type: "application/json"
|
|
337
337
|
when ::StandardError
|
|
338
338
|
message = "#{response.class}: #{response.message}\n#{response.backtrace}\n"
|
|
339
|
-
string_response message,
|
|
339
|
+
string_response message, 500
|
|
340
340
|
else
|
|
341
341
|
raise "Unexpected response type: #{response.inspect}"
|
|
342
342
|
end
|
|
343
343
|
end
|
|
344
344
|
|
|
345
345
|
## @private
|
|
346
|
-
def string_response string,
|
|
346
|
+
def string_response string, status, content_type: nil
|
|
347
|
+
string.force_encoding ::Encoding::ASCII_8BIT unless string.valid_encoding?
|
|
348
|
+
if string.encoding == ::Encoding::ASCII_8BIT
|
|
349
|
+
content_type ||= "application/octet-stream"
|
|
350
|
+
else
|
|
351
|
+
content_type ||= "text/plain"
|
|
352
|
+
content_type = "#{content_type}; charset=#{string.encoding.name.downcase}"
|
|
353
|
+
end
|
|
347
354
|
headers = {
|
|
348
355
|
"Content-Type" => content_type,
|
|
349
356
|
"Content-Length" => string.bytesize
|
metadata
CHANGED
|
@@ -1,43 +1,55 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: functions_framework
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Azuma
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cloud_events
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.6.0
|
|
20
|
+
- - "<"
|
|
18
21
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
22
|
+
version: 2.a
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
|
-
- - "
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.6.0
|
|
30
|
+
- - "<"
|
|
25
31
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
32
|
+
version: 2.a
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
34
|
name: puma
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
|
31
|
-
- - "
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 4.3.0
|
|
40
|
+
- - "<"
|
|
32
41
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
42
|
+
version: 6.a
|
|
34
43
|
type: :runtime
|
|
35
44
|
prerelease: false
|
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
46
|
requirements:
|
|
38
|
-
- - "
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 4.3.0
|
|
50
|
+
- - "<"
|
|
39
51
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
52
|
+
version: 6.a
|
|
41
53
|
- !ruby/object:Gem::Dependency
|
|
42
54
|
name: rack
|
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -87,10 +99,10 @@ homepage: https://github.com/GoogleCloudPlatform/functions-framework-ruby
|
|
|
87
99
|
licenses:
|
|
88
100
|
- Apache-2.0
|
|
89
101
|
metadata:
|
|
90
|
-
changelog_uri: https://googlecloudplatform.github.io/functions-framework-ruby/
|
|
102
|
+
changelog_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v1.0.1/file.CHANGELOG.html
|
|
91
103
|
source_code_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby
|
|
92
104
|
bug_tracker_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby/issues
|
|
93
|
-
documentation_uri: https://googlecloudplatform.github.io/functions-framework-ruby/
|
|
105
|
+
documentation_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v1.0.1
|
|
94
106
|
post_install_message:
|
|
95
107
|
rdoc_options: []
|
|
96
108
|
require_paths:
|
|
@@ -106,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
106
118
|
- !ruby/object:Gem::Version
|
|
107
119
|
version: '0'
|
|
108
120
|
requirements: []
|
|
109
|
-
rubygems_version: 3.2.
|
|
121
|
+
rubygems_version: 3.2.17
|
|
110
122
|
signing_key:
|
|
111
123
|
specification_version: 4
|
|
112
124
|
summary: Functions Framework for Ruby
|