Skip to content

Commit 20806ca

Browse files
committed
No throw on s3 write when throw_on_s3_write_exception is set to false f
1 parent 847d8a9 commit 20806ca

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

src/main/java/com/uid2/admin/AdminConst.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public class AdminConst {
44
public static String enableKeysetConfigProp = "enable_keysets";
5+
public static final String throwOnS3WriteException = "throw_on_s3_write_exception";
56
public static final String ROLE_OKTA_GROUP_MAP_MAINTAINER = "role_okta_group_map_maintainer";
67
public static final String ROLE_OKTA_GROUP_MAP_PRIVILEGED = "role_okta_group_map_privileged";
78
public static final String ROLE_OKTA_GROUP_MAP_SUPER_USER = "role_okta_group_map_super_user";

src/main/java/com/uid2/admin/Main.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import java.util.concurrent.CompletableFuture;
6969

7070
import static com.uid2.admin.AdminConst.enableKeysetConfigProp;
71+
import static com.uid2.admin.AdminConst.throwOnS3WriteException;
7172

7273
public class Main {
7374
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
@@ -291,8 +292,9 @@ public void run() {
291292
}
292293
}
293294

295+
boolean bThrowOnS3WriteException = config.getBoolean(throwOnS3WriteException, true);
294296
synchronized (writeLock) {
295-
cloudEncryptionKeyManager.backfillKeys();
297+
cloudEncryptionKeyManager.backfillKeys(bThrowOnS3WriteException);
296298
rotatingCloudEncryptionKeyProvider.loadContent();
297299
}
298300

src/main/java/com/uid2/admin/cloudencryption/CloudEncryptionKeyManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void rotateKeys(boolean shouldFail) throws Exception {
6363
}
6464

6565
// For any site that has an operator, if there are no keys, create a key activating now
66-
public void backfillKeys() throws Exception {
66+
public void backfillKeys(boolean throwOnS3WriteException) throws Exception {
6767
try {
6868
refreshCloudData();
6969
var desiredKeys = planner.planBackfill(existingKeys, operatorKeys);
@@ -72,7 +72,9 @@ public void backfillKeys() throws Exception {
7272
LOGGER.info("Key backfill complete. Diff: {}", diff);
7373
} catch (Exception e) {
7474
LOGGER.error("Key backfill failed", e);
75-
throw e;
75+
if (throwOnS3WriteException) {
76+
throw e;
77+
}
7678
}
7779
}
7880

src/main/java/com/uid2/admin/vertx/service/OperatorKeyService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.stream.Collectors;
2929

3030
import static com.uid2.admin.vertx.Endpoints.*;
31+
import static com.uid2.admin.AdminConst.throwOnS3WriteException;
3132

3233
public class OperatorKeyService implements IService {
3334
private static final Logger LOGGER = LoggerFactory.getLogger(OperatorKeyService.class);
@@ -48,7 +49,9 @@ public class OperatorKeyService implements IService {
4849
private final IKeyGenerator keyGenerator;
4950
private final KeyHasher keyHasher;
5051
private final String operatorKeyPrefix;
52+
5153
private final CloudEncryptionKeyManager cloudEncryptionKeyManager;
54+
private boolean bThrowOnS3WriteException;
5255

5356
public OperatorKeyService(JsonObject config,
5457
AdminAuthMiddleware auth,
@@ -69,6 +72,7 @@ public OperatorKeyService(JsonObject config,
6972
this.cloudEncryptionKeyManager = cloudEncryptionKeyManager;
7073

7174
this.operatorKeyPrefix = config.getString("operator_key_prefix");
75+
this.bThrowOnS3WriteException = config.getBoolean(throwOnS3WriteException, true);
7276
}
7377

7478
@Override
@@ -273,7 +277,7 @@ private void handleOperatorAdd(RoutingContext rc) {
273277
operatorKeyStoreWriter.upload(operators);
274278

275279
// generate cloud encryption keys as needed
276-
cloudEncryptionKeyManager.backfillKeys();
280+
cloudEncryptionKeyManager.backfillKeys(bThrowOnS3WriteException);
277281

278282
// respond with new key
279283
rc.response().end(JSON_WRITER.writeValueAsString(new RevealedKey<>(newOperator, key)));
@@ -412,7 +416,7 @@ private void handleOperatorUpdate(RoutingContext rc) {
412416
operatorKeyStoreWriter.upload(operators);
413417

414418
if (siteIdChanged) {
415-
cloudEncryptionKeyManager.backfillKeys();
419+
cloudEncryptionKeyManager.backfillKeys(bThrowOnS3WriteException);
416420
}
417421

418422
// return the updated client

src/test/java/com/uid2/admin/vertx/OperatorKeyServiceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public void operatorAddGeneratesCloudEncryptionKeys(Vertx vertx, VertxTestContex
276276
"operatorAddGeneratesCloudEncryptionKeys",
277277
() -> assertEquals(200, response.statusCode()),
278278
() -> assertNotNull(revealedOperator.getAuthorizable()),
279-
() -> verify(cloudEncryptionKeyManager).backfillKeys()
279+
() -> verify(cloudEncryptionKeyManager).backfillKeys(true)
280280
);
281281
testContext.completeNow();
282282
} catch (Exception e) {
@@ -301,7 +301,7 @@ public void operatorUpdateSiteIdGeneratesCloudEncryptionKeys(Vertx vertx, VertxT
301301
() -> assertEquals(200, response.statusCode()),
302302
() -> assertEquals(5, updatedOperator.getSiteId()),
303303
() -> assertNotEquals(1, updatedOperator.getSiteId()),
304-
() -> verify(cloudEncryptionKeyManager).backfillKeys()
304+
() -> verify(cloudEncryptionKeyManager).backfillKeys(true)
305305
);
306306
testContext.completeNow();
307307
} catch (Exception e) {
@@ -325,7 +325,7 @@ public void operatorUpdateWithoutSiteIdChangeDoesNotGenerateCloudEncryptionKeys(
325325
"operatorUpdateWithoutSiteIdChangeDoesNotGenerateCloudEncryptionKeys",
326326
() -> assertEquals(200, response.statusCode()),
327327
() -> assertEquals(existingOperator.getSiteId(), updatedOperator.getSiteId()),
328-
() -> verify(cloudEncryptionKeyManager, never()).backfillKeys()
328+
() -> verify(cloudEncryptionKeyManager, never()).backfillKeys(true)
329329
);
330330
testContext.completeNow();
331331
} catch (Exception e) {

0 commit comments

Comments
 (0)