mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
654d178cf2
This reverts commit 02e740f8b0.
82 lines
2.8 KiB
PHP
82 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Appwrite\Platform\Modules\Functions\Http\Deployments;
|
|
|
|
use Appwrite\Extend\Exception;
|
|
use Appwrite\SDK\AuthType;
|
|
use Appwrite\SDK\Method;
|
|
use Appwrite\SDK\Response as SDKResponse;
|
|
use Appwrite\Utopia\Response;
|
|
use Utopia\Database\Database;
|
|
use Utopia\Database\Validator\UID;
|
|
use Utopia\Platform\Action;
|
|
use Utopia\Platform\Scope\HTTP;
|
|
|
|
class Get extends Action
|
|
{
|
|
use HTTP;
|
|
|
|
public static function getName()
|
|
{
|
|
return 'getDeployment';
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
$this
|
|
->setHttpMethod(Action::HTTP_REQUEST_METHOD_GET)
|
|
->setHttpPath('/v1/functions/:functionId/deployments/:deploymentId')
|
|
->desc('Get deployment')
|
|
->groups(['api', 'functions'])
|
|
->label('scope', 'functions.read')
|
|
->label('resourceType', RESOURCE_TYPE_FUNCTIONS)
|
|
->label('sdk', new Method(
|
|
namespace: 'functions',
|
|
name: 'getDeployment',
|
|
description: <<<EOT
|
|
Get a function deployment by its unique ID.
|
|
EOT,
|
|
auth: [AuthType::KEY],
|
|
responses: [
|
|
new SDKResponse(
|
|
code: Response::STATUS_CODE_OK,
|
|
model: Response::MODEL_DEPLOYMENT,
|
|
)
|
|
]
|
|
))
|
|
->param('functionId', '', new UID(), 'Function ID.')
|
|
->param('deploymentId', '', new UID(), 'Deployment ID.')
|
|
->inject('response')
|
|
->inject('dbForProject')
|
|
->callback([$this, 'action']);
|
|
}
|
|
|
|
public function action(string $functionId, string $deploymentId, Response $response, Database $dbForProject)
|
|
{
|
|
$function = $dbForProject->getDocument('functions', $functionId);
|
|
|
|
if ($function->isEmpty()) {
|
|
throw new Exception(Exception::FUNCTION_NOT_FOUND);
|
|
}
|
|
|
|
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
|
|
|
|
if ($deployment->getAttribute('resourceId') !== $function->getId()) {
|
|
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
|
|
}
|
|
|
|
if ($deployment->isEmpty()) {
|
|
throw new Exception(Exception::DEPLOYMENT_NOT_FOUND);
|
|
}
|
|
|
|
$build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''));
|
|
$deployment->setAttribute('status', $build->getAttribute('status', 'waiting'));
|
|
$deployment->setAttribute('buildLogs', $build->getAttribute('logs', ''));
|
|
$deployment->setAttribute('buildTime', $build->getAttribute('duration', 0));
|
|
$deployment->setAttribute('buildSize', $build->getAttribute('size', 0));
|
|
$deployment->setAttribute('size', $deployment->getAttribute('size', 0));
|
|
|
|
$response->dynamic($deployment, Response::MODEL_DEPLOYMENT);
|
|
}
|
|
}
|