-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Roman Dmytrenko <[email protected]>
- Loading branch information
Showing
17 changed files
with
273 additions
and
92 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
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 kafka | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
|
||
"github.com/hamba/avro" | ||
"go.flipt.io/flipt/internal/server/audit" | ||
rpcaudit "go.flipt.io/flipt/rpc/flipt/audit" | ||
) | ||
|
||
func toAvro(v any) ([]byte, error) { | ||
if e, ok := v.(audit.Event); ok { | ||
if e.Payload != nil { | ||
//FIXME: this modifies the origin payload | ||
payloadString, err := json.Marshal(e.Payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var payload map[string]any | ||
err = json.Unmarshal(payloadString, &payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
e.Payload = payload | ||
} | ||
buf := &bytes.Buffer{} | ||
enc, err := avro.NewEncoder(rpcaudit.AvroSchema, buf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = enc.Encode(e) | ||
return buf.Bytes(), err | ||
} | ||
return nil, errors.New("unsupported struct") | ||
} |
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,43 @@ | ||
package kafka | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.flipt.io/flipt/internal/server/audit" | ||
"go.flipt.io/flipt/rpc/flipt" | ||
) | ||
|
||
func TestEncoding(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
f func(any) ([]byte, error) | ||
}{ | ||
{"protobuf", toProtobuf}, | ||
{"avro", toAvro}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
r := flipt.NewRequest(flipt.ResourceFlag, flipt.ActionCreate, flipt.WithSubject(flipt.SubjectRule)) | ||
e := audit.NewEvent( | ||
r, | ||
&audit.Actor{ | ||
Authentication: "token", | ||
IP: "127.0.0.1", | ||
}, | ||
&audit.Flag{ | ||
Key: "this-flag", | ||
Name: "this-flag", | ||
Description: "this description", | ||
Enabled: false, | ||
NamespaceKey: "default", | ||
}, | ||
) | ||
|
||
b, err := tt.f(*e) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, b) | ||
}) | ||
} | ||
} |
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,74 @@ | ||
{ | ||
"name": "event", | ||
"type": "record", | ||
"fields": [ | ||
{ | ||
"name": "version", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "type", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "action", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "metadata", | ||
"type": { | ||
"type": "record", | ||
"name": "metadata", | ||
"fields": [ | ||
{ | ||
"name": "actor", | ||
"type": [ | ||
"null", | ||
{ | ||
"type": "record", | ||
"name": "actor", | ||
"fields": [ | ||
{ | ||
"name": "authentication", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "ip", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "email", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "name", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "picture", | ||
"type": "string" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "timestamp", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "status", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "payload", | ||
"type": { | ||
"type":"map", | ||
"values": ["null", "string", "int", "boolean"] | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.