Skip to content

Commit f08ddd5

Browse files
authored
feat(retrigger): add retrigger process steps (#242)
Reviewed-By: Evelyn Gurschler <[email protected]> Refs: #209
1 parent f8cb1a4 commit f08ddd5

File tree

28 files changed

+2360
-59
lines changed

28 files changed

+2360
-59
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Create Credential Process
2+
3+
## Summary
4+
5+
The create credential process handles the creation of credentials. The process steps are the following:
6+
7+
```mermaid
8+
flowchart TD
9+
A(CREATE_SIGNED_CREDENTIAL) --> B(SAVE_CREDENTIAL_DOCUMENT)
10+
B --> C(CREATE_CREDENTIAL_FOR_HOLDER)
11+
C --> D(TRIGGER_CALLBACK)
12+
```
13+
14+
## External dependencies
15+
16+
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.
17+
18+
## Process Steps
19+
20+
### CREATE_SIGNED_CREDENTIAL
21+
22+
The process step `CREATE_SIGNED_CREDENTIAL` is automatically triggered from the process worker. It calls the issuer wallet to create the requested credential.
23+
24+
### SAVE_CREDENTIAL_DOCUMENT
25+
26+
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.
27+
28+
### CREATE_CREDENTIAL_FOR_HOLDER
29+
30+
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.
31+
32+
### TRIGGER_CALLBACK
33+
34+
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.
35+
36+
## Retrigger
37+
38+
| Step Name | Retrigger Step | Retrigger Endpoint |
39+
|------------------------------|----------------------------------------|------------------------------------------------------------------------------|
40+
| CREATE_SIGNED_CREDENTIAL | RETRIGGER_CREATE_SIGNED_CREDENTIAL | api/issuer/{processId}/retrigger-step/RETRIGGER_CREATE_SIGNED_CREDENTIAL |
41+
| SAVE_CREDENTIAL_DOCUMENT | RETRIGGER_SAVE_CREDENTIAL_DOCUMENT | api/issuer/{processId}/retrigger-step/RETRIGGER_SAVE_CREDENTIAL_DOCUMENT |
42+
| CREATE_CREDENTIAL_FOR_HOLDER | RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER | api/issuer/{processId}/retrigger-step/RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER |
43+
| TRIGGER_CALLBACK | RETRIGGER_TRIGGER_CALLBACK | api/issuer/{processId}/retrigger-step/RETRIGGER_TRIGGER_CALLBACK |
44+
45+
## NOTICE
46+
47+
This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).
48+
49+
- SPDX-License-Identifier: Apache-2.0
50+
- SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
51+
- Source URL: https://github.com/eclipse-tractusx/ssi-credential-issuer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Delete Credential Process
2+
3+
## Summary
4+
5+
The delete credential process handles the revocation of existing credentials. The process steps are the following:
6+
7+
```mermaid
8+
flowchart TD
9+
A(REVOKE_CREDENTIAL) --> B(TRIGGER_NOTIFICATION)
10+
B --> C(TRIGGER_MAIL)
11+
```
12+
13+
## External dependencies
14+
15+
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.
16+
17+
## Process Steps
18+
19+
### REVOKE_CREDENTIAL
20+
21+
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.
22+
23+
### TRIGGER_NOTIFICATION
24+
25+
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.
26+
27+
### TRIGGER_MAIL
28+
29+
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.
30+
31+
## Retrigger
32+
33+
| Step Name | Retrigger Step | Retrigger Endpoint |
34+
|----------------------|---------------------------------| ------------------------------------------------------------------------ |
35+
| REVOKE_CREDENTIAL | RETRIGGER_REVOKE_CREDENTIAL | api/revocation/{processId}/retrigger-step/RETRIGGER_REVOKE_CREDENTIAL |
36+
| TRIGGER_NOTIFICATION | RETRIGGER_TRIGGER_NOTIFICATION | api/revocation/{processId}/retrigger-step/RETRIGGER_TRIGGER_NOTIFICATION |
37+
| TRIGGER_MAIL | RETRIGGER_TRIGGER_MAIL | api/revocation/{processId}/retrigger-step/RETRIGGER_TRIGGER_MAIL |
38+
39+
## NOTICE
40+
41+
This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).
42+
43+
- SPDX-License-Identifier: Apache-2.0
44+
- SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
45+
- Source URL: https://github.com/eclipse-tractusx/ssi-credential-issuer

