Skip to content
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
21 changes: 16 additions & 5 deletions src/main/java/com/uid2/admin/model/CloudEncryptionKeySummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.uid2.shared.model.CloudEncryptionKey;

import java.time.Instant;

public record CloudEncryptionKeySummary(
@JsonProperty int id,
@JsonProperty int siteId,
@JsonProperty long activates,
@JsonProperty long created
@JsonProperty int id,
@JsonProperty int siteId,
@JsonProperty String activates,
@JsonProperty String created
) {
public static CloudEncryptionKeySummary fromFullKey(CloudEncryptionKey key) {
return new CloudEncryptionKeySummary(key.getId(), key.getSiteId(), key.getActivates(), key.getCreated());
return new CloudEncryptionKeySummary(
key.getId(),
key.getSiteId(),
toIsoTimestamp(key.getActivates()),
toIsoTimestamp(key.getCreated())
);
}

private static String toIsoTimestamp(Long epochSeconds) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract this to a repo-level util method? Might be useful for other pages as well in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do that when we actually have the 2nd use case. YAGNI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking we can reuse this for the salts and encryption keys tabs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But fair enough, we can just refactor it out once we start working on other stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we do that enhancement, we can move this to some utils.

return Instant.ofEpochSecond(epochSeconds).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ public void testList_noAccess(Vertx vertx, VertxTestContext testContext) {
public void testList_withKeys(Vertx vertx, VertxTestContext testContext) {
fakeAuth(Role.MAINTAINER);

CloudEncryptionKey key1 = new CloudEncryptionKey(1, 2, 100, 100, "secret 1");
CloudEncryptionKey key2 = new CloudEncryptionKey(2, 2, 200, 100, "secret 2");
var date1EpochSeconds = 100;
var date2EpochSeconds = 200;
var date1Iso = "1970-01-01T00:01:40Z";
var date2Iso = "1970-01-01T00:03:20Z";

CloudEncryptionKey key1 = new CloudEncryptionKey(1, 2, date1EpochSeconds, date1EpochSeconds, "secret 1");
CloudEncryptionKey key2 = new CloudEncryptionKey(2, 2, date2EpochSeconds, date1EpochSeconds, "secret 2");

setCloudEncryptionKeys(key1, key2);

var expected = new CloudEncryptionKeyListResponse(List.of(
new CloudEncryptionKeySummary(1, 2, 100, 100),
new CloudEncryptionKeySummary(2, 2, 200, 100)
new CloudEncryptionKeySummary(1, 2, date1Iso, date1Iso),
new CloudEncryptionKeySummary(2, 2, date2Iso, date1Iso)
));

get(vertx, testContext, Endpoints.CLOUD_ENCRYPTION_KEY_LIST, response -> {
Expand Down