-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cbc UI d2 4454 cloud encryption operator #1175
base: main
Are you sure you want to change the base?
Changes from 27 commits
0a1154c
582ea54
590b67e
e06509a
275e5cb
4ef6e87
7c25f1c
12131f9
1d85892
08bf71a
4c10d2d
d106180
195ec0d
8700b1f
20481ef
88f2716
8975886
fc96012
1083e59
18ccab1
578992c
264eefe
3343974
a0a099c
07f4da8
eb0fd11
aad4592
bc2d667
5922a29
5383c0b
bfe7849
9c9b1b9
3452457
fd2c0c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.uid2.operator.reader; | ||
|
||
import com.uid2.shared.cloud.DownloadCloudStorage; | ||
import com.uid2.shared.store.ScopedStoreReader; | ||
import com.uid2.shared.store.parser.Parser; | ||
import com.uid2.shared.store.parser.ParsingResult; | ||
import com.uid2.shared.store.scope.StoreScope; | ||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.JsonObject; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class ApiStoreReader<T> extends ScopedStoreReader<T> { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ApiStoreReader.class); | ||
|
||
public ApiStoreReader(DownloadCloudStorage fileStreamProvider, StoreScope scope, Parser<T> parser, String dataTypeName) { | ||
super(fileStreamProvider, scope, parser, dataTypeName); | ||
} | ||
|
||
@Override | ||
public long loadContent(JsonObject contents, String dataType) throws Exception { | ||
if (contents == null) { | ||
throw new IllegalArgumentException(String.format("No contents provided for loading data type %s, cannot load content", dataType)); | ||
} | ||
|
||
try { | ||
JsonArray dataArray = contents.getJsonArray(dataType); | ||
if (dataArray == null) { | ||
throw new IllegalArgumentException("No array found in the contents"); | ||
} | ||
|
||
String jsonString = dataArray.toString(); | ||
InputStream inputStream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8)); | ||
|
||
ParsingResult<T> parsed = parser.deserialize(inputStream); | ||
latestSnapshot.set(parsed.getData()); | ||
|
||
final int count = parsed.getCount(); | ||
latestEntryCount.set(count); | ||
LOGGER.info(String.format("Loaded %d %s", count, dataTypeName)); | ||
return count; | ||
} catch (Exception e) { | ||
LOGGER.error(String.format("Unable to load %s", dataTypeName)); | ||
throw e; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.uid2.operator.reader; | ||
|
||
import com.uid2.shared.cloud.DownloadCloudStorage; | ||
import com.uid2.shared.model.CloudEncryptionKey; | ||
import com.uid2.shared.store.CloudPath; | ||
import com.uid2.shared.store.parser.CloudEncryptionKeyParser; | ||
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider; | ||
import com.uid2.shared.store.scope.StoreScope; | ||
import io.vertx.core.json.JsonObject; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Instant; | ||
import java.util.*; | ||
|
||
public class RotatingCloudEncryptionKeyApiProvider extends RotatingCloudEncryptionKeyProvider { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(RotatingCloudEncryptionKeyApiProvider.class); | ||
|
||
public ApiStoreReader<Map<Integer, CloudEncryptionKey>> apiStoreReader; | ||
|
||
public RotatingCloudEncryptionKeyApiProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope) { | ||
super(fileStreamProvider, scope); | ||
this.apiStoreReader = new ApiStoreReader<>(fileStreamProvider, scope, new CloudEncryptionKeyParser(), "cloud_encryption_keys"); | ||
} | ||
|
||
@Override | ||
public JsonObject getMetadata() throws Exception { | ||
return apiStoreReader.getMetadata(); | ||
} | ||
|
||
@Override | ||
public CloudPath getMetadataPath() { | ||
return apiStoreReader.getMetadataPath(); | ||
} | ||
|
||
@Override | ||
public long loadContent(JsonObject metadata) throws Exception { | ||
return apiStoreReader.loadContent(metadata, "cloudEncryptionKeys"); | ||
} | ||
|
||
@Override | ||
public long getVersion(JsonObject metadata) { | ||
return Instant.now().getEpochSecond(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why isn't it metadata.getLong("version") ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this is using an API to get the data not a file, so there is no metadata to look the version up in. So I just used the time here to force a refresh everytime There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably needs a comment explaining why you are doing this as I feel we will forget |
||
} | ||
|
||
@Override | ||
public Map<Integer, CloudEncryptionKey> getAll() { | ||
Map<Integer, CloudEncryptionKey> keys = apiStoreReader.getSnapshot(); | ||
return keys != null ? keys : new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void loadContent() throws Exception { | ||
this.loadContent(this.getMetadata()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
[ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation format like this: https://github.com/IABTechLab/uid2-admin/blob/main/src/main/resources/localstack/s3/core/keys/keys.json? |
||
"id" : 1, | ||
"siteId" : 999, | ||
"activates" : 1720641670, | ||
"created" : 1720641670, | ||
"secret" : "mydrCudb2PZOm01Qn0SpthltmexHUAA11Hy1m+uxjVw=" | ||
}, { | ||
"id" : 2, | ||
"siteId" : 999, | ||
"activates" : 1720728070, | ||
"created" : 1720641670, | ||
"secret" : "FtdslrFSsvVXOuhOWGwEI+0QTkCvM8SGZAP3k2u3PgY=" | ||
}, { | ||
"id" : 3, | ||
"siteId" : 999, | ||
"activates" : 1720814470, | ||
"created" : 1720641670, | ||
"secret" : "/7zO6QbKrhZKIV36G+cU9UR4hZUVg5bD+KjbczICjHw=" | ||
}, { | ||
"id" : 4, | ||
"siteId" : 123, | ||
"activates" : 1720641671, | ||
"created" : 1720641671, | ||
"secret" : "XjiqRlWQQJGLr7xfV1qbueKwyzt881GVohuUkQt/ht4=" | ||
}, { | ||
"id" : 5, | ||
"siteId" : 123, | ||
"activates" : 1720728071, | ||
"created" : 1720641671, | ||
"secret" : "QmpIf5NzO+UROjl5XjB/BmF6paefM8n6ub9B2plC9aI=" | ||
}, { | ||
"id" : 6, | ||
"siteId" : 123, | ||
"activates" : 1720814471, | ||
"created" : 1720641671, | ||
"secret" : "40w9UMSYxGm+KldOWOXhBGI8QgjvUUQjivtkP4VpKV8=" | ||
}, { | ||
"id" : 7, | ||
"siteId" : 124, | ||
"activates" : 1720641671, | ||
"created" : 1720641671, | ||
"secret" : "QdwD0kQV1BwmLRD0PH1YpqgaOrgpVTfu08o98mSZ6uE=" | ||
}, { | ||
"id" : 8, | ||
"siteId" : 124, | ||
"activates" : 1720728071, | ||
"created" : 1720641671, | ||
"secret" : "yCVCM/HLf9/6k+aUNrx7w17VbyfSzI8JykLQLSR+CW0=" | ||
}, { | ||
"id" : 9, | ||
"siteId" : 124, | ||
"activates" : 1720814471, | ||
"created" : 1720641671, | ||
"secret" : "JqHl8BrTyx9XpR2lYj/5xvUpzgnibGeomETTwF4rn1U=" | ||
}, { | ||
"id" : 10, | ||
"siteId" : 127, | ||
"activates" : 1720641671, | ||
"created" : 1720641671, | ||
"secret" : "JqiG1b34AvrdO3Aj6cCcjOBJMijrDzTmrR+p9ZtP2es=" | ||
}, { | ||
"id" : 11, | ||
"siteId" : 127, | ||
"activates" : 1720728072, | ||
"created" : 1720641672, | ||
"secret" : "lp1CyHdfc7K0aO5JGpA+Ve5Z/V5LImtGEQwCg/YB0kY=" | ||
}, { | ||
"id" : 12, | ||
"siteId" : 127, | ||
"activates" : 1720814472, | ||
"created" : 1720641672, | ||
"secret" : "G99rFYJF+dnSlk/xG6fuC3WNqQxTLJbDIdVyPMbGQ6s=" | ||
} ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"version": 1, | ||
"generated": 1620253519, | ||
"cloud_encryption_keys": { | ||
"location": "/com.uid2.core/test/cloud_encryption_keys/cloud_encryption_keys.json" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this need to be public?