docs/admin/processes/index.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Summary
2+
3+
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.
4+
5+
## Processes
6+
7+
The process worker supports the following processes:
8+
9+
- [CreateCredential](../processes/01.%20create_credential.md) - handles the creation of new credentials
10+
- [DeleteCredential](../processes/02.%20delete_credential.md) - handles the revocation of credentials
11+
12+
## Retriggering
13+
14+
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.
15+
16+
## NOTICE
17+
18+
This work is licensed under the [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0).
19+
20+
- SPDX-License-Identifier: Apache-2.0
21+
- SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
22+
- Source URL: https://github.com/eclipse-tractusx/ssi-credential-issuer

src/database/SsiCredentialIssuer.DbAccess/Repositories/IProcessStepRepository.cs

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ public interface IProcessStepRepository
3434
void AttachAndModifyProcessSteps(IEnumerable<(Guid ProcessStepId, Action<ProcessStep>? Initialize, Action<ProcessStep> Modify)> processStepIdsInitializeModifyData);
3535
IAsyncEnumerable<Process> GetActiveProcesses(IEnumerable<ProcessTypeId> processTypeIds, IEnumerable<ProcessStepTypeId> processStepTypeIds, DateTimeOffset lockExpiryDate);
3636
IAsyncEnumerable<(Guid ProcessStepId, ProcessStepTypeId ProcessStepTypeId)> GetProcessStepData(Guid processId);
37+
Task<(bool ProcessExists, VerifyProcessData ProcessData)> IsValidProcess(Guid processId, ProcessTypeId processTypeId, IEnumerable<ProcessStepTypeId> processStepTypeIds);
3738
}

src/database/SsiCredentialIssuer.DbAccess/Repositories/ProcessStepRepository.cs

+15
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,19 @@ public IAsyncEnumerable<Process> GetActiveProcesses(IEnumerable<ProcessTypeId> p
9797
step.Id,
9898
step.ProcessStepTypeId))
9999
.AsAsyncEnumerable();
100+
101+
public Task<(bool ProcessExists, VerifyProcessData ProcessData)> IsValidProcess(Guid processId, ProcessTypeId processTypeId, IEnumerable<ProcessStepTypeId> processStepTypeIds) =>
102+
_context.Processes
103+
.AsNoTracking()
104+
.Where(x => x.Id == processId && x.ProcessTypeId == processTypeId)
105+
.Select(x => new ValueTuple<bool, VerifyProcessData>(
106+
true,
107+
new VerifyProcessData(
108+
x,
109+
x.ProcessSteps
110+
.Where(step =>
111+
processStepTypeIds.Contains(step.ProcessStepTypeId) &&
112+
step.ProcessStepStatusId == ProcessStepStatusId.TODO))
113+
))
114+
.SingleOrDefaultAsync();
100115
}

src/database/SsiCredentialIssuer.Entities/Enums/ProcessStepTypeId.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ public enum ProcessStepTypeId
2626
SAVE_CREDENTIAL_DOCUMENT = 3,
2727
CREATE_CREDENTIAL_FOR_HOLDER = 4,
2828
TRIGGER_CALLBACK = 5,
29+
RETRIGGER_CREATE_SIGNED_CREDENTIAL = 6,
30+
RETRIGGER_SAVE_CREDENTIAL_DOCUMENT = 7,
31+
RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER = 8,
32+
RETRIGGER_TRIGGER_CALLBACK = 9,
2933

