From e6fdeb3d9d0187287041d712a8867a5c8eb5aaa8 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 25 Jan 2022 02:59:02 +0400 Subject: [PATCH] feat: reneame update-function-tags endpoint --- app/config/scopes.php | 4 +-- app/controllers/api/functions.php | 34 +++++++++---------- .../functions/update-function-deployment.md | 1 + .../functions/update-function-tag.md | 1 - 4 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 docs/references/functions/update-function-deployment.md delete mode 100644 docs/references/functions/update-function-tag.md diff --git a/app/config/scopes.php b/app/config/scopes.php index cf40fb076..fb1f6b19f 100644 --- a/app/config/scopes.php +++ b/app/config/scopes.php @@ -44,10 +44,10 @@ return [ // List of publicly visible scopes 'description' => 'Access to create, update, and delete your project\'s storage files', ], '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' => [ - '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' => [ 'description' => 'Access to read your project\'s execution logs', diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 7152f0c90..8c7f14d8f 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -64,7 +64,7 @@ App::post('/v1/functions') 'status' => 'disabled', 'name' => $name, 'runtime' => $runtime, - 'tag' => '', + 'deployment' => '', 'vars' => $vars, 'events' => $events, 'schedule' => $schedule, @@ -314,8 +314,8 @@ App::put('/v1/functions/:functionId') } $original = $function->getAttribute('schedule', ''); - $cron = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? new CronExpression($schedule) : null; - $next = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0; + $cron = (!empty($function->getAttribute('deployment', null)) && !empty($schedule)) ? new CronExpression($schedule) : null; + $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(), [ 'execute' => $execute, @@ -343,38 +343,38 @@ App::put('/v1/functions/:functionId') $response->dynamic($function, Response::MODEL_FUNCTION); }); -App::patch('/v1/functions/:functionId/tag') +App::patch('/v1/functions/:functionId/deployment') ->groups(['api', 'functions']) - ->desc('Update Function Tag') + ->desc('Update Function Deployment') ->label('scope', 'functions.write') - ->label('event', 'functions.tags.update') + ->label('event', 'functions.deployments.update') ->label('sdk.auth', [APP_AUTH_TYPE_KEY]) ->label('sdk.namespace', 'functions') - ->label('sdk.method', 'updateTag') - ->label('sdk.description', '/docs/references/functions/update-function-tag.md') + ->label('sdk.method', 'updateDeployment') + ->label('sdk.description', '/docs/references/functions/update-function-deployment.md') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_FUNCTION) ->param('functionId', '', new UID(), 'Function ID.') - ->param('tag', '', new UID(), 'Tag ID.') + ->param('deployment', '', new UID(), 'Deployment ID.') ->inject('response') ->inject('dbForProject') ->inject('project') - ->action(function ($functionId, $tag, $response, $dbForProject, $project) { + ->action(function ($functionId, $deployment, $response, $dbForProject, $project) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Database\Document $project */ $function = $dbForProject->getDocument('functions', $functionId); - $tag = $dbForProject->getDocument('tags', $tag); - $build = $dbForProject->getDocument('builds', $tag->getAttribute('buildId')); + $deployment = $dbForProject->getDocument('deployments', $deployment); + $build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId')); if ($function->isEmpty()) { throw new Exception('Function not found', 404); } - if ($tag->isEmpty()) { - throw new Exception('Tag not found', 404); + if ($deployment->isEmpty()) { + throw new Exception('Deployment not found', 404); } if ($build->isEmpty()) { @@ -386,11 +386,11 @@ App::patch('/v1/functions/:functionId/tag') } $schedule = $function->getAttribute('schedule', ''); - $cron = (empty($function->getAttribute('tag')) && !empty($schedule)) ? new CronExpression($schedule) : null; - $next = (empty($function->getAttribute('tag')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0; + $cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null; + $next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0; $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ - 'tag' => $tag->getId(), + 'deployment' => $deployment->getId(), 'scheduleNext' => (int)$next, ]))); diff --git a/docs/references/functions/update-function-deployment.md b/docs/references/functions/update-function-deployment.md new file mode 100644 index 000000000..e91bebc20 --- /dev/null +++ b/docs/references/functions/update-function-deployment.md @@ -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. \ No newline at end of file diff --git a/docs/references/functions/update-function-tag.md b/docs/references/functions/update-function-tag.md deleted file mode 100644 index 5d3862868..000000000 --- a/docs/references/functions/update-function-tag.md +++ /dev/null @@ -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. \ No newline at end of file