Skip to content

Commit

Permalink
feat: Add support for client certs
Browse files Browse the repository at this point in the history
  • Loading branch information
jadyndev committed Jan 9, 2025
1 parent 822b8f4 commit 0666aa1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Requirements
* An already running instance of [Firefly III](https://www.firefly-iii.org/)
* It must be reachable over the network by PHP from the computer you run this import app
* A _Personal Access Token_ which you can generate on the Profile page in Firefly III
* _Optional_ TLS client certificate.


Tips
Expand Down
1 change: 1 addition & 0 deletions app/ChooseAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function () {
$bank_accounts = $list_accounts_handler->get_finished_action()->getAccounts();
$firefly_accounts_request = new GetAccountsRequest($session->get('firefly_url'), $session->get('firefly_access_token'));
$firefly_accounts_request->setType(GetAccountsRequest::ASSET);
$firefly_accounts_request->setCert($session->get('firefly_cert'));
$firefly_accounts = $firefly_accounts_request->get();

$requested_bank_index = -1;
Expand Down
1 change: 1 addition & 0 deletions app/CollectData.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function CollectData()
}
$session->set('firefly_url', $configuration->firefly_url);
$session->set('firefly_access_token', $configuration->firefly_access_token);
$session->set('firefly_cert', $configuration->firefly_cert);
$session->set('skip_transaction_review', $configuration->skip_transaction_review);
$session->set('bank_account_iban' , $configuration->bank_account_iban);
$session->set('firefly_account_id', $configuration->firefly_account_id);
Expand Down
2 changes: 2 additions & 0 deletions app/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Configuration {
public $bank_2fa_device;
public $firefly_url;
public $firefly_access_token;
public $firefly_cert;
public $skip_transaction_review;
public $bank_account_iban;
public $firefly_account_id;
Expand All @@ -37,6 +38,7 @@ static function load_from_file($fileName)
$configuration->bank_2fa_device = @$contentArray["bank_2fa_device"];
$configuration->firefly_url = $contentArray["firefly_url"];
$configuration->firefly_access_token = $contentArray["firefly_access_token"];
$configuration->firefly_cert = $contentArray["firefly_cert"];
$configuration->skip_transaction_review = filter_var($contentArray["skip_transaction_review"], FILTER_VALIDATE_BOOLEAN);
if (isset($contentArray["choose_account_automation"])) {
$configuration->bank_account_iban = $contentArray["choose_account_automation"]["bank_account_iban"];
Expand Down
1 change: 1 addition & 0 deletions app/RunImportBatched.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function RunImport($transactions)
$transactions,
$session->get('firefly_url'),
$session->get('firefly_access_token'),
$session->get('firefly_cert'),
$session->get('firefly_account'),
$session->get('description_regex_match', ""),
$session->get('description_regex_replace', "")
Expand Down
6 changes: 5 additions & 1 deletion app/TransactionsToFireflySender.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ class TransactionsToFireflySender
* @param int $firefly_account_id
*/
public function __construct(array $transactions, string $firefly_url, string $firefly_access_token,
int $firefly_account_id,
string|array|null $firefly_cert, int $firefly_account_id,
string $regex_match, string $regex_replace)
{
$this->transactions = $transactions;
$this->firefly_url = $firefly_url;
$this->firefly_access_token = $firefly_access_token;
$this->firefly_cert = $firefly_cert;
$this->firefly_account_id = $firefly_account_id;
$this->regex_match = $regex_match;
$this->regex_replace = $regex_replace;

$firefly_accounts_request = new GetAccountsRequest($this->firefly_url, $this->firefly_access_token);
$firefly_accounts_request->setType(GetAccountsRequest::ASSET);
$firefly_accounts_request->setCert($this->firefly_cert);
$this->firefly_accounts = $firefly_accounts_request->get();
}

Expand Down Expand Up @@ -128,6 +130,7 @@ public function send_transactions()
foreach ($this->transactions as $transaction) {
$request = new PostTransactionRequest($this->firefly_url, $this->firefly_access_token);

$request->setCert($this->firefly_cert);
$request->setBody(
self::transform_transaction_to_firefly_request_body($transaction, $this->firefly_account_id, $this->firefly_accounts, $this->regex_match, $this->regex_replace)
);
Expand All @@ -150,6 +153,7 @@ public function send_transactions()
private $transactions;
private $firefly_url;
private $firefly_access_token;
private $firefly_cert;
private $firefly_account_id;
private $firefly_accounts;
private $regex_match;
Expand Down
1 change: 1 addition & 0 deletions data/configurations/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"bank_2fa_device": "",
"firefly_url": "",
"firefly_access_token": "",
"firefly_cert": null,
"skip_transaction_review": "false",
"__description_regex_comment__": "To disable the regex search & replace of the transaction description, set both to an empty string.",
"description_regex_match": "/^(Übertrag \\/ Überweisung|Lastschrift \\/ Belastung)(.*)(END-TO-END-REF.*|Karte.*|KFN.*)(Ref\\..*)$/mi",
Expand Down

0 comments on commit 0666aa1

Please sign in to comment.