Merge branch 'feat-git-integration' into feat-usage-rollback

This commit is contained in:
Eldad A. Fux
2023-08-21 22:46:09 +03:00
committed by GitHub
9 changed files with 60 additions and 50 deletions
+24 -20
View File
@@ -200,6 +200,7 @@ App::post('/v1/functions')
'events' => $events,
'schedule' => $schedule,
'scheduleInternalId' => '',
'scheduleId' => '',
'timeout' => $timeout,
'entrypoint' => $entrypoint,
'commands' => $commands,
@@ -215,6 +216,22 @@ App::post('/v1/functions')
'providerSilentMode' => $providerSilentMode,
]));
$schedule = Authorization::skip(
fn () => $dbForConsole->createDocument('schedules', new Document([
'region' => App::getEnv('_APP_REGION', 'default'), // Todo replace with projects region
'resourceType' => 'function',
'resourceId' => $function->getId(),
'resourceInternalId' => $function->getInternalId(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
'schedule' => $function->getAttribute('schedule'),
'active' => false,
]))
);
$function->setAttribute('scheduleId', $schedule->getId());
$function->setAttribute('scheduleInternalId', $schedule->getInternalId());
// Git connect logic
if (!empty($providerRepositoryId)) {
$repository = $dbForConsole->createDocument('repositories', new Document([
@@ -235,23 +252,11 @@ App::post('/v1/functions')
'providerPullRequestIds' => []
]));
$function = $dbForProject->updateDocument('functions', $function->getId(), $function
->setAttribute('repositoryId', $repository->getId())
->setAttribute('repositoryInternalId', $repository->getInternalId()));
$function->setAttribute('repositoryId', $repository->getId());
$function->setAttribute('repositoryInternalId', $repository->getInternalId());
}
$schedule = Authorization::skip(
fn () => $dbForConsole->createDocument('schedules', new Document([
'region' => App::getEnv('_APP_REGION', 'default'), // Todo replace with projects region
'resourceType' => 'function',
'resourceId' => $function->getId(),
'resourceInternalId' => $function->getInternalId(),
'resourceUpdatedAt' => DateTime::now(),
'projectId' => $project->getId(),
'schedule' => $function->getAttribute('schedule'),
'active' => false,
]))
);
$function = $dbForProject->updateDocument('functions', $function->getId(), $function);
// Redeploy vcs logic
if (!empty($providerRepositoryId)) {
@@ -320,10 +325,6 @@ App::post('/v1/functions')
);
}
$function->setAttribute('scheduleId', $schedule->getId());
$function->setAttribute('scheduleInternalId', $schedule->getInternalId());
$dbForProject->updateDocument('functions', $function->getId(), $function);
$eventsInstance->setParam('functionId', $function->getId());
$response
@@ -1438,12 +1439,15 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId')
throw new Exception(Exception::BUILD_NOT_FOUND);
}
$deploymentId = ID::unique();
$deployment = $dbForProject->createDocument('deployments', $deployment->setAttributes([
'$id' => ID::unique(),
'$id' => $deploymentId,
'buildId' => '',
'buildInternalId' => '',
'entrypoint' => $function->getAttribute('entrypoint'),
'commands' => $function->getAttribute('commands', ''),
'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]),
]));
$buildEvent = new Build();
+1 -1
View File
@@ -889,7 +889,7 @@ App::get('/v1/migrations/nhost/report')
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_MIGRATION_REPORT)
->param('resources', [], new ArrayList(new WhiteList(NHost::getSupportedResources())), 'List of resources to migrate')
->param('subdomain', '', new URL(), 'Source\'s Subdomain')
->param('subdomain', '', new Text(512), 'Source\'s Subdomain')
->param('region', '', new Text(512), 'Source\'s Region')
->param('adminSecret', '', new Text(512), 'Source\'s Admin Secret')
->param('database', '', new Text(512), 'Source\'s Database Name')
+5
View File
@@ -41,6 +41,11 @@ App::post('/v1/proxy/rules')
->inject('dbForConsole')
->inject('dbForProject')
->action(function (string $domain, string $resourceType, string $resourceId, Response $response, Document $project, Event $events, Database $dbForConsole, Database $dbForProject) {
$mainDomain = App::getEnv('_APP_DOMAIN', '');
if ($domain === $mainDomain || $domain === 'localhost' || $domain === APP_HOSTNAME_INTERNAL) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed for security reasons.');
}
$document = $dbForConsole->findOne('rules', [
Query::equal('domain', [$domain]),
]);
+6 -15
View File
@@ -277,6 +277,11 @@ App::get('/v1/vcs/github/callback')
->inject('response')
->inject('dbForConsole')
->action(function (string $providerInstallationId, string $setupAction, string $state, string $code, GitHub $github, Document $user, Document $project, Request $request, Response $response, Database $dbForConsole) {
if (empty($state)) {
$error = 'Installation requests from organisation members for the Appwrite GitHub App are currently unsupported. To proceed with the installation, login to the Appwrite Console and install the GitHub App.';
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $error);
}
$state = \json_decode($state, true);
$projectId = $state['projectId'] ?? '';
@@ -285,25 +290,11 @@ App::get('/v1/vcs/github/callback')
'failure' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/settings/git-installations",
];
$state = \array_merge($defaultState, $state);
$state = \array_merge($defaultState, $state ?? []);
$redirectSuccess = $state['success'] ?? '';
$redirectFailure = $state['failure'] ?? '';
if (empty($state)) {
$error = 'Installation requests from organisation members for the Appwrite GitHub App are currently unsupported. To proceed with the installation, login to the Appwrite Console and install the GitHub App.';
if (!empty($redirectFailure)) {
$separator = \str_contains($redirectFailure, '?') ? '&' : ':';
return $response
->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
->addHeader('Pragma', 'no-cache')
->redirect($redirectFailure . $separator . \http_build_query(['error' => $error]));
}
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $error);
}
$project = $dbForConsole->getDocument('projects', $projectId);
if ($project->isEmpty()) {
+1 -1
View File
@@ -319,7 +319,7 @@ App::init()
* @see https://www.owasp.org/index.php/List_of_useful_HTTP_headers
*/
if (App::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'enabled') { // Force HTTPS
if ($request->getProtocol() !== 'https' && ($swooleRequest->header['host'] ?? '') !== 'localhost') { // Localhost allowed for proxy
if ($request->getProtocol() !== 'https' && ($swooleRequest->header['host'] ?? '') !== 'localhost' && ($swooleRequest->header['host'] ?? '') !== APP_HOSTNAME_INTERNAL) { // Localhost allowed for proxy, APP_HOSTNAME_INTERNAL allowed for migrations
if ($request->getMethod() !== Request::METHOD_GET) {
throw new AppwriteException(AppwriteException::GENERAL_PROTOCOL_UNSUPPORTED, 'Method unsupported over HTTP.');
}
+2 -1
View File
@@ -174,7 +174,8 @@ class BuildsV1 extends Worker
$cloneRepository = $deployment->getAttribute('providerRepositoryName', $repositoryName);
$branchName = $deployment->getAttribute('providerBranch');
$gitCloneCommand = $github->generateCloneCommand($cloneOwner, $cloneRepository, $branchName, $tmpDirectory, $rootDirectory);
$commitHash = $deployment->getAttribute('providerCommitHash', '');
$gitCloneCommand = $github->generateCloneCommand($cloneOwner, $cloneRepository, $branchName, $tmpDirectory, $rootDirectory, $commitHash);
$stdout = '';
$stderr = '';
Console::execute('mkdir -p /tmp/builds/' . \escapeshellcmd($buildId), '', $stdout, $stderr);
+1 -1
View File
@@ -65,7 +65,7 @@
"utopia-php/registry": "0.5.*",
"utopia-php/storage": "0.14.*",
"utopia-php/swoole": "0.5.*",
"utopia-php/vcs": "0.1.*",
"utopia-php/vcs": "0.2.*",
"utopia-php/websocket": "0.1.*",
"resque/php-resque": "1.3.6",
"matomo/device-detector": "6.1.*",
Generated
+18 -9
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f581e0be3663bcdcf888ec6237381d81",
"content-hash": "83427d18095b42c274d2bd6eb302e4aa",
"packages": [
{
"name": "adhocore/jwt",
@@ -3227,16 +3227,16 @@
},
{
"name": "utopia-php/vcs",
"version": "0.1.0",
"version": "dev-feat-clone-commit-hash",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/vcs.git",
"reference": "fc9c38a3f84a4391470cc7184199dec6f953b144"
"reference": "5ed5d1685b3b714d6f20f7922ab4f5f5188313ee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/fc9c38a3f84a4391470cc7184199dec6f953b144",
"reference": "fc9c38a3f84a4391470cc7184199dec6f953b144",
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/5ed5d1685b3b714d6f20f7922ab4f5f5188313ee",
"reference": "5ed5d1685b3b714d6f20f7922ab4f5f5188313ee",
"shasum": ""
},
"require": {
@@ -3270,9 +3270,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/vcs/issues",
"source": "https://github.com/utopia-php/vcs/tree/0.1.0"
"source": "https://github.com/utopia-php/vcs/tree/feat-clone-commit-hash"
},
"time": "2023-08-09T20:48:51+00:00"
"time": "2023-08-21T09:02:54+00:00"
},
{
"name": "utopia-php/websocket",
@@ -6069,9 +6069,18 @@
"time": "2023-07-26T07:16:09+00:00"
}
],
"aliases": [],
"aliases": [
{
"package": "utopia-php/vcs",
"version": "dev-feat-clone-commit-hash",
"alias": "0.1.99",
"alias_normalized": "0.1.99.0"
}
],
"minimum-stability": "stable",
"stability-flags": [],
"stability-flags": {
"utopia-php/vcs": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
+2 -2
View File
@@ -769,7 +769,7 @@ services:
appwrite-assistant:
container_name: appwrite-assistant
hostname: appwrite-assistant
image: appwrite/assistant:0.1.2
image: appwrite/assistant:0.1.3
networks:
- appwrite
environment:
@@ -780,7 +780,7 @@ services:
hostname: executor
<<: *x-logging
stop_signal: SIGINT
image: openruntimes/executor:0.3.2
image: openruntimes/executor:0.3.3
networks:
- appwrite
- runtimes