-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Option to register a webhook endpoints via "/admin/webhook" API - Each webhook is signed by a secret autogenerated when the webhook is created Signed-off-by: Kush Sharma <[email protected]>
- Loading branch information
1 parent
c000137
commit 86da957
Showing
38 changed files
with
5,758 additions
and
738 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
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,119 @@ | ||
package audit | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/protobuf/types/known/structpb" | ||
) | ||
|
||
func TestStructPB(t *testing.T) { | ||
input := make(map[string]interface{}) | ||
input["key"] = "value" | ||
input["data"] = map[string]interface{}{ | ||
"key2": "value2", | ||
} | ||
|
||
result, err := structpb.NewStruct(input) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, result) | ||
|
||
// map of string fails | ||
input["data2"] = map[string]string{ | ||
"key3": "value3", | ||
} | ||
_, err = structpb.NewStruct(input) | ||
assert.Error(t, err) | ||
delete(input, "data2") | ||
|
||
now := time.Now() | ||
logDecoded := map[string]interface{}{} | ||
err = mapstructure.Decode(&Log{ | ||
Source: "source", | ||
Target: Target{ | ||
ID: "target-id", | ||
Type: "target-type", | ||
}, | ||
Actor: Actor{ | ||
ID: "actor-id", | ||
Type: "actor-type", | ||
Name: "actor-name", | ||
}, | ||
Metadata: map[string]string{}, | ||
Action: "action", | ||
ID: "id", | ||
CreatedAt: now, | ||
}, &logDecoded) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, logDecoded) | ||
} | ||
|
||
func TestTransformToEventData(t *testing.T) { | ||
now := time.Now() | ||
type args struct { | ||
l *Log | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]interface{} | ||
}{ | ||
{ | ||
name: "should decode everything except metadata", | ||
args: args{ | ||
l: &Log{ | ||
Source: "source", | ||
Target: Target{ | ||
ID: "target-id", | ||
Type: "target-type", | ||
}, | ||
Actor: Actor{ | ||
ID: "actor-id", | ||
Type: "actor-type", | ||
Name: "actor-name", | ||
}, | ||
Metadata: map[string]string{}, | ||
Action: "action", | ||
ID: "id", | ||
CreatedAt: now, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"source": "source", | ||
"target": map[string]any{"id": "target-id", "type": "target-type"}, | ||
"actor": map[string]any{"id": "actor-id", "type": "actor-type", "name": "actor-name"}, | ||
"metadata": map[string]any{}, | ||
}, | ||
}, | ||
{ | ||
name: "should decode metadata correctly", | ||
args: args{ | ||
l: &Log{ | ||
Source: "source", | ||
Metadata: map[string]string{ | ||
"key": "value", | ||
}, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"source": "source", | ||
"actor": map[string]any{}, | ||
"target": map[string]any{}, | ||
"metadata": map[string]any{ | ||
"key": "value", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := TransformToEventData(tt.args.l) | ||
if diff := cmp.Diff(tt.want, got); diff != "" { | ||
t.Errorf("TransformToEventData() mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |
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,5 @@ | ||
package webhook | ||
|
||
type Config struct { | ||
EncryptionKey string `yaml:"encryption_key" mapstructure:"encryption_key" default:"hash-secret-should-be-32-chars--"` | ||
} |
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,11 @@ | ||
package webhook | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrNotFound = errors.New("webhook doesn't exist") | ||
ErrInvalidDetail = errors.New("invalid webhook details") | ||
ErrConflict = errors.New("webhook already exist") | ||
ErrInvalidUUID = errors.New("invalid syntax of uuid") | ||
ErrDisabled = errors.New("webhook is disabled") | ||
) |
Oops, something went wrong.