Fix more tests
This commit is contained in:
parent
9b2226b243
commit
69cf0161ff
9 changed files with 137 additions and 709 deletions
|
@ -774,7 +774,7 @@ services:
|
||||||
hostname: executor
|
hostname: executor
|
||||||
<<: *x-logging
|
<<: *x-logging
|
||||||
stop_signal: SIGINT
|
stop_signal: SIGINT
|
||||||
image: openruntimes/executor:0.3.1
|
image: openruntimes/executor:0.3.2
|
||||||
networks:
|
networks:
|
||||||
- appwrite
|
- appwrite
|
||||||
- runtimes
|
- runtimes
|
||||||
|
|
|
@ -918,14 +918,32 @@ class FunctionsCustomServerTest extends Scope
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function provideCustomExecutions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[ 'folder' => 'php-fn', 'name' => 'php-8.0', 'entrypoint' => 'index.php', 'runtimeName' => 'PHP', 'runtimeVersion' => '8.0' ],
|
||||||
|
[ 'folder' => 'node', 'name' => 'node-18.0', 'entrypoint' => 'index.js', 'runtimeName' => 'Node.js', 'runtimeVersion' => '18.0' ],
|
||||||
|
[ 'folder' => 'python', 'name' => 'python-3.9', 'entrypoint' => 'main.py', 'runtimeName' => 'Python', 'runtimeVersion' => '3.9' ],
|
||||||
|
[ 'folder' => 'ruby', 'name' => 'ruby-3.1', 'entrypoint' => 'main.rb', 'runtimeName' => 'Ruby', 'runtimeVersion' => '3.1' ],
|
||||||
|
[ 'folder' => 'dart', 'name' => 'dart-2.15', 'entrypoint' => 'main.dart', 'runtimeName' => 'Dart', 'runtimeVersion' => '2.15' ],
|
||||||
|
[ 'folder' => 'swift', 'name' => 'swift-5.5', 'entrypoint' => 'index.swift', 'runtimeName' => 'Swift', 'runtimeVersion' => '5.5' ],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $folder
|
||||||
|
* @param string $name
|
||||||
|
* @param string $entrypoint
|
||||||
|
*
|
||||||
|
* @dataProvider provideCustomExecutions
|
||||||
* @depends testTimeout
|
* @depends testTimeout
|
||||||
*/
|
*/
|
||||||
public function testCreateCustomPHPExecution()
|
public function testCreateCustomExecution(string $folder, string $name, string $entrypoint, string $runtimeName, string $runtimeVersion)
|
||||||
{
|
{
|
||||||
$name = 'php-8.0';
|
|
||||||
$entrypoint = 'index.php';
|
|
||||||
$timeout = 2;
|
$timeout = 2;
|
||||||
$folder = 'php-fn';
|
|
||||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz";
|
$code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz";
|
||||||
$this->packageCode($folder);
|
$this->packageCode($folder);
|
||||||
|
|
||||||
|
@ -945,6 +963,16 @@ class FunctionsCustomServerTest extends Scope
|
||||||
|
|
||||||
$this->assertEquals(201, $function['headers']['status-code']);
|
$this->assertEquals(201, $function['headers']['status-code']);
|
||||||
|
|
||||||
|
$variable = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'key' => 'CUSTOM_VARIABLE',
|
||||||
|
'value' => 'variable',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(201, $variable['headers']['status-code']);
|
||||||
|
|
||||||
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
|
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
|
||||||
'content-type' => 'multipart/form-data',
|
'content-type' => 'multipart/form-data',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
@ -958,281 +986,47 @@ class FunctionsCustomServerTest extends Scope
|
||||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
$this->assertEquals(202, $deployment['headers']['status-code']);
|
||||||
|
|
||||||
// Allow build step to run
|
// Allow build step to run
|
||||||
sleep(20);
|
sleep(60);
|
||||||
|
|
||||||
$deployment = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId, 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()), []);
|
||||||
|
|
||||||
|
\var_dump($deployment);
|
||||||
|
|
||||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||||
|
|
||||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([
|
$execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', 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()), [
|
||||||
'data' => 'foobar',
|
'body' => 'foobar',
|
||||||
'async' => true
|
'async' => false
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
\var_dump($execution);
|
||||||
|
|
||||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
$executionId = $execution['body']['$id'] ?? '';
|
||||||
|
$output = json_decode($execution['body']['responseBody'], true);
|
||||||
|
|
||||||
sleep(20);
|
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||||
|
$this->assertEquals('completed', $execution['body']['status']);
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions/' . $executionId, array_merge([
|
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$output = json_decode($executions['body']['response'], true);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $executions['headers']['status-code']);
|
|
||||||
$this->assertEquals('completed', $executions['body']['status']);
|
|
||||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
||||||
$this->assertEquals('Test ' . $name, $output['APPWRITE_FUNCTION_NAME']);
|
$this->assertEquals('Test ' . $name, $output['APPWRITE_FUNCTION_NAME']);
|
||||||
$this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']);
|
$this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']);
|
||||||
$this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']);
|
$this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']);
|
||||||
$this->assertEquals('PHP', $output['APPWRITE_FUNCTION_RUNTIME_NAME']);
|
$this->assertEquals($runtimeName, $output['APPWRITE_FUNCTION_RUNTIME_NAME']);
|
||||||
$this->assertEquals('8.0', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']);
|
$this->assertEquals($runtimeVersion, $output['APPWRITE_FUNCTION_RUNTIME_VERSION']);
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']);
|
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']);
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT_DATA']);
|
|
||||||
$this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_USER_ID']);
|
|
||||||
$this->assertEmpty($output['APPWRITE_FUNCTION_JWT']);
|
|
||||||
$this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']);
|
|
||||||
$this->assertStringContainsString('Amazing Function Log', $executions['body']['logs']);
|
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$this->assertEquals($executions['headers']['status-code'], 200);
|
|
||||||
$this->assertEquals($executions['body']['total'], 1);
|
|
||||||
$this->assertIsArray($executions['body']['executions']);
|
|
||||||
$this->assertCount(1, $executions['body']['executions']);
|
|
||||||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
|
||||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
|
||||||
$this->assertStringContainsString('foobar', $executions['body']['executions'][0]['response']);
|
|
||||||
|
|
||||||
// Cleanup : Delete function
|
|
||||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
||||||
], []);
|
|
||||||
|
|
||||||
$this->assertEquals(204, $response['headers']['status-code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function testCreateCustomNodeExecution()
|
|
||||||
{
|
|
||||||
$name = 'node-18.0';
|
|
||||||
$folder = 'node';
|
|
||||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz";
|
|
||||||
$this->packageCode($folder);
|
|
||||||
|
|
||||||
$entrypoint = 'index.js';
|
|
||||||
$timeout = 2;
|
|
||||||
|
|
||||||
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'functionId' => ID::unique(),
|
|
||||||
'name' => 'Test ' . $name,
|
|
||||||
'runtime' => $name,
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'events' => [],
|
|
||||||
'timeout' => $timeout,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$functionId = $function['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
$this->assertEquals(201, $function['headers']['status-code']);
|
|
||||||
|
|
||||||
// Create variable
|
|
||||||
$variable = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'key' => 'CUSTOM_VARIABLE',
|
|
||||||
'value' => 'variable',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals(201, $variable['headers']['status-code']);
|
|
||||||
|
|
||||||
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
|
|
||||||
'content-type' => 'multipart/form-data',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'code' => new CURLFile($code, 'application/x-gzip', basename($code)),
|
|
||||||
'activate' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$deploymentId = $deployment['body']['$id'] ?? '';
|
|
||||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
|
||||||
|
|
||||||
// Allow build step to run
|
|
||||||
sleep(20);
|
|
||||||
|
|
||||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'data' => 'foobar',
|
|
||||||
'async' => true
|
|
||||||
]);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
sleep(20);
|
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions/' . $executionId, array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$output = json_decode($executions['body']['response'], true);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $executions['headers']['status-code']);
|
|
||||||
$this->assertEquals('completed', $executions['body']['status']);
|
|
||||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
|
||||||
$this->assertEquals('Test ' . $name, $output['APPWRITE_FUNCTION_NAME']);
|
|
||||||
$this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']);
|
|
||||||
$this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']);
|
|
||||||
$this->assertEquals('Node.js', $output['APPWRITE_FUNCTION_RUNTIME_NAME']);
|
|
||||||
$this->assertEquals('18.0', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT_DATA']);
|
|
||||||
$this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_USER_ID']);
|
|
||||||
$this->assertEmpty($output['APPWRITE_FUNCTION_JWT']);
|
|
||||||
$this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']);
|
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$this->assertEquals($executions['headers']['status-code'], 200);
|
|
||||||
$this->assertEquals($executions['body']['total'], 1);
|
|
||||||
$this->assertIsArray($executions['body']['executions']);
|
|
||||||
$this->assertCount(1, $executions['body']['executions']);
|
|
||||||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
|
||||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
|
||||||
$this->assertStringContainsString('foobar', $executions['body']['executions'][0]['response']);
|
|
||||||
|
|
||||||
// Cleanup : Delete function
|
|
||||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
||||||
], []);
|
|
||||||
|
|
||||||
$this->assertEquals(204, $response['headers']['status-code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCreateCustomPythonExecution()
|
|
||||||
{
|
|
||||||
$name = 'python-3.9';
|
|
||||||
$folder = 'python';
|
|
||||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz";
|
|
||||||
$this->packageCode($folder);
|
|
||||||
|
|
||||||
$entrypoint = 'main.py';
|
|
||||||
$timeout = 2;
|
|
||||||
|
|
||||||
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'functionId' => ID::unique(),
|
|
||||||
'name' => 'Test ' . $name,
|
|
||||||
'runtime' => $name,
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'events' => [],
|
|
||||||
'timeout' => $timeout,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$functionId = $function['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
$this->assertEquals(201, $function['headers']['status-code']);
|
|
||||||
|
|
||||||
/** Create Variables */
|
|
||||||
$variable = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'key' => 'CUSTOM_VARIABLE',
|
|
||||||
'value' => 'variable',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals(201, $variable['headers']['status-code']);
|
|
||||||
|
|
||||||
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
|
|
||||||
'content-type' => 'multipart/form-data',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'code' => new CURLFile($code, 'application/x-gzip', basename($code)),
|
|
||||||
'activate' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$deploymentId = $deployment['body']['$id'] ?? '';
|
|
||||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
|
||||||
|
|
||||||
// Allow build step to run
|
|
||||||
sleep(60);
|
|
||||||
|
|
||||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'data' => 'foobar',
|
|
||||||
'async' => true
|
|
||||||
]);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
sleep(60);
|
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions/' . $executionId, array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$output = json_decode($executions['body']['response'], true);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $executions['headers']['status-code']);
|
|
||||||
$this->assertEquals('completed', $executions['body']['status']);
|
|
||||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
|
||||||
$this->assertEquals('Test ' . $name, $output['APPWRITE_FUNCTION_NAME']);
|
|
||||||
$this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']);
|
|
||||||
$this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']);
|
|
||||||
$this->assertEquals('Python', $output['APPWRITE_FUNCTION_RUNTIME_NAME']);
|
|
||||||
$this->assertEquals('3.9', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT_DATA']);
|
|
||||||
$this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']);
|
$this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']);
|
||||||
$this->assertEquals('variable', $output['CUSTOM_VARIABLE']);
|
$this->assertEquals('variable', $output['CUSTOM_VARIABLE']);
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_USER_ID']);
|
$this->assertEmpty($output['APPWRITE_FUNCTION_USER_ID']);
|
||||||
$this->assertEmpty($output['APPWRITE_FUNCTION_JWT']);
|
$this->assertEmpty($output['APPWRITE_FUNCTION_JWT']);
|
||||||
$this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']);
|
$this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']);
|
||||||
|
$this->assertStringContainsString('Amazing Function Log', $execution['body']['logs']);
|
||||||
|
$this->assertEmpty($execution['body']['errors']);
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
|
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -1245,7 +1039,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
$this->assertCount(1, $executions['body']['executions']);
|
$this->assertCount(1, $executions['body']['executions']);
|
||||||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
||||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
||||||
$this->assertStringContainsString('foobar', $executions['body']['executions'][0]['response']);
|
$this->assertStringContainsString('Amazing Function Log', $executions['body']['executions'][0]['logs']);
|
||||||
|
|
||||||
// Cleanup : Delete function
|
// Cleanup : Delete function
|
||||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
||||||
|
@ -1257,338 +1051,6 @@ class FunctionsCustomServerTest extends Scope
|
||||||
$this->assertEquals(204, $response['headers']['status-code']);
|
$this->assertEquals(204, $response['headers']['status-code']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateCustomDartExecution()
|
|
||||||
{
|
|
||||||
$name = 'dart-2.15';
|
|
||||||
$folder = 'dart';
|
|
||||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz";
|
|
||||||
$this->packageCode($folder);
|
|
||||||
|
|
||||||
$entrypoint = 'main.dart';
|
|
||||||
$timeout = 2;
|
|
||||||
|
|
||||||
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'functionId' => ID::unique(),
|
|
||||||
'name' => 'Test ' . $name,
|
|
||||||
'runtime' => $name,
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'events' => [],
|
|
||||||
'timeout' => $timeout,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$functionId = $function['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
$this->assertEquals(201, $function['headers']['status-code']);
|
|
||||||
|
|
||||||
/** Create Variables */
|
|
||||||
$variable = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'key' => 'CUSTOM_VARIABLE',
|
|
||||||
'value' => 'variable',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals(201, $variable['headers']['status-code']);
|
|
||||||
|
|
||||||
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
|
|
||||||
'content-type' => 'multipart/form-data',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'code' => new CURLFile($code, 'application/x-gzip', basename($code)),
|
|
||||||
'activate' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$deploymentId = $deployment['body']['$id'] ?? '';
|
|
||||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
|
||||||
|
|
||||||
// Allow build step to run
|
|
||||||
sleep(80);
|
|
||||||
|
|
||||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'data' => 'foobar',
|
|
||||||
'async' => true
|
|
||||||
]);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
sleep(20);
|
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions/' . $executionId, array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$output = json_decode($executions['body']['response'], true);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $executions['headers']['status-code']);
|
|
||||||
$this->assertEquals('completed', $executions['body']['status']);
|
|
||||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
|
||||||
$this->assertEquals('Test ' . $name, $output['APPWRITE_FUNCTION_NAME']);
|
|
||||||
$this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']);
|
|
||||||
$this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']);
|
|
||||||
$this->assertEquals('Dart', $output['APPWRITE_FUNCTION_RUNTIME_NAME']);
|
|
||||||
$this->assertEquals('2.15', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT_DATA']);
|
|
||||||
$this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_USER_ID']);
|
|
||||||
$this->assertEmpty($output['APPWRITE_FUNCTION_JWT']);
|
|
||||||
$this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']);
|
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$this->assertEquals($executions['headers']['status-code'], 200);
|
|
||||||
$this->assertEquals($executions['body']['total'], 1);
|
|
||||||
$this->assertIsArray($executions['body']['executions']);
|
|
||||||
$this->assertCount(1, $executions['body']['executions']);
|
|
||||||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
|
||||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
|
||||||
$this->assertStringContainsString('foobar', $executions['body']['executions'][0]['response']);
|
|
||||||
|
|
||||||
// Cleanup : Delete function
|
|
||||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
||||||
], []);
|
|
||||||
|
|
||||||
$this->assertEquals(204, $response['headers']['status-code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Retry(count: 1)]
|
|
||||||
public function testCreateCustomRubyExecution()
|
|
||||||
{
|
|
||||||
$name = 'ruby-3.1';
|
|
||||||
$folder = 'ruby';
|
|
||||||
$code = realpath(__DIR__ . '/../../../resources/functions') . "/$folder/code.tar.gz";
|
|
||||||
$this->packageCode($folder);
|
|
||||||
|
|
||||||
$entrypoint = 'main.rb';
|
|
||||||
$timeout = 2;
|
|
||||||
|
|
||||||
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'functionId' => ID::unique(),
|
|
||||||
'name' => 'Test ' . $name,
|
|
||||||
'runtime' => $name,
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'events' => [],
|
|
||||||
'timeout' => $timeout,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$functionId = $function['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
$this->assertEquals(201, $function['headers']['status-code']);
|
|
||||||
|
|
||||||
/** Create Variables */
|
|
||||||
$variable = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'key' => 'CUSTOM_VARIABLE',
|
|
||||||
'value' => 'variable',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals(201, $variable['headers']['status-code']);
|
|
||||||
|
|
||||||
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
|
|
||||||
'content-type' => 'multipart/form-data',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'entrypoint' => $entrypoint,
|
|
||||||
'code' => new CURLFile($code, 'application/x-gzip', basename($code)),
|
|
||||||
'activate' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$deploymentId = $deployment['body']['$id'] ?? '';
|
|
||||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
|
||||||
|
|
||||||
// Allow build step to run
|
|
||||||
sleep(60);
|
|
||||||
|
|
||||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'data' => 'foobar',
|
|
||||||
'async' => true
|
|
||||||
]);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
|
||||||
|
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
sleep(20);
|
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions/' . $executionId, array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$output = json_decode($executions['body']['response'], true);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $executions['headers']['status-code']);
|
|
||||||
$this->assertEquals('completed', $executions['body']['status']);
|
|
||||||
$this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
|
||||||
$this->assertEquals('Test ' . $name, $output['APPWRITE_FUNCTION_NAME']);
|
|
||||||
$this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']);
|
|
||||||
$this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']);
|
|
||||||
$this->assertEquals('Ruby', $output['APPWRITE_FUNCTION_RUNTIME_NAME']);
|
|
||||||
$this->assertEquals('3.1', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT_DATA']);
|
|
||||||
$this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']);
|
|
||||||
$this->assertEquals('', $output['APPWRITE_FUNCTION_USER_ID']);
|
|
||||||
$this->assertEmpty($output['APPWRITE_FUNCTION_JWT']);
|
|
||||||
$this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']);
|
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
], $this->getHeaders()));
|
|
||||||
|
|
||||||
$this->assertEquals($executions['headers']['status-code'], 200);
|
|
||||||
$this->assertEquals($executions['body']['total'], 1);
|
|
||||||
$this->assertIsArray($executions['body']['executions']);
|
|
||||||
$this->assertCount(1, $executions['body']['executions']);
|
|
||||||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
|
||||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
|
||||||
$this->assertStringContainsString('foobar', $executions['body']['executions'][0]['response']);
|
|
||||||
|
|
||||||
// Cleanup : Delete function
|
|
||||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
||||||
], []);
|
|
||||||
|
|
||||||
$this->assertEquals(204, $response['headers']['status-code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// public function testCreateCustomSwiftExecution()
|
|
||||||
// {
|
|
||||||
// $name = 'swift-5.5';
|
|
||||||
// $folder = 'swift';
|
|
||||||
// $code = realpath(__DIR__ . '/../../../resources/functions'). "/$folder/code.tar.gz";
|
|
||||||
// $this->packageCode($folder);
|
|
||||||
|
|
||||||
// $entrypoint = 'index.swift';
|
|
||||||
// $timeout = 5;
|
|
||||||
|
|
||||||
// $function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
|
||||||
// 'content-type' => 'application/json',
|
|
||||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
// ], $this->getHeaders()), [
|
|
||||||
// 'functionId' => ID::unique(),
|
|
||||||
// 'name' => 'Test '.$name,
|
|
||||||
// 'runtime' => $name,
|
|
||||||
// 'vars' => [
|
|
||||||
// 'CUSTOM_VARIABLE' => 'variable',
|
|
||||||
// ],
|
|
||||||
// 'events' => [],
|
|
||||||
// 'schedule' => '',
|
|
||||||
// 'timeout' => $timeout,
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
// $functionId = $function['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
// $this->assertEquals(201, $function['headers']['status-code']);
|
|
||||||
|
|
||||||
// $deployment = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/deployments', array_merge([
|
|
||||||
// 'content-type' => 'multipart/form-data',
|
|
||||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
// ], $this->getHeaders()), [
|
|
||||||
// 'entrypoint' => $entrypoint,
|
|
||||||
// 'code' => new CURLFile($code, 'application/x-gzip', basename($code)),
|
|
||||||
// 'activate' => true,
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
// $deploymentId = $deployment['body']['$id'] ?? '';
|
|
||||||
// $this->assertEquals(202, $deployment['headers']['status-code']);
|
|
||||||
|
|
||||||
// // Allow (slow) build step to run
|
|
||||||
// sleep(300);
|
|
||||||
|
|
||||||
// $execution = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/executions', array_merge([
|
|
||||||
// 'content-type' => 'application/json',
|
|
||||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
// ], $this->getHeaders()), [
|
|
||||||
// 'data' => 'foobar',
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
// $executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
// $this->assertEquals(202, $execution['headers']['status-code']);
|
|
||||||
|
|
||||||
// $executionId = $execution['body']['$id'] ?? '';
|
|
||||||
|
|
||||||
// sleep(10);
|
|
||||||
|
|
||||||
// $executions = $this->client->call(Client::METHOD_GET, '/functions/'.$functionId.'/executions/'.$executionId, array_merge([
|
|
||||||
// 'content-type' => 'application/json',
|
|
||||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
// ], $this->getHeaders()));
|
|
||||||
|
|
||||||
// $output = json_decode($executions['body']['response'], true);
|
|
||||||
|
|
||||||
// $this->assertEquals(200, $executions['headers']['status-code']);
|
|
||||||
// $this->assertEquals('completed', $executions['body']['status']);
|
|
||||||
// $this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']);
|
|
||||||
// $this->assertEquals('Test '.$name, $output['APPWRITE_FUNCTION_NAME']);
|
|
||||||
// $this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']);
|
|
||||||
// $this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']);
|
|
||||||
// $this->assertEquals('Swift', $output['APPWRITE_FUNCTION_RUNTIME_NAME']);
|
|
||||||
// $this->assertEquals('5.5', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']);
|
|
||||||
// $this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']);
|
|
||||||
// $this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT_DATA']);
|
|
||||||
// $this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']);
|
|
||||||
// $this->assertEquals('variable', $output['CUSTOM_VARIABLE']);
|
|
||||||
// $this->assertEquals('', $output['APPWRITE_FUNCTION_USER_ID']);
|
|
||||||
// $this->assertEmpty($output['APPWRITE_FUNCTION_JWT']);
|
|
||||||
// $this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']);
|
|
||||||
|
|
||||||
// $executions = $this->client->call(Client::METHOD_GET, '/functions/'.$functionId.'/executions', array_merge([
|
|
||||||
// 'content-type' => 'application/json',
|
|
||||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
// ], $this->getHeaders()));
|
|
||||||
|
|
||||||
// $this->assertEquals($executions['headers']['status-code'], 200);
|
|
||||||
// $this->assertEquals($executions['body']['total'], 1);
|
|
||||||
// $this->assertIsArray($executions['body']['executions']);
|
|
||||||
// $this->assertCount(1, $executions['body']['executions']);
|
|
||||||
// $this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
|
||||||
// $this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
|
||||||
// $this->assertStringContainsString('foobar', $executions['body']['executions'][0]['response']);
|
|
||||||
|
|
||||||
// // Cleanup : Delete function
|
|
||||||
// $response = $this->client->call(Client::METHOD_DELETE, '/functions/'. $functionId, [
|
|
||||||
// 'content-type' => 'application/json',
|
|
||||||
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
||||||
// 'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
||||||
// ], []);
|
|
||||||
|
|
||||||
// $this->assertEquals(204, $response['headers']['status-code']);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public function testGetRuntimes()
|
public function testGetRuntimes()
|
||||||
{
|
{
|
||||||
$runtimes = $this->client->call(Client::METHOD_GET, '/functions/runtimes', array_merge([
|
$runtimes = $this->client->call(Client::METHOD_GET, '/functions/runtimes', array_merge([
|
||||||
|
|
|
@ -1,29 +1,21 @@
|
||||||
/*
|
import 'dart:io' show Platform;
|
||||||
'req' variable has:
|
|
||||||
'headers' - object with request headers
|
|
||||||
'payload' - object with request body data
|
|
||||||
'variables' - object with function variables
|
|
||||||
'res' variable has:
|
|
||||||
'send(text, status)' - function to return text response. Status code defaults to 200
|
|
||||||
'json(obj, status)' - function to return JSON response. Status code defaults to 200
|
|
||||||
|
|
||||||
If an error is thrown, a response with code 500 will be returned.
|
Future<dynamic> main(final context) async {
|
||||||
*/
|
context.log('Amazing Function Log');
|
||||||
|
|
||||||
Future<void> start(final request, final response) async {
|
|
||||||
response.json({
|
response.json({
|
||||||
'APPWRITE_FUNCTION_ID' : request.variables['APPWRITE_FUNCTION_ID'],
|
'APPWRITE_FUNCTION_ID' : Platform.environment['APPWRITE_FUNCTION_ID'] ?? ''
|
||||||
'APPWRITE_FUNCTION_NAME' : request.variables['APPWRITE_FUNCTION_NAME'],
|
'APPWRITE_FUNCTION_NAME' : Platform.environment['APPWRITE_FUNCTION_NAME'] ?? ''
|
||||||
'APPWRITE_FUNCTION_DEPLOYMENT' : request.variables['APPWRITE_FUNCTION_DEPLOYMENT'],
|
'APPWRITE_FUNCTION_DEPLOYMENT' : Platform.environment['APPWRITE_FUNCTION_DEPLOYMENT'] ?? ''
|
||||||
'APPWRITE_FUNCTION_TRIGGER' : request.variables['APPWRITE_FUNCTION_TRIGGER'],
|
'APPWRITE_FUNCTION_TRIGGER' : context.req.headers['x-appwrite-trigger'] ?? '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_NAME' : request.variables['APPWRITE_FUNCTION_RUNTIME_NAME'],
|
'APPWRITE_FUNCTION_RUNTIME_NAME' : Platform.environment['APPWRITE_FUNCTION_RUNTIME_NAME'] ?? ''
|
||||||
'APPWRITE_FUNCTION_RUNTIME_VERSION' : request.variables['APPWRITE_FUNCTION_RUNTIME_VERSION'],
|
'APPWRITE_FUNCTION_RUNTIME_VERSION' : Platform.environment['APPWRITE_FUNCTION_RUNTIME_VERSION'] ?? ''
|
||||||
'APPWRITE_FUNCTION_EVENT' : request.variables['APPWRITE_FUNCTION_EVENT'],
|
'APPWRITE_FUNCTION_EVENT' : context.req.headers['x-appwrite-event'] ?? '',
|
||||||
'APPWRITE_FUNCTION_EVENT_DATA' : request.variables['APPWRITE_FUNCTION_EVENT_DATA'],
|
'APPWRITE_FUNCTION_EVENT_DATA' : context.req.bodyRaw ?? '',
|
||||||
'APPWRITE_FUNCTION_DATA' : request.variables['APPWRITE_FUNCTION_DATA'],
|
'APPWRITE_FUNCTION_DATA' : context.req.bodyRaw ?? '',
|
||||||
'APPWRITE_FUNCTION_USER_ID' : request.variables['APPWRITE_FUNCTION_USER_ID'],
|
'APPWRITE_FUNCTION_USER_ID' : context.req.headers['x-appwrite-user-id'] ?? '',
|
||||||
'APPWRITE_FUNCTION_JWT' : request.variables['APPWRITE_FUNCTION_JWT'],
|
'APPWRITE_FUNCTION_JWT' : context.req.headers['x-appwrite-user-jwt'] ?? '',
|
||||||
'APPWRITE_FUNCTION_PROJECT_ID' : request.variables['APPWRITE_FUNCTION_PROJECT_ID'],
|
'APPWRITE_FUNCTION_PROJECT_ID' : Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'] ?? ''
|
||||||
'CUSTOM_VARIABLE' : request.variables['CUSTOM_VARIABLE']
|
'CUSTOM_VARIABLE' : request.variables['CUSTOM_VARIABLE']
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -1,29 +1,19 @@
|
||||||
/*
|
module.exports = async(context) => {
|
||||||
'req' variable has:
|
context.log('Amazing Function Log');
|
||||||
'headers' - object with request headers
|
|
||||||
'payload' - object with request body data
|
|
||||||
'variables' - object with function variables
|
|
||||||
'res' variable has:
|
|
||||||
'send(text, status)' - function to return text response. Status code defaults to 200
|
|
||||||
'json(obj, status)' - function to return JSON response. Status code defaults to 200
|
|
||||||
|
|
||||||
If an error is thrown, a response with code 500 will be returned.
|
return context.res.json({
|
||||||
*/
|
'APPWRITE_FUNCTION_ID' : process.env.APPWRITE_FUNCTION_ID ?? '',
|
||||||
|
'APPWRITE_FUNCTION_NAME' : process.env.APPWRITE_FUNCTION_NAME ?? '',
|
||||||
module.exports = async(req, res) => {
|
'APPWRITE_FUNCTION_DEPLOYMENT' : process.env.APPWRITE_FUNCTION_DEPLOYMENT ?? '',
|
||||||
res.json({
|
'APPWRITE_FUNCTION_TRIGGER' : context.req.headers['x-appwrite-trigger'] ?? '',
|
||||||
'APPWRITE_FUNCTION_ID' : req.variables.APPWRITE_FUNCTION_ID,
|
'APPWRITE_FUNCTION_RUNTIME_NAME' : process.env.APPWRITE_FUNCTION_RUNTIME_NAME,
|
||||||
'APPWRITE_FUNCTION_NAME' : req.variables.APPWRITE_FUNCTION_NAME,
|
'APPWRITE_FUNCTION_RUNTIME_VERSION' : process.env.APPWRITE_FUNCTION_RUNTIME_VERSION,
|
||||||
'APPWRITE_FUNCTION_DEPLOYMENT' : req.variables.APPWRITE_FUNCTION_DEPLOYMENT,
|
'APPWRITE_FUNCTION_EVENT' : context.req.headers['x-appwrite-event'] ?? '',
|
||||||
'APPWRITE_FUNCTION_TRIGGER' : req.variables.APPWRITE_FUNCTION_TRIGGER,
|
'APPWRITE_FUNCTION_EVENT_DATA' : context.req.bodyRaw ?? '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_NAME' : req.variables.APPWRITE_FUNCTION_RUNTIME_NAME,
|
'APPWRITE_FUNCTION_DATA' : context.req.bodyRaw ?? '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_VERSION' : req.variables.APPWRITE_FUNCTION_RUNTIME_VERSION,
|
'APPWRITE_FUNCTION_USER_ID' : context.req.headers['x-appwrite-user-id'] ?? '',
|
||||||
'APPWRITE_FUNCTION_EVENT' : req.variables.APPWRITE_FUNCTION_EVENT,
|
'APPWRITE_FUNCTION_JWT' : context.req.headers['x-appwrite-user-jwt'] ?? '',
|
||||||
'APPWRITE_FUNCTION_EVENT_DATA' : req.variables.APPWRITE_FUNCTION_EVENT_DATA,
|
'APPWRITE_FUNCTION_PROJECT_ID' : process.env.APPWRITE_FUNCTION_PROJECT_ID,
|
||||||
'APPWRITE_FUNCTION_DATA' : req.variables.APPWRITE_FUNCTION_DATA,
|
'CUSTOM_VARIABLE' : process.env.CUSTOM_VARIABLE
|
||||||
'APPWRITE_FUNCTION_USER_ID' : req.variables.APPWRITE_FUNCTION_USER_ID,
|
|
||||||
'APPWRITE_FUNCTION_JWT' : req.variables.APPWRITE_FUNCTION_JWT,
|
|
||||||
'APPWRITE_FUNCTION_PROJECT_ID' : req.variables.APPWRITE_FUNCTION_PROJECT_ID,
|
|
||||||
'CUSTOM_VARIABLE' : req.variables.CUSTOM_VARIABLE
|
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -4,17 +4,18 @@ return function ($context) {
|
||||||
$context->log('Amazing Function Log');
|
$context->log('Amazing Function Log');
|
||||||
|
|
||||||
return $context->res->json([
|
return $context->res->json([
|
||||||
'APPWRITE_FUNCTION_ID' => \getenv('APPWRITE_FUNCTION_ID'),
|
'APPWRITE_FUNCTION_ID' => \getenv('APPWRITE_FUNCTION_ID') ?: '',
|
||||||
'APPWRITE_FUNCTION_NAME' => \getenv('APPWRITE_FUNCTION_NAME'),
|
'APPWRITE_FUNCTION_NAME' => \getenv('APPWRITE_FUNCTION_NAME') ?: '',
|
||||||
'APPWRITE_FUNCTION_DEPLOYMENT' => \getenv('APPWRITE_FUNCTION_DEPLOYMENT'),
|
'APPWRITE_FUNCTION_DEPLOYMENT' => \getenv('APPWRITE_FUNCTION_DEPLOYMENT') ?: '',
|
||||||
'APPWRITE_FUNCTION_TRIGGER' => $context->req->headers['x-appwrite-trigger'],
|
'APPWRITE_FUNCTION_TRIGGER' => $context->req->headers['x-appwrite-trigger'] ?? '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_NAME' => \getenv('APPWRITE_FUNCTION_RUNTIME_NAME'),
|
'APPWRITE_FUNCTION_RUNTIME_NAME' => \getenv('APPWRITE_FUNCTION_RUNTIME_NAME') ?: '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_VERSION' => \getenv('APPWRITE_FUNCTION_RUNTIME_VERSION'),
|
'APPWRITE_FUNCTION_RUNTIME_VERSION' => \getenv('APPWRITE_FUNCTION_RUNTIME_VERSION') ?: '',
|
||||||
'APPWRITE_FUNCTION_EVENT' => $context->req->headers['x-appwrite-event'],
|
'APPWRITE_FUNCTION_EVENT' => $context->req->headers['x-appwrite-event'] ?? '',
|
||||||
'APPWRITE_FUNCTION_EVENT_DATA' => $context->req->bodyRaw,
|
'APPWRITE_FUNCTION_EVENT_DATA' => $context->req->bodyRaw ?? '',
|
||||||
'APPWRITE_FUNCTION_DATA' => $context->req->bodyRaw,
|
'APPWRITE_FUNCTION_DATA' => $context->req->bodyRaw ?? '',
|
||||||
'APPWRITE_FUNCTION_USER_ID' => $context->req->headers['x-appwrite-user-id'],
|
'APPWRITE_FUNCTION_USER_ID' => $context->req->headers['x-appwrite-user-id'] ?? '',
|
||||||
'APPWRITE_FUNCTION_JWT' => $context->req->headers['x-appwrite-user-jwt'],
|
'APPWRITE_FUNCTION_JWT' => $context->req->headers['x-appwrite-user-jwt'] ?? '',
|
||||||
'APPWRITE_FUNCTION_PROJECT_ID' => \getenv('APPWRITE_FUNCTION_PROJECT_ID'),
|
'APPWRITE_FUNCTION_PROJECT_ID' => \getenv('APPWRITE_FUNCTION_PROJECT_ID') ?: '',
|
||||||
|
'CUSTOM_VARIABLE' => \getenv('CUSTOM_VARIABLE') ?: '',
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
return function ($context) {
|
return function ($context) {
|
||||||
return $context->res->json([
|
return $context->res->json([
|
||||||
'APPWRITE_FUNCTION_ID' => \getenv('APPWRITE_FUNCTION_ID'),
|
'APPWRITE_FUNCTION_ID' => \getenv('APPWRITE_FUNCTION_ID') ?: '',
|
||||||
'APPWRITE_FUNCTION_NAME' => \getenv('APPWRITE_FUNCTION_NAME'),
|
'APPWRITE_FUNCTION_NAME' => \getenv('APPWRITE_FUNCTION_NAME') ?: '',
|
||||||
'APPWRITE_FUNCTION_DEPLOYMENT' => \getenv('APPWRITE_FUNCTION_DEPLOYMENT'),
|
'APPWRITE_FUNCTION_DEPLOYMENT' => \getenv('APPWRITE_FUNCTION_DEPLOYMENT') ?: '',
|
||||||
'APPWRITE_FUNCTION_TRIGGER' => $context->req->headers['x-appwrite-trigger'] ?? '',
|
'APPWRITE_FUNCTION_TRIGGER' => $context->req->headers['x-appwrite-trigger'] ?? '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_NAME' => \getenv('APPWRITE_FUNCTION_RUNTIME_NAME'),
|
'APPWRITE_FUNCTION_RUNTIME_NAME' => \getenv('APPWRITE_FUNCTION_RUNTIME_NAME') ?: '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_VERSION' => \getenv('APPWRITE_FUNCTION_RUNTIME_VERSION'),
|
'APPWRITE_FUNCTION_RUNTIME_VERSION' => \getenv('APPWRITE_FUNCTION_RUNTIME_VERSION') ?: '',
|
||||||
'UNICODE_TEST' => "êä"
|
'UNICODE_TEST' => "êä"
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
return function ($context) {
|
return function ($context) {
|
||||||
return $context->res->json([
|
return $context->res->json([
|
||||||
'APPWRITE_FUNCTION_ID' => \getenv('APPWRITE_FUNCTION_ID'),
|
'APPWRITE_FUNCTION_ID' => \getenv('APPWRITE_FUNCTION_ID') ?: '',
|
||||||
'APPWRITE_FUNCTION_NAME' => \getenv('APPWRITE_FUNCTION_NAME'),
|
'APPWRITE_FUNCTION_NAME' => \getenv('APPWRITE_FUNCTION_NAME') ?: '',
|
||||||
'APPWRITE_FUNCTION_DEPLOYMENT' => \getenv('APPWRITE_FUNCTION_DEPLOYMENT'),
|
'APPWRITE_FUNCTION_DEPLOYMENT' => \getenv('APPWRITE_FUNCTION_DEPLOYMENT') ?: '',
|
||||||
'APPWRITE_FUNCTION_TRIGGER' => $context->req->headers['x-appwrite-trigger'] ?? '',
|
'APPWRITE_FUNCTION_TRIGGER' => $context->req->headers['x-appwrite-trigger'] ?? '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_NAME' => \getenv('APPWRITE_FUNCTION_RUNTIME_NAME'),
|
'APPWRITE_FUNCTION_RUNTIME_NAME' => \getenv('APPWRITE_FUNCTION_RUNTIME_NAME') ?: '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_VERSION' => \getenv('APPWRITE_FUNCTION_RUNTIME_VERSION'),
|
'APPWRITE_FUNCTION_RUNTIME_VERSION' => \getenv('APPWRITE_FUNCTION_RUNTIME_VERSION') ?: '',
|
||||||
'UNICODE_TEST' => "êä"
|
'UNICODE_TEST' => "êä"
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,28 +1,21 @@
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
# 'req' variable has:
|
def main(context):
|
||||||
# 'headers' - object with request headers
|
context.log('Amazing Function Log')
|
||||||
# 'payload' - object with request body data
|
|
||||||
# 'variables' - object with function variables
|
|
||||||
# 'res' variable has:
|
|
||||||
# 'send(text, status)' - function to return text response. Status code defaults to 200
|
|
||||||
# 'json(obj, status)' - function to return JSON response. Status code defaults to 200
|
|
||||||
#
|
|
||||||
# If an error is thrown, a response with code 500 will be returned.
|
|
||||||
|
|
||||||
def main(request, response):
|
return context.res.json({
|
||||||
return response.json({
|
'APPWRITE_FUNCTION_ID' : os.environ.get('APPWRITE_FUNCTION_ID',''),
|
||||||
'APPWRITE_FUNCTION_ID' : request.variables['APPWRITE_FUNCTION_ID'],
|
'APPWRITE_FUNCTION_NAME' : os.environ.get('APPWRITE_FUNCTION_NAME',''),
|
||||||
'APPWRITE_FUNCTION_NAME' : request.variables['APPWRITE_FUNCTION_NAME'],
|
'APPWRITE_FUNCTION_DEPLOYMENT' : os.environ.get('APPWRITE_FUNCTION_DEPLOYMENT',''),
|
||||||
'APPWRITE_FUNCTION_DEPLOYMENT' : request.variables['APPWRITE_FUNCTION_DEPLOYMENT'],
|
'APPWRITE_FUNCTION_TRIGGER' : context.req.headers.get('x-appwrite-trigger', ''),
|
||||||
'APPWRITE_FUNCTION_TRIGGER' : request.variables['APPWRITE_FUNCTION_TRIGGER'],
|
'APPWRITE_FUNCTION_RUNTIME_NAME' : os.environ.get('APPWRITE_FUNCTION_RUNTIME_NAME',''),
|
||||||
'APPWRITE_FUNCTION_RUNTIME_NAME' : request.variables['APPWRITE_FUNCTION_RUNTIME_NAME'],
|
'APPWRITE_FUNCTION_RUNTIME_VERSION' : os.environ.get('APPWRITE_FUNCTION_RUNTIME_VERSION',''),
|
||||||
'APPWRITE_FUNCTION_RUNTIME_VERSION' : request.variables['APPWRITE_FUNCTION_RUNTIME_VERSION'],
|
'APPWRITE_FUNCTION_EVENT' : context.req.headers.get('x-appwrite-event', ''),
|
||||||
'APPWRITE_FUNCTION_EVENT' : request.variables['APPWRITE_FUNCTION_EVENT'],
|
'APPWRITE_FUNCTION_EVENT_DATA' : context.req.body_raw,
|
||||||
'APPWRITE_FUNCTION_EVENT_DATA' : request.variables['APPWRITE_FUNCTION_EVENT_DATA'],
|
'APPWRITE_FUNCTION_DATA' : context.req.body_raw,
|
||||||
'APPWRITE_FUNCTION_DATA' : request.variables['APPWRITE_FUNCTION_DATA'],
|
'APPWRITE_FUNCTION_USER_ID' : context.req.headers.get('x-appwrite-user-id', ''),
|
||||||
'APPWRITE_FUNCTION_USER_ID' : request.variables['APPWRITE_FUNCTION_USER_ID'],
|
'APPWRITE_FUNCTION_JWT' : context.req.headers.get('x-appwrite-user-jwt', ''),
|
||||||
'APPWRITE_FUNCTION_JWT' : request.variables['APPWRITE_FUNCTION_JWT'],
|
'APPWRITE_FUNCTION_PROJECT_ID' : os.environ.get('APPWRITE_FUNCTION_PROJECT_ID',''),
|
||||||
'APPWRITE_FUNCTION_PROJECT_ID' : request.variables['APPWRITE_FUNCTION_PROJECT_ID'],
|
'CUSTOM_VARIABLE' : os.environ.get('CUSTOM_VARIABLE',''),
|
||||||
'CUSTOM_VARIABLE' : request.variables['CUSTOM_VARIABLE'],
|
|
||||||
})
|
})
|
|
@ -1,29 +1,19 @@
|
||||||
=begin
|
def main(context)
|
||||||
'req' variable has:
|
context.log('Amazing Function Log')
|
||||||
'headers' - object with request headers
|
|
||||||
'payload' - object with request body data
|
|
||||||
'variables' - object with function variables
|
|
||||||
'res' variable has:
|
|
||||||
'send(text, status)' - function to return text response. Status code defaults to 200
|
|
||||||
'json(obj, status)' - function to return JSON response. Status code defaults to 200
|
|
||||||
|
|
||||||
If an error is thrown, a response with code 500 will be returned.
|
return context.res.json({
|
||||||
=end
|
'APPWRITE_FUNCTION_ID' => ENV['APPWRITE_FUNCTION_ID'] || '',
|
||||||
|
'APPWRITE_FUNCTION_NAME' => ENV['APPWRITE_FUNCTION_NAME'] || '',
|
||||||
def main(request, response)
|
'APPWRITE_FUNCTION_DEPLOYMENT' => ENV['APPWRITE_FUNCTION_DEPLOYMENT'] || '',
|
||||||
return response.json({
|
'APPWRITE_FUNCTION_TRIGGER' => context.req.headers['x-appwrite-trigger'] || '',
|
||||||
'APPWRITE_FUNCTION_ID' => request.variables['APPWRITE_FUNCTION_ID'],
|
'APPWRITE_FUNCTION_RUNTIME_NAME' => ENV['APPWRITE_FUNCTION_RUNTIME_NAME'] || '',
|
||||||
'APPWRITE_FUNCTION_NAME' => request.variables['APPWRITE_FUNCTION_NAME'],
|
'APPWRITE_FUNCTION_RUNTIME_VERSION' => ENV['APPWRITE_FUNCTION_RUNTIME_VERSION'] || '',
|
||||||
'APPWRITE_FUNCTION_DEPLOYMENT' => request.variables['APPWRITE_FUNCTION_DEPLOYMENT'],
|
'APPWRITE_FUNCTION_EVENT' => context.req.headers['x-appwrite-event'] || '',
|
||||||
'APPWRITE_FUNCTION_TRIGGER' => request.variables['APPWRITE_FUNCTION_TRIGGER'],
|
'APPWRITE_FUNCTION_EVENT_DATA' => context.req.bodyRaw || '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_NAME' => request.variables['APPWRITE_FUNCTION_RUNTIME_NAME'],
|
'APPWRITE_FUNCTION_DATA' => context.req.bodyRaw || '',
|
||||||
'APPWRITE_FUNCTION_RUNTIME_VERSION' => request.variables['APPWRITE_FUNCTION_RUNTIME_VERSION'],
|
'APPWRITE_FUNCTION_USER_ID' => context.req.headers['x-appwrite-user-id'] || '',
|
||||||
'APPWRITE_FUNCTION_EVENT' => request.variables['APPWRITE_FUNCTION_EVENT'],
|
'APPWRITE_FUNCTION_JWT' => context.req.headers['x-appwrite-user-jwt'] || ''
|
||||||
'APPWRITE_FUNCTION_EVENT_DATA' => request.variables['APPWRITE_FUNCTION_EVENT_DATA'],
|
'APPWRITE_FUNCTION_PROJECT_ID' => ENV['APPWRITE_FUNCTION_PROJECT_ID'] || '',
|
||||||
'APPWRITE_FUNCTION_DATA' => request.variables['APPWRITE_FUNCTION_DATA'],
|
'CUSTOM_VARIABLE' => ENV['CUSTOM_VARIABLE'] || ''
|
||||||
'APPWRITE_FUNCTION_USER_ID' => request.variables['APPWRITE_FUNCTION_USER_ID'],
|
|
||||||
'APPWRITE_FUNCTION_JWT' => request.variables['APPWRITE_FUNCTION_JWT'],
|
|
||||||
'APPWRITE_FUNCTION_PROJECT_ID' => request.variables['APPWRITE_FUNCTION_PROJECT_ID'],
|
|
||||||
'CUSTOM_VARIABLE' => request.variables['CUSTOM_VARIABLE']
|
|
||||||
})
|
})
|
||||||
end
|
end
|
Loading…
Reference in a new issue