blob: 859281dbe180129c783ff5b2a6fab61e819a3a7e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.restapi.controller;
import com.yahoo.restapi.SlimeJsonResponse;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.Slime;
import com.yahoo.vespa.hosted.controller.auditlog.AuditLog;
/**
* @author mpolden
*/
public class AuditLogResponse extends SlimeJsonResponse {
public AuditLogResponse(AuditLog log) {
super(toSlime(log));
}
private static Slime toSlime(AuditLog log) {
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor entryArray = root.setArray("entries");
log.entries().forEach(entry -> {
Cursor entryObject = entryArray.addObject();
entryObject.setString("time", entry.at().toString());
entryObject.setString("client", entry.client().name());
entryObject.setString("user", entry.principal());
entryObject.setString("method", entry.method().name());
entryObject.setString("resource", entry.resource());
entry.data().ifPresent(data -> entryObject.setString("data", data));
});
return slime;
}
}
|