Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
589d1a09c5 |
@@ -14,6 +14,20 @@ You can run your application in dev mode that enables live coding using:
|
|||||||
|
|
||||||
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at <http://localhost:8080/q/dev/>.
|
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at <http://localhost:8080/q/dev/>.
|
||||||
|
|
||||||
|
## Bootstrapping buckets
|
||||||
|
|
||||||
|
Buckets can be created automatically on startup by setting the environment variable `DEV_DINAUER_R9T_INIT_BUCKETS` to a comma-separated list of bucket names:
|
||||||
|
|
||||||
|
```shell script
|
||||||
|
DEV_DINAUER_R9T_INIT_BUCKETS=invoices,images,backups
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively the property `dev.dinauer.r9t.init.buckets` can be set in `application.properties`.
|
||||||
|
|
||||||
|
- Buckets that already exist are skipped.
|
||||||
|
- Bucket names follow the regular naming rules (3-63 characters, lowercase letters, digits, `.` and `-`). An invalid name prevents the application from starting.
|
||||||
|
- If the variable is not set, no buckets are created.
|
||||||
|
|
||||||
## Packaging and running the application
|
## Packaging and running the application
|
||||||
|
|
||||||
The application can be packaged using:
|
The application can be packaged using:
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package dev.dinauer.r9t.core.audit;
|
|
||||||
|
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@ApplicationScoped
|
|
||||||
public class AuditLogCsvMapper
|
|
||||||
{
|
|
||||||
private static final String HEADER = "timestamp,action,resourceType,bucket,key,principal";
|
|
||||||
|
|
||||||
public String map(List<AuditLogEntry> input)
|
|
||||||
{
|
|
||||||
return Stream.concat(Stream.of(HEADER), input.stream().map(this::map))
|
|
||||||
.collect(Collectors.joining("\r\n", "", "\r\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String map(AuditLogEntry input)
|
|
||||||
{
|
|
||||||
return String.join(",",
|
|
||||||
csvField(input.timestamp().toString()),
|
|
||||||
csvField(input.action().name()),
|
|
||||||
csvField(input.resourceType().name()),
|
|
||||||
csvField(input.bucket()),
|
|
||||||
csvField(input.key()),
|
|
||||||
csvField(input.principal()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String csvField(String value)
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (needsQuoting(value))
|
|
||||||
{
|
|
||||||
return "\"" + value.replace("\"", "\"\"") + "\"";
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean needsQuoting(String value)
|
|
||||||
{
|
|
||||||
return value.contains(",") || value.contains("\"") || value.contains("\n") || value.contains("\r");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,23 +18,10 @@ public class AuditLogResource
|
|||||||
@Inject
|
@Inject
|
||||||
AuditLogJsonMapper auditLogJsonMapper;
|
AuditLogJsonMapper auditLogJsonMapper;
|
||||||
|
|
||||||
@Inject
|
|
||||||
AuditLogCsvMapper auditLogCsvMapper;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response list()
|
public Response list()
|
||||||
{
|
{
|
||||||
return Response.ok(auditLogJsonMapper.map(auditLogService.list())).build();
|
return Response.ok(auditLogJsonMapper.map(auditLogService.list())).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/csv")
|
|
||||||
@Produces("text/csv")
|
|
||||||
public Response csv()
|
|
||||||
{
|
|
||||||
return Response.ok(auditLogCsvMapper.map(auditLogService.list()))
|
|
||||||
.header("Content-Disposition", "attachment; filename=\"audit-logs.csv\"")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package dev.dinauer.r9t.core.audit;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
public class AuditLogCsvMapperTest
|
|
||||||
{
|
|
||||||
private final AuditLogCsvMapper mapper = new AuditLogCsvMapper();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void empty()
|
|
||||||
{
|
|
||||||
assertEquals("timestamp,action,resourceType,bucket,key,principal\r\n", mapper.map(List.of()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void escapesSpecialCharacters()
|
|
||||||
{
|
|
||||||
AuditLogEntry entry = new AuditLogEntry(Instant.parse("2026-10-03T12:00:00Z"), AuditAction.CREATE,
|
|
||||||
AuditResourceType.OBJECT, "bucket", "a,b \"c\"\nd.txt", null);
|
|
||||||
|
|
||||||
assertEquals("timestamp,action,resourceType,bucket,key,principal\r\n"
|
|
||||||
+ "2026-10-03T12:00:00Z,CREATE,OBJECT,bucket,\"a,b \"\"c\"\"\nd.txt\",\r\n", mapper.map(List.of(entry)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
package dev.dinauer.r9t.core.audit;
|
|
||||||
|
|
||||||
import dev.dinauer.r9t.core.auth.SigV4TestSigner;
|
|
||||||
import io.quarkus.test.common.http.TestHTTPResource;
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.http.HttpClient;
|
|
||||||
import java.net.http.HttpRequest;
|
|
||||||
import java.net.http.HttpResponse;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
@QuarkusTest
|
|
||||||
public class AuditLogCsvTest
|
|
||||||
{
|
|
||||||
private static final String BUCKET = "audit-csv-test-bucket";
|
|
||||||
private static final String KEY = "audit-csv-test.txt";
|
|
||||||
private static final String ACCESS_KEY = "testkey";
|
|
||||||
private static final String SECRET_KEY = "testsecret";
|
|
||||||
|
|
||||||
@TestHTTPResource
|
|
||||||
URI baseUri;
|
|
||||||
|
|
||||||
private final HttpClient client = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void csv() throws Exception
|
|
||||||
{
|
|
||||||
send("PUT", baseUri.resolve(BUCKET), "".getBytes(StandardCharsets.UTF_8));
|
|
||||||
send("PUT", baseUri.resolve(BUCKET + "/" + KEY), "content".getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
HttpResponse<String> response = send("GET", baseUri.resolve("_audit-logs/csv"), new byte[0]);
|
|
||||||
|
|
||||||
assertEquals(200, response.statusCode());
|
|
||||||
assertTrue(response.headers().firstValue("Content-Type").orElse("").startsWith("text/csv"));
|
|
||||||
assertEquals("attachment; filename=\"audit-logs.csv\"",
|
|
||||||
response.headers().firstValue("Content-Disposition").orElse(""));
|
|
||||||
String[] lines = response.body().split("\r\n");
|
|
||||||
assertEquals("timestamp,action,resourceType,bucket,key,principal", lines[0]);
|
|
||||||
assertTrue(lines[1].endsWith(",CREATE,OBJECT," + BUCKET + "," + KEY + "," + ACCESS_KEY));
|
|
||||||
assertTrue(lines[2].endsWith(",CREATE,BUCKET," + BUCKET + ",," + ACCESS_KEY));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void unsignedRequestIsRejected() throws Exception
|
|
||||||
{
|
|
||||||
HttpResponse<Void> response = client.send(
|
|
||||||
HttpRequest.newBuilder(baseUri.resolve("_audit-logs/csv")).GET().build(),
|
|
||||||
HttpResponse.BodyHandlers.discarding());
|
|
||||||
assertEquals(401, response.statusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
public void cleanup() throws Exception
|
|
||||||
{
|
|
||||||
send("DELETE", baseUri.resolve(BUCKET + "/" + KEY), new byte[0]);
|
|
||||||
send("DELETE", baseUri.resolve(BUCKET), new byte[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private HttpResponse<String> send(String method, URI uri, byte[] body) throws Exception
|
|
||||||
{
|
|
||||||
HttpRequest.Builder builder = HttpRequest.newBuilder(uri)
|
|
||||||
.method(method, HttpRequest.BodyPublishers.ofByteArray(body));
|
|
||||||
SigV4TestSigner.sign(builder, method, uri, ACCESS_KEY, SECRET_KEY, body);
|
|
||||||
return client.send(builder.build(), HttpResponse.BodyHandlers.ofString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user