functions_framework 0.2.1 → 0.3.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: 921150d16d50802b1fa0e5f4f6fb5d3c71aee1dd87e8242ce2e0b63dc8c6320b
4
- data.tar.gz: 9b2fd4967811fc1225319102a6aadb56497d90241f6678933843a88299ea926c
3
+ metadata.gz: f82e8f7fb76005b4b61225b3ca02e31e52caecb2742604b88b6b60ced2945d84
4
+ data.tar.gz: 5f274cc6bdd13c7367d55212d1fb39f26432d8d00a6d607c09543e3818637c49
5
5
  SHA512:
6
- metadata.gz: 90ea5d1622b446eb02a84a79717c92b47fadc6b5420f153acd48d0b01716a44dd6dc6cbea6851f446fde70e5a53522569b95cde61c5807563dee5b0bc4a6b50c
7
- data.tar.gz: 0dd19692bfaa5566c4da5151d78c9d233b9241089d186d5461ef13e83529ca9de7f04e8736fbae70fd361a1fc2b605c03947d23867d28c2c9f80995d9cf60d06
6
+ metadata.gz: 6470be9c192f2231a610830bf51563638ce27e4330f071dd28b41a8fc15811704ace7025cede45ea54a13b4862d86153401360523d6bb479735793e1ed1e00c4
7
+ data.tar.gz: c7fd524f8c7c4819a6cb6a95d7e7ec0aa371e4211c8b521efe42d63ab3ca794dbfad490613633660c89aaa01479cbfe4d5e98683454e6bd4cdc382f1978da396
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.3.0 / 2020-06-26
4
+
5
+ * Updated the CloudEvent data format for converted pubsub events to conform to Cloud Run's conversion.
6
+
3
7
  ### v0.2.1 / 2020-06-25
4
8
 
5
9
  * The `--signature-type` check recognizes the legacy `event` type.
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.2"
63
+ gem "functions_framework", "~> 0.3"
64
64
  ```
65
65
 
66
66
  Create a file called `app.rb` and include the following code. This defines a
@@ -30,12 +30,21 @@ Google Cloud Functions is Google's scalable pay-as-you-go Functions-as-a-Service
30
30
  Functions Framework is designed especially for functions that can be hosted on
31
31
  Cloud Functions.
32
32
 
33
+ You can run Ruby functions on Google Cloud Functions by selecting the `ruby26`
34
+ runtime. This runtime uses a recent release of Ruby 2.6. Support for other
35
+ versions of Ruby may be added in the future.
36
+
37
+ > **Note:** Ruby support on Cloud Functions is currently in limited preview.
38
+ > It is not yet suitable for production workloads, and support is best-effort
39
+ > only. Access is currently limited to selected early-access users.
40
+
33
41
  ### Deploying and updating your function
34
42
 
35
43
  Before you can deploy to Cloud Functions, make sure your bundle, and in
36
44
  particular your `Gemfile.lock` file, is up to date. The easiest way to do this
37
45
  is to `bundle install` or `bundle update` and run your local tests prior to
38
- deploying.
46
+ deploying. Cloud Functions will not accept your function unless an up-to-date
47
+ `Gemfile.lock` is present.
39
48
 
40
49
  Choose a name for your function. This function name is how it will appear in the
41
50
  cloud console, and will also be part of the function's URL. (It's different from
@@ -126,6 +135,10 @@ You must use your project ID, but you can choose an app name and build ID. The
126
135
  command may ask you for permission to enable the Cloud Build API for the project
127
136
  if it isn't already enabled.
128
137
 
138
+ Because you provide your own Docker image when deploying to Cloud Run, you can
139
+ use any version of Ruby supported by the Functions Framework, from 2.4 through
140
+ 2.7.
141
+
129
142
  ### Deploying an image to Cloud Run
130
143
 
131
144
  To deploy to Cloud Run, specify the same image URL that you built above. For
@@ -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.2"
67
+ gem "functions_framework", "~> 0.3"
68
68
  ```
69
69
 
70
70
  Create a file called `app.rb` and include the following code. This defines a
@@ -156,7 +156,7 @@ the [CloudEvents spec](https://github.com/cloudevents/spec/blob/v1.0/spec.md).
156
156
  Some Google Cloud services send events in a legacy event format that was defined
157
157
  prior to CloudEvents. The Functions Framework will convert these legacy events
158
158
  to an equivalent CloudEvents type, so your function will always receive a
159
- CloudEvent when it is sent an event from Google Cloud.
159
+ CloudEvent object when it is sent an event from Google Cloud.
160
160
 
161
161
  ## Error handling
162
162
 
@@ -188,9 +188,10 @@ end
188
188
 
189
189
  A Functions Framework based "project" or "application" is a typical Ruby
190
190
  application. It should include a `Gemfile` that specifies the gem dependencies
191
- (including the `functions_framework` gem itself), and at least one Ruby source
192
- file that defines functions. It can also include additional Ruby files defining
193
- classes and methods that assist in the function implementation.
191
+ (including the `functions_framework` gem itself), and any other dependencies
192
+ needed by the function. It must include at least one Ruby source file that
193
+ defines functions, and can also include additional Ruby files defining classes
194
+ and methods that assist in the function implementation.
194
195
 
195
196
  The "entrypoint" to the project, also called the "source", is a Ruby file. It
196
197
  can define any number of functions (with distinct names), although it is often
@@ -221,7 +222,7 @@ A simple project might look like this:
221
222
  ```ruby
222
223
  # Gemfile
223
224
  source "https://rubygems.org"
224
- gem "functions_framework", "~> 0.2"
225
+ gem "functions_framework", "~> 0.3"
225
226
  ```
226
227
 
227
228
  ```ruby
@@ -84,12 +84,13 @@ module FunctionsFramework
84
84
  source, subject = convert_source context[:service], context[:resource]
85
85
  type = LEGACY_TYPE_TO_CE_TYPE[context[:type]]
86
86
  return nil unless type && source
87
+ ce_data = convert_data context[:service], data
87
88
  CloudEvents::Event.new id: context[:id],
88
89
  source: source,
89
90
  type: type,
90
91
  spec_version: "1.0",
91
92
  data_content_type: "application/json",
92
- data: data,
93
+ data: ce_data,
93
94
  subject: subject,
94
95
  time: context[:timestamp]
95
96
  end
@@ -104,6 +105,14 @@ module FunctionsFramework
104
105
  end
105
106
  end
106
107
 
108
+ def convert_data service, data
109
+ if service == "pubsub.googleapis.com"
110
+ { "message" => data, "subscription" => nil }
111
+ else
112
+ data
113
+ end
114
+ end
115
+
107
116
  LEGACY_TYPE_TO_SERVICE = {
108
117
  %r{^providers/cloud\.firestore/} => "firestore.googleapis.com",
109
118
  %r{^providers/cloud\.pubsub/} => "pubsub.googleapis.com",
@@ -17,5 +17,5 @@ module FunctionsFramework
17
17
  # Version of the Ruby Functions Framework
18
18
  # @return [String]
19
19
  #
20
- VERSION = "0.2.1".freeze
20
+ VERSION = "0.3.0".freeze
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: functions_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma