Skip to content

Commit

Permalink
Feature/remove bankconfiguration from bankservice (#14)
Browse files Browse the repository at this point in the history
* moved configuration of banks from bankservice to plugin

* Refactor BankService and Plugin for async and clarity

Refactor BankService to separate account and transaction logic:
- Rename `GetTransactions` to `GetAccounts` and update functionality.
- Update `InvokeBank` to call new `GetAllAccounts` method.
- Enhance `GetAccountDetailsV2` to handle balances and transactions.
- Add helper methods: `GetAllAccounts`, `GetAccountById`, `ListTransactionsForAccount`.
- Update `MapToInternalV2` for additional account details.
- Modify `GetTransactionsForAccount` to use single `BankConfig`.
- Update `IBankService` interface for method changes.
- Improve logging with structured logging and named placeholders.
- Refactor `KARService` for structured logging and initialize cache.

Update Plugin for async processing and improved readability:
- Make `ProcessResponse` method asynchronous in `BankClient_v2.cs`.
- Simplify `ProcessResponse` in `Bankv2.cs`.
- Remove `SkipKAR` parameter in `Metadata.cs`.
- Introduce `IHttpClientFactory` in `Plugin.cs` and refactor methods.
- Rename `GetEndpoints` to `GetBankEndpoints`.
- Refactor `CreateBankConfigurations` for multiple configurations.
- Improve readability and logging in `ReadEndpointsAndCache`.
- Remove and redefine several methods with updated logic.

---------

Co-authored-by: DanRJ <daniel.rustadj@gmail.com>
  • Loading branch information
erlendoksvoll and DanRJ authored Dec 19, 2024
1 parent 9adec82 commit 4f18812
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="Altinn.ApiClients.Maskinporten" Version="9.2.1" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
<PackageReference Include="Dan.Common" Version="1.6.0" />
<PackageReference Include="Dan.Common" Version="1.6.1" />
<PackageReference Include="FileHelpers" Version="3.5.2" />
<PackageReference Include="jose-jwt" Version="5.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
Expand Down
8 changes: 4 additions & 4 deletions src/Altinn.Dan.Plugin.Banking/Clients/V2/BankClient_v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public virtual async System.Threading.Tasks.Task<AccountDetails> ShowAccountById
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);
await ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
Expand Down Expand Up @@ -606,7 +606,7 @@ public virtual async System.Threading.Tasks.Task<Transactions> ListTransactionsA
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);
await ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
Expand Down Expand Up @@ -829,7 +829,7 @@ public virtual async System.Threading.Tasks.Task<Cards> ListCardsAsync(string ac
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);
await ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
Expand Down Expand Up @@ -1051,7 +1051,7 @@ public virtual async System.Threading.Tasks.Task<Roles> ListRolesAsync(string ac
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);
await ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
Expand Down
14 changes: 1 addition & 13 deletions src/Altinn.Dan.Plugin.Banking/Clients/V2/Bankv2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,8 @@ public async partial Task ProcessResponse(HttpClient client, HttpResponseMessage
if (!response.IsSuccessStatusCode)
return;

bool isAppJose = false;

if (response.Headers.TryGetValues("content-type", out IEnumerable<string?> headervalues))
{
isAppJose = headervalues.Any(x => x == "application/jose");
}

var jwt = await response.Content.ReadAsStringAsync();

var decryptedContent =
JWT.Decode(jwt,
DecryptionCertificate
.GetRSAPrivateKey()); //, JweAlgorithm.RSA_OAEP_256, JweEncryption.A128CBC_HS256);

var decryptedContent = JWT.Decode(jwt, DecryptionCertificate.GetRSAPrivateKey()); //, JweAlgorithm.RSA_OAEP_256, JweEncryption.A128CBC_HS256);
response.Content = new StringContent(decryptedContent, Encoding.UTF8);
}

Expand Down
12 changes: 0 additions & 12 deletions src/Altinn.Dan.Plugin.Banking/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ public List<EvidenceCode> GetEvidenceCodes()
Required = false
},
new EvidenceParameter()
{
EvidenceParamName = "SkipKAR",
ParamType = EvidenceParamType.Boolean,
Required = false
},
new EvidenceParameter()
{
EvidenceParamName = "ReferanseId",
ParamType = EvidenceParamType.String,
Expand Down Expand Up @@ -216,12 +210,6 @@ public List<EvidenceCode> GetEvidenceCodes()
Required = false
},
new EvidenceParameter()
{
EvidenceParamName = "SkipKAR",
ParamType = EvidenceParamType.Boolean,
Required = false
},
new EvidenceParameter()
{
EvidenceParamName = "ReferanseId",
ParamType = EvidenceParamType.String,
Expand Down
Loading

0 comments on commit 4f18812

Please sign in to comment.