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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.uid2.admin.auth.AdminAuthMiddleware;
import com.uid2.admin.job.JobDispatcher;
import com.uid2.admin.job.jobsync.EncryptedFilesSyncJob;
import com.uid2.admin.vertx.Endpoints;
import com.uid2.admin.vertx.WriteLock;
import com.uid2.shared.auth.Role;
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
Expand Down Expand Up @@ -38,14 +39,14 @@ public EncryptedFilesSyncService(

@Override
public void setupRoutes(Router router) {
router.post("/api/encrypted-files/refresh").blockingHandler(auth.handle((ctx) -> {
router.post(Endpoints.API_ENCRYPTED_FILES_REFRESH.toString()).blockingHandler(auth.handle((ctx) -> {
synchronized (writeLock) {
this.handleEncryptedFileSync(ctx);
}
},
Role.MAINTAINER, Role.PRIVATE_OPERATOR_SYNC));

router.post("/api/encrypted-files/syncNow").blockingHandler(auth.handle(
router.post(Endpoints.API_ENCRYPTED_FILES_SYNC_NOW.toString()).blockingHandler(auth.handle(
this::handleEncryptedFileSyncNow,
Role.MAINTAINER, Role.PRIVATE_OPERATOR_SYNC));
}
Expand Down
81 changes: 57 additions & 24 deletions webroot/adm/cloud-encryption-key.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ <h3>Operations</h3>
<ul>
<li><a href="#" id="doMeta">Get Metadata</a></li>
<li><a href="#" id="doList">List Cloud Encryption Keys</a></li>
<li><a href="#" id="doRotate">Rotate Cloud Encryption Keys</a></li>
<li><a href="#" id="doEncrypt">Re-encrypt All S3 Files</a></li>
</ul>

<br>
Expand All @@ -46,7 +48,21 @@ <h3>Output</h3>
{
name: "Site",
formatter: (cell, row) => {
return gridjs.html(`<span class="${row.cells[4].data}">${cell.siteId} - ${cell.siteName}</span>`)
return gridjs.html(`<span class="${row.cells[4].data}">${formatSite(cell)}</span>`)
},
sort: {
compare: (a, b) => {
const fullA = formatSite(a);
const fullB = formatSite(b);

if (fullA > fullB) {
return 1;
} else if (fullA < fullB) {
return -1;
} else {
return 0;
}
}
}
},
{
Expand All @@ -73,7 +89,7 @@ <h3>Output</h3>
if (cellIndex === 0) {
return cell;
} else if (cellIndex === 1) {
return `${cell.siteId} - ${cell.siteName}`;
return formatSite(cell);
}
}
},
Expand All @@ -97,7 +113,11 @@ <h3>Output</h3>
timeZoneName: "short"
};
return date.toLocaleString("en-US", options);
}
};

const formatSite = (site) => {
return `${site.siteId} - ${site.siteName}`;
};

const updateGrid = (grid, data) => {
const groupedData = data.cloudEncryptionKeys.reduce((acc, key) => {
Expand All @@ -123,36 +143,49 @@ <h3>Output</h3>
grid
.updateConfig({ data: gridData })
.forceRender();
}
};

const clearGrid = (grid) => {
grid
.updateConfig({ data: [] })
.forceRender();
}
};

const doList = () => {
clearGrid(grid);
doApiCallWithCallback("GET", "/api/site/list", (text) => {
const sites = JSON.parse(text);
const siteDict = sites.reduce((acc, site) => {
acc[site.id] = site.name;
return acc;
}, {});

doApiCallWithCallback("GET", "/api/cloud-encryption-key/list", (text) => {
const data = JSON.parse(text);
data.cloudEncryptionKeys.forEach((key) => {
key.siteName = !siteDict[key.siteId] ? "Unknown site" : siteDict[key.siteId]
});
updateGrid(grid, data);
}, errorCallback);
}, errorCallback);
};

$(document).ready(function () {
$("#doMeta").on("click", function () {
$(document).ready(() => {
$("#doMeta").on("click", () => {
doApiCall("GET", "/api/cloud-encryption-key/metadata", "#standardOutput", "#errorOutput");
});

$("#doList").on("click", function () {
clearGrid(grid);
doApiCallWithCallback("GET", "/api/site/list", (text) => {
const sites = JSON.parse(text);
const siteDict = sites.reduce((acc, site) => {
acc[site.id] = site.name;
return acc;
}, {});

doApiCallWithCallback("GET", "/api/cloud-encryption-key/list", (text) => {
const data = JSON.parse(text);
data.cloudEncryptionKeys.forEach((key) => {
key.siteName = !siteDict[key.siteId] ? "Unknown site" : siteDict[key.siteId]
});
updateGrid(grid, data);
}, errorCallback);
}, errorCallback);
$("#doList").on("click", () => {
doList();
});

$("#doRotate").on("click", () => {
doApiCall("POST", "/api/cloud-encryption-key/rotate", "#standardOutput", "#errorOutput");
doList();
});

$("#doEncrypt").on("click", () => {
doApiCall("POST", "/api/encrypted-files/syncNow", "#standardOutput", "#errorOutput");
});
});
</script>
Expand Down