Skip to content
This repository was archived by the owner on Dec 18, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/amqp-echo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For this example we will register a service using the xfsrt-cli. This will simpl
Given the __`Enterprise Messaging`__ service instance name and binding, run the following command:

```bash
xfsrt-cli faas service register -s <EMInstanceServiceName> -b <EMInstanceServiceBinding>
xfsrt-cli faas service register -s <EMInstanceServiceName> -b <EMInstanceServiceKey>
```

Create a deployment file to provide credentials, topics and queue names.
Expand Down
9 changes: 5 additions & 4 deletions examples/amqp-echo/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
/**
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/
/**
* @namespace Faas
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/

/**
* @param {Faas.Event} event
Expand Down
9 changes: 4 additions & 5 deletions examples/call-other-function/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ $ xfsrt-cli faas project deploy -v
```

## Test
The HTTP trigger URL can be retrieved from:
```
xfsrt-cli faas project get chain
```
The `artifacts` array contains an object with the URL in its `name` property (and a `reference` to the HTTP trigger `chain-simple`)
The output received after executing the [deployment](#Deployment) step contains the trigger endpoint.

Invoke the __`chain-func1`__ function via invoking the HTTP trigger URL.


## License
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
Expand Down
9 changes: 5 additions & 4 deletions examples/call-other-function/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
/**
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/
/**
* @namespace Faas
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/

/**
* @param {Faas.Event} event
Expand Down
26 changes: 26 additions & 0 deletions examples/hello-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Example: hello-secret

This example deploys a function which extracts information from a secret.

## Deployment
First, create a deployment file to provide credentials.
Run inside the project directory:
```bash
faas-sdk init-values -y values.yaml
```
Update the generated file. And finally, deploy the project as usual:
```bash
xfsrt-cli faas project deploy -y ./deploy/values.yaml -v
```

### Test
The output received after executing the [deployment](#Deployment) step contains the trigger endpoint.

Invoke the function `hello-secret` via invoking the HTTP trigger URL.

The returned function output should be identical to the value specified in `values.yaml` under `secret-values`->`sec1`->`rv.json`->`Info`->`Success`


## License
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the [LICENSE file](../LICENSE.txt).
10 changes: 10 additions & 0 deletions examples/hello-config/data/rv.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Info": {
"Success": "Demo",
"Failure": "Todo"
},
"Code": {
"Success": "A",
"Failure": "X"
}
}
1 change: 1 addition & 0 deletions examples/hello-config/data/text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
25 changes: 25 additions & 0 deletions examples/hello-config/faas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"project": "hello-config",
"version": "0.0.1",
"runtime": "nodejs10",
"library": "./lib",
"configs": {
"cfg1": {
"source": "./data"
}
},
"functions": {
"hello-config": {
"module": "index.js",
"configs": [
"cfg1"
]
}
},
"triggers": {
"demo-config": {
"type": "HTTP",
"function": "hello-config"
}
}
}
17 changes: 17 additions & 0 deletions examples/hello-config/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';
/**
* @namespace Faas
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/

/**
* @param {Faas.Event} event
* @param {Faas.Context} context
* @return {Promise<*>}
*/
module.exports = async function (event, context) {
const text = await context.getConfigValueString('cfg1', 'text');
const rval = await context.getConfigValueJSON('cfg1', 'rv.json');
return rval.Info.Success;
};
26 changes: 26 additions & 0 deletions examples/hello-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "example",
"version": "1.0.0",
"keywords": [
"faas",
"example"
],
"engines": {
"node": ">=8.11.3"
},
"dependencies": {},
"devDependencies": {
"@sap/faas": ">=0.7.0",
"mocha": "=7.0.0"
},
"files": [
"data",
"lib",
"faas.json",
"package.json"
],
"scripts": {
"test": "npm run all-tests",
"all-tests": "node ./node_modules/mocha/bin/_mocha test/**/test*.js --colors -csdlJson --slow 200"
}
}
5 changes: 5 additions & 0 deletions examples/hello-config/test/mock/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config-values:
cfg1:
rv.json:
Info:
Success: Nice Test!
74 changes: 74 additions & 0 deletions examples/hello-config/test/unit/test-hello-secret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*jshint mocha:true*/
'use strict';

const assert = require('assert');
const faas = require('@sap/faas');

describe('hello secret example', () => {

// ************************************************************************************************

it('using default values', (done) => {
faas.test(done,
{
},
async (context) => {
const result = await context.callFunction('hello-config', {});
assert.equal(result.type, 'text/plain; charset=utf-8');
assert.equal(result.data, 'Demo');
}
);
});

// ************************************************************************************************

it('using deploy values', (done) => {
faas.test(done,
{
'deploy-values': '../mock/values.yaml'
},
async (context) => {
const result = await context.callFunction('hello-config', {});
assert.equal(result.type, 'text/plain; charset=utf-8');
assert.equal(result.data, 'Nice Test!');
}
);
});

// ************************************************************************************************

it('read config text', (done) => {
faas.test(done,
{
},
async (context) => {
assert.equal(await context.getConfigValueString('cfg1', 'text'), 'Hello World!');
}
);
});

// ************************************************************************************************

it('read config json', (done) => {
faas.test(done,
{
},
async (context) => {
assert.deepStrictEqual(await context.getConfigValueJSON('cfg1', 'rv.json'), {
"Info": {
"Success": "Demo",
"Failure": "Todo"
},
"Code": {
"Success": "A",
"Failure": "X"
}
});
}
);
});

// ************************************************************************************************

});

4 changes: 2 additions & 2 deletions examples/hello-oauth-xsuaa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ Once you have retrieved the token, the HTTP trigger URL can be retrieved from:
```bash
xfsrt-cli faas project get hello-oauth-xsuaa
```
The `artifacts` array contains an object with the URL in its `name` property (and a `reference` to HTTP trigger `trig-oauth`).
The output contains the trigger endpoint.

Call the function using the endpoint with the token:
Call the function `fun-oauth-xsuaa` using the endpoint with the token:

```
GET <HTTPTriggerURL>
Expand Down
9 changes: 5 additions & 4 deletions examples/hello-oauth-xsuaa/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
/**
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/
/**
* @namespace Faas
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/

const auth = require('./auth');

Expand Down
8 changes: 2 additions & 6 deletions examples/hello-oauth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ Update the generated file with the public key you generated above. And finally,
```

### Test
The HTTP trigger URL can be retrieved from:
```bash
xfsrt-cli faas project get hello-oauth
```
The `artifacts` array contains an object with the URL in its `name` property (and a `reference` to HTTP trigger `trig-oauth`)
The output received after executing the [deployment](#Deployment) step contains the trigger URL.

Setup your HTTP request according to this to trigger the function:
```
Expand All @@ -48,7 +44,7 @@ Authorization: Bearer <token>

Check the function log on the command line
```bash
xfsrt-cli faas project logs -n hello-oauth --functions fun-oauth
xfsrt-cli faas project logs hello-oauth --functions fun-oauth
```

The output should contain the token payload.
Expand Down
9 changes: 5 additions & 4 deletions examples/hello-oauth/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
/**
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/
/**
* @namespace Faas
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/

const auth = require('./auth');

Expand Down
6 changes: 1 addition & 5 deletions examples/hello-secret/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ Update the generated file. And finally, deploy the project as usual:
```

### Test
The HTTP trigger URL can be retrieved from:
```
xfsrt-cli faas project get hello-secret
```
The `artifacts` array contains an object with the URL in its `name` property (and a `reference` to HTTP trigger `demo`)
The output received after executing the [deployment](#Deployment) step contains the trigger URL.

Invoke the function `hello-secret` via invoking the HTTP trigger URL.

Expand Down
9 changes: 5 additions & 4 deletions examples/hello-secret/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
/**
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/
/**
* @namespace Faas
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/

/**
* @param {Faas.Event} event
Expand Down
4 changes: 2 additions & 2 deletions examples/hello-timer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ The function is triggered by the timers `timer1`, `timer2`, `timer3` and logs th
## Test
In order to verify that the function `hello-timer` is invoked according to the configurations of the three timer triggers, view the logs using:
```
xfsrt-cli faas project logs -n hello-timer --functions hello-timer
xfsrt-cli faas project logs --functions hello-timer
```

Expected result:
* You should be able to see that e.g. `timer1` causes log entries of format `"/faas/timer/timer1 <timestamp>` to be written every 15 seconds.
* You should be able to see that e.g. `timer1` causes log entries of format `"/default/sap.xfs.faas/timer1 <timestamp>` to be written every 15 seconds.

## License
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
Expand Down
9 changes: 5 additions & 4 deletions examples/hello-timer/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
/**
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/
/**
* @namespace Faas
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/

/**
* @param {Faas.Event} event
Expand Down
9 changes: 5 additions & 4 deletions examples/kafka-producer/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
/**
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/
/**
* @namespace Faas
* @typedef {import("@sap/faas").Faas.Event} Faas.Event
* @typedef {import("@sap/faas").Faas.Context} Faas.Context
*/


const { Kafka } = require('kafkajs');
Expand Down
8 changes: 2 additions & 6 deletions examples/qrcode-producer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ The QR code is displayed in a browser window.
## Deployment
Deploy the project:
```bash
xfsrt-cli faas project deploy -y ./deploy/values.yaml -v
xfsrt-cli faas project deploy
```

## Test
The HTTP trigger URL can be retrieved from:
```
xfsrt-cli faas project get qrcode-prodcuer
```
The `artifacts` array contains an object with the URL in its `name` property (and a `reference` to the HTTP trigger `build-qrcode`)
The output received after executing the [deployment](#Deployment) step contains the trigger endpoint.

Invoke the function `build-qrcode` via invoking the HTTP trigger URL.

Expand Down
Loading