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

feat(retrigger): add retrigger process steps #242

Merged
merged 6 commits into from
Sep 24, 2024
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
51 changes: 51 additions & 0 deletions docs/admin/processes/01. create_credential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Create Credential Process

## Summary

The create credential process handles the creation of credentials. The process steps are the following:

```mermaid
flowchart TD
A(CREATE_SIGNED_CREDENTIAL) --> B(SAVE_CREDENTIAL_DOCUMENT)
B --> C(CREATE_CREDENTIAL_FOR_HOLDER)
C --> D(TRIGGER_CALLBACK)
```

## External dependencies

The process worker communicates with the Issuer Wallet to revoke the credential. It further more communicates with the portal backend to create notifications and mails.

## Process Steps

### CREATE_SIGNED_CREDENTIAL

The process step `CREATE_SIGNED_CREDENTIAL` is automatically triggered from the process worker. It calls the issuer wallet to create the requested credential.

### SAVE_CREDENTIAL_DOCUMENT

The process step `SAVE_CREDENTIAL_DOCUMENT` is automatically triggered from the process worker. Calls the issuer wallet to get the created credential to save it in the `documents` table.

### CREATE_CREDENTIAL_FOR_HOLDER

The process step `CREATE_CREDENTIAL_FOR_HOLDER` is automatically triggered from the process worker. If the wallet address is equal to the issuer wallet this step is skipped. Otherwise the created credential is imported to the holder wallet.

### TRIGGER_CALLBACK

The process step `TRIGGER_CALLBACK` is automatically triggered from the process worker. Posts a callback to the portal with a status of the credential creation.

## Retrigger

| Step Name | Retrigger Step | Retrigger Endpoint |
|------------------------------|----------------------------------------|------------------------------------------------------------------------------|
| CREATE_SIGNED_CREDENTIAL | RETRIGGER_CREATE_SIGNED_CREDENTIAL | api/issuer/{processId}/retrigger-step/RETRIGGER_CREATE_SIGNED_CREDENTIAL |
| SAVE_CREDENTIAL_DOCUMENT | RETRIGGER_SAVE_CREDENTIAL_DOCUMENT | api/issuer/{processId}/retrigger-step/RETRIGGER_SAVE_CREDENTIAL_DOCUMENT |
| CREATE_CREDENTIAL_FOR_HOLDER | RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER | api/issuer/{processId}/retrigger-step/RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER |
| TRIGGER_CALLBACK | RETRIGGER_TRIGGER_CALLBACK | api/issuer/{processId}/retrigger-step/RETRIGGER_TRIGGER_CALLBACK |

## NOTICE

This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).

- SPDX-License-Identifier: Apache-2.0
- SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
- Source URL: https://github.com/eclipse-tractusx/ssi-credential-issuer
45 changes: 45 additions & 0 deletions docs/admin/processes/02. delete_credential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Delete Credential Process

## Summary

The delete credential process handles the revocation of existing credentials. The process steps are the following:

```mermaid
flowchart TD
A(REVOKE_CREDENTIAL) --> B(TRIGGER_NOTIFICATION)
B --> C(TRIGGER_MAIL)
```

## External dependencies

The process worker communicates with the Issuer Wallet to revoke the credential. It further more communicates with the portal backend to create notifications and mails.

## Process Steps

### REVOKE_CREDENTIAL

The process step `REVOKE_CREDENTIAL` is automatically triggered from the process worker. It revokes the credential in the wallet and sets the state of the document to inactive and the status of the ssi details to revoked.

### TRIGGER_NOTIFICATION

The process step `TRIGGER_NOTIFICATION` is automatically triggered from the process worker. It will create a notification for the requester of the credential via the portal.

### TRIGGER_MAIL

The process step `TRIGGER_MAIL` is automatically triggered from the process worker. It will create a mail for the requester of the credential via the portal.

## Retrigger

| Step Name | Retrigger Step | Retrigger Endpoint |
|----------------------|---------------------------------| ------------------------------------------------------------------------ |
| REVOKE_CREDENTIAL | RETRIGGER_REVOKE_CREDENTIAL | api/revocation/{processId}/retrigger-step/RETRIGGER_REVOKE_CREDENTIAL |
| TRIGGER_NOTIFICATION | RETRIGGER_TRIGGER_NOTIFICATION | api/revocation/{processId}/retrigger-step/RETRIGGER_TRIGGER_NOTIFICATION |
| TRIGGER_MAIL | RETRIGGER_TRIGGER_MAIL | api/revocation/{processId}/retrigger-step/RETRIGGER_TRIGGER_MAIL |

## NOTICE

This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).

- SPDX-License-Identifier: Apache-2.0
- SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
- Source URL: https://github.com/eclipse-tractusx/ssi-credential-issuer
22 changes: 22 additions & 0 deletions docs/admin/processes/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Summary

The main process worker project is the `Processes.Worker` which runs all the processes. It therefor looks up `process_steps` in status `TODO` and their respective `processes` and executes those.

## Processes

The process worker supports the following processes:

- [CreateCredential](../processes/01.%20create_credential.md) - handles the creation of new credentials
- [DeleteCredential](../processes/02.%20delete_credential.md) - handles the revocation of credentials

## Retriggering

The process has a logic to retrigger failing steps. For this a retrigger step is created which can be triggered via an api call to retrigger the step. This logic is implemented separately for each process. In general the retriggering of a step is possible if for example external services are not available. The retrigger logic for each process can be found in the process file.

## NOTICE

This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).

