forked from eclipse-edc/RegistrationService
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): resolve the enrollment url from DID (#15)
* CLI: Resolve the enrollment url from DID (#16) * removed dead code * Avoid use of Optional Co-authored-by: Izabela Kulakowska <ikulakowska@microsoft.com>
- Loading branch information
Showing
14 changed files
with
344 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...rc/main/java/org/eclipse/dataspaceconnector/registration/cli/RegistrationUrlResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2022 Microsoft Corporation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Microsoft Corporation - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.dataspaceconnector.registration.cli; | ||
|
||
import org.eclipse.dataspaceconnector.iam.did.spi.document.DidDocument; | ||
import org.eclipse.dataspaceconnector.iam.did.spi.document.Service; | ||
import org.eclipse.dataspaceconnector.iam.did.spi.resolution.DidResolver; | ||
import org.eclipse.dataspaceconnector.spi.result.Result; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Resolves the registration url from the DID. | ||
*/ | ||
public class RegistrationUrlResolver { | ||
|
||
public static final String REGISTRATION_URL = "RegistrationUrl"; | ||
|
||
/** | ||
* Resolves the DID document from did:web. | ||
*/ | ||
private final DidResolver resolver; | ||
|
||
public RegistrationUrlResolver(DidResolver resolver) { | ||
this.resolver = resolver; | ||
} | ||
|
||
@NotNull | ||
public Result<String> resolveUrl(String did) { | ||
Result<DidDocument> didDocument = resolver.resolve(did); | ||
if (didDocument.failed()) { | ||
throw new CliException("Error resolving the DID " + did); | ||
} | ||
return didDocument.getContent().getService() | ||
.stream() | ||
.filter(service -> service.getType().equals(REGISTRATION_URL)) | ||
.map(Service::getServiceEndpoint) | ||
.findFirst() | ||
.map(Result::success) | ||
.orElse(Result.failure("Error resolving service endpoint from DID Document for " + did)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.