mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 03:14:32 +02:00
Moved digikey IPS configuration to new settings system
This commit is contained in:
parent
6e28f2a74e
commit
1dbcff66d1
7 changed files with 96 additions and 28 deletions
11
.env
11
.env
|
@ -71,17 +71,6 @@ ERROR_PAGE_SHOW_HELP=1
|
||||||
# Info provider settings
|
# Info provider settings
|
||||||
##################################################################################
|
##################################################################################
|
||||||
|
|
||||||
# Digikey Provider:
|
|
||||||
# You can get your client id and secret from https://developer.digikey.com/
|
|
||||||
PROVIDER_DIGIKEY_CLIENT_ID=
|
|
||||||
PROVIDER_DIGIKEY_SECRET=
|
|
||||||
# The currency to get prices in
|
|
||||||
PROVIDER_DIGIKEY_CURRENCY=EUR
|
|
||||||
# The language to get results in (en, de, fr, it, es, zh, ja, ko)
|
|
||||||
PROVIDER_DIGIKEY_LANGUAGE=en
|
|
||||||
# The country to get results for
|
|
||||||
PROVIDER_DIGIKEY_COUNTRY=DE
|
|
||||||
|
|
||||||
# Octopart / Nexar Provider:
|
# Octopart / Nexar Provider:
|
||||||
# You can get your API key from https://nexar.com/api
|
# You can get your API key from https://nexar.com/api
|
||||||
PROVIDER_OCTOPART_CLIENT_ID=
|
PROVIDER_OCTOPART_CLIENT_ID=
|
||||||
|
|
|
@ -6,8 +6,8 @@ knpu_oauth2_client:
|
||||||
type: generic
|
type: generic
|
||||||
provider_class: '\League\OAuth2\Client\Provider\GenericProvider'
|
provider_class: '\League\OAuth2\Client\Provider\GenericProvider'
|
||||||
|
|
||||||
client_id: '%env(PROVIDER_DIGIKEY_CLIENT_ID)%'
|
client_id: '%env(settings:digikey:clientId)%'
|
||||||
client_secret: '%env(PROVIDER_DIGIKEY_SECRET)%'
|
client_secret: '%env(settings:digikey:secret)%'
|
||||||
|
|
||||||
redirect_route: 'oauth_client_check'
|
redirect_route: 'oauth_client_check'
|
||||||
redirect_params: {name: 'ip_digikey_oauth'}
|
redirect_params: {name: 'ip_digikey_oauth'}
|
||||||
|
|
|
@ -199,13 +199,6 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
$providers: !tagged_iterator 'app.info_provider'
|
$providers: !tagged_iterator 'app.info_provider'
|
||||||
|
|
||||||
App\Services\InfoProviderSystem\Providers\DigikeyProvider:
|
|
||||||
arguments:
|
|
||||||
$clientId: '%env(string:PROVIDER_DIGIKEY_CLIENT_ID)%'
|
|
||||||
$currency: '%env(string:PROVIDER_DIGIKEY_CURRENCY)%'
|
|
||||||
$language: '%env(string:PROVIDER_DIGIKEY_LANGUAGE)%'
|
|
||||||
$country: '%env(string:PROVIDER_DIGIKEY_COUNTRY)%'
|
|
||||||
|
|
||||||
App\Services\InfoProviderSystem\Providers\OctopartProvider:
|
App\Services\InfoProviderSystem\Providers\OctopartProvider:
|
||||||
arguments:
|
arguments:
|
||||||
$clientId: '&env(string:PROVIDER_OCTOPART_CLIENT_ID)%'
|
$clientId: '&env(string:PROVIDER_OCTOPART_CLIENT_ID)%'
|
||||||
|
|
|
@ -31,6 +31,7 @@ use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
||||||
use App\Services\OAuth\OAuthTokenManager;
|
use App\Services\OAuth\OAuthTokenManager;
|
||||||
|
use App\Settings\InfoProviderSystem\DigikeySettings;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
class DigikeyProvider implements InfoProviderInterface
|
class DigikeyProvider implements InfoProviderInterface
|
||||||
|
@ -55,17 +56,16 @@ class DigikeyProvider implements InfoProviderInterface
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(HttpClientInterface $httpClient, private readonly OAuthTokenManager $authTokenManager,
|
public function __construct(HttpClientInterface $httpClient, private readonly OAuthTokenManager $authTokenManager,
|
||||||
private readonly string $currency, private readonly string $clientId,
|
private readonly DigikeySettings $settings,)
|
||||||
private readonly string $language, private readonly string $country)
|
|
||||||
{
|
{
|
||||||
//Create the HTTP client with some default options
|
//Create the HTTP client with some default options
|
||||||
$this->digikeyClient = $httpClient->withOptions([
|
$this->digikeyClient = $httpClient->withOptions([
|
||||||
"base_uri" => self::BASE_URI,
|
"base_uri" => self::BASE_URI,
|
||||||
"headers" => [
|
"headers" => [
|
||||||
"X-DIGIKEY-Client-Id" => $clientId,
|
"X-DIGIKEY-Client-Id" => $this->settings->clientId,
|
||||||
"X-DIGIKEY-Locale-Site" => $this->country,
|
"X-DIGIKEY-Locale-Site" => $this->settings->country,
|
||||||
"X-DIGIKEY-Locale-Language" => $this->language,
|
"X-DIGIKEY-Locale-Language" => $this->settings->language,
|
||||||
"X-DIGIKEY-Locale-Currency" => $this->currency,
|
"X-DIGIKEY-Locale-Currency" => $this->settings->currency,
|
||||||
"X-DIGIKEY-Customer-Id" => 0,
|
"X-DIGIKEY-Customer-Id" => 0,
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
@ -101,7 +101,7 @@ class DigikeyProvider implements InfoProviderInterface
|
||||||
public function isActive(): bool
|
public function isActive(): bool
|
||||||
{
|
{
|
||||||
//The client ID has to be set and a token has to be available (user clicked connect)
|
//The client ID has to be set and a token has to be available (user clicked connect)
|
||||||
return $this->clientId !== '' && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
return $this->settings->clientId !== '' && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchByKeyword(string $keyword): array
|
public function searchByKeyword(string $keyword): array
|
||||||
|
@ -268,7 +268,7 @@ class DigikeyProvider implements InfoProviderInterface
|
||||||
$prices = [];
|
$prices = [];
|
||||||
|
|
||||||
foreach ($price_breaks as $price_break) {
|
foreach ($price_breaks as $price_break) {
|
||||||
$prices[] = new PriceDTO(minimum_discount_amount: $price_break['BreakQuantity'], price: (string) $price_break['UnitPrice'], currency_iso_code: $this->currency);
|
$prices[] = new PriceDTO(minimum_discount_amount: $price_break['BreakQuantity'], price: (string) $price_break['UnitPrice'], currency_iso_code: $this->settings->currency);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
65
src/Settings/InfoProviderSystem/DigikeySettings.php
Normal file
65
src/Settings/InfoProviderSystem/DigikeySettings.php
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Settings\InfoProviderSystem;
|
||||||
|
|
||||||
|
use App\Settings\SettingsIcon;
|
||||||
|
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||||
|
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CountryType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
|
||||||
|
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||||
|
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
#[Settings(label: new TM("settings.ips.digikey"))]
|
||||||
|
#[SettingsIcon("fa-plug")]
|
||||||
|
class DigikeySettings
|
||||||
|
{
|
||||||
|
use SettingsTrait;
|
||||||
|
|
||||||
|
#[SettingsParameter(
|
||||||
|
label: new TM("settings.ips.digikey.client_id"),
|
||||||
|
envVar: "PROVIDER_DIGIKEY_CLIENT_ID"
|
||||||
|
)]
|
||||||
|
public ?string $clientId = null;
|
||||||
|
|
||||||
|
#[SettingsParameter(
|
||||||
|
label: new TM("settings.ips.digikey.secret"),
|
||||||
|
envVar: "PROVIDER_DIGIKEY_SECRET"
|
||||||
|
)]
|
||||||
|
public ?string $secret = null;
|
||||||
|
|
||||||
|
#[SettingsParameter(label: new TM("settings.ips.tme.currency"), formType: CurrencyType::class, formOptions: ["preferred_choices" => ["EUR", "USD", "CHF", "GBP"]], envVar: "PROVIDER_DIGIKEY_CURRENCY")]
|
||||||
|
#[Assert\Currency()]
|
||||||
|
public string $currency = "EUR";
|
||||||
|
|
||||||
|
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: CountryType::class, envVar: "PROVIDER_DIGIKEY_COUNTRY")]
|
||||||
|
#[Assert\Country]
|
||||||
|
public string $country = "DE";
|
||||||
|
|
||||||
|
#[SettingsParameter(label: new TM("settings.ips.tme.language"), formType: LanguageType::class, envVar: "PROVIDER_DIGIKEY_LANGUAGE")]
|
||||||
|
#[Assert\Language]
|
||||||
|
public string $language = "en";
|
||||||
|
}
|
|
@ -32,6 +32,9 @@ class InfoProviderSettings
|
||||||
{
|
{
|
||||||
use SettingsTrait;
|
use SettingsTrait;
|
||||||
|
|
||||||
|
#[EmbeddedSettings]
|
||||||
|
public ?DigikeySettings $digikey = null;
|
||||||
|
|
||||||
#[EmbeddedSettings]
|
#[EmbeddedSettings]
|
||||||
public ?MouserSettings $mouser = null;
|
public ?MouserSettings $mouser = null;
|
||||||
|
|
||||||
|
|
|
@ -12928,5 +12928,23 @@ Please note, that you can not impersonate a disabled user. If you try you will g
|
||||||
<target>Root nodes redirect to new entity pages</target>
|
<target>Root nodes redirect to new entity pages</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="j7HiQ80" name="settings.ips.digikey">
|
||||||
|
<segment>
|
||||||
|
<source>settings.ips.digikey</source>
|
||||||
|
<target>Digikey</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="_ViyVdh" name="settings.ips.digikey.client_id">
|
||||||
|
<segment>
|
||||||
|
<source>settings.ips.digikey.client_id</source>
|
||||||
|
<target>Client ID</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="eB9dDyp" name="settings.ips.digikey.secret">
|
||||||
|
<segment>
|
||||||
|
<source>settings.ips.digikey.secret</source>
|
||||||
|
<target>Secret</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue