-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#27 channelpattern
- Loading branch information
Showing
14 changed files
with
604 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Gateway using Default Channel Pattern | ||
Link: https://github.com/project-flogo/microgateway/internal/pattern/DefaultChannelPattern.json | ||
Examples: | ||
https://github.com/project-flogo/microgateway/examples/api/default-channel-pattern | ||
https://github.com/project-flogo/microgateway/examples/json/default-channel-pattern | ||
|
||
|
||
|
||
This recipe is a gateway using the defult channel pattern which uses JWT. | ||
This receipe uses 2 triggers. | ||
1. REST trigger:- For calling the channel pattern | ||
Link: https://github.com/project-flogo/contrib/trigger/rest | ||
|
||
2. Channel Trigger:- For calling second microgateway action | ||
Link: https://github.com/project-flogo/contrib/trigger/channel | ||
|
||
Channel Pattern: | ||
Channels allow one action to call another action. Channel pattern checks for JWT conditions. | ||
If valid ... it runs corresponding channel activity and message is sent over the channel defined by its name. | ||
Channel trigger then receives the message from channel and corresponding action (eg: log activity) is called. | ||
|
||
|
||
#Channel Activity | ||
| Name | Type | Description | | ||
|:-----------|:--------|:--------------| | ||
| channel | string | The channel to put the value on | | ||
| value | string | The value to put on channel | | ||
|
||
Link: https://github.com/project-flogo/contrib/activity/channel | ||
|
||
|
||
#JWT | ||
| Name | Type | Description | | ||
|:-----------|:--------|:--------------| | ||
| token | string | The raw token | | ||
| key | string | The key used to sign the token | | ||
| signingMethod | string | The signing method used (HMAC, ECDSA, RSA, RSAPSS) | | ||
| issuer | string | The 'iss' standard claim to match against | | ||
| subject | string | The 'sub' standard claim to match against | | ||
| audience | string | The 'aud' standard claim to match against | | ||
|
||
Link: https://github.com/project-flogo/microgateway/activity/jwt | ||
|
||
|
||
## Installation | ||
* Install [Go](https://golang.org/) | ||
|
||
## Setup | ||
```bash | ||
git clone https://github.com/project-flogo/microgateway | ||
cd microgateway/examples/api/default-http-pattern | ||
``` | ||
|
||
## Testing | ||
Start the gateway: | ||
```bash | ||
go run main.go | ||
``` | ||
|
||
|
||
### Request is successful | ||
Run the following command: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oKs" | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"response":"Success!"} | ||
``` | ||
On the server screen, you get 200 response code and log service outputs "Output: Test log message service invoked" | ||
|
||
|
||
### JWT token is invalid | ||
Run the following command: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oK" | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"errorMessage":"","validationMessage":"signature is invalid"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Gateway using Default Http Pattern | ||
This recipe is a gateway using the defult http pattern which uses JWT, Rate Limiter, and Circuit Breaker. | ||
Link: https://github.com/project-flogo/microgateway/internal/pattern/DefaultHttpPattern.json | ||
Examples: | ||
https://github.com/project-flogo/microgateway/examples/api/default-http-pattern | ||
https://github.com/project-flogo/microgateway/examples/json/default-http-pattern | ||
|
||
|
||
Http Pattern: | ||
Pattern checks for JWT, Ratelimiter and CircuitBreaker conditions. | ||
If valid ... it runs corresponding activity. | ||
This receipe uses REST trigger. | ||
1. REST trigger:- For calling the http pattern | ||
Link: https://github.com/project-flogo/contrib/trigger/rest | ||
|
||
|
||
#Circuit Breaker Service: | ||
| Name | Type | Description | | ||
|:-----------|:--------|:--------------| | ||
| mode | string | The tripping mode: 'a' for contiguous errors, 'b' for errors within a time period, 'c' for contiguous errors within a time period, and 'd' for a probabilistic smart circuit breaker mode. Defaults to mode 'a' | | ||
| threshold | number | The number of errors required for tripping| | ||
| period | number | Number of seconds in which errors have to occur for the circuit breaker to trip. Applies to modes 'b' and 'c'| | ||
| timeout | number | Number of seconds that the circuit breaker will remain tripped. Applies to modes 'a', 'b', 'c'| | ||
|
||
Link: https://github.com/project-flogo/microgateway/activity/circuitbreaker | ||
|
||
|
||
#Rate Limiter | ||
| Name | Type | Description | | ||
|:-----------|:--------|:--------------| | ||
| limit | string | Limit can be specifed in the format of "limit-period". Valid periods are 'S', 'M' & 'H' to represent Second, Minute & Hour. Example: "10-S" represents 10 request/second | | ||
|
||
Link: https://github.com/project-flogo/microgateway/activity/ratelimiter | ||
|
||
|
||
|
||
#JWT | ||
| Name | Type | Description | | ||
|:-----------|:--------|:--------------| | ||
| token | string | The raw token | | ||
| key | string | The key used to sign the token | | ||
| signingMethod | string | The signing method used (HMAC, ECDSA, RSA, RSAPSS) | | ||
| issuer | string | The 'iss' standard claim to match against | | ||
| subject | string | The 'sub' standard claim to match against | | ||
| audience | string | The 'aud' standard claim to match against | | ||
|
||
Link: https://github.com/project-flogo/microgateway/activity/jwt | ||
|
||
|
||
|
||
## Installation | ||
* Install [Go](https://golang.org/) | ||
|
||
## Setup | ||
```bash | ||
git clone https://github.com/project-flogo/microgateway | ||
cd microgateway/examples/api/default-http-pattern | ||
``` | ||
|
||
## Testing | ||
Start the gateway: | ||
```bash | ||
go run main.go | ||
``` | ||
and test below scenario. | ||
|
||
In another terminal start the server: | ||
```bash | ||
go run main.go -server | ||
``` | ||
|
||
### Request is successful | ||
Run the following command: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oKs" | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"category":{"id":0,"name":"string"},"id":1,"name":"sally","photoUrls":["string"],"status":"available","tags":[{"id":0,"name":"string"}]} | ||
``` | ||
|
||
### JWT token is invalid | ||
Run the following command: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oK" | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"errorMessage":"","validationMessage":"signature is invalid"} | ||
``` | ||
|
||
### Rate limit is exceeded | ||
Run the following command faster the 1 per second: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oKs" | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"status":"Rate Limit Exceeded - The service you have requested is over the allowed limit."} | ||
``` | ||
|
||
### Circuit breaker tripped | ||
Stop the server and run the following command 6 times: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oKs" | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"error":"circuit breaker tripped"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Gateway using Default Channel Pattern | ||
This recipe is a gateway using the defult channel pattern which uses JWT. | ||
|
||
#Channel Activity | ||
| Name | Type | Description | | ||
|:-----------|:--------|:--------------| | ||
| channel | string | The channel to put the value on | | ||
| value | string | The value to put on channel | | ||
|
||
|
||
#JWT | ||
| Name | Type | Description | | ||
|:-----------|:--------|:--------------| | ||
| token | string | The raw token | | ||
| key | string | The key used to sign the token | | ||
| signingMethod | string | The signing method used (HMAC, ECDSA, RSA, RSAPSS) | | ||
| issuer | string | The 'iss' standard claim to match against | | ||
| subject | string | The 'sub' standard claim to match against | | ||
| audience | string | The 'aud' standard claim to match against | | ||
|
||
|
||
## Installation | ||
* Install [Go](https://golang.org/) | ||
|
||
## Setup | ||
```bash | ||
git clone https://github.com/project-flogo/microgateway | ||
cd microgateway/examples/api/default-http-pattern | ||
``` | ||
|
||
## Testing | ||
Start the gateway: | ||
```bash | ||
go run main.go | ||
``` | ||
|
||
|
||
### Request is successful | ||
Run the following command: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oKs" | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"response":"Success!"} | ||
``` | ||
On the server screen, you get 200 response code and log service outputs "Output: Test log message service invoked" | ||
|
||
|
||
### JWT token is invalid | ||
Run the following command: | ||
```bash | ||
curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oK" | ||
``` | ||
|
||
You should see: | ||
```json | ||
{"errorMessage":"","validationMessage":"signature is invalid"} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
|
||
"github.com/project-flogo/core/engine" | ||
"github.com/project-flogo/microgateway/examples" | ||
_ "github.com/project-flogo/microgateway/activity/circuitbreaker" | ||
_ "github.com/project-flogo/microgateway/activity/jwt" | ||
_ "github.com/project-flogo/contrib/activity/channel" | ||
) | ||
|
||
|
||
func main() { | ||
|
||
e, err := examples.DefaultChannelPattern() | ||
if err != nil { | ||
panic(err) | ||
} | ||
engine.RunEngine(e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.