domovoy/app/Models/Credential.php

44 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Domovoy\Models;
class Credential
{
public ?int $id = null;
public int $deviceId;
public string $type = 'ssh';
public string $name = '';
public string $username = '';
public int $port = 22;
public string $authMethod = 'password';
public ?string $encryptedSecret = null;
public ?string $encryptedPrivateKey = null;
public ?string $publicKeyFingerprint = null;
public ?string $lastTestStatus = null;
public ?\DateTimeImmutable $lastTestAt = null;
public ?\DateTimeImmutable $createdAt = null;
public ?\DateTimeImmutable $updatedAt = null;
public static function fromArray(array $data): self
{
$obj = new self();
$obj->id = (int)$data['id'];
$obj->deviceId = (int)$data['device_id'];
$obj->type = $data['type'];
$obj->name = $data['name'];
$obj->username = $data['username'];
$obj->port = (int)$data['port'];
$obj->authMethod = $data['auth_method'];
$obj->encryptedSecret = $data['encrypted_secret'] ?? null;
$obj->encryptedPrivateKey = $data['encrypted_private_key'] ?? null;
$obj->publicKeyFingerprint = $data['public_key_fingerprint'] ?? null;
$obj->lastTestStatus = $data['last_test_status'] ?? null;
$obj->lastTestAt = $data['last_test_at'] !== null ? new \DateTimeImmutable($data['last_test_at']) : null;
$obj->createdAt = new \DateTimeImmutable($data['created_at']);
$obj->updatedAt = new \DateTimeImmutable($data['updated_at']);
return $obj;
}
}