functions_framework 0.10.0 → 1.1.0
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 +38 -17
- data/README.md +2 -2
- data/RELEASING.md +78 -0
- data/docs/overview.md +2 -2
- data/docs/writing-functions.md +3 -3
- data/lib/functions_framework/legacy_event_converter.rb +31 -11
- data/lib/functions_framework/server.rb +27 -8
- data/lib/functions_framework/testing.rb +2 -1
- data/lib/functions_framework/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7181bfabab004b16d032f16f2598fb80027422481c9ce5ee3c048f5331422d10
|
|
4
|
+
data.tar.gz: 73344235c945308d98a44bb7536bbc32d6fdb5b58ed0379696a09becdf2be016
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4edeb7e9b2fbd5ab9ee3d28f442336363c32ab2faf928b81738b5c82a3c6b16b8e9dd0983417427db4145930eaf12b1f0d709e638999edba01c55c3b5cbdcf97
|
|
7
|
+
data.tar.gz: ffe0f772f40ff8d8c1a74e8cf6f2e5adfa663513290f88b4c9ad119dfb91b7b0caa3887337bad1736eb556b8d5312b376606b266602069db32fd75973867fa06
|
data/CHANGELOG.md
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 1.1.0 (2022-01-17)
|
|
4
|
+
|
|
5
|
+
* Increase default max thread pool size to 8.
|
|
6
|
+
* Return 204 when a GET request is sent to an event function, to support health checks.
|
|
7
|
+
* Flush stdout and stderr streams at the end of each request.
|
|
8
|
+
* Format the error backtrace.
|
|
9
|
+
|
|
10
|
+
## 1.0.1 (2021-09-10)
|
|
11
|
+
|
|
12
|
+
* FIXED: Update legacy event conversion to set the correct types for firebase database events
|
|
13
|
+
|
|
14
|
+
## 1.0.0 (2021-07-07)
|
|
15
|
+
|
|
16
|
+
* Bumped the version to 1.0.
|
|
17
|
+
* Removed the "preview" notices for Google Cloud Functions since the Ruby runtime is now GA.
|
|
18
|
+
|
|
19
|
+
## v0.11.0 / 2021-06-28
|
|
20
|
+
|
|
21
|
+
* UPDATED: Update CloudEvents dependency to 0.5 to get fixes for JSON formatting cases
|
|
22
|
+
* FIXED: Updated Pub/Sub and Firebase event conversion logic to better align to Eventarc
|
|
23
|
+
|
|
24
|
+
## v0.10.0 / 2021-06-01
|
|
4
25
|
|
|
5
26
|
* ADDED: Support raw pubsub events sent by the pubsub emulator
|
|
6
27
|
* FIXED: Set proper response content-type charset when a function returns a string (plain text) or hash (JSON)
|
|
7
28
|
* FIXED: Properly handle conversion of non-ascii characters in legacy event strings
|
|
8
29
|
|
|
9
|
-
|
|
30
|
+
## v0.9.0 / 2021-03-18
|
|
10
31
|
|
|
11
32
|
* BREAKING CHANGE: Servers are configured as single-threaded in production by default, matching the current behavior of Google Cloud Functions.
|
|
12
33
|
* FIXED: Fixed conversion of Firebase events to CloudEvents to conform to the specs used by Cloud Functions and Cloud Run.
|
|
13
34
|
* 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.
|
|
14
35
|
|
|
15
|
-
|
|
36
|
+
## v0.8.0 / 2021-03-02
|
|
16
37
|
|
|
17
38
|
* ADDED: Support for lazily-initialized globals
|
|
18
39
|
|
|
19
|
-
|
|
40
|
+
## v0.7.1 / 2021-01-26
|
|
20
41
|
|
|
21
42
|
* DOCS: Fixed several errors in the writing-functions doc samples
|
|
22
43
|
* DOCS: Updated documentation to note public release of GCF support
|
|
23
44
|
|
|
24
|
-
|
|
45
|
+
## v0.7.0 / 2020-09-25
|
|
25
46
|
|
|
26
47
|
* Now requires Ruby 2.5 or later.
|
|
27
48
|
* BREAKING CHANGE: Renamed "context" hash to "globals" and made it read-only for normal functions.
|
|
@@ -35,33 +56,33 @@
|
|
|
35
56
|
* DOCS: Expanded documentation on initialization, execution context, and shared resources.
|
|
36
57
|
* DEPRECATED: The functions-framework executable is deprecated. Use functions-framework-ruby instead.
|
|
37
58
|
|
|
38
|
-
|
|
59
|
+
## v0.6.0 / 2020-09-17
|
|
39
60
|
|
|
40
61
|
* ADDED: You can use the --version flag to print the framework version
|
|
41
62
|
* ADDED: You can use the --verify flag to verify that a given function is defined
|
|
42
63
|
* ADDED: You can now define blocks that are executed at server startup
|
|
43
64
|
|
|
44
|
-
|
|
65
|
+
## v0.5.2 / 2020-09-06
|
|
45
66
|
|
|
46
67
|
* FIXED: Use global $stderr rather than STDERR for logger
|
|
47
68
|
* DOCS: Fix instructions for deployment to Google Cloud Functions
|
|
48
69
|
|
|
49
|
-
|
|
70
|
+
## v0.5.1 / 2020-07-20
|
|
50
71
|
|
|
51
72
|
* Updated some documentation links. No functional changes.
|
|
52
73
|
|
|
53
|
-
|
|
74
|
+
## v0.5.0 / 2020-07-09
|
|
54
75
|
|
|
55
76
|
* Removed embedded CloudEvents classes and added the official CloudEvents SDK as a dependency. A `FunctionsFramework::CloudEvents` alias provides backward compatibility.
|
|
56
77
|
|
|
57
|
-
|
|
78
|
+
## v0.4.1 / 2020-07-08
|
|
58
79
|
|
|
59
80
|
* Fixed unsupported signal error on Windows.
|
|
60
81
|
* Fixed several edge case errors in legacy event conversion.
|
|
61
82
|
* Generated Content-Type headers now properly quote param values if needed.
|
|
62
83
|
* Minor documentation updates.
|
|
63
84
|
|
|
64
|
-
|
|
85
|
+
## v0.4.0 / 2020-06-29
|
|
65
86
|
|
|
66
87
|
* Dropped the legacy and largely unsupported `:event` function type. All event functions should be of type `:cloud_event`.
|
|
67
88
|
* Define the object context for function execution, and include an extensible context helper.
|
|
@@ -72,21 +93,21 @@
|
|
|
72
93
|
* Removed redundant `_string` accessors from event classes since raw forms are already available via `[]`.
|
|
73
94
|
* A variety of corrections to event-related class documentation.
|
|
74
95
|
|
|
75
|
-
|
|
96
|
+
## v0.3.1 / 2020-06-27
|
|
76
97
|
|
|
77
98
|
* Fixed crash when using "return" directly in a function block.
|
|
78
99
|
* Added a more flexible request generation helper in the testing module.
|
|
79
100
|
* Fixed several typos in the documentation.
|
|
80
101
|
|
|
81
|
-
|
|
102
|
+
## v0.3.0 / 2020-06-26
|
|
82
103
|
|
|
83
104
|
* Updated the CloudEvent data format for converted pubsub events to conform to Cloud Run's conversion.
|
|
84
105
|
|
|
85
|
-
|
|
106
|
+
## v0.2.1 / 2020-06-25
|
|
86
107
|
|
|
87
108
|
* The `--signature-type` check recognizes the legacy `event` type for `:cloud_event` functions.
|
|
88
109
|
|
|
89
|
-
|
|
110
|
+
## v0.2.0 / 2020-06-24
|
|
90
111
|
|
|
91
112
|
Significant changes:
|
|
92
113
|
|
|
@@ -105,11 +126,11 @@ Minor changes:
|
|
|
105
126
|
* Renamed a few undocumented environment variables, and added support for a logging level environment variable. All CLI flags now have associated environment variables.
|
|
106
127
|
* Several fixes to the example code, and added a new Sinatra example.
|
|
107
128
|
|
|
108
|
-
|
|
129
|
+
## v0.1.1 / 2020-02-27
|
|
109
130
|
|
|
110
131
|
* Server returns 404 when receiving a /favicon.ico or /robots.txt request.
|
|
111
132
|
* Correct a rack constant name in Testing#make_post_request
|
|
112
133
|
|
|
113
|
-
|
|
134
|
+
## v0.1.0 / 2020-01-30
|
|
114
135
|
|
|
115
136
|
* 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/RELEASING.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Releasing
|
|
2
|
+
|
|
3
|
+
Releases are performed using tooling developed by Google's GitHub Automation
|
|
4
|
+
team, and are partially automated, but can be controlled by maintainers.
|
|
5
|
+
|
|
6
|
+
## The automated release pipeline
|
|
7
|
+
|
|
8
|
+
Whenever a commit is pushed to the main branch with a
|
|
9
|
+
[Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0/) message,
|
|
10
|
+
the automated release pipeline will trigger.
|
|
11
|
+
|
|
12
|
+
### Release pull requests
|
|
13
|
+
|
|
14
|
+
The [release-please](https://github.com/googleapis/release-please) bot watches
|
|
15
|
+
for commits that indicate a semantic change, normally either `feat:` or `fix:`,
|
|
16
|
+
or any commit that includes a breaking change. When new commits are pushed,
|
|
17
|
+
release-please will propose a new release whose version is based on the semver
|
|
18
|
+
implication of the change: a patch release for a `fix:`, a minor release for a
|
|
19
|
+
`feat:`, or a major release for a breaking change. This will appear in the form
|
|
20
|
+
of a pull request, which will include the proposed new version, and a changelog
|
|
21
|
+
entry.
|
|
22
|
+
|
|
23
|
+
A maintainer can either:
|
|
24
|
+
|
|
25
|
+
* Close the pull request to defer the release until more changes have been
|
|
26
|
+
committed.
|
|
27
|
+
* Accept the release by merging the pull request, possibly after modifying the
|
|
28
|
+
changelog.
|
|
29
|
+
|
|
30
|
+
Do NOT modify the version in the pull request. If you want to release a
|
|
31
|
+
different version, see the next section on proposing releases manually.
|
|
32
|
+
|
|
33
|
+
When merging a release pull request, make sure the `autorelease: pending` label
|
|
34
|
+
remains applied. This is important for correct operation of the rest of the
|
|
35
|
+
release pipeline.
|
|
36
|
+
|
|
37
|
+
### Release scripts
|
|
38
|
+
|
|
39
|
+
After a release pull request is merged, another bot will trigger the rest of
|
|
40
|
+
the release pipeline. This bot runs every 15 minutes, so this process may be
|
|
41
|
+
delayed a few minutes. Once it runs, it will do the following automatically:
|
|
42
|
+
|
|
43
|
+
* Tag the release and create a GitHub release. This takes place in a kokoro
|
|
44
|
+
(internal Google) job. Once finished, it will switch the tag from
|
|
45
|
+
`autorelease: pending` to `autorelease: tagged`. If it seems to be
|
|
46
|
+
malfunctioning, you can find logs on the internal fusion dashboard under the
|
|
47
|
+
job `cloud-devrel/client-libraries/autorelease/tag`.
|
|
48
|
+
* Build and push the gem to Rubygems, and build and push the documentation to
|
|
49
|
+
googleapis.dev. This takes place in a second kokoro job. Once finished, it
|
|
50
|
+
will switch the tag from `autorelease: tagged` to `autorelease: published`.
|
|
51
|
+
If this job seems to be malfunctioning, find the logs under the kokoro job
|
|
52
|
+
`cloud-devrel/ruby/functions-framework-ruby/release`.
|
|
53
|
+
|
|
54
|
+
## Manually proposing a release
|
|
55
|
+
|
|
56
|
+
If you want to propose a release out-of-band or customize the version number to
|
|
57
|
+
use, you can use a command line tool to create a release pull request.
|
|
58
|
+
|
|
59
|
+
### Prerequisites
|
|
60
|
+
|
|
61
|
+
You need to install:
|
|
62
|
+
|
|
63
|
+
* git version 2.22 or later
|
|
64
|
+
* The gh cli (https://cli.github.com/)
|
|
65
|
+
* The release-please npm module
|
|
66
|
+
* The toys rubygem
|
|
67
|
+
|
|
68
|
+
### Running the release proposal script
|
|
69
|
+
|
|
70
|
+
Once the prerequisites are installed, run:
|
|
71
|
+
|
|
72
|
+
toys release please functions_framework:1.2.3
|
|
73
|
+
|
|
74
|
+
(Replace `1.2.3` with the version to release.)
|
|
75
|
+
|
|
76
|
+
This will open an appropriate release pull request. Then you can merge it
|
|
77
|
+
(possibly after modifying the changelog) and the release pipeline will proceed
|
|
78
|
+
as described above.
|
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
|
|
@@ -84,10 +84,11 @@ module FunctionsFramework
|
|
|
84
84
|
id = normalized_context_field input, "eventId"
|
|
85
85
|
timestamp = normalized_context_field input, "timestamp"
|
|
86
86
|
type = normalized_context_field input, "eventType"
|
|
87
|
+
domain = normalized_context_field input, "domain"
|
|
87
88
|
service, resource = analyze_resource normalized_context_field input, "resource"
|
|
88
89
|
service ||= service_from_type type
|
|
89
90
|
return nil unless id && timestamp && type && service && resource
|
|
90
|
-
{ id: id, timestamp: timestamp, type: type, service: service, resource: resource }
|
|
91
|
+
{ id: id, timestamp: timestamp, type: type, service: service, resource: resource, domain: domain }
|
|
91
92
|
end
|
|
92
93
|
|
|
93
94
|
def normalized_context_field input, field
|
|
@@ -114,10 +115,10 @@ module FunctionsFramework
|
|
|
114
115
|
end
|
|
115
116
|
|
|
116
117
|
def construct_cloud_event context, data
|
|
117
|
-
source, subject = convert_source context[:service], context[:resource]
|
|
118
|
+
source, subject = convert_source context[:service], context[:resource], context[:domain]
|
|
118
119
|
type = LEGACY_TYPE_TO_CE_TYPE[context[:type]]
|
|
119
120
|
return nil unless type && source
|
|
120
|
-
ce_data, data_subject = convert_data context
|
|
121
|
+
ce_data, data_subject = convert_data context, data
|
|
121
122
|
content_type = "application/json"
|
|
122
123
|
::CloudEvents::Event.new id: context[:id],
|
|
123
124
|
source: source,
|
|
@@ -129,17 +130,36 @@ module FunctionsFramework
|
|
|
129
130
|
time: context[:timestamp]
|
|
130
131
|
end
|
|
131
132
|
|
|
132
|
-
def convert_source service, resource
|
|
133
|
+
def convert_source service, resource, domain
|
|
133
134
|
return ["//#{service}/#{resource}", nil] unless CE_SERVICE_TO_RESOURCE_RE.key? service
|
|
134
135
|
|
|
135
136
|
match = CE_SERVICE_TO_RESOURCE_RE[service].match resource
|
|
136
137
|
return [nil, nil] unless match
|
|
137
|
-
|
|
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
|
|
138
155
|
end
|
|
139
156
|
|
|
140
|
-
def convert_data
|
|
157
|
+
def convert_data context, data
|
|
158
|
+
service = context[:service]
|
|
141
159
|
case service
|
|
142
160
|
when "pubsub.googleapis.com"
|
|
161
|
+
data["messageId"] = context[:id]
|
|
162
|
+
data["publishTime"] = context[:timestamp]
|
|
143
163
|
[{ "message" => data }, nil]
|
|
144
164
|
when "firebaseauth.googleapis.com"
|
|
145
165
|
if data.key? "metadata"
|
|
@@ -180,16 +200,16 @@ module FunctionsFramework
|
|
|
180
200
|
"providers/firebase.auth/eventTypes/user.create" => "google.firebase.auth.user.v1.created",
|
|
181
201
|
"providers/firebase.auth/eventTypes/user.delete" => "google.firebase.auth.user.v1.deleted",
|
|
182
202
|
"providers/google.firebase.analytics/eventTypes/event.log" => "google.firebase.analytics.log.v1.written",
|
|
183
|
-
"providers/google.firebase.database/eventTypes/ref.create" => "google.firebase.database.
|
|
184
|
-
"providers/google.firebase.database/eventTypes/ref.write" => "google.firebase.database.
|
|
185
|
-
"providers/google.firebase.database/eventTypes/ref.update" => "google.firebase.database.
|
|
186
|
-
"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",
|
|
187
207
|
"providers/cloud.storage/eventTypes/object.change" => "google.cloud.storage.object.v1.finalized"
|
|
188
208
|
}.freeze
|
|
189
209
|
|
|
190
210
|
CE_SERVICE_TO_RESOURCE_RE = {
|
|
191
211
|
"firebase.googleapis.com" => %r{^(projects/[^/]+)/(events/[^/]+)$},
|
|
192
|
-
"firebasedatabase.googleapis.com" => %r{^
|
|
212
|
+
"firebasedatabase.googleapis.com" => %r{^projects/_/(instances/[^/]+)/(refs/.+)$},
|
|
193
213
|
"firestore.googleapis.com" => %r{^(projects/[^/]+/databases/\(default\))/(documents/.+)$},
|
|
194
214
|
"storage.googleapis.com" => %r{^(projects/[^/]+/buckets/[^/]+)/([^#]+)(?:#.*)?$}
|
|
195
215
|
}.freeze
|
|
@@ -306,7 +306,7 @@ module FunctionsFramework
|
|
|
306
306
|
# @return [Integer]
|
|
307
307
|
#
|
|
308
308
|
def max_threads
|
|
309
|
-
@max_threads ||
|
|
309
|
+
@max_threads || 8
|
|
310
310
|
end
|
|
311
311
|
|
|
312
312
|
##
|
|
@@ -352,7 +352,9 @@ module FunctionsFramework
|
|
|
352
352
|
when ::CloudEvents::CloudEventsError
|
|
353
353
|
cloud_events_error_response response
|
|
354
354
|
when ::StandardError
|
|
355
|
-
|
|
355
|
+
message = "#{response.class}: #{response.message}"
|
|
356
|
+
message = [message, *response.backtrace].join "\n\t"
|
|
357
|
+
error_response message
|
|
356
358
|
else
|
|
357
359
|
error_response "Unexpected response type: #{response.class}"
|
|
358
360
|
end
|
|
@@ -362,6 +364,10 @@ module FunctionsFramework
|
|
|
362
364
|
string_response "Not found", 404
|
|
363
365
|
end
|
|
364
366
|
|
|
367
|
+
def no_content_response
|
|
368
|
+
[204, [], []]
|
|
369
|
+
end
|
|
370
|
+
|
|
365
371
|
def string_response string, status, content_type: nil
|
|
366
372
|
string.force_encoding ::Encoding::ASCII_8BIT unless string.valid_encoding?
|
|
367
373
|
if string.encoding == ::Encoding::ASCII_8BIT
|
|
@@ -387,6 +393,11 @@ module FunctionsFramework
|
|
|
387
393
|
message = "Unexpected internal error" unless @config.show_error_details?
|
|
388
394
|
string_response message, 500
|
|
389
395
|
end
|
|
396
|
+
|
|
397
|
+
def flush_streams
|
|
398
|
+
$stdout.flush
|
|
399
|
+
$stderr.flush
|
|
400
|
+
end
|
|
390
401
|
end
|
|
391
402
|
|
|
392
403
|
## @private
|
|
@@ -401,7 +412,7 @@ module FunctionsFramework
|
|
|
401
412
|
return notfound_response if excluded_path? env
|
|
402
413
|
response =
|
|
403
414
|
begin
|
|
404
|
-
logger = env[
|
|
415
|
+
logger = env[::Rack::RACK_LOGGER] ||= @config.logger
|
|
405
416
|
request = ::Rack::Request.new env
|
|
406
417
|
logger.info "FunctionsFramework: Handling HTTP #{request.request_method} request"
|
|
407
418
|
@function.call request, globals: @globals, logger: logger
|
|
@@ -409,6 +420,8 @@ module FunctionsFramework
|
|
|
409
420
|
e
|
|
410
421
|
end
|
|
411
422
|
interpret_response response
|
|
423
|
+
ensure
|
|
424
|
+
flush_streams
|
|
412
425
|
end
|
|
413
426
|
end
|
|
414
427
|
|
|
@@ -424,28 +437,34 @@ module FunctionsFramework
|
|
|
424
437
|
|
|
425
438
|
def call env
|
|
426
439
|
return notfound_response if excluded_path? env
|
|
427
|
-
|
|
440
|
+
return no_content_response if env[::Rack::REQUEST_METHOD] == "GET"
|
|
441
|
+
logger = env[::Rack::RACK_LOGGER] ||= @config.logger
|
|
428
442
|
event = decode_event env
|
|
429
443
|
response =
|
|
430
444
|
case event
|
|
431
445
|
when ::CloudEvents::Event
|
|
432
446
|
handle_cloud_event event, logger
|
|
433
447
|
when ::Array
|
|
434
|
-
::CloudEvents::
|
|
448
|
+
::CloudEvents::CloudEventsError.new "Batched CloudEvents are not supported"
|
|
435
449
|
when ::CloudEvents::CloudEventsError
|
|
436
450
|
event
|
|
437
451
|
else
|
|
438
452
|
raise "Unexpected event type: #{event.class}"
|
|
439
453
|
end
|
|
440
454
|
interpret_response response
|
|
455
|
+
ensure
|
|
456
|
+
flush_streams
|
|
441
457
|
end
|
|
442
458
|
|
|
443
459
|
private
|
|
444
460
|
|
|
445
461
|
def decode_event env
|
|
446
|
-
|
|
447
|
-
@
|
|
448
|
-
|
|
462
|
+
begin
|
|
463
|
+
@cloud_events.decode_event env
|
|
464
|
+
rescue ::CloudEvents::NotCloudEventError
|
|
465
|
+
env[::Rack::RACK_INPUT].rewind rescue nil
|
|
466
|
+
@legacy_events.decode_rack_env(env) || ::CloudEvents::CloudEventsError.new("Unrecognized event format")
|
|
467
|
+
end
|
|
449
468
|
rescue ::CloudEvents::CloudEventsError => e
|
|
450
469
|
e
|
|
451
470
|
end
|
|
@@ -335,7 +335,8 @@ module FunctionsFramework
|
|
|
335
335
|
json = ::JSON.dump response
|
|
336
336
|
string_response json, 200, content_type: "application/json"
|
|
337
337
|
when ::StandardError
|
|
338
|
-
message = "#{response.class}: #{response.message}
|
|
338
|
+
message = "#{response.class}: #{response.message}"
|
|
339
|
+
message = [message, *response.backtrace].join "\n\t"
|
|
339
340
|
string_response message, 500
|
|
340
341
|
else
|
|
341
342
|
raise "Unexpected response type: #{response.inspect}"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: functions_framework
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.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:
|
|
11
|
+
date: 2022-01-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cloud_events
|
|
@@ -16,7 +16,7 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 0.7.0
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
22
|
version: 2.a
|
|
@@ -26,7 +26,7 @@ dependencies:
|
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version:
|
|
29
|
+
version: 0.7.0
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: 2.a
|
|
@@ -80,6 +80,7 @@ files:
|
|
|
80
80
|
- CHANGELOG.md
|
|
81
81
|
- LICENSE
|
|
82
82
|
- README.md
|
|
83
|
+
- RELEASING.md
|
|
83
84
|
- bin/functions-framework
|
|
84
85
|
- bin/functions-framework-ruby
|
|
85
86
|
- docs/deploying-functions.md
|
|
@@ -99,10 +100,10 @@ homepage: https://github.com/GoogleCloudPlatform/functions-framework-ruby
|
|
|
99
100
|
licenses:
|
|
100
101
|
- Apache-2.0
|
|
101
102
|
metadata:
|
|
102
|
-
changelog_uri: https://googlecloudplatform.github.io/functions-framework-ruby/
|
|
103
|
+
changelog_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v1.1.0/file.CHANGELOG.html
|
|
103
104
|
source_code_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby
|
|
104
105
|
bug_tracker_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby/issues
|
|
105
|
-
documentation_uri: https://googlecloudplatform.github.io/functions-framework-ruby/
|
|
106
|
+
documentation_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v1.1.0
|
|
106
107
|
post_install_message:
|
|
107
108
|
rdoc_options: []
|
|
108
109
|
require_paths:
|
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
118
119
|
- !ruby/object:Gem::Version
|
|
119
120
|
version: '0'
|
|
120
121
|
requirements: []
|
|
121
|
-
rubygems_version: 3.
|
|
122
|
+
rubygems_version: 3.3.5
|
|
122
123
|
signing_key:
|
|
123
124
|
specification_version: 4
|
|
124
125
|
summary: Functions Framework for Ruby
|