Move integration credentials into encrypted dashboard settings
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m42s
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 1m42s
This commit is contained in:
@@ -8,9 +8,16 @@ use Throwable;
|
||||
|
||||
class Bambuddy
|
||||
{
|
||||
public function __construct(private IntegrationSettings $settings) {}
|
||||
|
||||
public function url(): string
|
||||
{
|
||||
return (string) ($this->settings->for('bambuddy')['url'] ?? '');
|
||||
}
|
||||
|
||||
public function configured(): bool
|
||||
{
|
||||
return filled(config('services.bambuddy.url')) && filled(config('services.bambuddy.api_key'));
|
||||
return filled($this->url()) && filled($this->settings->for('bambuddy')['api_key'] ?? null);
|
||||
}
|
||||
|
||||
public function printers(): array
|
||||
@@ -19,17 +26,18 @@ class Bambuddy
|
||||
throw new RuntimeException('BamBuddy API key is not configured.');
|
||||
}
|
||||
|
||||
$url = rtrim(config('services.bambuddy.url'), '/').'/api/v1/printers';
|
||||
$url = rtrim($this->url(), '/').'/api/v1/printers';
|
||||
$apiKey = $this->settings->for('bambuddy')['api_key'];
|
||||
|
||||
$printers = Http::withHeaders(['X-API-Key' => config('services.bambuddy.api_key')])
|
||||
$printers = Http::withHeaders(['X-API-Key' => $apiKey])
|
||||
->acceptJson()->connectTimeout(3)->timeout(8)->get($url)->throw()->json() ?? [];
|
||||
|
||||
return collect($printers)->filter(fn ($printer) => is_array($printer) && isset($printer['id']))
|
||||
->take(20)->map(function (array $printer): array {
|
||||
->take(20)->map(function (array $printer) use ($apiKey): array {
|
||||
try {
|
||||
$status = Http::withHeaders(['X-API-Key' => config('services.bambuddy.api_key')])
|
||||
$status = Http::withHeaders(['X-API-Key' => $apiKey])
|
||||
->acceptJson()->connectTimeout(3)->timeout(5)
|
||||
->get(rtrim(config('services.bambuddy.url'), '/').'/api/v1/printers/'.(int) $printer['id'].'/status')
|
||||
->get(rtrim($this->url(), '/').'/api/v1/printers/'.(int) $printer['id'].'/status')
|
||||
->throw()->json() ?? [];
|
||||
|
||||
return $printer + ['live' => $status];
|
||||
|
||||
Reference in New Issue
Block a user