Skip to content

Commit f820ccc

Browse files
Making change to multiscope writer to not copy all salts for each site
1 parent 3883853 commit f820ccc

File tree

6 files changed

+36
-31
lines changed

6 files changed

+36
-31
lines changed

src/main/java/com/uid2/admin/job/EncryptionJob/SaltEncryptionJob.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.uid2.shared.store.RotatingSaltProvider;
1111

1212
import java.util.Collection;
13+
import java.util.List;
1314

1415
public class SaltEncryptionJob extends Job {
1516
private final Collection<OperatorKey> globalOperators;
@@ -32,9 +33,9 @@ public String getId() {
3233

3334
@Override
3435
public void execute() throws Exception {
35-
PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> desiredPrivateState = PrivateSiteUtil.getPrivateSaltEntries(saltEntries, globalOperators);
36-
multiScopeStoreWriter.uploadPrivateWithEncryption(desiredPrivateState, null);
37-
PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> desiredPublicState = PublicSiteUtil.getPublicSaltEntries(saltEntries, globalOperators);
38-
multiScopeStoreWriter.uploadPublicWithEncryption(desiredPublicState, null);
36+
List<Integer> desiredPrivateState = PrivateSiteUtil.getPrivateSaltSites(globalOperators);
37+
multiScopeStoreWriter.uploadPrivateWithEncryption(desiredPrivateState, saltEntries, null);
38+
List<Integer> desiredPublicState = PublicSiteUtil.getPublicSaltSites(globalOperators);
39+
multiScopeStoreWriter.uploadPublicWithEncryption(desiredPublicState, saltEntries, null);
3940
}
4041
}

src/main/java/com/uid2/admin/store/MultiScopeStoreWriter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ public void uploadPrivateWithEncryption(Map<Integer, T> desiredState, JsonObject
6969
}
7070
}
7171

