1
0
Fork 0
mirror of synced 2024-06-13 16:24:47 +12:00

* Move default host value from code to env variables

* Add validation for host value
This commit is contained in:
Andrey 2022-04-13 18:15:25 +02:00
parent ade4024593
commit e37d1be6a6
7 changed files with 11 additions and 15 deletions

2
.env
View file

@ -56,7 +56,7 @@ _APP_FUNCTIONS_MEMORY_SWAP=0
_APP_FUNCTIONS_INACTIVE_THRESHOLD=60
OPEN_RUNTIMES_NETWORK=appwrite_runtimes
_APP_EXECUTOR_SECRET=your-secret-key
_APP_EXECUTOR_HOST=
_APP_EXECUTOR_HOST=http://appwrite-executor/v1
_APP_MAINTENANCE_INTERVAL=86400
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600
_APP_MAINTENANCE_RETENTION_ABUSE=86400

View file

@ -185,7 +185,7 @@ ENV _APP_SERVER=swoole \
_APP_FUNCTIONS_MEMORY=128 \
_APP_FUNCTIONS_MEMORY_SWAP=128 \
_APP_EXECUTOR_SECRET=a-random-secret \
_APP_EXECUTOR_HOST= \
_APP_EXECUTOR_HOST=http://appwrite-executor/v1 \
_APP_EXECUTOR_RUNTIME_NETWORK=appwrite_runtimes \
_APP_SETUP=self-hosted \
_APP_VERSION=$VERSION \

View file

@ -938,7 +938,7 @@ App::post('/v1/functions/:functionId/executions')
]);
/** Execute function */
$executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1'));
$executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
$executionResponse = [];
try {
$executionResponse = $executor->createExecution(

View file

@ -33,7 +33,7 @@ class BuildsV1 extends Worker
}
public function init(): void {
$this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1'));
$this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
}
public function run(): void

View file

@ -368,7 +368,7 @@ class DeletesV1 extends Worker
* Request executor to delete all deployment containers
*/
Console::info("Requesting executor to delete all deployment containers for function " . $functionId);
$executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1'));
$executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
foreach ($deploymentIds as $deploymentId) {
try {
$executor->deleteRuntime($projectId, $deploymentId);
@ -420,7 +420,7 @@ class DeletesV1 extends Worker
*/
Console::info("Requesting executor to delete deployment container for deployment " . $deploymentId);
try {
$executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1'));
$executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
$executor->deleteRuntime($projectId, $deploymentId);
} catch (Throwable $th) {
Console::error($th->getMessage());

View file

@ -37,7 +37,7 @@ class FunctionsV1 extends Worker
public function init(): void
{
$this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST', 'http://appwrite-executor/v1'));
$this->executor = new Executor(App::getEnv('_APP_EXECUTOR_HOST'));
}
public function run(): void

View file

@ -18,8 +18,6 @@ class Executor
const METHOD_CONNECT = 'CONNECT';
const METHOD_TRACE = 'TRACE';
const DEFAULT_HOST = 'http://appwrite-executor/v1';
private $endpoint;
private $selfSigned = false;
@ -28,14 +26,12 @@ class Executor
'content-type' => '',
];
public function __construct(string $endpoint = self::DEFAULT_HOST)
public function __construct(string $endpoint)
{
if (empty($endpoint)) {
Console::warning('Undefined Executor host (fallback to ' . self::DEFAULT_HOST . ')');
$this->endpoint = self::DEFAULT_HOST;
} else {
$this->endpoint = $endpoint;
if (!filter_var($endpoint, FILTER_VALIDATE_URL)) {
throw new Exception('Unsupported endpoint');
}
$this->endpoint = $endpoint;
}
/**