- SPDX-License-Identifier: Apache-2.0
- SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
- Source URL: https://github.com/eclipse-tractusx/ssi-credential-issuer
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ public interface IProcessStepRepository
void AttachAndModifyProcessSteps(IEnumerable<(Guid ProcessStepId, Action<ProcessStep>? Initialize, Action<ProcessStep> Modify)> processStepIdsInitializeModifyData);
IAsyncEnumerable<Process> GetActiveProcesses(IEnumerable<ProcessTypeId> processTypeIds, IEnumerable<ProcessStepTypeId> processStepTypeIds, DateTimeOffset lockExpiryDate);
IAsyncEnumerable<(Guid ProcessStepId, ProcessStepTypeId ProcessStepTypeId)> GetProcessStepData(Guid processId);
Task<(bool ProcessExists, VerifyProcessData ProcessData)> IsValidProcess(Guid processId, ProcessTypeId processTypeId, IEnumerable<ProcessStepTypeId> processStepTypeIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ public IAsyncEnumerable<Process> GetActiveProcesses(IEnumerable<ProcessTypeId> p
step.Id,
step.ProcessStepTypeId))
.AsAsyncEnumerable();

public Task<(bool ProcessExists, VerifyProcessData ProcessData)> IsValidProcess(Guid processId, ProcessTypeId processTypeId, IEnumerable<ProcessStepTypeId> processStepTypeIds) =>
_context.Processes
.AsNoTracking()
.Where(x => x.Id == processId && x.ProcessTypeId == processTypeId)
.Select(x => new ValueTuple<bool, VerifyProcessData>(
true,
new VerifyProcessData(
x,
x.ProcessSteps
.Where(step =>
processStepTypeIds.Contains(step.ProcessStepTypeId) &&
step.ProcessStepStatusId == ProcessStepStatusId.TODO))
))
.SingleOrDefaultAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ public enum ProcessStepTypeId
SAVE_CREDENTIAL_DOCUMENT = 3,
CREATE_CREDENTIAL_FOR_HOLDER = 4,
TRIGGER_CALLBACK = 5,
RETRIGGER_CREATE_SIGNED_CREDENTIAL = 6,
RETRIGGER_SAVE_CREDENTIAL_DOCUMENT = 7,
RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER = 8,
RETRIGGER_TRIGGER_CALLBACK = 9,

// DECLINE PROCESS
REVOKE_CREDENTIAL = 100,
TRIGGER_NOTIFICATION = 101,
TRIGGER_MAIL = 102
TRIGGER_MAIL = 102,
RETRIGGER_REVOKE_CREDENTIAL = 103,
RETRIGGER_TRIGGER_NOTIFICATION = 104,
RETRIGGER_TRIGGER_MAIL = 105
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Enums;

namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Extensions;

public static class ProcessStepTypeExtensions
{
public static ProcessStepTypeId GetRetriggerStep(this ProcessStepTypeId processStepTypeId) =>
processStepTypeId switch
{
ProcessStepTypeId.CREATE_SIGNED_CREDENTIAL => ProcessStepTypeId.RETRIGGER_CREATE_SIGNED_CREDENTIAL,
ProcessStepTypeId.SAVE_CREDENTIAL_DOCUMENT => ProcessStepTypeId.RETRIGGER_SAVE_CREDENTIAL_DOCUMENT,
ProcessStepTypeId.CREATE_CREDENTIAL_FOR_HOLDER => ProcessStepTypeId.RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER,
ProcessStepTypeId.TRIGGER_CALLBACK => ProcessStepTypeId.RETRIGGER_TRIGGER_CALLBACK,
ProcessStepTypeId.REVOKE_CREDENTIAL => ProcessStepTypeId.RETRIGGER_REVOKE_CREDENTIAL,
ProcessStepTypeId.TRIGGER_NOTIFICATION => ProcessStepTypeId.RETRIGGER_TRIGGER_NOTIFICATION,
ProcessStepTypeId.TRIGGER_MAIL => ProcessStepTypeId.RETRIGGER_TRIGGER_MAIL,
_ => throw new ArgumentOutOfRangeException($"{processStepTypeId} is not a valid value")
};

public static (ProcessTypeId processTypeId, ProcessStepTypeId processStepTypeId) GetProcessStepForRetrigger(this ProcessStepTypeId processStepTypeId) =>
processStepTypeId switch
{
ProcessStepTypeId.RETRIGGER_CREATE_SIGNED_CREDENTIAL => (ProcessTypeId.CREATE_CREDENTIAL, ProcessStepTypeId.CREATE_SIGNED_CREDENTIAL),
ProcessStepTypeId.RETRIGGER_SAVE_CREDENTIAL_DOCUMENT => (ProcessTypeId.CREATE_CREDENTIAL, ProcessStepTypeId.SAVE_CREDENTIAL_DOCUMENT),
ProcessStepTypeId.RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER => (ProcessTypeId.CREATE_CREDENTIAL, ProcessStepTypeId.CREATE_CREDENTIAL_FOR_HOLDER),
ProcessStepTypeId.RETRIGGER_TRIGGER_CALLBACK => (ProcessTypeId.CREATE_CREDENTIAL, ProcessStepTypeId.TRIGGER_CALLBACK),
ProcessStepTypeId.RETRIGGER_REVOKE_CREDENTIAL => (ProcessTypeId.DECLINE_CREDENTIAL, ProcessStepTypeId.REVOKE_CREDENTIAL),
ProcessStepTypeId.RETRIGGER_TRIGGER_NOTIFICATION => (ProcessTypeId.DECLINE_CREDENTIAL, ProcessStepTypeId.TRIGGER_NOTIFICATION),
ProcessStepTypeId.RETRIGGER_TRIGGER_MAIL => (ProcessTypeId.DECLINE_CREDENTIAL, ProcessStepTypeId.TRIGGER_MAIL),
_ => throw new ArgumentOutOfRangeException($"{processStepTypeId} is not a valid value")
};
}
Loading