fix(templates): reconcile immutable upload results
Keep one PSR-7 owner for the PUT body so Guzzle cannot trigger a double-close TypeError. Reconcile ambiguous writes with an exact-key HEAD before publishing or fencing the template, and distinguish usable versions from failed catalog records in the admin UI.go
parent
9162aacd0e
commit
47fe5b74c2
@ -1,2 +1,2 @@
|
||||
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
|
||||
{assign var=venix_asset_version value='2026103013' scope='global'}
|
||||
{assign var=venix_asset_version value='2026103014' scope='global'}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use App\Services\Cloud\CloudObjectStorageS3Client;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Promise\Create;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$path = tempnam(sys_get_temp_dir(), 'virt-template-put-');
|
||||
if ($path === false) {
|
||||
throw new RuntimeException('Cannot create immutable PUT fixture.');
|
||||
}
|
||||
file_put_contents($path, str_repeat('immutable-put-fixture-', 128));
|
||||
$bytes = filesize($path);
|
||||
$sha256 = hash_file('sha256', $path);
|
||||
|
||||
// A real HTTP handler may release its request body before request() returns.
|
||||
// Closing the request body here deterministically reproduces that ownership
|
||||
// boundary without crossing the network.
|
||||
$handler = static function (RequestInterface $request, array $options) {
|
||||
$request->getBody()->close();
|
||||
return Create::promiseFor(new Response(200, [
|
||||
'ETag' => '"closed-body-etag"',
|
||||
'x-amz-version-id' => 'closed-body-version',
|
||||
]));
|
||||
};
|
||||
$client = new CloudObjectStorageS3Client(new Client([
|
||||
'handler' => HandlerStack::create($handler),
|
||||
]));
|
||||
|
||||
try {
|
||||
$identity = $client->putImmutableFile(
|
||||
[
|
||||
'endpoint' => 'https://objects.example.com',
|
||||
'region' => 'ewr',
|
||||
'bucket' => 'template-bucket',
|
||||
'prefix' => 'virt-cloud',
|
||||
'path_style' => true,
|
||||
],
|
||||
[
|
||||
'access_key_id' => 'TEMPLATEACCESSKEY',
|
||||
'secret_access_key' => 'template-secret',
|
||||
],
|
||||
'virt-cloud/cloud-templates/template/generation/system.qcow2',
|
||||
$path,
|
||||
$bytes,
|
||||
$sha256
|
||||
);
|
||||
} finally {
|
||||
@unlink($path);
|
||||
}
|
||||
|
||||
$assert($identity === [
|
||||
'size_bytes' => $bytes,
|
||||
'etag' => '"closed-body-etag"',
|
||||
'version_id' => 'closed-body-version',
|
||||
], 'Immutable PUT double-closed an HTTP-owned body stream.');
|
||||
|
||||
echo "Immutable object PUT stream ownership passed.\n";
|
||||
Loading…
Reference in New Issue