|
16 | 16 | import java.nio.file.Files; |
17 | 17 | import java.nio.file.Path; |
18 | 18 | import java.time.Instant; |
19 | | -import java.util.Collections; |
| 19 | +import java.util.ArrayList; |
20 | 20 | import java.util.Comparator; |
21 | 21 | import java.util.List; |
22 | 22 | import java.util.Map; |
@@ -48,23 +48,27 @@ protected List<RotatingSaltProvider.SaltSnapshot> getSnapshots(RotatingSaltProvi |
48 | 48 | throw new IllegalStateException("Snapshots cannot be null"); |
49 | 49 | } |
50 | 50 | final Instant now = Instant.now(); |
51 | | - List<RotatingSaltProvider.SaltSnapshot> currentSnapshots = Stream.concat(provider.getSnapshots().stream(), Stream.of(data)) |
| 51 | + List<RotatingSaltProvider.SaltSnapshot> currentSnapshots = provider.getSnapshots(); |
| 52 | + List<RotatingSaltProvider.SaltSnapshot> snapshots = null; |
| 53 | + snapshots = Stream.concat(currentSnapshots.stream(), Stream.of(data)) |
52 | 54 | .sorted(Comparator.comparing(RotatingSaltProvider.SaltSnapshot::getEffective)) |
53 | 55 | .collect(Collectors.toList()); |
54 | | - RotatingSaltProvider.SaltSnapshot newestEffectiveSnapshot = currentSnapshots.stream() |
| 56 | + RotatingSaltProvider.SaltSnapshot newestEffectiveSnapshot = snapshots.stream() |
55 | 57 | .filter(snapshot -> snapshot.isEffective(now)) |
56 | 58 | .reduce((a, b) -> b).orElse(null); |
57 | | - return Stream.concat(provider.getSnapshots().stream(), Stream.of(data)) |
58 | | - .filter(snapshot -> { |
59 | | - boolean isValid = newestEffectiveSnapshot == null || snapshot == newestEffectiveSnapshot; |
60 | | - if (!isValid) { |
| 59 | + |
| 60 | + List<RotatingSaltProvider.SaltSnapshot> filteredSnapshots = new ArrayList<>(); |
| 61 | + |
| 62 | + for (RotatingSaltProvider.SaltSnapshot snapshot : snapshots) { |
| 63 | + if (newestEffectiveSnapshot != null && snapshot != newestEffectiveSnapshot) { |
61 | 64 | LOGGER.info("Skipping effective snapshot, effective=" + snapshot.getEffective() + ", expires=" + snapshot.getExpires() |
62 | 65 | + " in favour of newer snapshot, effective=" + newestEffectiveSnapshot.getEffective() + ", expires=" + newestEffectiveSnapshot.getExpires()); |
63 | | - } |
64 | | - return isValid; |
65 | | - }) |
66 | | - .sorted(Comparator.comparing(RotatingSaltProvider.SaltSnapshot::getEffective)) |
67 | | - .collect(Collectors.toList()); |
| 66 | + continue; |
| 67 | + } |
| 68 | + filteredSnapshots.add(snapshot); |
| 69 | + newestEffectiveSnapshot = null; |
| 70 | + } |
| 71 | + return filteredSnapshots; |
68 | 72 | } |
69 | 73 |
|
70 | 74 | public void upload(RotatingSaltProvider.SaltSnapshot data) throws Exception { |
|
0 commit comments