@@ -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 ;
0 commit comments