1
0
Fork 0
mirror of synced 2024-06-29 19:50:26 +12:00

Merge pull request #2793 from appwrite/feat-rename-deploymentid

Improved deployment and build path structure
This commit is contained in:
Christy Jacob 2022-02-16 13:22:38 +04:00 committed by GitHub
commit c90581e469
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 41 deletions

View file

@ -345,7 +345,7 @@ App::put('/v1/functions/:functionId')
$response->dynamic($function, Response::MODEL_FUNCTION); $response->dynamic($function, Response::MODEL_FUNCTION);
}); });
App::patch('/v1/functions/:functionId/deployment') App::patch('/v1/functions/:functionId/deployments/:deploymentId')
->groups(['api', 'functions']) ->groups(['api', 'functions'])
->desc('Update Function Deployment') ->desc('Update Function Deployment')
->label('scope', 'functions.write') ->label('scope', 'functions.write')
@ -358,17 +358,17 @@ App::patch('/v1/functions/:functionId/deployment')
->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_FUNCTION) ->label('sdk.response.model', Response::MODEL_FUNCTION)
->param('functionId', '', new UID(), 'Function ID.') ->param('functionId', '', new UID(), 'Function ID.')
->param('deployment', '', new UID(), 'Deployment ID.') ->param('deploymentId', '', new UID(), 'Deployment ID.')
->inject('response') ->inject('response')
->inject('dbForProject') ->inject('dbForProject')
->inject('project') ->inject('project')
->action(function ($functionId, $deployment, $response, $dbForProject, $project) { ->action(function ($functionId, $deploymentId, $response, $dbForProject, $project) {
/** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Database\Database $dbForProject */
/** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Document $project */
$function = $dbForProject->getDocument('functions', $functionId); $function = $dbForProject->getDocument('functions', $functionId);
$deployment = $dbForProject->getDocument('deployments', $deployment); $deployment = $dbForProject->getDocument('deployments', $deploymentId);
$build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', '')); $build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''));
if ($function->isEmpty()) { if ($function->isEmpty()) {
@ -992,7 +992,7 @@ App::get('/v1/functions/:functionId/executions/:executionId')
$response->dynamic($execution, Response::MODEL_EXECUTION); $response->dynamic($execution, Response::MODEL_EXECUTION);
}); });
App::post('/v1/builds/:buildId') App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId')
->groups(['api', 'functions']) ->groups(['api', 'functions'])
->desc('Retry Build') ->desc('Retry Build')
->label('scope', 'functions.write') ->label('scope', 'functions.write')
@ -1003,15 +1003,28 @@ App::post('/v1/builds/:buildId')
->label('sdk.description', '/docs/references/functions/retry-build.md') ->label('sdk.description', '/docs/references/functions/retry-build.md')
->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT) ->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT)
->label('sdk.response.model', Response::MODEL_NONE) ->label('sdk.response.model', Response::MODEL_NONE)
->param('functionId', '', new UID(), 'Function ID.')
->param('deploymentId', '', new UID(), 'Deployment ID.')
->param('buildId', '', new UID(), 'Build unique ID.') ->param('buildId', '', new UID(), 'Build unique ID.')
->inject('response') ->inject('response')
->inject('dbForProject') ->inject('dbForProject')
->inject('project') ->inject('project')
->action(function ($buildId, $response, $dbForProject, $project) { ->action(function ($functionId, $deploymentId, $buildId, $response, $dbForProject, $project) {
/** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Database\Database $dbForProject */
/** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Document $project */
$function = $dbForProject->getDocument('functions', $functionId);
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
if ($function->isEmpty()) {
throw new Exception('Function not found', 404);
}
if ($deployment->isEmpty()) {
throw new Exception('Deployment not found', 404);
}
$build = Authorization::skip(fn() => $dbForProject->getDocument('builds', $buildId)); $build = Authorization::skip(fn() => $dbForProject->getDocument('builds', $buildId));
if ($build->isEmpty()) { if ($build->isEmpty()) {

View file

@ -89,15 +89,11 @@ class FunctionsCustomClientTest extends Scope
// Wait for deployment to be built. // Wait for deployment to be built.
sleep(10); sleep(10);
$function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$function['body']['$id'].'/deployment', [ $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$function['body']['$id'].'/deployments/'.$deploymentId, [
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'], 'x-appwrite-key' => $this->getProject()['apiKey'],
], [ ], []);
'deployment' => $deploymentId,
]);
// var_dump($function);
$this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals(200, $function['headers']['status-code']);
@ -176,13 +172,11 @@ class FunctionsCustomClientTest extends Scope
$this->assertEquals(201, $deployment['headers']['status-code']); $this->assertEquals(201, $deployment['headers']['status-code']);
$function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', [ $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, [
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $projectId, 'x-appwrite-project' => $projectId,
'x-appwrite-key' => $apikey, 'x-appwrite-key' => $apikey,
], [ ], []);
'deployment' => $deploymentId,
]);
$this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals(200, $function['headers']['status-code']);
@ -360,13 +354,11 @@ class FunctionsCustomClientTest extends Scope
// Wait for deployment to be built. // Wait for deployment to be built.
sleep(10); sleep(10);
$function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', [ $function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, [
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $projectId, 'x-appwrite-project' => $projectId,
'x-appwrite-key' => $apikey, 'x-appwrite-key' => $apikey,
], [ ], []);
'deployment' => $deploymentId,
]);
$this->assertEquals(200, $function['headers']['status-code']); $this->assertEquals(200, $function['headers']['status-code']);

