Skip to content

Commit 345a708

Browse files
Salts fixes to optimize
1 parent fd653d9 commit 345a708

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!-- check micrometer.version vertx-micrometer-metrics consumes before bumping up -->
1717
<micrometer.version>1.12.2</micrometer.version>
1818
<junit-jupiter.version>5.11.2</junit-jupiter.version>
19-
<uid2-shared.version>8.0.13-alpha-175-SNAPSHOT</uid2-shared.version>
19+
<uid2-shared.version>8.0.14-alpha-176-SNAPSHOT</uid2-shared.version>
2020
<okta-jwt.version>0.5.10</okta-jwt.version>
2121
<image.version>${project.version}</image.version>
2222
</properties>

src/main/java/com/uid2/admin/store/factory/SaltStoreFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public SaltStoreFactory(JsonObject config, CloudPath rootMetadataPath, FileManag
4242
@Override
4343
public StoreWriter<Collection<RotatingSaltProvider.SaltSnapshot>> getEncryptedWriter(Integer siteId, boolean isPublic) {
4444
EncryptedScope scope = new EncryptedScope(rootMetadatapath, siteId, isPublic);
45-
EncryptedRotatingSaltProvider saltProvider = new EncryptedRotatingSaltProvider(taggableCloudStorage,
46-
scope.resolve(new CloudPath(config.getString(Const.Config.SaltsMetadataPathProp))).toString(), cloudEncryptionKeyProvider );
45+
EncryptedRotatingSaltProvider saltProvider = new EncryptedRotatingSaltProvider(taggableCloudStorage, cloudEncryptionKeyProvider, scope);
4746
return new EncryptedSaltStoreWriter(config, saltProvider, fileManager, taggableCloudStorage, versionGenerator, scope, cloudEncryptionKeyProvider, siteId);
4847
}
4948

src/main/java/com/uid2/admin/store/writer/EncryptedSaltStoreWriter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public EncryptedSaltStoreWriter(JsonObject config, RotatingSaltProvider provider
3838

3939
@Override
4040
protected java.lang.String getSaltSnapshotLocation(RotatingSaltProvider.SaltSnapshot snapshot) {
41-
return scope.resolve(new CloudPath(saltSnapshotLocationPrefix + snapshot.getEffective().toEpochMilli())).toString();
41+
return scope.resolve(new CloudPath("salts.txt." + snapshot.getEffective().toEpochMilli())).toString();
4242
}
4343

4444
@Override
@@ -47,6 +47,12 @@ protected void uploadSaltsSnapshot(RotatingSaltProvider.SaltSnapshot snapshot, S
4747
throw new IllegalStateException("Site ID is not set.");
4848
}
4949

50+
if (!cloudStorage.list(location).isEmpty()) {
51+
// update the tags on the file to ensure it is still marked as current
52+
this.setStatusTagToCurrent(location);
53+
return;
54+
}
55+
5056
StringBuilder stringBuilder = new StringBuilder();
5157

5258
for (SaltEntry entry: snapshot.getAllRotatingSalts()) {
@@ -79,7 +85,7 @@ protected void uploadSaltsSnapshot(RotatingSaltProvider.SaltSnapshot snapshot, S
7985

8086
this.upload(newSaltsFile.toString(), location);
8187
}
82-
88+
8389
@Override
8490
protected void refreshProvider() {
8591
// we do not need to refresh the provider on encrypted writers

src/main/java/com/uid2/admin/store/writer/SaltStoreWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class SaltStoreWriter {
3030
protected final String saltSnapshotLocationPrefix;
3131
private final VersionGenerator versionGenerator;
3232

33-
private final TaggableCloudStorage cloudStorage;
33+
protected final TaggableCloudStorage cloudStorage;
3434

3535
private final Map<String, String> currentTags = Map.of("status", "current");
3636
private final Map<String, String> obsoleteTags = Map.of("status", "obsolete");
@@ -159,7 +159,7 @@ protected void upload(String data, String location) throws Exception {
159159

160160
}
161161

162-
private void setStatusTagToCurrent(String location) throws CloudStorageException {
162+
protected void setStatusTagToCurrent(String location) throws CloudStorageException {
163163
this.cloudStorage.setTags(location, this.currentTags);
164164
}
165165

0 commit comments

Comments
 (0)