Skip to content

Commit 7232f27

Browse files
Phil91evegufy
andauthored
feat(config): make wallet application and paths configurable (#230)
Refs: #226 Co-authored-by: Evelyn Gurschler <[email protected]> Reviewed-by: Evelyn Gurschler <[email protected]>
1 parent a1dd326 commit 7232f27

File tree

10 files changed

+89
-25
lines changed

10 files changed

+89
-25
lines changed

charts/ssi-credential-issuer/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ dependencies:
9393
| processesworker.wallet.grantType | string | `"client_credentials"` | |
9494
| processesworker.wallet.clientId | string | `"wallet-client-id"` | Provide wallet client-id from CX IAM centralidp. |
9595
| processesworker.wallet.clientSecret | string | `""` | Client-secret for wallet client-id. Secret-key 'wallet-client-secret'. |
96+
| processesworker.wallet.application | string | `"catena-x-portal"` | the application set in the wallet |
97+
| processesworker.wallet.createCredentialPath | string | `"api/v2.0.0/credentials"` | path to create a credential |
98+
| processesworker.wallet.signCredentialPath | string | `"/api/v2.0.0/credentials/{0}"` | path to sign a specific credential; {0} will be replaced by the credential id |
99+
| processesworker.wallet.getCredentialPath | string | `"/api/v2.0.0/credentials/{0}"` | path to get a specific credential; {0} will be replaced by the credential id |
100+
| processesworker.wallet.revokeCredentialPath | string | `"/api/v2.0.0/credentials/{0}"` | path to revoke a specific credential; {0} will be replaced by the credential id |
96101
| credentialExpiry.name | string | `"expiry"` | |
97102
| credentialExpiry.image.name | string | `"docker.io/tractusx/ssi-credential-expiry-app"` | |
98103
| credentialExpiry.image.tag | string | `""` | |

charts/ssi-credential-issuer/templates/cronjob-issuer-processes.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ spec:
136136
secretKeyRef:
137137
name: "{{ template "issuer.secretName" . }}"
138138
key: "credential-encryption-key0"
139+
- name: "WALLET__WALLETAPPLICATION"
140+
value: "{{ .Values.processesworker.wallet.application }}"
141+
- name: "WALLET__CREATECREDENTIALPATH"
142+
value: "{{ .Values.processesworker.wallet.createCredentialPath }}"
143+
- name: "WALLET__SIGNCREDENTIALPATH"
144+
value: "{{ .Values.processesworker.wallet.signCredentialPath }}"
145+
- name: "WALLET__GETCREDENTIALPATH"
146+
value: "{{ .Values.processesworker.wallet.getCredentialPath }}"
147+
- name: "WALLET__REVOKECREDENTIALPATH"
148+
value: "{{ .Values.processesworker.wallet.revokeCredentialPath }}"
139149
- name: "SERILOG__MINIMUMLEVEL__Default"
140150
value: "{{ .Values.processesworker.logging.default }}"
141151
- name: "PROCESSES__IDENTITYID"

charts/ssi-credential-issuer/templates/deployment-issuer-service.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ spec:
163163
secretKeyRef:
164164
name: "{{ template "issuer.secretName" . }}"
165165
key: "credential-encryption-key0"
166+
- name: "WALLET__WALLETAPPLICATION"
167+
value: "{{ .Values.processesworker.wallet.application }}"
168+
- name: "WALLET__CREATECREDENTIALPATH"
169+
value: "{{ .Values.processesworker.wallet.createCredentialPath }}"
170+
- name: "WALLET__SIGNCREDENTIALPATH"
171+
value: "{{ .Values.processesworker.wallet.signCredentialPath }}"
172+
- name: "WALLET__GETCREDENTIALPATH"
173+
value: "{{ .Values.processesworker.wallet.getCredentialPath }}"
174+
- name: "WALLET__REVOKECREDENTIALPATH"
175+
value: "{{ .Values.processesworker.wallet.revokeCredentialPath }}"
166176
ports:
167177
- name: http
168178
containerPort: {{ .Values.portContainer }}

charts/ssi-credential-issuer/values.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ processesworker:
124124
clientId: "wallet-client-id"
125125
# -- Client-secret for wallet client-id. Secret-key 'wallet-client-secret'.
126126
clientSecret: ""
127+
# -- the application set in the wallet
128+
application: "catena-x-portal"
129+
# -- path to create a credential
130+
createCredentialPath: "api/v2.0.0/credentials"
131+
# -- path to sign a specific credential; {0} will be replaced by the credential id
132+
signCredentialPath: "/api/v2.0.0/credentials/{0}"
133+
# -- path to get a specific credential; {0} will be replaced by the credential id
134+
getCredentialPath: "/api/v2.0.0/credentials/{0}"
135+
# -- path to revoke a specific credential; {0} will be replaced by the credential id
136+
revokeCredentialPath: "/api/v2.0.0/credentials/{0}"
127137

128138
credentialExpiry:
129139
name: "expiry"

src/externalservices/Wallet.Service/DependencyInjection/WalletSettings.cs

+15
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,19 @@ public class WalletSettings : BasicAuthSettings
3333

3434
[Required]
3535
public int EncryptionConfigIndex { get; set; }
36+
37+
[Required]
38+
public string WalletApplication { get; set; } = null!;
39+
40+
[Required]
41+
public string CreateCredentialPath { get; set; } = null!;
42+
43+
[Required]
44+
public string SignCredentialPath { get; set; } = null!;
45+
46+
[Required]
47+
public string GetCredentialPath { get; set; } = null!;
48+
49+
[Required]
50+
public string RevokeCredentialPath { get; set; } = null!;
3651
}

