Skip to content

Commit

Permalink
Adjust interface to let the consumer get the real timestamp (#190)
Browse files Browse the repository at this point in the history
* Adjust interface to let the consumer get the real timestamp
* Remove dead code
* Fix typo
  • Loading branch information
jastBytes authored Jul 5, 2022
1 parent f983046 commit d7f1e78
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 440 deletions.
4 changes: 3 additions & 1 deletion api/domain/audit/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ syntax = "proto3";
// This file follows google's gRPC naming conventions:
// https://cloud.google.com/apis/design/naming_convention

import "google/protobuf/timestamp.proto";

option go_package = "github.com/finleap-connect/monoskope/pkg/api/domain/audit";

package audit;

// human readable representation of an event for auditing
message HumanReadableEvent {
// the timestamp when the event occurred
string when = 1;
google.protobuf.Timestamp timestamp = 1;
// issuer name of the event
string issuer = 2;
// the uuid of the issuer
Expand Down
2 changes: 1 addition & 1 deletion api/domain/queryhandler_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ service ClusterAccess {
}

service AuditLog {
// GetByDateRange returns human-readable events within the specified data
// GetByDateRange returns human-readable events within the specified date
// range
rpc GetByDateRange(GetAuditLogByDateRangeRequest)
returns (stream audit.HumanReadableEvent);
Expand Down
20 changes: 1 addition & 19 deletions internal/audit_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
cmdData "github.com/finleap-connect/monoskope/pkg/api/domain/commanddata"
esApi "github.com/finleap-connect/monoskope/pkg/api/eventsourcing"
cmd "github.com/finleap-connect/monoskope/pkg/domain/commands"
"github.com/finleap-connect/monoskope/pkg/domain/constants/aggregates"
commandTypes "github.com/finleap-connect/monoskope/pkg/domain/constants/commands"
fConsts "github.com/finleap-connect/monoskope/pkg/domain/constants/formatters"
"github.com/finleap-connect/monoskope/pkg/domain/constants/roles"
Expand Down Expand Up @@ -262,23 +261,6 @@ var _ = Describe("AuditLog Test", func() {
expectedNumEventsDoneByAdmin++
expectedDetailMsgs = append(expectedDetailMsgs, fConsts.TenantClusterBindingCreatedDetailsFormat.Sprint(testEnv.gatewayTestEnv.AdminUser.Email, "Tenant Z", "Cluster Z"))

// RequestCertificate
command, err = cmd.AddCommandData(
cmd.CreateCommand(uuid.Nil, commandTypes.RequestCertificate),
&cmdData.RequestCertificate{
ReferencedAggregateId: clusterId.String(),
ReferencedAggregateType: aggregates.Cluster.String(),
SigningRequest: []byte("-----BEGIN CERTIFICATE REQUEST-----this is a CSR-----END CERTIFICATE REQUEST-----"),
},
)
Expect(err).ToNot(HaveOccurred())
Eventually(func(g Gomega) {
reply, err = commandHandlerClient().Execute(ctx, command)
g.Expect(err).ToNot(HaveOccurred())
}).Should(Succeed())
expectedNumEventsDoneByAdmin++
expectedDetailMsgs = append(expectedDetailMsgs, fConsts.CertificateRequestedDetailsFormat.Sprint(testEnv.gatewayTestEnv.AdminUser.Email))

// DeleteUser
_, err = commandHandlerClient().Execute(ctx,
cmd.CreateCommand(userId, commandTypes.DeleteUser))
Expand Down Expand Up @@ -342,7 +324,7 @@ var _ = Describe("AuditLog Test", func() {
}
Expect(err).ToNot(HaveOccurred())

Expect(e.When).ToNot(BeEmpty())
Expect(e.Timestamp).ToNot(BeNil())
Expect(e.Issuer).ToNot(BeEmpty())
Expect(e.IssuerId).ToNot(BeEmpty())
Expect(e.EventType).ToNot(BeEmpty())
Expand Down
57 changes: 32 additions & 25 deletions pkg/api/domain/audit/event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion pkg/api/domain/audit/event.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/api/domain/queryhandler_service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/audit/formatters/audit/audit_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
esApi "github.com/finleap-connect/monoskope/pkg/api/eventsourcing"
"github.com/finleap-connect/monoskope/pkg/audit/formatters"
"github.com/finleap-connect/monoskope/pkg/audit/formatters/event"
fConsts "github.com/finleap-connect/monoskope/pkg/domain/constants/formatters"
_ "github.com/finleap-connect/monoskope/pkg/domain/formatters/events"
"github.com/finleap-connect/monoskope/pkg/domain/formatters/overviews"
"github.com/finleap-connect/monoskope/pkg/domain/projectors"
Expand Down Expand Up @@ -57,7 +56,7 @@ func NewAuditFormatter(esClient esApi.EventStoreClient, efRegistry event.EventFo
// NewHumanReadableEvent creates a HumanReadableEvent of a given event
func (f *auditFormatter) NewHumanReadableEvent(ctx context.Context, event *esApi.Event) *audit.HumanReadableEvent {
humanReadableEvent := &audit.HumanReadableEvent{
When: event.Timestamp.AsTime().Format(fConsts.TimeFormat),
Timestamp: event.Timestamp,
Issuer: event.Metadata[auth.HeaderAuthEmail],
IssuerId: event.Metadata[auth.HeaderAuthId],
EventType: event.Type,
Expand Down
104 changes: 0 additions & 104 deletions pkg/domain/aggregates/certificate.go

This file was deleted.

Loading

0 comments on commit d7f1e78

Please sign in to comment.