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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d313c253cf23573fe55628885064699cf1da8ca51545446cd3a6adf58ffaf3ff
4
- data.tar.gz: 2b82761a46c066f2a32af713c85e559afe5fe892bc1c761ec765772dd2633db2
3
+ metadata.gz: 6a4d1e19c5565de4604964e48ff818b05460b2211ef2c8cfbd100bd572d802d7
4
+ data.tar.gz: 380d987acf157075cfe7fca5bf038404eb800f48b80614ce9781f44cbd6de764
5
5
  SHA512:
6
- metadata.gz: b58f6f2c3fbebf5cf6c5eb28031a4ec7a389c063b9f2b8edba6b7e346f20683a8a9339202e8075299c67c5a347313c37bd82aac47422981008858e301133cccf
7
- data.tar.gz: fbd5515ed316ab193eec32efe17eb66cc937582d1af9b6196854bac8d2dee16de6d0b7429aac66ce287b97043b5dfadc35d989451e7bb3495d62dee512cd1681
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.8"
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.8"
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
@@ -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.8"
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.8"
473
+ gem "functions_framework", "~> 0.9"
474
474
  ```
475
475
 
476
476
  ```ruby
@@ -219,7 +219,7 @@ module FunctionsFramework
219
219
  #
220
220
  def global key
221
221
  value = @__globals[key]
222
- value = value.value if value.is_a? LazyGlobal
222
+ value = value.value if LazyGlobal === value
223
223
  value
224
224
  end
225
225
 
@@ -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"], content_type.charset
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, charset
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; charset=#{charset}"
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
- if service == "storage.googleapis.com"
102
- match = %r{^(projects/[^/]+/buckets/[^/]+)/([^#]+)(?:#.*)?$}.match resource
103
- return [nil, nil] unless match
104
- ["//#{service}/#{match[1]}", match[2]]
105
- else
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
- if service == "pubsub.googleapis.com"
112
- { "message" => data, "subscription" => nil }
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/} => "firebase.googleapis.com",
123
- %r{^providers/google\.firebase} => "firebase.googleapis.com"
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
@@ -306,7 +306,7 @@ module FunctionsFramework
306
306
  # @return [Integer]
307
307
  #
308
308
  def max_threads
309
- @max_threads || (@rack_env == "development" ? 1 : 16)
309
+ @max_threads || 1
310
310
  end
311
311
 
312
312
  ##
@@ -17,5 +17,5 @@ module FunctionsFramework
17
17
  # Version of the Ruby Functions Framework
18
18
  # @return [String]
19
19
  #
20
- VERSION = "0.8.0".freeze
20
+ VERSION = "0.9.0".freeze
21
21
  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.8.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-02 00:00:00.000000000 Z
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.8.0/file.CHANGELOG.html
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.8.0
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: