Skip to content

Commit c0c847c

Browse files
committed
Moved octopart / nexar integration configuration to the new settings system
1 parent 1dbcff6 commit c0c847c

File tree

7 files changed

+116
-40
lines changed

7 files changed

+116
-40
lines changed

.env

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,6 @@ ERROR_PAGE_ADMIN_EMAIL=''
6767
# If this is set to true, solutions to common problems are shown on error pages. Disable this, if you do not want your users to see them...
6868
ERROR_PAGE_SHOW_HELP=1
6969

70-
##################################################################################
71-
# Info provider settings
72-
##################################################################################
73-
74-
# Octopart / Nexar Provider:
75-
# You can get your API key from https://nexar.com/api
76-
PROVIDER_OCTOPART_CLIENT_ID=
77-
PROVIDER_OCTOPART_SECRET=
78-
# The currency and country to get prices for (you have to set both to get meaningful results)
79-
# 3 letter ISO currency code (e.g. EUR, USD, GBP)
80-
PROVIDER_OCTOPART_CURRENCY=EUR
81-
# 2 letter ISO country code (e.g. DE, US, GB)
82-
PROVIDER_OCTOPART_COUNTRY=DE
83-
# The number of results to get from Octopart while searching (please note that this counts towards your API limits)
84-
PROVIDER_OCTOPART_SEARCH_LIMIT=10
85-
# Set to false to include non authorized offers in the results
86-
PROVIDER_OCTOPART_ONLY_AUTHORIZED_SELLERS=1
8770

8871
##################################################################################
8972
# EDA integration related settings

config/packages/knpu_oauth2_client.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ knpu_oauth2_client:
2626
type: generic
2727
provider_class: '\League\OAuth2\Client\Provider\GenericProvider'
2828

29-
client_id: '%env(PROVIDER_OCTOPART_CLIENT_ID)%'
30-
client_secret: '%env(PROVIDER_OCTOPART_SECRET)%'
29+
client_id: '%env(settings:octopart:clientId)%'
30+
client_secret: '%env(settings:octopart:secret)%'
3131

3232
redirect_route: 'oauth_client_check'
3333
redirect_params: { name: 'ip_octopart_oauth' }

config/services.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,6 @@ services:
199199
arguments:
200200
$providers: !tagged_iterator 'app.info_provider'
201201

202-
App\Services\InfoProviderSystem\Providers\OctopartProvider:
203-
arguments:
204-
$clientId: '&env(string:PROVIDER_OCTOPART_CLIENT_ID)%'
205-
$secret: '%env(string:PROVIDER_OCTOPART_SECRET)%'
206-
$country: '%env(string:PROVIDER_OCTOPART_COUNTRY)%'
207-
$currency: '%env(string:PROVIDER_OCTOPART_CURRENCY)%'
208-
$search_limit: '%env(int:PROVIDER_OCTOPART_SEARCH_LIMIT)%'
209-
$onlyAuthorizedSellers: '%env(bool:PROVIDER_OCTOPART_ONLY_AUTHORIZED_SELLERS)%'
210-
211-
212202
####################################################################################################################
213203
# API system
214204
####################################################################################################################

src/Services/InfoProviderSystem/Providers/OctopartProvider.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
3131
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
3232
use App\Services\OAuth\OAuthTokenManager;
33+
use App\Settings\InfoProviderSystem\OctopartSettings;
3334
use Psr\Cache\CacheItemPoolInterface;
3435
use Symfony\Component\HttpClient\HttpOptions;
3536
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -114,9 +115,8 @@ class OctopartProvider implements InfoProviderInterface
114115

115116
public function __construct(private readonly HttpClientInterface $httpClient,
116117
private readonly OAuthTokenManager $authTokenManager, private readonly CacheItemPoolInterface $partInfoCache,
117-
private readonly string $clientId, private readonly string $secret,
118-
private readonly string $currency, private readonly string $country,
119-
private readonly int $search_limit, private readonly bool $onlyAuthorizedSellers)
118+
private readonly OctopartSettings $settings,
119+
)
120120
{
121121

122122
}
@@ -183,7 +183,7 @@ public function isActive(): bool
183183
{
184184
//The client ID has to be set and a token has to be available (user clicked connect)
185185
//return /*!empty($this->clientId) && */ $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
186-
return $this->clientId !== '' && $this->secret !== '';
186+
return $this->settings->clientId !== '' && $this->settings->secret !== '';
187187
}
188188

189189
private function mapLifeCycleStatus(?string $value): ?ManufacturingStatus
@@ -347,10 +347,10 @@ public function searchByKeyword(string $keyword): array
347347

348348
$result = $this->makeGraphQLCall($graphQL, [
349349
'keyword' => $keyword,
350-
'limit' => $this->search_limit,
351-
'currency' => $this->currency,
352-
'country' => $this->country,
353-
'authorizedOnly' => $this->onlyAuthorizedSellers,
350+
'limit' => $this->settings->searchLimit,
351+
'currency' => $this->settings->currency,
352+
'country' => $this->settings->country,
353+
'authorizedOnly' => $this->settings->onlyAuthorizedSellers,
354354
]);
355355

356356
$tmp = [];
@@ -383,9 +383,9 @@ public function getDetails(string $id): PartDetailDTO
383383

