Skip to content

added interface for readers #46

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/com/uid2/shared/cloud/InMemoryStorageMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public InputStream download(String cloudPath) throws CloudStorageException {
}

byte[] content = data.clone();
ByteArrayInputStream inputStream = new ByteArrayInputStream(content);
return inputStream;
return new ByteArrayInputStream(content);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
...
]
*/
public class RotatingClientKeyProvider implements IClientKeyProvider, IMetadataVersionedStore {
public class RotatingClientKeyProvider implements IClientKeyProvider, StoreReader<Collection<ClientKey>> {
private final ScopedStoreReader<Map<String, ClientKey>> reader;
public RotatingClientKeyProvider(ICloudStorage fileStreamProvider, StoreScope scope) {
this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new ClientParser(), "auth keys");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.uid2.shared.store.reader;

import com.uid2.shared.auth.AclSnapshot;
import com.uid2.shared.auth.EncryptionKeyAcl;
import com.uid2.shared.cloud.ICloudStorage;
import com.uid2.shared.store.*;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.IKeyAclProvider;
import com.uid2.shared.store.ScopedStoreReader;
import com.uid2.shared.store.parser.KeyAclParser;
import com.uid2.shared.store.scope.StoreScope;
import io.vertx.core.json.JsonObject;

import java.time.Instant;
import java.util.Map;

public class RotatingKeyAclProvider implements IKeyAclProvider, IMetadataVersionedStore {
public class RotatingKeyAclProvider implements IKeyAclProvider, StoreReader<Map<Integer, EncryptionKeyAcl>> {
private final ScopedStoreReader<AclSnapshot> reader;

public RotatingKeyAclProvider(ICloudStorage fileStreamProvider, StoreScope scope) {
Expand All @@ -33,6 +37,12 @@ public long loadContent(JsonObject metadata) throws Exception {
return reader.loadContent(metadata, "keys_acl");
}

@Override
public Map<Integer, EncryptionKeyAcl> getAll() {
return reader.getSnapshot().getAllAcls();
}

@Override
public void loadContent() throws Exception {
this.loadContent(this.getMetadata());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.uid2.shared.store.reader;

import com.uid2.shared.cloud.ICloudStorage;
import com.uid2.shared.model.EncryptionKey;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.IKeyStore;
import com.uid2.shared.store.ScopedStoreReader;
Expand All @@ -9,6 +10,7 @@
import io.vertx.core.json.JsonObject;

import java.time.Instant;
import java.util.Collection;

/*
1. metadata.json format
Expand Down Expand Up @@ -41,7 +43,7 @@
]

*/
public class RotatingKeyStore implements IKeyStore, IMetadataVersionedStore {
public class RotatingKeyStore implements IKeyStore, StoreReader<Collection<EncryptionKey>> {
private final ScopedStoreReader<IKeyStoreSnapshot> reader;

public RotatingKeyStore(ICloudStorage fileStreamProvider, StoreScope scope) {
Expand Down Expand Up @@ -75,6 +77,12 @@ public long loadContent(JsonObject metadata) throws Exception {
return reader.loadContent(metadata, "keys");
}

@Override
public Collection<EncryptionKey> getAll() {
return reader.getSnapshot().getActiveKeySet();
}

@Override
public void loadContent() throws Exception {
this.loadContent(this.getMetadata());
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/uid2/shared/store/reader/StoreReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.uid2.shared.store.reader;

import io.vertx.core.json.JsonObject;

public interface StoreReader<T> extends IMetadataVersionedStore {
T getAll();
void loadContent() throws Exception;
JsonObject getMetadata() throws Exception;
}