Skip to content

Commit

Permalink
chore: add API Version info to IdentityHub (#430)
Browse files Browse the repository at this point in the history
* chore(api): add version information resources

* register version info with service

* DEPENDENCIES

* set maturity null

* fixed file name
  • Loading branch information
paullatzelsperger authored Aug 23, 2024
1 parent 0cbe1cf commit 77a2434
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 5 deletions.
2 changes: 2 additions & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ maven/mavencentral/org.codehaus.plexus/plexus-container-default/2.1.0, Apache-2.
maven/mavencentral/org.codehaus.plexus/plexus-utils/3.1.1, , approved, CQ16492
maven/mavencentral/org.codehaus.plexus/plexus-utils/3.3.0, , approved, CQ21066
maven/mavencentral/org.eclipse.angus/angus-activation/1.0.0, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.angus
maven/mavencentral/org.eclipse.edc/api-core/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/api-observability/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/asset-spi/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/auth-spi/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
Expand Down Expand Up @@ -296,6 +297,7 @@ maven/mavencentral/org.eclipse.edc/validator-lib/0.8.2-SNAPSHOT, Apache-2.0, app
maven/mavencentral/org.eclipse.edc/validator-spi/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/verifiable-credentials-spi/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/verifiable-credentials/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/version-api/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.edc/web-spi/0.8.2-SNAPSHOT, Apache-2.0, approved, technology.edc
maven/mavencentral/org.eclipse.jetty.toolchain/jetty-jakarta-servlet-api/5.0.2, EPL-2.0 OR Apache-2.0, approved, rt.jetty
maven/mavencentral/org.eclipse.jetty.toolchain/jetty-jakarta-websocket-api/2.0.0, EPL-2.0 OR Apache-2.0, approved, rt.jetty
Expand Down
2 changes: 1 addition & 1 deletion core/presentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ dependencies {

edcBuild {
swagger {
apiGroup.set("ih-resolution-api")
apiGroup.set("presentation-api")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.eclipse.edc.identityhub.api;

import com.fasterxml.jackson.databind.DeserializationFeature;
import org.eclipse.edc.iam.identitytrust.spi.model.PresentationQueryMessage;
import org.eclipse.edc.iam.identitytrust.transform.from.JsonObjectFromPresentationResponseMessageTransformer;
import org.eclipse.edc.iam.identitytrust.transform.to.JsonObjectToPresentationQueryTransformer;
Expand All @@ -26,8 +27,11 @@
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.apiversion.ApiVersionService;
import org.eclipse.edc.spi.system.apiversion.VersionRecord;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.transform.transformer.edc.to.JsonValueToGenericTypeTransformer;
Expand All @@ -36,16 +40,20 @@
import org.eclipse.edc.web.jersey.providers.jsonld.ObjectMapperProvider;
import org.eclipse.edc.web.spi.WebService;

import java.io.IOException;
import java.util.stream.Stream;

import static org.eclipse.edc.iam.identitytrust.spi.DcpConstants.DCP_CONTEXT_URL;
import static org.eclipse.edc.identityhub.api.PresentationApiExtension.NAME;
import static org.eclipse.edc.identityhub.spi.IdentityHubApiContext.PRESENTATION;
import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD;

@Extension(value = NAME)
public class PresentationApiExtension implements ServiceExtension {

public static final String NAME = "Presentation API Extension";
public static final String RESOLUTION_SCOPE = "resolution-scope";
public static final String RESOLUTION_CONTEXT = "resolution";
private static final String API_VERSION_JSON_FILE = "presentation-api-version.json";
@Inject
private TypeTransformerRegistry typeTransformer;
@Inject
Expand All @@ -64,6 +72,8 @@ public class PresentationApiExtension implements ServiceExtension {
private TypeManager typeManager;
@Inject
private ParticipantContextService participantContextService;
@Inject
private ApiVersionService apiVersionService;

@Override
public String name() {
Expand All @@ -79,17 +89,32 @@ public void initialize(ServiceExtensionContext context) {
var controller = new PresentationApiController(validatorRegistry, typeTransformer, credentialResolver, accessTokenVerifier, verifiablePresentationService, context.getMonitor(), participantContextService);

var jsonLdMapper = typeManager.getMapper(JSON_LD);
webService.registerResource(RESOLUTION_CONTEXT, new ObjectMapperProvider(jsonLdMapper));
webService.registerResource(RESOLUTION_CONTEXT, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, RESOLUTION_SCOPE));
webService.registerResource(RESOLUTION_CONTEXT, controller);
webService.registerResource(PRESENTATION, new ObjectMapperProvider(jsonLdMapper));
webService.registerResource(PRESENTATION, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, RESOLUTION_SCOPE));
webService.registerResource(PRESENTATION, controller);

jsonLd.registerContext(DCP_CONTEXT_URL, RESOLUTION_SCOPE);

// register transformer -- remove once registration is handled in EDC
typeTransformer.register(new JsonObjectToPresentationQueryTransformer(jsonLdMapper));
typeTransformer.register(new JsonValueToGenericTypeTransformer(jsonLdMapper));
typeTransformer.register(new JsonObjectFromPresentationResponseMessageTransformer());

registerVersionInfo(getClass().getClassLoader());
}

private void registerVersionInfo(ClassLoader resourceClassLoader) {
try (var versionContent = resourceClassLoader.getResourceAsStream(API_VERSION_JSON_FILE)) {
if (versionContent == null) {
throw new EdcException("Version file not found or not readable.");
}
Stream.of(typeManager.getMapper()
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.readValue(versionContent, VersionRecord[].class))
.forEach(vr -> apiVersionService.addRecord("presentation", vr));
} catch (IOException e) {
throw new EdcException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"version": "1.0.0",
"urlPath": "/v1",
"lastUpdated": "2024-08-22T09:20:00Z",
"maturity": "stable"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,30 @@

package org.eclipse.edc.identityhub.api.configuration;

import com.fasterxml.jackson.databind.DeserializationFeature;
import jakarta.ws.rs.core.SecurityContext;
import org.eclipse.edc.identityhub.spi.AuthorizationService;
import org.eclipse.edc.identityhub.spi.IdentityHubApiContext;
import org.eclipse.edc.identityhub.spi.participantcontext.ParticipantContextService;
import org.eclipse.edc.identityhub.spi.participantcontext.model.ParticipantResource;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.result.ServiceResult;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.apiversion.ApiVersionService;
import org.eclipse.edc.spi.system.apiversion.VersionRecord;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.web.spi.WebServer;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer;

import java.io.IOException;
import java.util.function.Function;
import java.util.stream.Stream;

import static org.eclipse.edc.identityhub.api.configuration.IdentityApiConfigurationExtension.NAME;

Expand All @@ -37,6 +46,7 @@ public class IdentityApiConfigurationExtension implements ServiceExtension {


public static final String NAME = "Identity API Extension";
private static final String API_VERSION_JSON_FILE = "identity-api-version.json";
@Inject
private WebService webService;
@Inject
Expand All @@ -47,18 +57,41 @@ public class IdentityApiConfigurationExtension implements ServiceExtension {
private WebServer webServer;
@Inject
private Vault vault;
@Inject
private TypeManager typeManager;

@Inject
private ApiVersionService apiVersionService;

@Override
public String name() {
return NAME;
}


@Override
public void initialize(ServiceExtensionContext context) {
registerVersionInfo(getClass().getClassLoader());
}

@Provider(isDefault = true)
public AuthorizationService authorizationService() {
return new AllowAllAuthorizationService();
}

private void registerVersionInfo(ClassLoader resourceClassLoader) {
try (var versionContent = resourceClassLoader.getResourceAsStream(API_VERSION_JSON_FILE)) {
if (versionContent == null) {
throw new EdcException("Version file not found or not readable.");
}
Stream.of(typeManager.getMapper()
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.readValue(versionContent, VersionRecord[].class))
.forEach(vr -> apiVersionService.addRecord(IdentityHubApiContext.IDENTITY, vr));
} catch (IOException e) {
throw new EdcException(e);
}
}

private static class AllowAllAuthorizationService implements AuthorizationService {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"version": "1.0.0-alpha",
"urlPath": "/v1alpha",
"lastUpdated": "2024-08-22T09:20:00Z",
"maturity": null
}
]
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ edc-ext-transaction-local = { module = "org.eclipse.edc:transaction-local", vers
edc-testfixtures-managementapi = { module = "org.eclipse.edc:management-api-test-fixtures", version.ref = "edc" }
edc-sql-pool = { module = "org.eclipse.edc:sql-pool-apache-commons", version.ref = "edc" }
edc-sql-bootstrapper = { module = "org.eclipse.edc:sql-bootstrapper", version.ref = "edc" }
edc-api-version = { module = "org.eclipse.edc:version-api", version.ref = "edc" }


# EDC libs
edc-lib-keys = { "module" = "org.eclipse.edc:keys-lib", version.ref = "edc" }
Expand Down
1 change: 1 addition & 0 deletions launcher/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
runtimeOnly(project(":extensions:api:identityhub-api-authorization"))
runtimeOnly(libs.edc.identity.did.core)
runtimeOnly(libs.edc.core.token)
runtimeOnly(libs.edc.api.version)

runtimeOnly(libs.edc.identity.did.web)
runtimeOnly(libs.bundles.connector)
Expand Down
1 change: 1 addition & 0 deletions resources/openapi/identity-api.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions/api/identity-api/api-configuration/src/main/resources/identity-api-version.json
1 change: 1 addition & 0 deletions resources/openapi/presentation-api.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
core/presentation-api/src/main/resources/presentation-api-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
public interface IdentityHubApiContext {
String IDENTITY = "identity";
String IH_DID = "did";
String PRESENTATION = "resolution"; // should be "presentation", but this would break config
}

0 comments on commit 77a2434

Please sign in to comment.