-
Notifications
You must be signed in to change notification settings - Fork 6
sch-UID2-5444 added feature switch for default min ages in salt rotation #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
86b47c9
adbd718
69b5892
cc55e0a
5fb8972
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,10 +21,7 @@ | |
|
|
||
| import java.time.*; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.*; | ||
|
|
||
| import static com.uid2.admin.vertx.Endpoints.*; | ||
|
|
||
|
|
@@ -36,6 +33,7 @@ public class SaltService implements IService { | |
| private final SaltStoreWriter storageManager; | ||
| private final RotatingSaltProvider saltProvider; | ||
| private final SaltRotation saltRotation; | ||
| private final Duration[] defaultSaltRotationAgeThresholds; | ||
|
|
||
| public SaltService(AdminAuthMiddleware auth, | ||
| WriteLock writeLock, | ||
|
|
@@ -47,6 +45,7 @@ public SaltService(AdminAuthMiddleware auth, | |
| this.storageManager = storageManager; | ||
| this.saltProvider = saltProvider; | ||
| this.saltRotation = saltRotation; | ||
| this.defaultSaltRotationAgeThresholds = generateThresholds(30, 390, 30); | ||
|
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -117,8 +116,15 @@ private void handleSaltRotate(RoutingContext rc) { | |
| try { | ||
| final Optional<Double> fraction = RequestUtil.getDouble(rc, "fraction"); | ||
| if (fraction.isEmpty()) return; | ||
| final Duration[] minAges = RequestUtil.getDurations(rc, "min_ages_in_seconds"); | ||
| if (minAges == null) return; | ||
|
|
||
| final Duration[] ageThresholds; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's log what thresholds we ended up using |
||
| if (saltRotation.isCustomAgeThresholdEnabled()) { | ||
| ageThresholds = RequestUtil.getDurations(rc, "min_ages_in_seconds"); | ||
| if (ageThresholds == null) return; | ||
| } else { | ||
| ageThresholds = defaultSaltRotationAgeThresholds; | ||
| } | ||
|
|
||
|
|
||
| final TargetDate targetDate = | ||
| RequestUtil.getDate(rc, "target_date", DateTimeFormatter.ISO_LOCAL_DATE) | ||
|
|
@@ -134,7 +140,7 @@ private void handleSaltRotate(RoutingContext rc) { | |
| final List<RotatingSaltProvider.SaltSnapshot> snapshots = saltProvider.getSnapshots(); | ||
| final RotatingSaltProvider.SaltSnapshot lastSnapshot = snapshots.getLast(); | ||
|
|
||
| final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, minAges, fraction.get(), targetDate); | ||
| final SaltRotation.Result result = saltRotation.rotateSalts(lastSnapshot, ageThresholds, fraction.get(), targetDate); | ||
| if (!result.hasSnapshot()) { | ||
| ResponseUtil.error(rc, 200, result.getReason()); | ||
| return; | ||
|
|
@@ -151,6 +157,14 @@ private void handleSaltRotate(RoutingContext rc) { | |
| } | ||
| } | ||
|
|
||
| private Duration[] generateThresholds(int minAge, int maxAge, int interval) { | ||
| List<Duration> thresholds = new ArrayList<>(); | ||
| for (int i = minAge; i <= maxAge; i += interval) { | ||
| thresholds.add(Duration.ofDays(i)); | ||
| } | ||
| return thresholds.toArray(new Duration[0]); | ||
| } | ||
|
|
||
| private JsonObject toJson(RotatingSaltProvider.SaltSnapshot snapshot) { | ||
| JsonObject jo = new JsonObject(); | ||
| jo.put("effective", snapshot.getEffective().toEpochMilli()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can directly just set this variable to be a
static finale.g.
or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do the former, remember to make
generateThresholds()a static function