3034
// DECLINE PROCESS
3135
REVOKE_CREDENTIAL = 100,
3236
TRIGGER_NOTIFICATION = 101,
33-
TRIGGER_MAIL = 102
37+
TRIGGER_MAIL = 102,
38+
RETRIGGER_REVOKE_CREDENTIAL = 103,
39+
RETRIGGER_TRIGGER_NOTIFICATION = 104,
40+
RETRIGGER_TRIGGER_MAIL = 105
3441
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/********************************************************************************
2+
* Copyright (c) 2024 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Apache License, Version 2.0 which is available at
9+
* https://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations
15+
* under the License.
16+
*
17+
* SPDX-License-Identifier: Apache-2.0
18+
********************************************************************************/
19+
20+
using Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Enums;
21+
22+
namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Entities.Extensions;
23+
24+
public static class ProcessStepTypeExtensions
25+
{
26+
public static ProcessStepTypeId GetRetriggerStep(this ProcessStepTypeId processStepTypeId) =>
27+
processStepTypeId switch
28+
{
29+
ProcessStepTypeId.CREATE_SIGNED_CREDENTIAL => ProcessStepTypeId.RETRIGGER_CREATE_SIGNED_CREDENTIAL,
30+
ProcessStepTypeId.SAVE_CREDENTIAL_DOCUMENT => ProcessStepTypeId.RETRIGGER_SAVE_CREDENTIAL_DOCUMENT,
31+
ProcessStepTypeId.CREATE_CREDENTIAL_FOR_HOLDER => ProcessStepTypeId.RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER,
32+
ProcessStepTypeId.TRIGGER_CALLBACK => ProcessStepTypeId.RETRIGGER_TRIGGER_CALLBACK,
33+
ProcessStepTypeId.REVOKE_CREDENTIAL => ProcessStepTypeId.RETRIGGER_REVOKE_CREDENTIAL,
34+
ProcessStepTypeId.TRIGGER_NOTIFICATION => ProcessStepTypeId.RETRIGGER_TRIGGER_NOTIFICATION,
35+
ProcessStepTypeId.TRIGGER_MAIL => ProcessStepTypeId.RETRIGGER_TRIGGER_MAIL,
36+
_ => throw new ArgumentOutOfRangeException($"{processStepTypeId} is not a valid value")
37+
};
38+
39+
public static (ProcessTypeId processTypeId, ProcessStepTypeId processStepTypeId) GetProcessStepForRetrigger(this ProcessStepTypeId processStepTypeId) =>
40+
processStepTypeId switch
41+
{
42+
ProcessStepTypeId.RETRIGGER_CREATE_SIGNED_CREDENTIAL => (ProcessTypeId.CREATE_CREDENTIAL, ProcessStepTypeId.CREATE_SIGNED_CREDENTIAL),
43+
ProcessStepTypeId.RETRIGGER_SAVE_CREDENTIAL_DOCUMENT => (ProcessTypeId.CREATE_CREDENTIAL, ProcessStepTypeId.SAVE_CREDENTIAL_DOCUMENT),
44+
ProcessStepTypeId.RETRIGGER_CREATE_CREDENTIAL_FOR_HOLDER => (ProcessTypeId.CREATE_CREDENTIAL, ProcessStepTypeId.CREATE_CREDENTIAL_FOR_HOLDER),
45+
ProcessStepTypeId.RETRIGGER_TRIGGER_CALLBACK => (ProcessTypeId.CREATE_CREDENTIAL, ProcessStepTypeId.TRIGGER_CALLBACK),
46+
ProcessStepTypeId.RETRIGGER_REVOKE_CREDENTIAL => (ProcessTypeId.DECLINE_CREDENTIAL, ProcessStepTypeId.REVOKE_CREDENTIAL),
47+
ProcessStepTypeId.RETRIGGER_TRIGGER_NOTIFICATION => (ProcessTypeId.DECLINE_CREDENTIAL, ProcessStepTypeId.TRIGGER_NOTIFICATION),
48+
ProcessStepTypeId.RETRIGGER_TRIGGER_MAIL => (ProcessTypeId.DECLINE_CREDENTIAL, ProcessStepTypeId.TRIGGER_MAIL),
49+
_ => throw new ArgumentOutOfRangeException($"{processStepTypeId} is not a valid value")
50+
};
51+
}

0 commit comments

Comments
 (0)