View file

@ -310,12 +310,10 @@ class FunctionsCustomServerTest extends Scope
/** /**
* Test for SUCCESS * Test for SUCCESS
*/ */
$response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/deployment', array_merge([ $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/deployments/'.$data['deploymentId'], array_merge([
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [ ], $this->getHeaders()), []);
'deployment' => $data['deploymentId'],
]);
$this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']); $this->assertNotEmpty($response['body']['$id']);
@ -687,13 +685,10 @@ class FunctionsCustomServerTest extends Scope
// Allow build step to run // Allow build step to run
sleep(10); sleep(10);
$deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', array_merge([ $deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, array_merge([
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [ ], $this->getHeaders()), []);
'functionId' => $functionId,
'deployment' => $deploymentId,
]);
$this->assertEquals(200, $deployment['headers']['status-code']); $this->assertEquals(200, $deployment['headers']['status-code']);
@ -779,12 +774,10 @@ class FunctionsCustomServerTest extends Scope
// Allow build step to run // Allow build step to run
sleep(10); sleep(10);
$deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', array_merge([ $deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, array_merge([
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [ ], $this->getHeaders()), []);
'deployment' => $deploymentId,
]);
$this->assertEquals(200, $deployment['headers']['status-code']); $this->assertEquals(200, $deployment['headers']['status-code']);

View file

@ -1002,13 +1002,11 @@ class RealtimeCustomClientTest extends Scope
// Wait for deployment to be built. // Wait for deployment to be built.
sleep(5); sleep(5);
$response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', array_merge([ $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployments/'.$deploymentId, array_merge([
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'] 'x-appwrite-key' => $this->getProject()['apiKey']
]), [ ]), []);
'deployment' => $deploymentId,
]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
$this->assertNotEmpty($response['body']['$id']); $this->assertNotEmpty($response['body']['$id']);

View file

@ -434,12 +434,10 @@ class WebhooksCustomServerTest extends Scope
/** /**
* Test for SUCCESS * Test for SUCCESS
*/ */
$response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/deployment', array_merge([ $response = $this->client->call(Client::METHOD_PATCH, '/functions/'.$data['functionId'].'/deployments/'.$data['deploymentId'], array_merge([
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [ ], $this->getHeaders()), []);
'deployment' => $data['deploymentId'],
]);
$this->assertEquals($response['headers']['status-code'], 200); $this->assertEquals($response['headers']['status-code'], 200);
$this->assertNotEmpty($response['body']['$id']); $this->assertNotEmpty($response['body']['$id']);