-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(callback): create callback plugin
Signed-off-by: Thomas Bétrancourt <thomas@betrancourt.net>
- Loading branch information
Showing
25 changed files
with
1,390 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,8 @@ dist/ | |
|
||
# VScode extension | ||
**/*.vsix | ||
|
||
# Related to tests | ||
docker-compose.override.yaml | ||
hack/test.env | ||
report.xml |
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
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,40 @@ | ||
package api | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/loopfz/gadgeto/tonic" | ||
) | ||
|
||
// bodyBindHook is a wrapper around the default binding hook of tonic. | ||
// It adds the possibility to bind a specific field in an object rather than | ||
// unconditionally binding the whole object. | ||
func bodyBindHook(c *gin.Context, v interface{}) error { | ||
val := reflect.ValueOf(v) | ||
typ := reflect.TypeOf(v).Elem() | ||
|
||
for i := 0; i < typ.NumField(); i++ { | ||
ft := typ.Field(i) | ||
if _, ok := ft.Tag.Lookup("body"); !ok { | ||
continue | ||
} | ||
flt := ft.Type | ||
var fv reflect.Value | ||
if flt.Kind() == reflect.Map { | ||
fv = reflect.New(flt) | ||
} else { | ||
fv = reflect.New(flt.Elem()) | ||
} | ||
if err := tonic.DefaultBindingHook(c, fv.Interface()); err != nil { | ||
return err | ||
} | ||
if flt.Kind() == reflect.Map { | ||
val.Elem().Field(i).Set(fv.Elem()) | ||
} else { | ||
val.Elem().Field(i).Set(fv) | ||
} | ||
} | ||
|
||
return tonic.DefaultBindingHook(c, v) | ||
} |
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
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,37 @@ | ||
package db | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/loopfz/gadgeto/zesty" | ||
) | ||
|
||
type KeyRotationCallback func(dbp zesty.DBProvider) error | ||
|
||
var ( | ||
keyRotationsCb []KeyRotationCallback | ||
keyRotationsCbMu sync.Mutex | ||
) | ||
|
||
// RegisterKeyRotations registers a callback which will be called during the encrypt | ||
// keys rotations | ||
func RegisterKeyRotations(cb KeyRotationCallback) { | ||
keyRotationsCbMu.Lock() | ||
defer keyRotationsCbMu.Unlock() | ||
|
||
keyRotationsCb = append(keyRotationsCb, cb) | ||
} | ||
|
||
// CallKeyRotations calls registered callbacks to rotate the encryption keys | ||
func CallKeyRotations(dbp zesty.DBProvider) error { | ||
keyRotationsCbMu.Lock() | ||
defer keyRotationsCbMu.Unlock() | ||
|
||
for _, cb := range keyRotationsCb { | ||
if err := cb(dbp); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
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
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,38 @@ | ||
name: callbackTemplate | ||
description: Template that test the callbacks | ||
title_format: "[test] callback template test" | ||
variables: | ||
- name: successField | ||
value: 'success' | ||
steps: | ||
createCallback: | ||
description: create a callback | ||
action: | ||
type: callback | ||
configuration: | ||
action: create | ||
schema: |- | ||
{ | ||
"$schema": "http://json-schema.org/schema#", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["{{evalCache `successField`}}"], | ||
"properties": { | ||
"{{evalCache `successField`}}": { | ||
"type": "boolean" | ||
} | ||
} | ||
} | ||
waitCallback: | ||
dependencies: | ||
- createCallback | ||
description: everything is OK | ||
action: | ||
type: callback | ||
configuration: | ||
action: wait | ||
id: '{{.step.createCallback.output.id}}' | ||
|
||
result_format: | ||
foo: "{{.step.waitCallback.output.success}}" |
Oops, something went wrong.