functions_framework 0.8.0 → 0.9.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 +6 -0
- data/README.md +1 -1
- data/docs/overview.md +1 -1
- data/docs/writing-functions.md +2 -2
- data/lib/functions_framework/function.rb +1 -1
- data/lib/functions_framework/legacy_event_converter.rb +41 -17
- data/lib/functions_framework/server.rb +1 -1
- data/lib/functions_framework/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a4d1e19c5565de4604964e48ff818b05460b2211ef2c8cfbd100bd572d802d7
|
4
|
+
data.tar.gz: 380d987acf157075cfe7fca5bf038404eb800f48b80614ce9781f44cbd6de764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c76cb765863334411e7ab3bd448912fabc14c7725ae66465426ee996b05557d44653f64d47c98eb429d077f0df558b550b228a3fce014dd5aa9e02e4933cbc62
|
7
|
+
data.tar.gz: af8d74d419c75dc8f850fa989d48780a26e2639045ff945d4b0a1cd29fa0085d3a82d058db6e49ed9c9f2c2855b3bc495a44ab530e129a846b24c111c76f79f2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### v0.9.0 / 2021-03-18
|
4
|
+
|
5
|
+
* BREAKING CHANGE: Servers are configured as single-threaded in production by default, matching the current behavior of Google Cloud Functions.
|
6
|
+
* FIXED: Fixed conversion of Firebase events to CloudEvents to conform to the specs used by Cloud Functions and Cloud Run.
|
7
|
+
* 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
|
+
|
3
9
|
### v0.8.0 / 2021-03-02
|
4
10
|
|
5
11
|
* ADDED: Support for lazily-initialized globals
|
data/README.md
CHANGED
@@ -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", "~> 0.9"
|
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
@@ -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", "~> 0.9"
|
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", "~> 0.9"
|
115
115
|
gem "sinatra", "~> 2.0"
|
116
116
|
```
|
117
117
|
|
@@ -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", "~> 0.9"
|
474
474
|
```
|
475
475
|
|
476
476
|
```ruby
|
@@ -33,7 +33,7 @@ module FunctionsFramework
|
|
33
33
|
return nil unless input
|
34
34
|
context = normalized_context input
|
35
35
|
return nil unless context
|
36
|
-
construct_cloud_event context, input["data"]
|
36
|
+
construct_cloud_event context, input["data"]
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
@@ -81,37 +81,47 @@ module FunctionsFramework
|
|
81
81
|
nil
|
82
82
|
end
|
83
83
|
|
84
|
-
def construct_cloud_event context, data
|
84
|
+
def construct_cloud_event context, data
|
85
85
|
source, subject = convert_source context[:service], context[:resource]
|
86
86
|
type = LEGACY_TYPE_TO_CE_TYPE[context[:type]]
|
87
87
|
return nil unless type && source
|
88
|
-
ce_data = convert_data context[:service], data
|
89
|
-
content_type = "application/json
|
88
|
+
ce_data, data_subject = convert_data context[:service], data
|
89
|
+
content_type = "application/json"
|
90
90
|
::CloudEvents::Event.new id: context[:id],
|
91
91
|
source: source,
|
92
92
|
type: type,
|
93
93
|
spec_version: "1.0",
|
94
94
|
data_content_type: content_type,
|
95
95
|
data: ce_data,
|
96
|
-
subject: subject,
|
96
|
+
subject: subject || data_subject,
|
97
97
|
time: context[:timestamp]
|
98
98
|
end
|
99
99
|
|
100
100
|
def convert_source service, resource
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
["//#{service}/#{resource}", nil]
|
107
|
-
end
|
101
|
+
return ["//#{service}/#{resource}", nil] unless CE_SERVICE_TO_RESOURCE_RE.key? service
|
102
|
+
|
103
|
+
match = CE_SERVICE_TO_RESOURCE_RE[service].match resource
|
104
|
+
return [nil, nil] unless match
|
105
|
+
["//#{service}/#{match[1]}", match[2]]
|
108
106
|
end
|
109
107
|
|
110
108
|
def convert_data service, data
|
111
|
-
|
112
|
-
|
109
|
+
case service
|
110
|
+
when "pubsub.googleapis.com"
|
111
|
+
[{ "message" => data }, nil]
|
112
|
+
when "firebaseauth.googleapis.com"
|
113
|
+
if data.key? "metadata"
|
114
|
+
FIREBASE_AUTH_METADATA_LEGACY_TO_CE.each do |old_key, new_key|
|
115
|
+
if data["metadata"].key? old_key
|
116
|
+
data["metadata"][new_key] = data["metadata"][old_key]
|
117
|
+
data["metadata"].delete old_key
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
subject = "users/#{data['uid']}" if data.key? "uid"
|
122
|
+
[data, subject]
|
113
123
|
else
|
114
|
-
data
|
124
|
+
[data, nil]
|
115
125
|
end
|
116
126
|
end
|
117
127
|
|
@@ -119,8 +129,9 @@ module FunctionsFramework
|
|
119
129
|
%r{^providers/cloud\.firestore/} => "firestore.googleapis.com",
|
120
130
|
%r{^providers/cloud\.pubsub/} => "pubsub.googleapis.com",
|
121
131
|
%r{^providers/cloud\.storage/} => "storage.googleapis.com",
|
122
|
-
%r{^providers/firebase\.auth/} => "
|
123
|
-
%r{^providers/google\.firebase}
|
132
|
+
%r{^providers/firebase\.auth/} => "firebaseauth.googleapis.com",
|
133
|
+
%r{^providers/google\.firebase\.analytics/} => "firebase.googleapis.com",
|
134
|
+
%r{^providers/google\.firebase\.database/} => "firebasedatabase.googleapis.com"
|
124
135
|
}.freeze
|
125
136
|
|
126
137
|
LEGACY_TYPE_TO_CE_TYPE = {
|
@@ -143,5 +154,18 @@ module FunctionsFramework
|
|
143
154
|
"providers/google.firebase.database/eventTypes/ref.delete" => "google.firebase.database.document.v1.deleted",
|
144
155
|
"providers/cloud.storage/eventTypes/object.change" => "google.cloud.storage.object.v1.finalized"
|
145
156
|
}.freeze
|
157
|
+
|
158
|
+
CE_SERVICE_TO_RESOURCE_RE = {
|
159
|
+
"firebase.googleapis.com" => %r{^(projects/[^/]+)/(events/[^/]+)$},
|
160
|
+
"firebasedatabase.googleapis.com" => %r{^(projects/_/instances/[^/]+)/(refs/.+)$},
|
161
|
+
"firestore.googleapis.com" => %r{^(projects/[^/]+/databases/\(default\))/(documents/.+)$},
|
162
|
+
"storage.googleapis.com" => %r{^(projects/[^/]+/buckets/[^/]+)/([^#]+)(?:#.*)?$}
|
163
|
+
}.freeze
|
164
|
+
|
165
|
+
# Map Firebase Auth legacy event metadata field names to their equivalent CloudEvent field names.
|
166
|
+
FIREBASE_AUTH_METADATA_LEGACY_TO_CE = {
|
167
|
+
"createdAt" => "createTime",
|
168
|
+
"lastSignedInAt" => "lastSignInTime"
|
169
|
+
}.freeze
|
146
170
|
end
|
147
171
|
end
|
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: 0.
|
4
|
+
version: 0.9.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: 2021-03-
|
11
|
+
date: 2021-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cloud_events
|
@@ -87,10 +87,10 @@ homepage: https://github.com/GoogleCloudPlatform/functions-framework-ruby
|
|
87
87
|
licenses:
|
88
88
|
- Apache-2.0
|
89
89
|
metadata:
|
90
|
-
changelog_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v0.
|
90
|
+
changelog_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v0.9.0/file.CHANGELOG.html
|
91
91
|
source_code_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby
|
92
92
|
bug_tracker_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby/issues
|
93
|
-
documentation_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v0.
|
93
|
+
documentation_uri: https://googlecloudplatform.github.io/functions-framework-ruby/v0.9.0
|
94
94
|
post_install_message:
|
95
95
|
rdoc_options: []
|
96
96
|
require_paths:
|