Skip to content

Commit

Permalink
fix(schema): make redirect defaults/forces fields required
Browse files Browse the repository at this point in the history
BREAKING CHANGE: service redirect must have both the `defaults` and
`forces` top-level keys, which may be empty. `redirect: {}` should
be replaced with `redirect: {defaults: {}, forces: {}}`.
  • Loading branch information
ssube committed Apr 19, 2020
1 parent 6851a80 commit 6d4db51
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 15 deletions.
4 changes: 3 additions & 1 deletion docs/controller/account-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ data:
- session:create
roles:
- user
redirect: {}
redirect:
defaults: {}
forces: {}
root:
allow: true
name: root
Expand Down
4 changes: 3 additions & 1 deletion docs/controller/bot-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ metadata:
name: default-bot
data:
filters: []
redirect: {}
redirect:
defaults: {}
forces: {}
transforms:
- metadata:
kind: template-transform
Expand Down
4 changes: 3 additions & 1 deletion docs/controller/command-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ data:
labels: {}
noun: echo
verb: create
redirect: {}
redirect:
defaults: {}
forces: {}
1 change: 1 addition & 0 deletions docs/controller/completion-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ metadata:
name: default-completion
data:
redirect:
defaults: {}
forces:
target:
source: false
Expand Down
4 changes: 3 additions & 1 deletion docs/controller/dice-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ metadata:
kind: dice-controller
name: test-dice
data:
redirect: {}
redirect:
defaults: {}
forces: {}
1 change: 1 addition & 0 deletions docs/controller/echo-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ metadata:
name: test-echo-controller
data:
redirect:
defaults: {}
forces:
target:
source: false
Expand Down
4 changes: 3 additions & 1 deletion docs/controller/learn-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ data:
- time
- weather
mode: include
redirect: {}
redirect:
defaults: {}
forces: {}
4 changes: 3 additions & 1 deletion docs/controller/math-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ data:
math:
matrix: Array
number: number
redirect: {}
redirect:
defaults: {}
forces: {}
4 changes: 3 additions & 1 deletion docs/controller/random-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ metadata:
kind: random-controller
name: test-random
data:
redirect: {}
redirect:
defaults: {}
forces: {}
4 changes: 3 additions & 1 deletion docs/controller/reaction-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ data:
values:
- regexp: !regexp /maple/
add: [":maple_leaf:"]
redirect: {}
redirect:
defaults: {}
forces: {}
4 changes: 3 additions & 1 deletion docs/controller/search-controller-mdn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ metadata:
data:
count: 3
field: args
redirect: {}
redirect:
defaults: {}
forces: {}
request:
method: GET
url: https://developer.mozilla.org/en-US/search.json?q={{ data }}
Expand Down
4 changes: 3 additions & 1 deletion docs/controller/sed-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ metadata:
kind: sed-controller
name: test-sed
data:
redirect: {}
redirect:
defaults: {}
forces: {}
4 changes: 3 additions & 1 deletion docs/controller/time-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ metadata:
name: test-time
data:
locale: en-US
redirect: {}
redirect:
defaults: {}
forces: {}
zone: America/Chicago
4 changes: 3 additions & 1 deletion docs/controller/token-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ metadata:
kind: token-controller
name: default-token
data:
redirect: {}
redirect:
defaults: {}
forces: {}
# nothing about these token settings is secure and they should not be used in production
token:
audience: [test-audience]
Expand Down
4 changes: 3 additions & 1 deletion docs/controller/user-controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ metadata:
kind: user-controller
name: default-user
data:
redirect: {}
redirect:
defaults: {}
forces: {}
4 changes: 3 additions & 1 deletion docs/controller/weather-controller-owm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ data:
api:
key: !env ISOLEX_WEATHER_API_KEY
root: https://api.openweathermap.org/data/2.5/
redirect: {}
redirect:
defaults: {}
forces: {}
transforms:
- metadata:
kind: template-transform
Expand Down
3 changes: 2 additions & 1 deletion docs/generator/command-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ data:
source: false
service:
kind: discord-listener
name: test-discord
name: test-discord
forces: {}
1 change: 1 addition & 0 deletions docs/generator/cron-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ data:
service: &target
kind: discord-listener
name: test-discord
forces: {}
services:
- *target
1 change: 1 addition & 0 deletions docs/generator/event-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ data:
service: &discord-metadata
kind: discord-listener
name: test-discord
forces: {}
services:
- *discord-metadata
1 change: 1 addition & 0 deletions docs/generator/github-listener-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ data:
service: &github-metadata
kind: github-listener
name: test-github
forces: {}
services:
- *github-metadata
1 change: 1 addition & 0 deletions docs/generator/message-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data:
service:
kind: discord-listener
name: test-discord
forces: {}
transforms:
- metadata:
kind: template-transform
Expand Down
1 change: 1 addition & 0 deletions docs/generator/metrics-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ data:
service:
kind: discord-listener
name: test-discord
forces: {}
timeout: 100ms
1 change: 1 addition & 0 deletions docs/listener/express-listener.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data:
service:
kind: discord-listener
name: test-discord
forces: {}
token:
audience: test-audience
issuer: !env ISOLEX_TOKEN_ISSUER
Expand Down
5 changes: 5 additions & 0 deletions src/controller/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ export abstract class BaseController<TData extends ControllerData> extends BotSe
}

protected async reply(baseCtx: Context, body: string): Promise<void> {
this.logger.debug({
original: baseCtx,
redirect: this.data.redirect,
}, 'preparing context redirect');

const context = redirectContext(baseCtx, this.data.redirect, this.services);
const msg = new Message({
body,
Expand Down
3 changes: 3 additions & 0 deletions src/schema/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ definitions:
entity-context-redirect:
type: object
additionalProperties: false
required:
- defaults
- forces
properties:
defaults:
allOf:
Expand Down

0 comments on commit 6d4db51

Please sign in to comment.