From ac2ca267d7ef235f74860e833d3eef0c01ad7250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 31 Jul 2023 08:47:47 +0200 Subject: [PATCH] Address more PR reviews --- Dockerfile | 11 +++- app/config/errors.php | 12 ++-- app/config/variables.php | 60 +++++++++++++++++++ app/controllers/api/vcs.php | 26 ++++---- app/workers/deletes.php | 4 +- src/Appwrite/Extend/Exception.php | 4 +- src/Appwrite/Platform/Tasks/Specs.php | 2 - src/Appwrite/Utopia/Response.php | 12 ++-- ...{Repository.php => ProviderRepository.php} | 6 +- 9 files changed, 101 insertions(+), 36 deletions(-) rename src/Appwrite/Utopia/Response/Model/{Repository.php => ProviderRepository.php} (94%) diff --git a/Dockerfile b/Dockerfile index eb6bc16370..281fe0c90e 100755 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ ENV VITE_APPWRITE_GROWTH_ENDPOINT=$VITE_APPWRITE_GROWTH_ENDPOINT RUN npm ci RUN npm run build -FROM meldiron/base:0.2.3 as final +FROM appwrite/base:0.4.2 as final LABEL maintainer="team@appwrite.io" @@ -45,6 +45,7 @@ ENV _APP_SERVER=swoole \ _APP_LOCALE=en \ _APP_WORKER_PER_CORE= \ _APP_DOMAIN=localhost \ + _APP_DOMAIN_FUNCTIONS=functions.localhost \ _APP_DOMAIN_TARGET=localhost \ _APP_HOME=https://appwrite.io \ _APP_EDITION=community \ @@ -122,7 +123,13 @@ ENV _APP_SERVER=swoole \ _APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000 \ _APP_MAINTENANCE_INTERVAL=86400 \ _APP_LOGGING_PROVIDER= \ - _APP_LOGGING_CONFIG= + _APP_LOGGING_CONFIG= \ + _APP_VCS_GITHUB_APP_NAME= \ + _APP_VCS_GITHUB_PRIVATE_KEY= \ + _APP_VCS_GITHUB_APP_ID= \ + _APP_VCS_GITHUB_CLIENT_ID= \ + _APP_VCS_GITHUB_CLIENT_SECRET= \ + _APP_VCS_GITHUB_WEBHOOK_SECRET= RUN apk add git diff --git a/app/config/errors.php b/app/config/errors.php index bfbd84a082..44f4899d28 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -330,18 +330,18 @@ return [ 'description' => 'Installation with the requested ID could not be found.', 'code' => 404, ], - Exception::REPOSITORY_NOT_FOUND => [ - 'name' => Exception::REPOSITORY_NOT_FOUND, + Exception::PROVIDER_REPOSITORY_NOT_FOUND => [ + 'name' => Exception::PROVIDER_REPOSITORY_NOT_FOUND, 'description' => 'Repository with the requested ID could not be found.', 'code' => 404, ], - Exception::VCS_REPOSITORY_NOT_FOUND => [ - 'name' => Exception::VCS_REPOSITORY_NOT_FOUND, + Exception::REPOSITORY_NOT_FOUND => [ + 'name' => Exception::REPOSITORY_NOT_FOUND, 'description' => 'VCS Repository with the requested ID could not be found.', 'code' => 404, ], - Exception::VCS_CONTRIBUTION_ALREADY_AUTHORIZED => [ - 'name' => Exception::VCS_CONTRIBUTION_ALREADY_AUTHORIZED, + Exception::PROVIDER_CONTRIBUTION_CONFLICT => [ + 'name' => Exception::PROVIDER_CONTRIBUTION_CONFLICT, 'description' => 'External ontribution is already authorized.', 'code' => 409, ], diff --git a/app/config/variables.php b/app/config/variables.php index 024f6c332e..22fc6ff03d 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -898,6 +898,66 @@ return [ ], ], ], + [ + 'category' => 'VCS (Version Control System)', + 'description' => '', + 'variables' => [ + [ + 'name' => '_APP_VCS_GITHUB_APP_NAME', + 'description' => 'Name of your GitHub app. You can find it in URL of your GitHub application.', + 'introduction' => '1.4.0', + 'default' => '', + 'required' => false, + 'question' => '', + 'filter' => '' + ], + [ + 'name' => '_APP_VCS_GITHUB_PRIVATE_KEY', + 'description' => 'GitHub app RSA private key. You can generate private keys from GitHub application settings.', + 'introduction' => '1.4.0', + 'default' => '', + 'required' => false, + 'question' => '', + 'filter' => '' + ], + [ + 'name' => '_APP_VCS_GITHUB_APP_ID', + 'description' => 'GitHub application ID. You can find it in your GitHub application details.', + 'introduction' => '1.4.0', + 'default' => '', + 'required' => false, + 'question' => '', + 'filter' => '' + ], + [ + 'name' => '_APP_VCS_GITHUB_CLIENT_ID', + 'description' => 'GitHub client ID. You can find it in your GitHub application details.', + 'introduction' => '1.4.0', + 'default' => '', + 'required' => false, + 'question' => '', + 'filter' => '' + ], + [ + 'name' => '_APP_VCS_GITHUB_CLIENT_SECRET', + 'description' => 'GitHub client secret. You can generate secrets in your GitHub application settings.', + 'introduction' => '1.4.0', + 'default' => '', + 'required' => false, + 'question' => '', + 'filter' => '' + ], + [ + 'name' => '_APP_VCS_GITHUB_WEBHOOK_SECRET', + 'description' => 'GitHub webhook secret. You can configure it in your GitHub application settings under webhook section.', + 'introduction' => '1.4.0', + 'default' => '', + 'required' => false, + 'question' => '', + 'filter' => '' + ], + ], + ], [ 'category' => 'Maintenance', 'description' => '', diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 9ac616fda9..3ead305eda 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -95,7 +95,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $repositoryName = $github->getRepositoryName($providerRepositoryId) ?? ''; if (empty($repositoryName)) { - throw new Exception(Exception::REPOSITORY_NOT_FOUND); + throw new Exception(Exception::PROVIDER_REPOSITORY_NOT_FOUND); } $isAuthorized = !$external; @@ -227,7 +227,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId } }; -App::get('/v1/vcs/github/installations') +App::get('/v1/vcs/github/authorize') ->desc('Install GitHub App') ->groups(['api', 'vcs']) ->label('scope', 'public') @@ -402,7 +402,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories/:pr $repositoryName = $github->getRepositoryName($providerRepositoryId); if (empty($repositoryName)) { - throw new Exception(Exception::REPOSITORY_NOT_FOUND); + throw new Exception(Exception::PROVIDER_REPOSITORY_NOT_FOUND); } $files = $github->listRepositoryContents($owner, $repositoryName, $providerRootDirectory); @@ -444,7 +444,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories') ->label('sdk.description', '') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) - ->label('sdk.response.model', Response::MODEL_REPOSITORY_LIST) + ->label('sdk.response.model', Response::MODEL_PROVIDER_REPOSITORY_LIST) ->param('installationId', '', new Text(256), 'Installation Id') ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) ->inject('gitHub') @@ -561,7 +561,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories') $response->dynamic(new Document([ 'repositories' => $repos, 'total' => \count($repos), - ]), Response::MODEL_REPOSITORY_LIST); + ]), Response::MODEL_PROVIDER_REPOSITORY_LIST); }); App::post('/v1/vcs/github/installations/:installationId/providerRepositories') @@ -573,7 +573,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories') ->label('sdk.description', '') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) - ->label('sdk.response.model', Response::MODEL_REPOSITORY) + ->label('sdk.response.model', Response::MODEL_PROVIDER_REPOSITORY) ->param('installationId', '', new Text(256), 'Installation Id') ->param('name', '', new Text(256), 'Repository name (slug)') ->param('private', '', new Boolean(false), 'Mark repository public or private') @@ -635,7 +635,7 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories') $repository['organization'] = $installation->getAttribute('organization', ''); $repository['provider'] = $installation->getAttribute('provider', ''); - $response->dynamic(new Document($repository), Response::MODEL_REPOSITORY); + $response->dynamic(new Document($repository), Response::MODEL_PROVIDER_REPOSITORY); }); App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:providerRepositoryId') @@ -647,7 +647,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro ->label('sdk.description', '') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) - ->label('sdk.response.model', Response::MODEL_REPOSITORY) + ->label('sdk.response.model', Response::MODEL_PROVIDER_REPOSITORY) ->param('installationId', '', new Text(256), 'Installation Id') ->param('providerRepositoryId', '', new Text(256), 'Repository Id') ->inject('gitHub') @@ -672,7 +672,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro $repositoryName = $github->getRepositoryName($providerRepositoryId) ?? ''; if (empty($repositoryName)) { - throw new Exception(Exception::REPOSITORY_NOT_FOUND); + throw new Exception(Exception::PROVIDER_REPOSITORY_NOT_FOUND); } $repository = $github->getRepository($owner, $repositoryName); @@ -682,7 +682,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro $repository['organization'] = $installation->getAttribute('organization', ''); $repository['provider'] = $installation->getAttribute('provider', ''); - $response->dynamic(new Document($repository), Response::MODEL_REPOSITORY); + $response->dynamic(new Document($repository), Response::MODEL_PROVIDER_REPOSITORY); }); App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:providerRepositoryId/branches') @@ -719,7 +719,7 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories/:pro $repositoryName = $github->getRepositoryName($providerRepositoryId) ?? ''; if (empty($repositoryName)) { - throw new Exception(Exception::REPOSITORY_NOT_FOUND); + throw new Exception(Exception::PROVIDER_REPOSITORY_NOT_FOUND); } $branches = $github->listBranches($owner, $repositoryName) ?? []; @@ -996,11 +996,11 @@ App::patch('/v1/vcs/github/installations/:installationId/repositories/:repositor ]); if ($repository->isEmpty()) { - throw new Exception(Exception::VCS_REPOSITORY_NOT_FOUND); + throw new Exception(Exception::REPOSITORY_NOT_FOUND); } if (\in_array($providerPullRequestId, $repository->getAttribute('providerPullRequestIds', []))) { - throw new Exception(Exception::VCS_CONTRIBUTION_ALREADY_AUTHORIZED); + throw new Exception(Exception::PROVIDER_CONTRIBUTION_CONFLICT); } $providerPullRequestIds = \array_unique(\array_merge($repository->getAttribute('providerPullRequestIds', []), [$providerPullRequestId])); diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 08684e375e..7380b57246 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -462,9 +462,9 @@ class DeletesV1 extends Worker $functionInternalId = $document->getInternalId(); /** - * Delete routes + * Delete rules */ - Console::info("Deleting routes for function " . $functionId); + Console::info("Deleting rules for function " . $functionId); $this->deleteByGroup('rules', [ Query::equal('resourceType', ['function']), Query::equal('resourceInternalId', [$functionInternalId]), diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index a134def953..d0ba05c4c3 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -108,9 +108,9 @@ class Exception extends \Exception /** VCS */ public const INSTALLATION_NOT_FOUND = 'installation_not_found'; + public const PROVIDER_REPOSITORY_NOT_FOUND = 'provider_repository_not_found'; public const REPOSITORY_NOT_FOUND = 'repository_not_found'; - public const VCS_REPOSITORY_NOT_FOUND = 'vcs_repository_not_found'; - public const VCS_CONTRIBUTION_ALREADY_AUTHORIZED = 'vcs_contribution_already_authorized'; + public const PROVIDER_CONTRIBUTION_CONFLICT = 'provider_contribution_conflict'; /** Functions */ public const FUNCTION_NOT_FOUND = 'function_not_found'; diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 69ac3d769b..2a22c59103 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -40,8 +40,6 @@ class Specs extends Action public function action(string $version, string $mode, Registry $register): void { - // $db = $register->get('db'); - // $redis = $register->get('cache'); $appRoutes = App::getRoutes(); $response = new Response(new HttpResponse()); $mocks = ($mode === 'mocks'); diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 8cf24cf54b..e39cea0f86 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -73,9 +73,8 @@ use Appwrite\Utopia\Response\Model\HealthStatus; use Appwrite\Utopia\Response\Model\HealthTime; use Appwrite\Utopia\Response\Model\HealthVersion; use Appwrite\Utopia\Response\Model\Installation; -use Appwrite\Utopia\Response\Model\Repository; -use Appwrite\Utopia\Response\Model\Mock; // Keep last use Appwrite\Utopia\Response\Model\Provider; +use Appwrite\Utopia\Response\Model\ProviderRepository; use Appwrite\Utopia\Response\Model\Runtime; use Appwrite\Utopia\Response\Model\UsageBuckets; use Appwrite\Utopia\Response\Model\UsageCollection; @@ -87,6 +86,7 @@ use Appwrite\Utopia\Response\Model\UsageProject; use Appwrite\Utopia\Response\Model\UsageStorage; use Appwrite\Utopia\Response\Model\UsageUsers; use Appwrite\Utopia\Response\Model\Variable; +use Appwrite\Utopia\Response\Model\Mock; // Keep last /** * @method Response setStatusCode(int $code = 200) @@ -183,8 +183,8 @@ class Response extends SwooleResponse // VCS public const MODEL_INSTALLATION = 'installation'; public const MODEL_INSTALLATION_LIST = 'installationList'; - public const MODEL_REPOSITORY = 'repository'; - public const MODEL_REPOSITORY_LIST = 'repositoryList'; + public const MODEL_PROVIDER_REPOSITORY = 'providerRepository'; + public const MODEL_PROVIDER_REPOSITORY_LIST = 'providerRepositoryList'; public const MODEL_BRANCH = 'branch'; public const MODEL_BRANCH_LIST = 'branchList'; public const MODEL_DETECTION = 'detection'; @@ -275,7 +275,7 @@ class Response extends SwooleResponse ->setModel(new BaseList('Memberships List', self::MODEL_MEMBERSHIP_LIST, 'memberships', self::MODEL_MEMBERSHIP)) ->setModel(new BaseList('Functions List', self::MODEL_FUNCTION_LIST, 'functions', self::MODEL_FUNCTION)) ->setModel(new BaseList('Installations List', self::MODEL_INSTALLATION_LIST, 'installations', self::MODEL_INSTALLATION)) - ->setModel(new BaseList('Repositories List', self::MODEL_REPOSITORY_LIST, 'repositories', self::MODEL_REPOSITORY)) + ->setModel(new BaseList('Provider Repositories List', self::MODEL_PROVIDER_REPOSITORY_LIST, 'providerRepositories', self::MODEL_PROVIDER_REPOSITORY)) ->setModel(new BaseList('Branches List', self::MODEL_BRANCH_LIST, 'branches', self::MODEL_BRANCH)) ->setModel(new BaseList('Runtimes List', self::MODEL_RUNTIME_LIST, 'runtimes', self::MODEL_RUNTIME)) ->setModel(new BaseList('Deployments List', self::MODEL_DEPLOYMENT_LIST, 'deployments', self::MODEL_DEPLOYMENT)) @@ -332,7 +332,7 @@ class Response extends SwooleResponse ->setModel(new Membership()) ->setModel(new Func()) ->setModel(new Installation()) - ->setModel(new Repository()) + ->setModel(new ProviderRepository()) ->setModel(new Detection()) ->setModel(new Branch()) ->setModel(new Runtime()) diff --git a/src/Appwrite/Utopia/Response/Model/Repository.php b/src/Appwrite/Utopia/Response/Model/ProviderRepository.php similarity index 94% rename from src/Appwrite/Utopia/Response/Model/Repository.php rename to src/Appwrite/Utopia/Response/Model/ProviderRepository.php index ee5eebabf2..7f75b96943 100644 --- a/src/Appwrite/Utopia/Response/Model/Repository.php +++ b/src/Appwrite/Utopia/Response/Model/ProviderRepository.php @@ -5,7 +5,7 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Model; -class Repository extends Model +class ProviderRepository extends Model { public function __construct() { @@ -63,7 +63,7 @@ class Repository extends Model */ public function getName(): string { - return 'Repository'; + return 'ProviderRepository'; } /** @@ -73,6 +73,6 @@ class Repository extends Model */ public function getType(): string { - return Response::MODEL_REPOSITORY; + return Response::MODEL_PROVIDER_REPOSITORY; } }