384384
$result = $this->makeGraphQLCall($graphql, [
385385
'ids' => [$id],
386-
'currency' => $this->currency,
387-
'country' => $this->country,
388-
'authorizedOnly' => $this->onlyAuthorizedSellers,
386+
'currency' => $this->settings->currency,
387+
'country' => $this->settings->country,
388+
'authorizedOnly' => $this->settings->onlyAuthorizedSellers,
389389
]);
390390

391391
$tmp = $this->partResultToDTO($result['data']['supParts'][0]);

src/Settings/InfoProviderSystem/InfoProviderSettings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class InfoProviderSettings
4444
#[EmbeddedSettings]
4545
public ?Element14Settings $element14 = null;
4646

47+
#[EmbeddedSettings]
48+
public ?OctopartSettings $octopartSettings = null;
49+
4750
#[EmbeddedSettings]
4851
public ?LCSCSettings $lcsc = null;
4952

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published
9+
* by the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
24+
namespace App\Settings\InfoProviderSystem;
25+
26+
use App\Settings\SettingsIcon;
27+
use Jbtronics\SettingsBundle\Settings\Settings;
28+
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
29+
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
30+
use Symfony\Component\Form\Extension\Core\Type\CountryType;
31+
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
32+
use Symfony\Component\Form\Extension\Core\Type\NumberType;
33+
use Symfony\Component\Translation\TranslatableMessage as TM;
34+
use Symfony\Component\Validator\Constraints as Assert;
35+
36+
#[Settings(label: new TM("settings.ips.octopart"))]
37+
#[SettingsIcon("fa-plug")]
38+
class OctopartSettings
39+
{
40+
use SettingsTrait;
41+
42+
#[SettingsParameter(
43+
label: new TM("settings.ips.digikey.client_id"),
44+
envVar: "PROVIDER_OCTOPART_CLIENT_ID"
45+
)]
46+
public ?string $clientId = null;
47+
48+
#[SettingsParameter(
49+
label: new TM("settings.ips.digikey.secret"),
50+
envVar: "PROVIDER_OCTOPART_SECRET"
51+
)]
52+
public ?string $secret = null;
53+
54+
#[SettingsParameter(label: new TM("settings.ips.tme.currency"), formType: CurrencyType::class, formOptions: ["preferred_choices" => ["EUR", "USD", "CHF", "GBP"]], envVar: "PROVIDER_OCTOPART_CURRENCY")]
55+
#[Assert\Currency()]
56+
public string $currency = "EUR";
57+
58+
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: CountryType::class, envVar: "PROVIDER_OCTOPART_COUNTRY")]
59+
#[Assert\Country]
60+
public string $country = "DE";
61+
62+
#[SettingsParameter(label: new TM("settings.ips.octopart.searchLimit"), description: new TM("settings.ips.octopart.searchLimit.help"),
63+
formType: NumberType::class, formOptions: ["attr" => ["min" => 1, "max" => 100]], envVar: "PROVIDER_OCTOPART_SEARCH_LIMIT")]
64+
#[Assert\Range(min: 1, max: 100)]
65+
public int $searchLimit = 10;
66+
67+
#[SettingsParameter(label: new TM("settings.ips.octopart.onlyAuthorizedSellers"), description: new TM("settings.ips.octopart.onlyAuthorizedSellers.help"))]
68+
public bool $onlyAuthorizedSellers = true;
69+
70+
}

translations/messages.en.xlf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12946,5 +12946,35 @@ Please note, that you can not impersonate a disabled user. If you try you will g
1294612946
<target>Secret</target>
1294712947
</segment>
1294812948
</unit>
12949+
<unit id="5xjmMzf" name="settings.ips.octopart">
12950+
<segment>
12951+
<source>settings.ips.octopart</source>
12952+
<target>Octopart / Nexar</target>
12953+
</segment>
12954+
</unit>
12955+
<unit id="vGv90iO" name="settings.ips.octopart.searchLimit">
12956+
<segment>
12957+
<source>settings.ips.octopart.searchLimit</source>
12958+
<target>Number of results</target>
12959+
</segment>
12960+
</unit>
12961+
<unit id="au4Yeps" name="settings.ips.octopart.searchLimit.help">
12962+
<segment>
12963+
<source>settings.ips.octopart.searchLimit.help</source>
12964+
<target>The number of results to get from Octopart while searching (please note that this counts towards your API limits)</target>
12965+
</segment>
12966+
</unit>
12967+
<unit id="Tiqmk.8" name="settings.ips.octopart.onlyAuthorizedSellers">
12968+
<segment>
12969+
<source>settings.ips.octopart.onlyAuthorizedSellers</source>
12970+
<target>Only authorized sellers</target>
12971+
</segment>
12972+
</unit>
12973+
<unit id="ECQkeJy" name="settings.ips.octopart.onlyAuthorizedSellers.help">
12974+
<segment>
12975+
<source>settings.ips.octopart.onlyAuthorizedSellers.help</source>
12976+
<target>Set to false to include non-authorized offers in the results</target>
12977+
</segment>
12978+
</unit>
1294912979
</file>
1295012980
</xliff>

0 commit comments

Comments
 (0)