mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge pull request #12208 from appwrite/feat-public-proxy-api
Feat: Public Proxy API
This commit is contained in:
@@ -59,7 +59,7 @@ class Create extends Base
|
||||
],
|
||||
))
|
||||
->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', optional: false)
|
||||
->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Maximum duration is 3600 seconds.', optional: false)
|
||||
->param('duration', null, new Range(1, 3600), 'Time in seconds before ephemeral key expires. Maximum duration is 3600 seconds.', optional: false, example: 600)
|
||||
->inject('response')
|
||||
->inject('queueForEvents')
|
||||
->inject('project')
|
||||
|
||||
@@ -14,6 +14,7 @@ use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\System\System;
|
||||
@@ -43,12 +44,14 @@ class Create extends Action
|
||||
->label('audits.resource', 'rule/{response.$id}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'proxy',
|
||||
group: null,
|
||||
group: 'rules',
|
||||
name: 'createAPIRule',
|
||||
description: <<<EOT
|
||||
Create a new proxy rule for serving Appwrite's API on custom domain.
|
||||
|
||||
Rule ID is automatically generated as MD5 hash of a rule domain for performance purposes.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN],
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_CREATED,
|
||||
@@ -67,11 +70,21 @@ class Create extends Action
|
||||
->inject('dbForPlatform')
|
||||
->inject('platform')
|
||||
->inject('log')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(string $domain, Response $response, Document $project, Certificate $publisherForCertificates, Event $queueForEvents, Database $dbForPlatform, array $platform, Log $log)
|
||||
{
|
||||
public function action(
|
||||
string $domain,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Certificate $publisherForCertificates,
|
||||
Event $queueForEvents,
|
||||
Database $dbForPlatform,
|
||||
array $platform,
|
||||
Log $log,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
$this->validateDomainRestrictions($domain, $platform);
|
||||
|
||||
// TODO: (@Meldiron) Remove after 1.7.x migration
|
||||
@@ -108,7 +121,7 @@ class Create extends Action
|
||||
}
|
||||
|
||||
try {
|
||||
$rule = $dbForPlatform->createDocument('rules', $rule);
|
||||
$rule = $authorization->skip(fn () => $dbForPlatform->createDocument('rules', $rule));
|
||||
} catch (Duplicate $e) {
|
||||
throw new Exception(Exception::RULE_ALREADY_EXISTS);
|
||||
}
|
||||
@@ -126,6 +139,13 @@ class Create extends Action
|
||||
|
||||
$queueForEvents->setParam('ruleId', $rule->getId());
|
||||
|
||||
// Rename 'created' status to 'unverified' for consistency.
|
||||
// 'verifying' and 'verified' statuses stay as is.
|
||||
// 'unverified' in the meaning of failed certificate generation stays as is.
|
||||
if ($rule->getAttribute('status') === 'created') {
|
||||
$rule->setAttribute('status', 'unverified');
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($rule, Response::MODEL_PROXY_RULE);
|
||||
|
||||
@@ -12,6 +12,7 @@ use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
@@ -38,12 +39,12 @@ class Delete extends Action
|
||||
->label('audits.resource', 'rule/{request.ruleId}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'proxy',
|
||||
group: null,
|
||||
group: 'rules',
|
||||
name: 'deleteRule',
|
||||
description: <<<EOT
|
||||
Delete a proxy rule by its unique ID.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN],
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_NOCONTENT,
|
||||
@@ -58,6 +59,7 @@ class Delete extends Action
|
||||
->inject('dbForPlatform')
|
||||
->inject('queueForDeletes')
|
||||
->inject('queueForEvents')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
@@ -67,15 +69,16 @@ class Delete extends Action
|
||||
Document $project,
|
||||
Database $dbForPlatform,
|
||||
DeleteEvent $queueForDeletes,
|
||||
Event $queueForEvents
|
||||
Event $queueForEvents,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
$rule = $dbForPlatform->getDocument('rules', $ruleId);
|
||||
$rule = $authorization->skip(fn () => $dbForPlatform->getDocument('rules', $ruleId));
|
||||
|
||||
if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) {
|
||||
throw new Exception(Exception::RULE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$dbForPlatform->deleteDocument('rules', $rule->getId());
|
||||
$authorization->skip(fn () => $dbForPlatform->deleteDocument('rules', $rule->getId()));
|
||||
|
||||
$queueForDeletes
|
||||
->setType(DELETE_TYPE_DOCUMENT)
|
||||
|
||||
@@ -14,6 +14,7 @@ use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
@@ -45,12 +46,14 @@ class Create extends Action
|
||||
->label('audits.resource', 'rule/{response.$id}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'proxy',
|
||||
group: null,
|
||||
group: 'rules',
|
||||
name: 'createFunctionRule',
|
||||
description: <<<EOT
|
||||
Create a new proxy rule for executing Appwrite Function on custom domain.
|
||||
|
||||
Rule ID is automatically generated as MD5 hash of a rule domain for performance purposes.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN],
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_CREATED,
|
||||
@@ -72,11 +75,25 @@ class Create extends Action
|
||||
->inject('dbForProject')
|
||||
->inject('platform')
|
||||
->inject('log')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(string $domain, string $functionId, string $branch, Response $response, Document $project, Certificate $publisherForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject, array $platform, Log $log)
|
||||
{
|
||||
public function action(
|
||||
string $domain,
|
||||
string $functionId,
|
||||
string $branch,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Certificate $publisherForCertificates,
|
||||
Event $queueForEvents,
|
||||
Database $dbForPlatform,
|
||||
Database $dbForProject,
|
||||
array $platform,
|
||||
Log $log,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
|
||||
$this->validateDomainRestrictions($domain, $platform);
|
||||
|
||||
$function = $dbForProject->getDocument('functions', $functionId);
|
||||
@@ -126,7 +143,7 @@ class Create extends Action
|
||||
}
|
||||
|
||||
try {
|
||||
$rule = $dbForPlatform->createDocument('rules', $rule);
|
||||
$rule = $authorization->skip(fn () => $dbForPlatform->createDocument('rules', $rule));
|
||||
} catch (Duplicate $e) {
|
||||
throw new Exception(Exception::RULE_ALREADY_EXISTS);
|
||||
}
|
||||
@@ -144,6 +161,13 @@ class Create extends Action
|
||||
|
||||
$queueForEvents->setParam('ruleId', $rule->getId());
|
||||
|
||||
// Rename 'created' status to 'unverified' for consistency.
|
||||
// 'verifying' and 'verified' statuses stay as is.
|
||||
// 'unverified' in the meaning of failed certificate generation stays as is.
|
||||
if ($rule->getAttribute('status') === 'created') {
|
||||
$rule->setAttribute('status', 'unverified');
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($rule, Response::MODEL_PROXY_RULE);
|
||||
|
||||
@@ -10,6 +10,7 @@ use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
|
||||
@@ -34,12 +35,12 @@ class Get extends Action
|
||||
->label('scope', 'rules.read')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'proxy',
|
||||
group: null,
|
||||
group: 'rules',
|
||||
name: 'getRule',
|
||||
description: <<<EOT
|
||||
Get a proxy rule by its unique ID.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN],
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_OK,
|
||||
@@ -51,6 +52,7 @@ class Get extends Action
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->inject('dbForPlatform')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
@@ -58,15 +60,16 @@ class Get extends Action
|
||||
string $ruleId,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Database $dbForPlatform
|
||||
Database $dbForPlatform,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
$rule = $dbForPlatform->getDocument('rules', $ruleId);
|
||||
$rule = $authorization->skip(fn () => $dbForPlatform->getDocument('rules', $ruleId));
|
||||
|
||||
if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) {
|
||||
throw new Exception(Exception::RULE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', ''));
|
||||
$certificate = $authorization->skip(fn () => $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')));
|
||||
|
||||
// Give priority to certificate generation logs if present
|
||||
if (!empty($certificate->getAttribute('logs', ''))) {
|
||||
@@ -75,6 +78,13 @@ class Get extends Action
|
||||
|
||||
$rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', ''));
|
||||
|
||||
// Rename 'created' status to 'unverified' for consistency.
|
||||
// 'verifying' and 'verified' statuses stay as is.
|
||||
// 'unverified' in the meaning of failed certificate generation stays as is.
|
||||
if ($rule->getAttribute('status') === 'created') {
|
||||
$rule->setAttribute('status', 'unverified');
|
||||
}
|
||||
|
||||
$response->dynamic($rule, Response::MODEL_PROXY_RULE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
@@ -46,12 +47,14 @@ class Create extends Action
|
||||
->label('audits.resource', 'rule/{response.$id}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'proxy',
|
||||
group: null,
|
||||
group: 'rules',
|
||||
name: 'createRedirectRule',
|
||||
description: <<<EOT
|
||||
Create a new proxy rule for to redirect from custom domain to another domain.
|
||||
|
||||
Rule ID is automatically generated as MD5 hash of a rule domain for performance purposes.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN],
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_CREATED,
|
||||
@@ -75,11 +78,27 @@ class Create extends Action
|
||||
->inject('dbForProject')
|
||||
->inject('platform')
|
||||
->inject('log')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(string $domain, string $url, int $statusCode, string $resourceId, string $resourceType, Response $response, Document $project, Certificate $publisherForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject, array $platform, Log $log)
|
||||
{
|
||||
public function action(
|
||||
string $domain,
|
||||
string $url,
|
||||
int $statusCode,
|
||||
string $resourceId,
|
||||
string $resourceType,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Certificate $publisherForCertificates,
|
||||
Event $queueForEvents,
|
||||
Database $dbForPlatform,
|
||||
Database $dbForProject,
|
||||
array $platform,
|
||||
Log $log,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
|
||||
$this->validateDomainRestrictions($domain, $platform);
|
||||
|
||||
$collection = match ($resourceType) {
|
||||
@@ -131,7 +150,7 @@ class Create extends Action
|
||||
}
|
||||
|
||||
try {
|
||||
$rule = $dbForPlatform->createDocument('rules', $rule);
|
||||
$rule = $authorization->skip(fn () => $dbForPlatform->createDocument('rules', $rule));
|
||||
} catch (Duplicate $e) {
|
||||
throw new Exception(Exception::RULE_ALREADY_EXISTS);
|
||||
}
|
||||
@@ -149,6 +168,13 @@ class Create extends Action
|
||||
|
||||
$queueForEvents->setParam('ruleId', $rule->getId());
|
||||
|
||||
// Rename 'created' status to 'unverified' for consistency.
|
||||
// 'verifying' and 'verified' statuses stay as is.
|
||||
// 'unverified' in the meaning of failed certificate generation stays as is.
|
||||
if ($rule->getAttribute('status') === 'created') {
|
||||
$rule->setAttribute('status', 'unverified');
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($rule, Response::MODEL_PROXY_RULE);
|
||||
|
||||
@@ -14,6 +14,7 @@ use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
@@ -45,12 +46,14 @@ class Create extends Action
|
||||
->label('audits.resource', 'rule/{response.$id}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'proxy',
|
||||
group: null,
|
||||
group: 'rules',
|
||||
name: 'createSiteRule',
|
||||
description: <<<EOT
|
||||
Create a new proxy rule for serving Appwrite Site on custom domain.
|
||||
|
||||
Rule ID is automatically generated as MD5 hash of a rule domain for performance purposes.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN],
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_CREATED,
|
||||
@@ -72,11 +75,25 @@ class Create extends Action
|
||||
->inject('dbForProject')
|
||||
->inject('platform')
|
||||
->inject('log')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(string $domain, string $siteId, ?string $branch, Response $response, Document $project, Certificate $publisherForCertificates, Event $queueForEvents, Database $dbForPlatform, Database $dbForProject, array $platform, Log $log)
|
||||
{
|
||||
public function action(
|
||||
string $domain,
|
||||
string $siteId,
|
||||
?string $branch,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Certificate $publisherForCertificates,
|
||||
Event $queueForEvents,
|
||||
Database $dbForPlatform,
|
||||
Database $dbForProject,
|
||||
array $platform,
|
||||
Log $log,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
|
||||
$this->validateDomainRestrictions($domain, $platform);
|
||||
|
||||
$site = $dbForProject->getDocument('sites', $siteId);
|
||||
@@ -126,7 +143,7 @@ class Create extends Action
|
||||
}
|
||||
|
||||
try {
|
||||
$rule = $dbForPlatform->createDocument('rules', $rule);
|
||||
$rule = $authorization->skip(fn () => $dbForPlatform->createDocument('rules', $rule));
|
||||
} catch (Duplicate $e) {
|
||||
throw new Exception(Exception::RULE_ALREADY_EXISTS);
|
||||
}
|
||||
@@ -144,6 +161,13 @@ class Create extends Action
|
||||
|
||||
$queueForEvents->setParam('ruleId', $rule->getId());
|
||||
|
||||
// Rename 'created' status to 'unverified' for consistency.
|
||||
// 'verifying' and 'verified' statuses stay as is.
|
||||
// 'unverified' in the meaning of failed certificate generation stays as is.
|
||||
if ($rule->getAttribute('status') === 'created') {
|
||||
$rule->setAttribute('status', 'unverified');
|
||||
}
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($rule, Response::MODEL_PROXY_RULE);
|
||||
|
||||
+19
-15
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Proxy\Http\Rules\Verification;
|
||||
namespace Appwrite\Platform\Modules\Proxy\Http\Rules\Status;
|
||||
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Event\Publisher\Certificate;
|
||||
@@ -13,6 +13,7 @@ use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Logger\Log;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
@@ -32,8 +33,9 @@ class Update extends Action
|
||||
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH)
|
||||
->setHttpPath('/v1/proxy/rules/:ruleId/verification')
|
||||
->desc('Update rule verification status')
|
||||
->setHttpPath('/v1/proxy/rules/:ruleId/status')
|
||||
->httpAlias('/v1/proxy/rules/:ruleId/verification')
|
||||
->desc('Update rule status')
|
||||
->groups(['api', 'proxy'])
|
||||
->label('scope', 'rules.write')
|
||||
->label('event', 'rules.[ruleId].update')
|
||||
@@ -41,12 +43,12 @@ class Update extends Action
|
||||
->label('audits.resource', 'rule/{response.$id}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'proxy',
|
||||
group: null,
|
||||
name: 'updateRuleVerification',
|
||||
group: 'rules',
|
||||
name: 'updateRuleStatus',
|
||||
description: <<<EOT
|
||||
Retry getting verification process of a proxy rule. This endpoint triggers domain verification by checking DNS records (CNAME) against the configured target domain. If verification is successful, a TLS certificate will be automatically provisioned for the domain.
|
||||
If not succeeded yet, retry verification process of a proxy rule domain. This endpoint triggers domain verification by checking DNS records. If verification is successful, a TLS certificate will be automatically provisioned for the domain asynchronously in the background.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN],
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_OK,
|
||||
@@ -61,6 +63,7 @@ class Update extends Action
|
||||
->inject('project')
|
||||
->inject('dbForPlatform')
|
||||
->inject('log')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
@@ -71,9 +74,10 @@ class Update extends Action
|
||||
Event $queueForEvents,
|
||||
Document $project,
|
||||
Database $dbForPlatform,
|
||||
Log $log
|
||||
Log $log,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
$rule = $dbForPlatform->getDocument('rules', $ruleId);
|
||||
$rule = $authorization->skip(fn () => $dbForPlatform->getDocument('rules', $ruleId));
|
||||
|
||||
if ($rule->isEmpty() || $rule->getAttribute('projectInternalId') !== $project->getSequence()) {
|
||||
throw new Exception(Exception::RULE_NOT_FOUND);
|
||||
@@ -90,22 +94,22 @@ class Update extends Action
|
||||
try {
|
||||
$this->verifyRule($rule, $log);
|
||||
// Reset logs and status for the rule
|
||||
$rule = $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
|
||||
$rule = $authorization->skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
|
||||
'logs' => '',
|
||||
'status' => RULE_STATUS_CERTIFICATE_GENERATING,
|
||||
]));
|
||||
])));
|
||||
|
||||
$certificateId = $rule->getAttribute('certificateId', '');
|
||||
// Reset logs for the associated certificate.
|
||||
if (!empty($certificateId)) {
|
||||
$certificate = $dbForPlatform->updateDocument('certificates', $certificateId, new Document([
|
||||
$certificate = $authorization->skip(fn () => $dbForPlatform->updateDocument('certificates', $certificateId, new Document([
|
||||
'logs' => '',
|
||||
]));
|
||||
])));
|
||||
}
|
||||
} catch (Exception $err) {
|
||||
$dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
|
||||
$authorization->skip(fn () => $dbForPlatform->updateDocument('rules', $rule->getId(), new Document([
|
||||
'$updatedAt' => DateTime::now(),
|
||||
]));
|
||||
])));
|
||||
throw $err;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception\Query as QueryException;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Database\Validator\Query\Cursor;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Boolean;
|
||||
@@ -39,12 +40,12 @@ class XList extends Action
|
||||
->label('scope', 'rules.read')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'proxy',
|
||||
group: null,
|
||||
group: 'rules',
|
||||
name: 'listRules',
|
||||
description: <<<EOT
|
||||
Get a list of all the proxy rules. You can use the query params to filter your results.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN],
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_OK,
|
||||
@@ -53,21 +54,23 @@ class XList extends Action
|
||||
]
|
||||
))
|
||||
->param('queries', [], new Rules(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Rules::ALLOWED_ATTRIBUTES), true)
|
||||
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
|
||||
->param('total', true, new Boolean(true), 'When set to false, the total count returned will be 0 and will not be calculated.', true)
|
||||
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true, deprecated: true)
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->inject('dbForPlatform')
|
||||
->inject('authorization')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(
|
||||
array $queries,
|
||||
bool $total,
|
||||
string $search,
|
||||
bool $includeTotal,
|
||||
Response $response,
|
||||
Document $project,
|
||||
Database $dbForPlatform
|
||||
Database $dbForPlatform,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
try {
|
||||
$queries = Query::parseQueries($queries);
|
||||
@@ -91,7 +94,7 @@ class XList extends Action
|
||||
}
|
||||
|
||||
$ruleId = $cursor->getValue();
|
||||
$cursorDocument = $dbForPlatform->getDocument('rules', $ruleId);
|
||||
$cursorDocument = $authorization->skip(fn () => $dbForPlatform->getDocument('rules', $ruleId));
|
||||
|
||||
if ($cursorDocument->isEmpty()) {
|
||||
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Rule '{$ruleId}' for the 'cursor' value not found.");
|
||||
@@ -102,9 +105,9 @@ class XList extends Action
|
||||
|
||||
$filterQueries = Query::groupByType($queries)['filters'];
|
||||
|
||||
$rules = $dbForPlatform->find('rules', $queries);
|
||||
$rules = $authorization->skip(fn () => $dbForPlatform->find('rules', $queries));
|
||||
foreach ($rules as $rule) {
|
||||
$certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', ''));
|
||||
$certificate = $authorization->skip(fn () => $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')));
|
||||
|
||||
// Give priority to certificate generation logs if present
|
||||
if (!empty($certificate->getAttribute('logs', ''))) {
|
||||
@@ -112,11 +115,18 @@ class XList extends Action
|
||||
}
|
||||
|
||||
$rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', ''));
|
||||
|
||||
// Rename 'created' status to 'unverified' for consistency.
|
||||
// 'verifying' and 'verified' statuses stay as is.
|
||||
// 'unverified' in the meaning of failed certificate generation stays as is.
|
||||
if ($rule->getAttribute('status') === 'created') {
|
||||
$rule->setAttribute('status', 'unverified');
|
||||
}
|
||||
}
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'rules' => $rules,
|
||||
'total' => $includeTotal ? $dbForPlatform->count('rules', $filterQueries, APP_LIMIT_COUNT) : 0,
|
||||
'total' => $total ? $authorization->skip(fn () => $dbForPlatform->count('rules', $filterQueries, APP_LIMIT_COUNT)) : 0,
|
||||
]), Response::MODEL_PROXY_RULE_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use Appwrite\Platform\Modules\Proxy\Http\Rules\Function\Create as CreateFunction
|
||||
use Appwrite\Platform\Modules\Proxy\Http\Rules\Get as GetRule;
|
||||
use Appwrite\Platform\Modules\Proxy\Http\Rules\Redirect\Create as CreateRedirectRule;
|
||||
use Appwrite\Platform\Modules\Proxy\Http\Rules\Site\Create as CreateSiteRule;
|
||||
use Appwrite\Platform\Modules\Proxy\Http\Rules\Verification\Update as UpdateRuleVerification;
|
||||
use Appwrite\Platform\Modules\Proxy\Http\Rules\Status\Update as UpdateRuleStatus;
|
||||
use Appwrite\Platform\Modules\Proxy\Http\Rules\XList as ListRules;
|
||||
use Utopia\Platform\Service;
|
||||
|
||||
@@ -26,6 +26,6 @@ class Http extends Service
|
||||
$this->addAction(GetRule::getName(), new GetRule());
|
||||
$this->addAction(ListRules::getName(), new ListRules());
|
||||
$this->addAction(DeleteRule::getName(), new DeleteRule());
|
||||
$this->addAction(UpdateRuleVerification::getName(), new UpdateRuleVerification());
|
||||
$this->addAction(UpdateRuleStatus::getName(), new UpdateRuleStatus());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class Rule extends Model
|
||||
])
|
||||
->addRule('deploymentResourceId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'ID deployment\'s resource. Used if type is "deployment"',
|
||||
'description' => 'ID of deployment\'s resource (site or function ID). Used if type is "deployment"',
|
||||
'default' => '',
|
||||
'example' => 'n3u9feiwmf',
|
||||
])
|
||||
@@ -86,10 +86,10 @@ class Rule extends Model
|
||||
])
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_ENUM,
|
||||
'description' => 'Domain verification status. Possible values are "created", "verifying", "verified" and "unverified"',
|
||||
'default' => 'created',
|
||||
'description' => 'Domain verification status. Possible values are "unverified", "verifying", "verified"',
|
||||
'default' => 'unverified',
|
||||
'example' => 'verified',
|
||||
'enum' => ['created', 'verifying', 'verified', 'unverified'],
|
||||
'enum' => ['unverified', 'verifying', 'verified'],
|
||||
])
|
||||
->addRule('logs', [
|
||||
'type' => self::TYPE_STRING,
|
||||
|
||||
Reference in New Issue
Block a user