Skip to content

Commit 1d75c80

Browse files
authored
Merge pull request #445 from IABTechLab/gdm-UID2-3577-cloud-encryption-rotate
Added re-encrypting S3 files in UI
2 parents f83f975 + 0a9b111 commit 1d75c80

File tree

2 files changed

+60
-26
lines changed

2 files changed

+60
-26
lines changed

src/main/java/com/uid2/admin/vertx/service/EncryptedFilesSyncService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.uid2.admin.auth.AdminAuthMiddleware;
44
import com.uid2.admin.job.JobDispatcher;
55
import com.uid2.admin.job.jobsync.EncryptedFilesSyncJob;
6+
import com.uid2.admin.vertx.Endpoints;
67
import com.uid2.admin.vertx.WriteLock;
78
import com.uid2.shared.auth.Role;
89
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
@@ -38,14 +39,14 @@ public EncryptedFilesSyncService(
3839

3940
@Override
4041
public void setupRoutes(Router router) {
41-
router.post("/api/encrypted-files/refresh").blockingHandler(auth.handle((ctx) -> {
42+
router.post(Endpoints.API_ENCRYPTED_FILES_REFRESH.toString()).blockingHandler(auth.handle((ctx) -> {
4243
synchronized (writeLock) {
4344
this.handleEncryptedFileSync(ctx);
4445
}
4546
},
4647
Role.MAINTAINER, Role.PRIVATE_OPERATOR_SYNC));
4748

48-
router.post("/api/encrypted-files/syncNow").blockingHandler(auth.handle(
49+
router.post(Endpoints.API_ENCRYPTED_FILES_SYNC_NOW.toString()).blockingHandler(auth.handle(
4950
this::handleEncryptedFileSyncNow,
5051
Role.MAINTAINER, Role.PRIVATE_OPERATOR_SYNC));
5152
}

webroot/adm/cloud-encryption-key.html

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ <h3>Operations</h3>
2222
<ul>
2323
<li><a href="#" id="doMeta">Get Metadata</a></li>
2424
<li><a href="#" id="doList">List Cloud Encryption Keys</a></li>
25+
<li><a href="#" id="doRotate">Rotate Cloud Encryption Keys</a></li>
26+
<li><a href="#" id="doEncrypt">Re-encrypt All S3 Files</a></li>
2527
</ul>
2628

2729
<br>
@@ -46,7 +48,21 @@ <h3>Output</h3>
4648
{
4749
name: "Site",
4850
formatter: (cell, row) => {
49-
return gridjs.html(`<span class="${row.cells[4].data}">${cell.siteId} - ${cell.siteName}</span>`)
51+
return gridjs.html(`<span class="${row.cells[4].data}">${formatSite(cell)}</span>`)
52+
},
53+
sort: {
54+
compare: (a, b) => {
55+
const fullA = formatSite(a);
56+
const fullB = formatSite(b);
57+
58+
if (fullA > fullB) {
59+
return 1;
60+
} else if (fullA < fullB) {
61+
return -1;
62+
} else {
63+
return 0;
64+
}
65+
}
5066
}
5167
},
5268
{
@@ -73,7 +89,7 @@ <h3>Output</h3>
7389
if (cellIndex === 0) {
7490
return cell;
7591
} else if (cellIndex === 1) {
76-
return `${cell.siteId} - ${cell.siteName}`;
92+
return formatSite(cell);
7793
}
7894
}
7995
},
@@ -97,7 +113,11 @@ <h3>Output</h3>
97113
timeZoneName: "short"
98114
};
99115
return date.toLocaleString("en-US", options);
100-
}
116+
};
117+
118+
const formatSite = (site) => {
119+
return `${site.siteId} - ${site.siteName}`;
120+
};
101121

102122
const updateGrid = (grid, data) => {
103123
const groupedData = data.cloudEncryptionKeys.reduce((acc, key) => {
@@ -123,36 +143,49 @@ <h3>Output</h3>
123143
grid
124144
.updateConfig({ data: gridData })
125145
.forceRender();
126-
}
146+
};
127147

128148
const clearGrid = (grid) => {
129149
grid
130150
.updateConfig({ data: [] })
131151
.forceRender();
132-
}
152+
};
153+
154+
const doList = () => {
155+
clearGrid(grid);
156+
doApiCallWithCallback("GET", "/api/site/list", (text) => {
157+
const sites = JSON.parse(text);
158+
const siteDict = sites.reduce((acc, site) => {
159+
acc[site.id] = site.name;
160+
return acc;
161+
}, {});
162+
163+
doApiCallWithCallback("GET", "/api/cloud-encryption-key/list", (text) => {
164+
const data = JSON.parse(text);
165+
data.cloudEncryptionKeys.forEach((key) => {
166+
key.siteName = !siteDict[key.siteId] ? "Unknown site" : siteDict[key.siteId]
167+
});
168+
updateGrid(grid, data);
169+
}, errorCallback);
170+
}, errorCallback);
171+
};
133172

134-
$(document).ready(function () {
135-
$("#doMeta").on("click", function () {
173+
$(document).ready(() => {
174+
$("#doMeta").on("click", () => {
136175
doApiCall("GET", "/api/cloud-encryption-key/metadata", "#standardOutput", "#errorOutput");
137176
});
138177

139-
$("#doList").on("click", function () {
140-
clearGrid(grid);
141-
doApiCallWithCallback("GET", "/api/site/list", (text) => {
142-
const sites = JSON.parse(text);
143-
const siteDict = sites.reduce((acc, site) => {
144-
acc[site.id] = site.name;
145-
return acc;
146-
}, {});
147-
148-
doApiCallWithCallback("GET", "/api/cloud-encryption-key/list", (text) => {
149-
const data = JSON.parse(text);
150-
data.cloudEncryptionKeys.forEach((key) => {
151-
key.siteName = !siteDict[key.siteId] ? "Unknown site" : siteDict[key.siteId]
152-
});
153-
updateGrid(grid, data);
154-
}, errorCallback);
155-
}, errorCallback);
178+
$("#doList").on("click", () => {
179+
doList();
180+
});
181+
182+
$("#doRotate").on("click", () => {
183+
doApiCall("POST", "/api/cloud-encryption-key/rotate", "#standardOutput", "#errorOutput");
184+
doList();
185+
});
186+
187+
$("#doEncrypt").on("click", () => {
188+
doApiCall("POST", "/api/encrypted-files/syncNow", "#standardOutput", "#errorOutput");
156189
});
157190
});
158191
</script>

0 commit comments

Comments
 (0)