72+
public void uploadPrivateWithEncryption(List<Integer> siteIds, T desiredState, JsonObject extraMeta) throws Exception {
73+
EncryptedStoreFactory<T> encryptedFactory = (EncryptedStoreFactory<T>) factory;
74+
for (Integer siteId : siteIds) {
75+
encryptedFactory.getEncryptedWriter(siteId,false).upload(desiredState, extraMeta);
76+
}
77+
}
78+
7279
public void uploadPublicWithEncryption(Map<Integer, T> desiredPublicState, JsonObject extraMeta) throws Exception {
7380
EncryptedStoreFactory<T> encryptedFactory = (EncryptedStoreFactory<T>) factory;
7481
for (Map.Entry<Integer, T> entry : desiredPublicState.entrySet()) {
@@ -77,6 +84,13 @@ public void uploadPublicWithEncryption(Map<Integer, T> desiredPublicState, JsonO
7784
}
7885
}
7986

87+
public void uploadPublicWithEncryption(List<Integer> siteIds, T desiredState, JsonObject extraMeta) throws Exception {
88+
EncryptedStoreFactory<T> encryptedFactory = (EncryptedStoreFactory<T>) factory;
89+
for (Integer siteId : siteIds) {
90+
encryptedFactory.getEncryptedWriter(siteId,true).upload(desiredState, extraMeta);
91+
}
92+
}
93+
8094
public static <K, V> boolean areMapsEqual(Map<K, V> a, Map<K, V> b) {
8195
return a.size() == b.size() && a.entrySet().stream().allMatch(b.entrySet()::contains);
8296
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
import com.uid2.shared.store.reader.StoreReader;
1414
import com.uid2.shared.store.scope.EncryptedScope;
1515
import io.vertx.core.json.JsonObject;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618

1719
import java.util.Collection;
1820

1921
public class SaltStoreFactory implements EncryptedStoreFactory<Collection<RotatingSaltProvider.SaltSnapshot>> {
22+
private static final Logger LOGGER = LoggerFactory.getLogger(SaltStoreFactory.class);
23+
2024
JsonObject config;
2125
CloudPath rootMetadatapath;
2226
FileManager fileManager;
@@ -45,6 +49,7 @@ public StoreWriter<Collection<RotatingSaltProvider.SaltSnapshot>> getEncryptedWr
4549

4650
@Override
4751
public StoreReader<Collection<RotatingSaltProvider.SaltSnapshot>> getEncryptedReader(Integer siteId, boolean isPublic) {
52+
LOGGER.warn("getEncryptedReader called on SaltStoreFactory. This method is not implemented.");
4853
return null;
4954
}
5055

@@ -55,11 +60,13 @@ public RotatingCloudEncryptionKeyProvider getCloudEncryptionProvider() {
5560

5661
@Override
5762
public StoreReader<Collection<RotatingSaltProvider.SaltSnapshot>> getReader(Integer siteId) {
63+
LOGGER.warn("getReader called on SaltStoreFactory. This method is not implemented.");
5864
return null;
5965
}
6066

6167
@Override
6268
public StoreWriter<Collection<RotatingSaltProvider.SaltSnapshot>> getWriter(Integer siteId) {
69+
LOGGER.warn("getWriter called on SaltStoreFactory. This method is not implemented.");
6370
return null;
6471
}
6572
}

src/main/java/com/uid2/admin/util/PrivateSiteUtil.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,8 @@ public static PrivateSiteDataMap<KeysetKey> getKeysetKeys(Collection<OperatorKey
313313
return result;
314314
}
315315

316-
public static PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> getPrivateSaltEntries(
317-
Collection<RotatingSaltProvider.SaltSnapshot> globalSaltEntries,
318-
Collection<OperatorKey> operators) {
316+
public static List<Integer> getPrivateSaltSites(Collection<OperatorKey> operators) {
319317
final PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> result = getPrivateSites(operators);
320-
321-
globalSaltEntries.forEach(saltEntry -> {
322-
result.forEach((publicSiteId, publicSiteData) -> {
323-
publicSiteData.add(saltEntry);
324-
});
325-
});
326-
327-
return result;
318+
return result.keySet().stream().toList();
328319
}
329320
}

src/main/java/com/uid2/admin/util/PublicSiteUtil.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313

14-
import java.util.Collection;
15-
import java.util.HashMap;
16-
import java.util.HashSet;
17-
import java.util.Map;
14+
import java.util.*;
1815

1916
public class PublicSiteUtil {
2017
private static final Logger LOGGER = LoggerFactory.getLogger(PrivateSiteUtil.class);
@@ -128,18 +125,9 @@ public static PrivateSiteDataMap<KeysetKey> getPublicKeysetKeys(
128125
return result;
129126
}
130127

131-
public static PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> getPublicSaltEntries(
132-
Collection<RotatingSaltProvider.SaltSnapshot> globalSaltEntries,
133-
Collection<OperatorKey> operators) {
128+
public static List<Integer> getPublicSaltSites(Collection<OperatorKey> operators) {
134129
final PrivateSiteDataMap<RotatingSaltProvider.SaltSnapshot> result = getPublicSitesMap(operators);
135-
136-
globalSaltEntries.forEach(saltEntry -> {
137-
result.forEach((publicSiteId, publicSiteData) -> {
138-
publicSiteData.add(saltEntry);
139-
});
140-
});
141-
142-
return result;
130+
return result.keySet().stream().toList();
143131
}
144132

145133
public static PrivateSiteDataMap<ClientSideKeypair> getPublicClientKeypairs(

src/test/java/com/uid2/admin/store/writer/EncryptedSaltStoreWriterTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class EncryptedSaltStoreWriterTest {
5959

6060
@Captor
6161
private ArgumentCaptor<String> pathCaptor;
62+
@Captor
63+
private ArgumentCaptor<String> cloudPathCaptor;
6264

6365
@BeforeEach
6466
public void setUp() throws Exception {
@@ -118,7 +120,9 @@ public void testUploadNew() throws Exception {
118120

119121
encryptedSaltStoreWriter.upload(snapshot);
120122

121-
verify(taggableCloudStorage).upload(pathCaptor.capture(), any(), any());
123+
verify(taggableCloudStorage).upload(pathCaptor.capture(), cloudPathCaptor.capture(), any());
124+
assertEquals(cloudPathCaptor.getValue(), "test/path");
125+
122126
verifyFile(pathCaptor.getValue(), snapshot);
123127
}
124128
}

0 commit comments

Comments
 (0)