Skip to content
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

switch avs store to redis #387

Merged
merged 1 commit into from
Feb 25, 2025
Merged
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
2 changes: 0 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dependencies {
implementation(project(":module:client"))
implementation(project(":module:crypto-demo"))
implementation(project(":module:request-demo"))
implementation(project(":module:store-demo"))
implementation(project(":module:store-redis"))
implementation(project(":service"))
implementation(project(":service:module"))
Expand All @@ -21,7 +20,6 @@ dependencies {
implementation(libs.jackson.databind)
implementation(libs.jakartaInject.api)
implementation(libs.jakartaValidation.api)
implementation(libs.jedis.jedis) // for Dagger
implementation(libs.okhttp.okhttp)
implementation(libs.retrofit.retrofit)

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/example/age/app/AvsApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.example.age.module.client.AvsClientModule;
import org.example.age.module.crypto.demo.DemoAvsCryptoModule;
import org.example.age.module.request.demo.DemoAccountIdModule;
import org.example.age.module.store.demo.DemoAvsAccountStoreModule;
import org.example.age.module.store.redis.RedisAvsAccountStoreModule;
import org.example.age.module.store.redis.RedisPendingStoreModule;
import org.example.age.service.AvsServiceModule;
import org.example.age.service.module.request.RequestContextProvider;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void run(AvsAppConfig appConfig, Environment env) {
AvsServiceModule.class,
DemoAccountIdModule.class,
AvsClientModule.class,
DemoAvsAccountStoreModule.class,
RedisAvsAccountStoreModule.class,
RedisPendingStoreModule.class,
DemoAvsCryptoModule.class,
AvsConfigModule.class,
Expand Down
15 changes: 0 additions & 15 deletions app/src/main/java/org/example/age/app/config/AvsAppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jakarta.validation.constraints.NotNull;
import org.example.age.module.client.AvsClientsConfig;
import org.example.age.module.crypto.demo.AvsKeysConfig;
import org.example.age.module.store.demo.AvsStoresConfig;
import org.example.age.module.store.redis.RedisConfig;
import org.example.age.service.AvsServiceConfig;

Expand All @@ -25,10 +24,6 @@ public final class AvsAppConfig extends Configuration {
@NotNull
private RedisConfig redis;

@Valid
@NotNull
private AvsStoresConfig stores;

@Valid
@NotNull
private AvsKeysConfig keys;
Expand Down Expand Up @@ -63,16 +58,6 @@ public void setRedis(RedisConfig redis) {
this.redis = redis;
}

@JsonProperty
public AvsStoresConfig getStores() {
return stores;
}

@JsonProperty
public void setStores(AvsStoresConfig stores) {
this.stores = stores;
}

@JsonProperty
public AvsKeysConfig getKeys() {
return keys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dagger.Provides;
import org.example.age.module.client.AvsClientsConfig;
import org.example.age.module.crypto.demo.AvsKeysConfig;
import org.example.age.module.store.demo.AvsStoresConfig;
import org.example.age.module.store.redis.RedisConfig;
import org.example.age.service.AvsServiceConfig;

Expand All @@ -14,7 +13,6 @@
* <li>{@link AvsServiceConfig}
* <li>{@link AvsClientsConfig}
* <li>{@link RedisConfig}
* <li>{@link AvsStoresConfig}
* <li>{@link AvsKeysConfig}
* </ul>
* <p>
Expand All @@ -38,11 +36,6 @@ static RedisConfig provideRedisConfig(AvsAppConfig appConfig) {
return appConfig.getRedis();
}

@Provides
static AvsStoresConfig provideAvsStoresConfig(AvsAppConfig appConfig) {
return appConfig.getStores();
}

@Provides
static AvsKeysConfig provideAvsKeysConfig(AvsAppConfig appConfig) {
return appConfig.getKeys();
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/org/example/age/demo/Demo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public final class Demo {
@SuppressWarnings("CatchAndPrintStackTrace")
public static void main(String[] args) throws IOException {
try {
DemoInfra.startRedis();
DemoInfra.startServer(checkMyAge, "config-check-my-age.yaml");
DemoInfra.startServer(crackle, "config-crackle.yaml");
DemoInfra.startServer(pop, "config-pop.yaml");

startServers();
verifyAge(parentCrackleClient, parentAvsClient, "Crackle", "publius", "John Smith", true);
verifyAge(childCrackleClient, childAvsClient, "Crackle", "publius-jr", "Billy Smith", false);
verifyAge(parentPopClient, parentAvsClient, "Pop", "JohnS", "John Smith", false);
Expand All @@ -46,6 +42,15 @@ public static void main(String[] args) throws IOException {
}
}

/** Starts all servers. */
private static void startServers() throws Exception {
DemoInfra.startRedis();
DemoInfra.populateRedis();
DemoInfra.startServer(checkMyAge, "config-check-my-age.yaml");
DemoInfra.startServer(crackle, "config-crackle.yaml");
DemoInfra.startServer(pop, "config-pop.yaml");
}

/** Verifies a single account. */
private static void verifyAge(
SiteApi siteClient, AvsApi avsClient, String siteName, String accountName, String realName, boolean verbose)
Expand Down
26 changes: 25 additions & 1 deletion app/src/main/java/org/example/age/demo/DemoInfra.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.example.age.api.AgeRange;
import org.example.age.api.VerifiedUser;
import org.example.age.api.client.retrofit.ApiClient;
import org.example.age.api.crypto.SecureId;
import org.example.age.testing.RedisExtension;
import org.example.age.testing.TestObjectMapper;

/** Client/server infrastructure for the demo. */
public final class DemoInfra {

private static final RedisExtension redis = new RedisExtension(6379);
private static final RedisExtension redis = new RedisExtension(6379); // can safely share between apps
private static final OkHttpClient httpClient = new OkHttpClient();
private static final ObjectWriter objectWriter = Jackson.newObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
Expand All @@ -27,6 +32,25 @@ public static void startRedis() throws IOException {
redis.beforeAll(null);
}

/** Populates Redis with verified persons. */
public static void populateRedis() throws IOException {
SecureId parentPseudonym = SecureId.fromString("uhzmISXl7szUDLVuYNvDVf6jiL3ExwCybtg-KlazHU4");
SecureId childPseudonym = SecureId.fromString("KB0b9pDo8j7-1p90fFokbgHj8hzbbU7jCGGjfuMzLR4");
VerifiedUser parent = VerifiedUser.builder()
.pseudonym(parentPseudonym)
.ageRange(AgeRange.builder().min(40).max(40).build())
.build();
VerifiedUser child = VerifiedUser.builder()
.pseudonym(childPseudonym)
.ageRange(AgeRange.builder().min(13).max(13).build())
.guardianPseudonyms(List.of(parentPseudonym))
.build();
String parentJson = TestObjectMapper.get().writeValueAsString(parent);
redis.client().set("age:user:John Smith", parentJson);
String childJson = TestObjectMapper.get().writeValueAsString(child);
redis.client().set("age:user:Billy Smith", childJson);
}

/** Starts an application. */
public static void startServer(Application<?> app, String configPath) throws Exception {
app.run("server", getResourcePath(configPath));
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/resources/config-check-my-age.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ clients:
redis:
url: http://localhost:6379

stores:
verifiedAccounts:
John Smith:
pseudonym: uhzmISXl7szUDLVuYNvDVf6jiL3ExwCybtg-KlazHU4
ageRange:
min: 40
max: 40
Billy Smith:
pseudonym: KB0b9pDo8j7-1p90fFokbgHj8hzbbU7jCGGjfuMzLR4
ageRange:
min: 13
max: 13
guardianPseudonyms: [uhzmISXl7szUDLVuYNvDVf6jiL3ExwCybtg-KlazHU4]

keys:
signing:
s: 87808632867103956881705523559918117434194472117688001288631494927155518459976
Expand Down
15 changes: 14 additions & 1 deletion app/src/test/java/org/example/age/app/AppVerificationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import org.example.age.api.VerificationRequest;
import org.example.age.api.VerificationState;
import org.example.age.api.VerificationStatus;
import org.example.age.api.VerifiedUser;
import org.example.age.api.client.AvsApi;
import org.example.age.api.client.SiteApi;
import org.example.age.api.crypto.SecureId;
import org.example.age.app.config.AvsAppConfig;
import org.example.age.app.config.SiteAppConfig;
import org.example.age.app.testing.TestServiceClient;
import org.example.age.testing.RedisExtension;
import org.example.age.testing.TestObjectMapper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import retrofit2.Response;
Expand All @@ -31,7 +34,7 @@ public final class AppVerificationTest {
new DropwizardAppExtension<>(AvsApp.class, ResourceHelpers.resourceFilePath("config-avs.yaml"));

@RegisterExtension
private static final RedisExtension redis = new RedisExtension(6379);
private static final RedisExtension redis = new RedisExtension(6379); // can safely share between apps

@RegisterExtension
private static final TestServiceClient<SiteApi> siteClient =
Expand All @@ -40,6 +43,16 @@ public final class AppVerificationTest {
@RegisterExtension
private static final TestServiceClient<AvsApi> avsClient = new TestServiceClient<>(9090, "person", AvsApi.class);

@BeforeAll
public static void populateData() throws IOException {
VerifiedUser user = VerifiedUser.builder()
.pseudonym(SecureId.fromString("uhzmISXl7szUDLVuYNvDVf6jiL3ExwCybtg-KlazHU4"))
.ageRange(AgeRange.builder().min(40).max(40).build())
.build();
String json = TestObjectMapper.get().writeValueAsString(user);
redis.client().set("age:user:person", json);
}

@Test
public void verify() throws IOException {
Response<VerificationRequest> requestResponse =
Expand Down
8 changes: 0 additions & 8 deletions app/src/test/resources/config-avs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ clients:
redis:
url: http://localhost:6379

stores:
verifiedAccounts:
person:
pseudonym: uhzmISXl7szUDLVuYNvDVf6jiL3ExwCybtg-KlazHU4
ageRange:
min: 40
max: 40

keys:
signing:
s: 87808632867103956881705523559918117434194472117688001288631494927155518459976
Expand Down
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
dagger = "2.55"
dropwizard = "4.0.11"
errorprone = "2.36.0"
guava = "33.4.0-jre"
immutables = "2.10.1"
jackson = "2.18.2"
jakartaAnnotation = "3.0.0"
Expand All @@ -16,6 +15,7 @@ retrofit = "2.11.0"

# test
assertj = "3.27.2"
guava = "33.4.0-jre"
junitJupiter = "5.11.4"
junitPlatform = "1.11.4"
redisEmbedded = "1.4.3"
Expand All @@ -36,7 +36,6 @@ immutables-value = { module = "org.immutables:value", version.ref = "immutables"
dagger-dagger = { module = "com.google.dagger:dagger", version.ref = "dagger" }
dropwizard-core = { module = "io.dropwizard:dropwizard-core", version.ref = "dropwizard" }
jedis-jedis = { module = "redis.clients:jedis", version.ref = "jedis" }
guava-guava = { module = "com.google.guava:guava", version.ref = "guava" }
immutables-annotations = { module = "org.immutables:value-annotations", version.ref = "immutables" }
jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
Expand Down
22 changes: 0 additions & 22 deletions module/store-demo/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading