Skip to content

chore: scope auth to executor #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function logError(Log $log, Throwable $error, string $action, Logger $logger = n


Http::get('/v1/runtimes/:runtimeId/logs')
->groups(['api'])
->desc("Get live stream of logs of a runtime")
->param('runtimeId', '', new Text(64), 'Runtime unique ID.')
->param('timeout', '600', new Text(16), 'Maximum logs timeout.', true)
Expand All @@ -83,6 +84,7 @@ function logError(Log $log, Throwable $error, string $action, Logger $logger = n
});

Http::post('/v1/runtimes')
->groups(['api'])
->desc("Create a new runtime server")
->param('runtimeId', '', new Text(64), 'Unique runtime ID.')
->param('image', '', new Text(128), 'Base image name of the runtime.')
Expand Down Expand Up @@ -137,6 +139,7 @@ function logError(Log $log, Throwable $error, string $action, Logger $logger = n
});

Http::get('/v1/runtimes')
->groups(['api'])
->desc("List currently active runtimes")
->inject('runner')
->inject('response')
Expand All @@ -145,6 +148,7 @@ function logError(Log $log, Throwable $error, string $action, Logger $logger = n
});

Http::get('/v1/runtimes/:runtimeId')
->groups(['api'])
->desc("Get a runtime by its ID")
->param('runtimeId', '', new Text(64), 'Runtime unique ID.')
->inject('runner')
Expand All @@ -157,6 +161,7 @@ function logError(Log $log, Throwable $error, string $action, Logger $logger = n
});

Http::delete('/v1/runtimes/:runtimeId')
->groups(['api'])
->desc('Delete a runtime')
->param('runtimeId', '', new Text(64), 'Runtime unique ID.')
->inject('response')
Expand All @@ -168,6 +173,7 @@ function logError(Log $log, Throwable $error, string $action, Logger $logger = n
});

Http::post('/v1/runtimes/:runtimeId/executions')
->groups(['api'])
->alias('/v1/runtimes/:runtimeId/execution')
->desc('Create an execution')
// Execution-related
Expand Down Expand Up @@ -323,6 +329,7 @@ function (
);

Http::get('/v1/health')
->groups(['api'])
->desc("Get health status of host machine and runtimes.")
->inject('runner')
->inject('response')
Expand Down Expand Up @@ -397,6 +404,7 @@ function (
});

Http::init()
->groups(['api'])
->inject('request')
->action(function (Request $request) {
$secretKey = \explode(' ', $request->getHeader('authorization', ''))[1] ?? '';
Expand Down
94 changes: 45 additions & 49 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
{
"name": "open-runtimes/executor",
"description": "Serverless runtimes executor for container based environments ⚡️",
"type": "project",
"license": "MIT",
"autoload": {
"psr-4": {
"OpenRuntimes\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests"
}
},
"scripts": {
"lint": "./vendor/bin/pint --test --config pint.json",
"format": "./vendor/bin/pint --config pint.json",
"check": "./vendor/bin/phpstan analyse --level 8 -c phpstan.neon app src tests",
"test": [
"Composer\\Config::disableProcessTimeout",
"./vendor/bin/phpunit --configuration phpunit.xml --debug"
]
},
"require": {
"php": ">=8.3.0",
"ext-curl": "*",
"ext-json": "*",
"ext-swoole": "*",
"utopia-php/framework": "0.34.*",
"utopia-php/logger": "0.6.*",
"utopia-php/cli": "0.16.*",
"utopia-php/storage": "0.18.*",
"utopia-php/dsn": "0.1.*",
"utopia-php/registry": "0.5.*",
"utopia-php/preloader": "0.2.*",
"utopia-php/system": "0.9.*",
"utopia-php/orchestration": "0.14.*",
"appwrite/php-runtimes": "0.17.*"
},
"require-dev": {
"swoole/ide-helper": "4.8.5",
"phpunit/phpunit": "^9.3",
"laravel/pint": "1.2.*",
"phpstan/phpstan": "1.8.*"
},
"config": {
"platform": {
"php": "8.3"
}
"name": "open-runtimes/executor",
"description": "Serverless runtimes executor for container based environments ⚡️",
"type": "project",
"license": "MIT",
"autoload": {
"psr-4": {
"OpenRuntimes\\": "src/",
"Tests\\": "tests"
}
},
"scripts": {
"lint": "./vendor/bin/pint --test --config pint.json",
"format": "./vendor/bin/pint --config pint.json",
"check": "./vendor/bin/phpstan analyse --level 8 -c phpstan.neon app src tests",
"test": [
"Composer\\Config::disableProcessTimeout",
"./vendor/bin/phpunit --configuration phpunit.xml --debug"
]
},
"require": {
"php": ">=8.3.0",
"ext-curl": "*",
"ext-json": "*",
"ext-swoole": "*",
"utopia-php/framework": "0.34.*",
"utopia-php/logger": "0.6.*",
"utopia-php/cli": "0.16.*",
"utopia-php/storage": "0.18.*",
"utopia-php/dsn": "0.1.*",
"utopia-php/registry": "0.5.*",
"utopia-php/preloader": "0.2.*",
"utopia-php/system": "0.9.*",
"utopia-php/orchestration": "0.14.*",
"appwrite/php-runtimes": "0.17.*"
},
"require-dev": {
"swoole/ide-helper": "4.8.5",
"phpunit/phpunit": "^9.3",
"laravel/pint": "1.2.*",
"phpstan/phpstan": "1.8.*"
},
"config": {
"platform": {
"php": "8.3"
}
}
}
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions src/Executor/BodyMultipart.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BodyMultipart
private array $parts = [];
private string $boundary = "";

public function __construct(string $boundary = null)
public function __construct(?string $boundary = null)
{
if (is_null($boundary)) {
$this->boundary = self::generateBoundary();
Expand Down Expand Up @@ -130,13 +130,20 @@ public function exportBody(): string
foreach ($this->parts as $key => $value) {
$query .= $eol . 'Content-Disposition: form-data; name="' . $key . '"';

if (\is_array($value)) {
$query .= $eol . 'Content-Type: application/json';
$value = \json_encode($value);
if ($value instanceof \CURLFile) {
$filename = $value->getPostFilename() ?: \basename($value->getFilename());
$mime = $value->getMimeType() ?: 'application/octet-stream';

$query .= '; filename="' . $filename . '"' . $eol;
$query .= 'Content-Type: ' . $mime . $eol . $eol;
$query .= \file_get_contents($value->getFilename()) . $eol;
} elseif (\is_array($value)) {
$query .= $eol . 'Content-Type: application/json' . $eol . $eol;
$query .= \json_encode($value) . $eol;
} else {
$query .= $eol . $eol . $value . $eol;
}

$query .= $eol . $eol;
$query .= $value . $eol;
$query .= '--' . $this->boundary;
}

Expand Down