src/externalservices/Wallet.Service/Services/WalletService.cs

+15-21
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,19 @@
2828

2929
namespace Org.Eclipse.TractusX.SsiCredentialIssuer.Wallet.Service.Services;
3030

31-
public class WalletService : IWalletService
31+
public class WalletService(IBasicAuthTokenService basicAuthTokenService, IOptions<WalletSettings> options)
32+
: IWalletService
3233
{
3334
private const string NoIdErrorMessage = "Response must contain a valid id";
3435
private static readonly JsonSerializerOptions Options = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
3536

36-
private readonly IBasicAuthTokenService _basicAuthTokenService;
37-
private readonly WalletSettings _settings;
38-
39-
public WalletService(IBasicAuthTokenService basicAuthTokenService, IOptions<WalletSettings> options)
40-
{
41-
_basicAuthTokenService = basicAuthTokenService;
42-
_settings = options.Value;
43-
}
37+
private readonly WalletSettings _settings = options.Value;
4438

4539
public async Task<Guid> CreateCredential(JsonDocument payload, CancellationToken cancellationToken)
4640
{
47-
using var client = await _basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(_settings, cancellationToken);
48-
var data = new CreateCredentialRequest("catena-x-portal", new CredentialPayload(payload));
49-
var result = await client.PostAsJsonAsync("api/v2.0.0/credentials", data, Options, cancellationToken)
41+
using var client = await basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(_settings, cancellationToken);
42+
var data = new CreateCredentialRequest(_settings.WalletApplication, new CredentialPayload(payload));
43+
var result = await client.PostAsJsonAsync(_settings.CreateCredentialPath, data, Options, cancellationToken)
5044
.CatchingIntoServiceExceptionFor("create-credential", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE,
5145
async x => (false, await x.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None)))
5246
.ConfigureAwait(false);
@@ -61,9 +55,9 @@ public async Task<Guid> CreateCredential(JsonDocument payload, CancellationToken
6155

6256
public async Task<string> SignCredential(Guid credentialId, CancellationToken cancellationToken)
6357
{
64-
using var client = await _basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(_settings, cancellationToken);
58+
using var client = await basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(_settings, cancellationToken);
6559
var data = new SignCredentialRequest(new SignPayload(new SignUpdate("external", "jwt")));
66-
var result = await client.PatchAsJsonAsync($"/api/v2.0.0/credentials/{credentialId}", data, Options, cancellationToken)
60+
var result = await client.PatchAsJsonAsync(string.Format(_settings.SignCredentialPath, credentialId), data, Options, cancellationToken)
6761
.CatchingIntoServiceExceptionFor("sign-credential", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE,
6862
async x => (false, await x.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None)))
6963
.ConfigureAwait(false);
@@ -78,8 +72,8 @@ public async Task<string> SignCredential(Guid credentialId, CancellationToken ca
7872

7973
public async Task<JsonDocument> GetCredential(Guid externalCredentialId, CancellationToken cancellationToken)
8074
{
81-
using var client = await _basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(_settings, cancellationToken);
82-
var result = await client.GetAsync($"/api/v2.0.0/credentials/{externalCredentialId}", cancellationToken)
75+
using var client = await basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(_settings, cancellationToken);
76+
var result = await client.GetAsync(string.Format(_settings.GetCredentialPath, externalCredentialId), cancellationToken)
8377
.CatchingIntoServiceExceptionFor("get-credential", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE,
8478
async x => (false, await x.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None)))
8579
.ConfigureAwait(false);
@@ -100,9 +94,9 @@ public async Task<Guid> CreateCredentialForHolder(string holderWalletUrl, string
10094
ClientSecret = clientSecret,
10195
TokenAddress = $"{holderWalletUrl}/oauth/token"
10296
};
103-
using var client = await _basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(authSettings, cancellationToken);
104-
var data = new DeriveCredentialData("catena-x-portal", new DeriveCredentialPayload(new DeriveCredential(credential)));
105-
var result = await client.PostAsJsonAsync("/api/v2.0.0/credentials", data, Options, cancellationToken)
97+
using var client = await basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(authSettings, cancellationToken);
98+
var data = new DeriveCredentialData(_settings.WalletApplication, new DeriveCredentialPayload(new DeriveCredential(credential)));
99+
var result = await client.PostAsJsonAsync(_settings.CreateCredentialPath, data, Options, cancellationToken)
106100
.CatchingIntoServiceExceptionFor("create-holder-credential", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE,
107101
async x => (false, await x.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None)))
108102
.ConfigureAwait(false);
@@ -117,9 +111,9 @@ public async Task<Guid> CreateCredentialForHolder(string holderWalletUrl, string
117111

118112
public async Task RevokeCredentialForIssuer(Guid externalCredentialId, CancellationToken cancellationToken)
119113
{
120-
using var client = await _basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(_settings, cancellationToken);
114+
using var client = await basicAuthTokenService.GetBasicAuthorizedClient<WalletService>(_settings, cancellationToken);
121115
var data = new RevokeCredentialRequest(new RevokePayload(true));
122-
await client.PatchAsJsonAsync($"/api/v2.0.0/credentials/{externalCredentialId}", data, Options, cancellationToken)
116+
await client.PatchAsJsonAsync(string.Format(_settings.RevokeCredentialPath, externalCredentialId), data, Options, cancellationToken)
123117
.CatchingIntoServiceExceptionFor("revoke-credential", HttpAsyncResponseMessageExtension.RecoverOptions.INFRASTRUCTURE,
124118
async x => (false, await x.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None)))
125119
.ConfigureAwait(false);

src/issuer/SsiCredentialIssuer.Service/appsettings.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@
6363
"TokenAddress": "",
6464
"BaseAddress": "",
6565
"EncryptionConfigIndex": 0,
66-
"EncryptionConfigs": []
66+
"EncryptionConfigs": [],
67+
"WalletApplication": "",
68+
"CreateCredentialPath": "",
69+
"SignCredentialPath": "",
70+
"GetCredentialPath": "",
71+
"RevokeCredentialPath": ""
6772
},
6873
"Credential": {
6974
"IssuerDid": "",

src/processes/Processes.Worker/appsettings.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
"TokenAddress": "",
4848
"BaseAddress": "",
4949
"EncryptionConfigIndex": 0,
50-
"EncryptionConfigs": []
50+
"EncryptionConfigs": [],
51+
"WalletApplication": "",
52+
"CreateCredentialPath": "",
53+
"SignCredentialPath": "",
54+
"GetCredentialPath": "",
55+
"RevokeCredentialPath": ""
5156
}
5257
}

tests/externalservices/Wallet.Service.Tests/Services/WalletServiceTests.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ public WalletServiceTests()
3838
ClientId = "CatenaX",
3939
ClientSecret = "pass@Secret",
4040
TokenAddress = "https://example.org/token",
41-
EncryptionConfigIndex = 0
41+
EncryptionConfigIndex = 0,
42+
WalletApplication = "catena-x-portal",
43+
CreateCredentialPath = "api/v2.0.0/credentials",
44+
SignCredentialPath = "/api/v2.0.0/credentials/{0}",
45+
GetCredentialPath = "/api/v2.0.0/credentials/{0}",
46+
RevokeCredentialPath = "/api/v2.0.0/credentials/{0}"
4247
});
4348
_sut = new WalletService(_basicAuthTokenService, _options);
4449
}

tests/issuer/SsiCredentialIssuer.Service.Tests/appsettings.IntegrationTests.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
"CipherMode": "CBC",
6363
"PaddingMode": "PKCS7"
6464
}
65-
]
65+
],
66+
"WalletApplication": "catena-x-portal",
67+
"CreateCredentialPath": "api/v2.0.0/credentials",
68+
"SignCredentialPath": "/api/v2.0.0/credentials/{0}",
69+
"GetCredentialPath": "/api/v2.0.0/credentials/{0}",
70+
"RevokeCredentialPath": "/api/v2.0.0/credentials/{0}"
6671
}
6772
}

0 commit comments

Comments
 (0)