Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

fix event logging #1860

Merged
merged 5 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions src/ApiService/ApiService/onefuzzlib/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,20 @@ public void LogEvent(BaseEvent anEvent, EventType eventType) {
var options = EntityConverter.GetJsonSerializerOptions();
options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
options.Converters.Add(new RemoveUserInfo());
var serializedEvent = JsonSerializer.Serialize(anEvent, options);
var serializedEvent = JsonSerializer.Serialize(anEvent, anEvent.GetType(), options);
_log.WithTag("Event Type", eventType.ToString()).Info($"sending event: {eventType} - {serializedEvent}");
}
}


internal class RemoveUserInfo : JsonConverter<UserInfo> {
public class RemoveUserInfo : JsonConverter<UserInfo> {
chkeita marked this conversation as resolved.
Show resolved Hide resolved
public override UserInfo? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
//TODO: I might be wrong but seems like better way of doing this is to have a separate type,
//that if object of the type - then ignore user info...
var newOptions = new JsonSerializerOptions(options);
RemoveUserInfo? self = null;
foreach (var converter in newOptions.Converters) {
if (converter is RemoveUserInfo) {
self = (RemoveUserInfo)converter;
break;
}
}

if (self != null) {
newOptions.Converters.Remove(self);
}

return JsonSerializer.Deserialize<UserInfo>(ref reader, newOptions);
throw new NotImplementedException();
}

public override void Write(Utf8JsonWriter writer, UserInfo value, JsonSerializerOptions options) {
writer.WriteStringValue("{}");
writer.WriteStartObject();
writer.WriteEndObject();
}
}
}
19 changes: 19 additions & 0 deletions src/ApiService/Tests/RemoveUserInfoTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Text.Json;
using Microsoft.OneFuzz.Service;
using Xunit;

namespace Tests {
public class RemoveUserInfoTest {

[Fact]
void TestSerilize() {
var userInfo = new UserInfo(Guid.NewGuid(), Guid.NewGuid(), "test");
var options = new JsonSerializerOptions();
options.Converters.Add(new RemoveUserInfo());
var serialized = JsonSerializer.Serialize(userInfo, options);

Assert.Equal("{}", serialized);
}
}
}