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

feat: reneame update-function-tags endpoint

This commit is contained in:
Christy Jacob 2022-01-25 02:59:02 +04:00
parent 8307c8d432
commit e6fdeb3d9d
4 changed files with 20 additions and 20 deletions

View file

@ -44,10 +44,10 @@ return [ // List of publicly visible scopes
'description' => 'Access to create, update, and delete your project\'s storage files', 'description' => 'Access to create, update, and delete your project\'s storage files',
], ],
'functions.read' => [ 'functions.read' => [
'description' => 'Access to read your project\'s functions and code tags', 'description' => 'Access to read your project\'s functions and deployments',
], ],
'functions.write' => [ 'functions.write' => [
'description' => 'Access to create, update, and delete your project\'s functions and code tags', 'description' => 'Access to create, update, and delete your project\'s functions and deployments',
], ],
'execution.read' => [ 'execution.read' => [
'description' => 'Access to read your project\'s execution logs', 'description' => 'Access to read your project\'s execution logs',

View file

@ -64,7 +64,7 @@ App::post('/v1/functions')
'status' => 'disabled', 'status' => 'disabled',
'name' => $name, 'name' => $name,
'runtime' => $runtime, 'runtime' => $runtime,
'tag' => '', 'deployment' => '',
'vars' => $vars, 'vars' => $vars,
'events' => $events, 'events' => $events,
'schedule' => $schedule, 'schedule' => $schedule,
@ -314,8 +314,8 @@ App::put('/v1/functions/:functionId')
} }
$original = $function->getAttribute('schedule', ''); $original = $function->getAttribute('schedule', '');
$cron = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? new CronExpression($schedule) : null; $cron = (!empty($function->getAttribute('deployment', null)) && !empty($schedule)) ? new CronExpression($schedule) : null;
$next = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0; $next = (!empty($function->getAttribute('deployment', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
'execute' => $execute, 'execute' => $execute,
@ -343,38 +343,38 @@ App::put('/v1/functions/:functionId')
$response->dynamic($function, Response::MODEL_FUNCTION); $response->dynamic($function, Response::MODEL_FUNCTION);
}); });
App::patch('/v1/functions/:functionId/tag') App::patch('/v1/functions/:functionId/deployment')
->groups(['api', 'functions']) ->groups(['api', 'functions'])
->desc('Update Function Tag') ->desc('Update Function Deployment')
->label('scope', 'functions.write') ->label('scope', 'functions.write')
->label('event', 'functions.tags.update') ->label('event', 'functions.deployments.update')
->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.auth', [APP_AUTH_TYPE_KEY])
->label('sdk.namespace', 'functions') ->label('sdk.namespace', 'functions')
->label('sdk.method', 'updateTag') ->label('sdk.method', 'updateDeployment')
->label('sdk.description', '/docs/references/functions/update-function-tag.md') ->label('sdk.description', '/docs/references/functions/update-function-deployment.md')
->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.code', Response::STATUS_CODE_OK)
->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('tag', '', new UID(), 'Tag ID.') ->param('deployment', '', new UID(), 'Deployment ID.')
->inject('response') ->inject('response')
->inject('dbForProject') ->inject('dbForProject')
->inject('project') ->inject('project')
->action(function ($functionId, $tag, $response, $dbForProject, $project) { ->action(function ($functionId, $deployment, $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);
$tag = $dbForProject->getDocument('tags', $tag); $deployment = $dbForProject->getDocument('deployments', $deployment);
$build = $dbForProject->getDocument('builds', $tag->getAttribute('buildId')); $build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId'));
if ($function->isEmpty()) { if ($function->isEmpty()) {
throw new Exception('Function not found', 404); throw new Exception('Function not found', 404);
} }
if ($tag->isEmpty()) { if ($deployment->isEmpty()) {
throw new Exception('Tag not found', 404); throw new Exception('Deployment not found', 404);
} }
if ($build->isEmpty()) { if ($build->isEmpty()) {
@ -386,11 +386,11 @@ App::patch('/v1/functions/:functionId/tag')
} }
$schedule = $function->getAttribute('schedule', ''); $schedule = $function->getAttribute('schedule', '');
$cron = (empty($function->getAttribute('tag')) && !empty($schedule)) ? new CronExpression($schedule) : null; $cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
$next = (empty($function->getAttribute('tag')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0; $next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
'tag' => $tag->getId(), 'deployment' => $deployment->getId(),
'scheduleNext' => (int)$next, 'scheduleNext' => (int)$next,
]))); ])));

View file

@ -0,0 +1 @@
Update the function deployment ID using the unique function ID. Use this endpoint to switch the deployment that should be executed by the execution endpoint.

View file

@ -1 +0,0 @@
Update the function code tag ID using the unique function ID. Use this endpoint to switch the code tag that should be executed by the execution endpoint.