From d6347477682c475667bb03388b2e15b1be18a4c6 Mon Sep 17 00:00:00 2001 From: Markus Sabadello Date: Sun, 24 Nov 2024 22:17:01 +0100 Subject: [PATCH] feat: More work on DID Traits support. --- .../uniresolver/local/LocalUniResolver.java | 4 ++-- .../LocalUniResolverConfigurator.java | 1 + .../uniresolver/web/config/WebAppConfig.java | 17 ++++++++++------- .../src/main/resources/application.yml | 10 +++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/uni-resolver-local/src/main/java/uniresolver/local/LocalUniResolver.java b/uni-resolver-local/src/main/java/uniresolver/local/LocalUniResolver.java index f46c20059..8145a8a74 100644 --- a/uni-resolver-local/src/main/java/uniresolver/local/LocalUniResolver.java +++ b/uni-resolver-local/src/main/java/uniresolver/local/LocalUniResolver.java @@ -247,7 +247,7 @@ public Map> properties() throws ResolutionException if (log.isDebugEnabled()) log.debug("Loading properties for driver " + driver.getClass().getSimpleName()); - String driverKey = "driver-" + i; + String driverKey = (driver instanceof HttpDriver httpDriver) ? httpDriver.getPattern().toString() : "driver-" + i; Map driverProperties = driver.properties(); if (driverProperties == null) driverProperties = Collections.emptyMap(); @@ -319,7 +319,7 @@ public Map> traits() throws ResolutionException { if (log.isDebugEnabled()) log.debug("Loading traits for driver " + driver.getClass().getSimpleName()); - String driverKey = "driver-" + i; + String driverKey = (driver instanceof HttpDriver httpDriver) ? httpDriver.getPattern().toString() : "driver-" + i; Map driverTraits = driver.traits(); if (driverTraits == null) driverTraits = Collections.emptyMap(); diff --git a/uni-resolver-local/src/main/java/uniresolver/local/configuration/LocalUniResolverConfigurator.java b/uni-resolver-local/src/main/java/uniresolver/local/configuration/LocalUniResolverConfigurator.java index d9ac5be8f..fefabc802 100644 --- a/uni-resolver-local/src/main/java/uniresolver/local/configuration/LocalUniResolverConfigurator.java +++ b/uni-resolver-local/src/main/java/uniresolver/local/configuration/LocalUniResolverConfigurator.java @@ -54,6 +54,7 @@ public static void configureLocalUniResolver(String filePath, LocalUniResolver l driver.setResolveUri(url + "1.0/identifiers/"); if ("true".equals(propertiesEndpoint)) driver.setPropertiesUri(url + "1.0/properties"); } + if (testIdentifiers != null) driver.setTestIdentifiers(testIdentifiers); if (traits != null) driver.setTraits(traits); diff --git a/uni-resolver-web/src/main/java/uniresolver/web/config/WebAppConfig.java b/uni-resolver-web/src/main/java/uniresolver/web/config/WebAppConfig.java index 19b1dac65..060c805f0 100644 --- a/uni-resolver-web/src/main/java/uniresolver/web/config/WebAppConfig.java +++ b/uni-resolver-web/src/main/java/uniresolver/web/config/WebAppConfig.java @@ -15,6 +15,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; +import java.util.Map; @Configuration public class WebAppConfig { @@ -101,12 +102,13 @@ public void configureLocalUniresolver(DriverConfigs driverConfigs, LocalUniResol List drivers = new ArrayList<>(); - for (DriverConfigs.DriverConfig dc : driverConfigs.getDrivers()) { + for (DriverConfigs.DriverConfig driverConfig : driverConfigs.getDrivers()) { - String pattern = dc.getPattern(); - String url = dc.getUrl(); - String propertiesEndpoint = dc.getPropertiesEndpoint(); - List testIdentifiers = dc.getTestIdentifiers(); + String pattern = driverConfig.getPattern(); + String url = driverConfig.getUrl(); + String propertiesEndpoint = driverConfig.getPropertiesEndpoint(); + List testIdentifiers = driverConfig.getTestIdentifiers(); + Map traits = driverConfig.getTraits(); if (pattern == null) throw new IllegalArgumentException("Missing 'pattern' entry in driver configuration."); if (url == null) throw new IllegalArgumentException("Missing 'url' entry in driver configuration."); @@ -125,12 +127,13 @@ public void configureLocalUniresolver(DriverConfigs driverConfigs, LocalUniResol if ("true".equals(propertiesEndpoint)) driver.setPropertiesUri(normalizeUri((url + servletMappings.getProperties()), false)); } - driver.setTestIdentifiers(testIdentifiers); + if (testIdentifiers != null) driver.setTestIdentifiers(testIdentifiers); + if (traits != null) driver.setTraits(traits); // done drivers.add(driver); - if (log.isInfoEnabled()) log.info("Added driver for pattern '" + dc.getPattern() + "' at " + driver.getResolveUri() + " (" + driver.getPropertiesUri() + ")"); + if (log.isInfoEnabled()) log.info("Added driver for pattern '" + driverConfig.getPattern() + "' at " + driver.getResolveUri() + " (" + driver.getPropertiesUri() + ")"); } uniResolver.setDrivers(drivers); diff --git a/uni-resolver-web/src/main/resources/application.yml b/uni-resolver-web/src/main/resources/application.yml index 6ebff33fd..901a39c43 100644 --- a/uni-resolver-web/src/main/resources/application.yml +++ b/uni-resolver-web/src/main/resources/application.yml @@ -30,6 +30,11 @@ uniresolver: - did:sov:idunion:2GMSLg2A8JXcdYVsPC4Jui - did:sov:idunion:test:BDrEcHc8Tb4Lb2VyQZWEDE - did:sov:indicio:demo:KKyAeG7woJMV6MhhAREVKp + traits: + deactivatable: true + enumerable: true + historyAvailable: true + humanReadbale: false - pattern: "^(did:indy:.+)$" url: ${uniresolver_web_driver_url_did_indy:http://driver-did-indy:8080/} propertiesEndpoint: "true" @@ -41,11 +46,6 @@ uniresolver: - did:indy:idunion:test:BDrEcHc8Tb4Lb2VyQZWEDE - did:indy:indicio:demo:KKyAeG7woJMV6MhhAREVKp - did:indy:nxd:LLDnZr8iaYM3F77pUWXnVX - traits: - deactivatable: true - enumerable: true - historyAvailable: true - humanReadbale: false - pattern: "^(did:v1:nym:.+)$" url: ${uniresolver_web_driver_url_did_v1_nym:http://uni-resolver-did-v1-driver:8080/} propertiesEndpoint: "true"