diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 46b6100cd2..fcc9d1fea2 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -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 diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index e8f4670417..1bd01a76e6 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -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]), ]);