Skip to content

Commit 8161780

Browse files
committed
Renamed salt rotate zero to salt rebuild
1 parent 0d1938b commit 8161780

File tree

3 files changed

+37
-39
lines changed

3 files changed

+37
-39
lines changed

src/main/java/com/uid2/admin/vertx/Endpoints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public enum Endpoints {
6767
API_PRIVATE_SITES_REFRESH_NOW("/api/private-sites/refreshNow"),
6868

6969
API_SALT_SNAPSHOTS("/api/salt/snapshots"),
70+
API_SALT_REBUILD("/api/salt/rebuild"),
7071
API_SALT_ROTATE("/api/salt/rotate"),
71-
API_SALT_ROTATE_ZERO("/api/salt/rotate-zero"),
7272

7373
API_SEARCH("/api/search"),
7474

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

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ public void setupRoutes(Router router) {
5454
router.get(API_SALT_SNAPSHOTS.toString()).handler(
5555
auth.handle(this::handleSaltSnapshots, Role.MAINTAINER));
5656

57-
router.post(API_SALT_ROTATE.toString()).blockingHandler(auth.handle((ctx) -> {
57+
router.post(API_SALT_REBUILD.toString()).blockingHandler(auth.handle(ctx -> {
5858
synchronized (writeLock) {
59-
this.handleSaltRotate(ctx);
59+
this.handleSaltRebuild(ctx);
6060
}
61-
}, new AuditParams(List.of("fraction", "min_ages_in_seconds", "target_date"), Collections.emptyList()), Role.SUPER_USER, Role.SECRET_ROTATION));
61+
}, new AuditParams(List.of(), Collections.emptyList()), Role.MAINTAINER));
6262

63-
router.post(API_SALT_ROTATE_ZERO.toString()).blockingHandler(auth.handle((ctx) -> {
63+
router.post(API_SALT_ROTATE.toString()).blockingHandler(auth.handle((ctx) -> {
6464
synchronized (writeLock) {
65-
this.handleSaltRotateZero(ctx);
65+
this.handleSaltRotate(ctx);
6666
}
67-
}, new AuditParams(List.of(), Collections.emptyList()), Role.MAINTAINER));
67+
}, new AuditParams(List.of("fraction", "min_ages_in_seconds", "target_date"), Collections.emptyList()), Role.SUPER_USER, Role.SECRET_ROTATION));
6868
}
6969

7070
private void handleSaltSnapshots(RoutingContext rc) {
7171
try {
7272
final JsonArray ja = new JsonArray();
73-
this.saltProvider.getSnapshots().stream()
73+
saltProvider.getSnapshots().stream()
7474
.forEachOrdered(s -> ja.add(toJson(s)));
7575

7676
rc.response()
@@ -82,30 +82,21 @@ private void handleSaltSnapshots(RoutingContext rc) {
8282
}
8383
}
8484

85-
private void handleSaltRotate(RoutingContext rc) {
85+
private void handleSaltRebuild(RoutingContext rc) {
8686
try {
87-
final Optional<Double> fraction = RequestUtil.getDouble(rc, "fraction");
88-
if (fraction.isEmpty()) return;
89-
final Duration[] minAges = RequestUtil.getDurations(rc, "min_ages_in_seconds");
90-
if (minAges == null) return;
91-
92-
93-
final TargetDate targetDate =
94-
RequestUtil.getDate(rc, "target_date", DateTimeFormatter.ISO_LOCAL_DATE)
95-
.map(TargetDate::new)
96-
.orElse(TargetDate.now().plusDays(1))
97-
;
87+
Instant now = Instant.now();
9888

9989
// force refresh
100-
this.saltProvider.loadContent();
90+
saltProvider.loadContent();
10191

10292
// mark all the referenced files as ready to archive
10393
storageManager.archiveSaltLocations();
10494

105-
final List<RotatingSaltProvider.SaltSnapshot> snapshots = this.saltProvider.getSnapshots();
106-
final RotatingSaltProvider.SaltSnapshot lastSnapshot = snapshots.getLast();
95+
// Unlike in regular salt rotation, this should be based on the currently effective snapshot.
96+
// The latest snapshot may be in the future, and we may have changes that shouldn't be activated yet.
97+
var effectiveSnapshot = saltProvider.getSnapshot(now);
10798

108-
final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, minAges, fraction.get(), targetDate);
99+
var result = saltRotation.rotateSaltsZero(effectiveSnapshot, TargetDate.now(), now);
109100
if (!result.hasSnapshot()) {
110101
ResponseUtil.error(rc, 200, result.getReason());
111102
return;
@@ -122,21 +113,28 @@ private void handleSaltRotate(RoutingContext rc) {
122113
}
123114
}
124115

125-
private void handleSaltRotateZero(RoutingContext rc) {
116+
private void handleSaltRotate(RoutingContext rc) {
126117
try {
127-
Instant now = Instant.now();
118+
final Optional<Double> fraction = RequestUtil.getDouble(rc, "fraction");
119+
if (fraction.isEmpty()) return;
120+
final Duration[] minAges = RequestUtil.getDurations(rc, "min_ages_in_seconds");
121+
if (minAges == null) return;
128122

129-
// force refresh
130-
this.saltProvider.loadContent();
123+
final TargetDate targetDate =
124+
RequestUtil.getDate(rc, "target_date", DateTimeFormatter.ISO_LOCAL_DATE)
125+
.map(TargetDate::new)
126+
.orElse(TargetDate.now().plusDays(1));
131127

132-
// mark all the referenced files as ready to archive
128+
// Force refresh
129+
saltProvider.loadContent();
130+
131+
// Mark all the referenced files as ready to archive
133132
storageManager.archiveSaltLocations();
134133

135-
// Unlike in regular salt rotation, this should be based on the currently effective snapshot.
136-
// The latest snapshot may be in the future, and we may have changes that shouldn't be activated yet.
137-
var effectiveSnapshot = this.saltProvider.getSnapshot(now);
134+
final List<RotatingSaltProvider.SaltSnapshot> snapshots = saltProvider.getSnapshots();
135+
final RotatingSaltProvider.SaltSnapshot lastSnapshot = snapshots.getLast();
138136

139-
var result = saltRotation.rotateSaltsZero(effectiveSnapshot, TargetDate.now(), now);
137+
final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, minAges, fraction.get(), targetDate);
140138
if (!result.hasSnapshot()) {
141139
ResponseUtil.error(rc, 200, result.getReason());
142140
return;

webroot/adm/salt.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ <h3>Operations</h3>
3333

3434
<ul>
3535
<li class="ro-sem" style="display: none"><a href="#" id="doSnapshots">List Salt Snapshots</a></li>
36-
<li class="ro-sem" style="display: none"><a href="#" id="doRotate">Rotate second level salts (SUPER_USER)</a></li>
37-
<li class="ro-sem" style="display: none"><a href="#" id="doRotateZero">Rotate zero salts</a></li>
36+
<li class="ro-sem" style="display: none"><a href="#" id="doRebuild">Rebuild Salts File</a></li>
37+
<li class="ro-sem" style="display: none"><a href="#" id="doRotate">Rotate Second Level Salts (SUPER_USER)</a></li>
3838
</ul>
3939

4040
<br>
@@ -64,6 +64,10 @@ <h3>Output</h3>
6464
doApiCall('GET', '/api/salt/snapshots', '#standardOutput', '#errorOutput');
6565
});
6666

67+
$('#doRebuild').on('click', function () {
68+
doApiCall('POST', '/api/salt/rebuild', '#standardOutput', '#errorOutput');
69+
});
70+
6771
$('#doRotate').on('click', function () {
6872
const minAges = encodeURIComponent($('#minAges').val());
6973
const fraction = encodeURIComponent($('#fraction').val());
@@ -72,10 +76,6 @@ <h3>Output</h3>
7276

7377
doApiCall('POST', url, '#standardOutput', '#errorOutput');
7478
});
75-
76-
$('#doRotateZero').on('click', function () {
77-
doApiCall('POST', '/api/salt/rotate-zero', '#standardOutput', '#errorOutput');
78-
});
7979
});
8080
</script>
8181

0 commit comments

Comments
 (0)