Skip to content

Commit

Permalink
Salts fixes to optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-constine-ttd committed Dec 13, 2024
1 parent fd653d9 commit 345a708
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- check micrometer.version vertx-micrometer-metrics consumes before bumping up -->
<micrometer.version>1.12.2</micrometer.version>
<junit-jupiter.version>5.11.2</junit-jupiter.version>
<uid2-shared.version>8.0.13-alpha-175-SNAPSHOT</uid2-shared.version>
<uid2-shared.version>8.0.14-alpha-176-SNAPSHOT</uid2-shared.version>
<okta-jwt.version>0.5.10</okta-jwt.version>
<image.version>${project.version}</image.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public SaltStoreFactory(JsonObject config, CloudPath rootMetadataPath, FileManag
@Override
public StoreWriter<Collection<RotatingSaltProvider.SaltSnapshot>> getEncryptedWriter(Integer siteId, boolean isPublic) {
EncryptedScope scope = new EncryptedScope(rootMetadatapath, siteId, isPublic);
EncryptedRotatingSaltProvider saltProvider = new EncryptedRotatingSaltProvider(taggableCloudStorage,
scope.resolve(new CloudPath(config.getString(Const.Config.SaltsMetadataPathProp))).toString(), cloudEncryptionKeyProvider );
EncryptedRotatingSaltProvider saltProvider = new EncryptedRotatingSaltProvider(taggableCloudStorage, cloudEncryptionKeyProvider, scope);
return new EncryptedSaltStoreWriter(config, saltProvider, fileManager, taggableCloudStorage, versionGenerator, scope, cloudEncryptionKeyProvider, siteId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public EncryptedSaltStoreWriter(JsonObject config, RotatingSaltProvider provider

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

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

if (!cloudStorage.list(location).isEmpty()) {
// update the tags on the file to ensure it is still marked as current
this.setStatusTagToCurrent(location);
return;
}

StringBuilder stringBuilder = new StringBuilder();

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

this.upload(newSaltsFile.toString(), location);
}

@Override
protected void refreshProvider() {
// we do not need to refresh the provider on encrypted writers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SaltStoreWriter {
protected final String saltSnapshotLocationPrefix;
private final VersionGenerator versionGenerator;

private final TaggableCloudStorage cloudStorage;
protected final TaggableCloudStorage cloudStorage;

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

}

private void setStatusTagToCurrent(String location) throws CloudStorageException {
protected void setStatusTagToCurrent(String location) throws CloudStorageException {
this.cloudStorage.setTags(location, this.currentTags);
}

Expand Down

0 comments on commit 345a708

Please sign in to comment.