Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 8f06a4b

Browse files
authored
Adds examples of accessing CE extensions in functions (#392)
1 parent eef63cf commit 8f06a4b

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

docs/transformation/functions/nodejsfunctions.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ spec:
1414
ceOverrides:
1515
extensions:
1616
type: io.triggermesh.nodejs.sample
17-
entrypoint: transformName
17+
entrypoint: handler
1818
code: |
19-
module.exports.transformName = async (event) => {
19+
exports.handler = async function(event, context) {
20+
2021
if (event.name == "") {
21-
event.name = "placeholder";
22+
event.name = "placeholder"; # (1)
2223
}
24+
25+
console.log(context.clientContext.custom["foo"]) # (2)
2326
return event;
2427
};
2528
```
29+
30+
1. Tests if the event.name property has a value, if not sets it to placeholder.
31+
2. Logs the value of a CloudEvents extension attribute called "foo". To pass an extension attribute called foo in a request using curl, use -H "ce-foo: bar".
32+

docs/transformation/functions/pythonfunctions.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ spec:
2727
runtime: python
2828
adapterOverrides:
2929
public: true
30-
entrypoint: endpoint
30+
entrypoint: handler
3131
code: |
3232
import json
33-
def endpoint(event, context):
33+
def handler(event, context):
3434
jsonEvent = json.loads(event)
35-
return "Hello " + jsonEvent['name']
35+
print(context.client_context.custom["foo"]) # (1)
36+
return "Hello " + jsonEvent['name'] # (2)
3637
```
3738
39+
1. Logs the value of a CloudEvents extension attribute called "foo". To pass an extension attribute called foo in a request using curl, use -H "ce-foo: bar".
40+
2. Returns "Hello" followed by the value of the name attribute in the event message
41+
3842
You can then create the function with:
3943
4044
```console

docs/transformation/functions/rubyfunctions.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ spec:
1414
ceOverrides:
1515
extensions:
1616
type: io.triggermesh.ruby.sample
17-
entrypoint: endpoint
17+
entrypoint: handler
1818
code: |
19-
def endpoint(event:, context:)
19+
def handler(event:, context:)
20+
puts context.client_context["custom"]["foo"] # (1)
2021
hash = {date: Time.new}
21-
{ statusCode: 200, body: JSON.generate(hash) }
22+
{ statusCode: 200, body: JSON.generate(hash) } (2)
2223
end
2324
```
25+
26+
1. Logs the value of a CloudEvents extension attribute called "foo". To pass an extension attribute called foo in a request using curl, use -H "ce-foo: bar".
27+
2. returns the current time

0 commit comments

Comments
 (0)