Initial commit
This commit is contained in:
50
src/Registry/RegistryV2Client.php
Normal file
50
src/Registry/RegistryV2Client.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\FreshDocker\Registry;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class RegistryV2Client
|
||||
{
|
||||
private Client $client;
|
||||
|
||||
public function __construct(string $registry, ?array $auth)
|
||||
{
|
||||
$this->createClient($registry, $auth);
|
||||
}
|
||||
|
||||
private function createClient(string $registry, ?array $auth)
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => 'https://' . $registry . '/v2/',
|
||||
'auth' => $auth,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getManifest(string $image, string $tag)
|
||||
{
|
||||
$response = $this->client->get("{$image}/manifests/{$tag}");
|
||||
$body = $response->getBody();
|
||||
return json_decode($body);
|
||||
}
|
||||
|
||||
public function getImageStatus(string $image, string $tag)
|
||||
{
|
||||
$manifest = $this->getManifest($image, $tag);
|
||||
|
||||
$fslayers = (array)$manifest->fsLayers;
|
||||
$fshashes = array_map(fn($layer) => $layer->blobSum, $fslayers);
|
||||
$metahash = hash("sha256", join("|", $fshashes));
|
||||
|
||||
$history = $manifest->history[0];
|
||||
$info = json_decode($history->v1Compatibility);
|
||||
|
||||
return [
|
||||
'image' => $image,
|
||||
'tag' => $tag,
|
||||
'hash' => $metahash,
|
||||
'created' => $info->created??null,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user