mirror of
https://github.com/appwrite/appwrite
synced 2026-05-18 22:48:31 +00:00
refactor module namings
This commit is contained in:
parent
179684e8b2
commit
10dab10cc5
10 changed files with 101 additions and 29 deletions
|
|
@ -11,6 +11,6 @@ class Appwrite extends Platform
|
|||
public function __construct()
|
||||
{
|
||||
parent::__construct(new Core());
|
||||
$this->addModule(new DevelopmentKeys());
|
||||
$this->addModule(new DevelopmentKeys\Module());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http;
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
|
@ -15,12 +15,12 @@ use Utopia\Platform\Action;
|
|||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class Create extends Action
|
||||
class CreateKey extends Action
|
||||
{
|
||||
use HTTP;
|
||||
public static function getName()
|
||||
{
|
||||
return 'create';
|
||||
return 'createKey';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http;
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
|
@ -10,12 +10,12 @@ use Utopia\Database\Validator\UID;
|
|||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
|
||||
class Delete extends Action
|
||||
class DeleteKey extends Action
|
||||
{
|
||||
use HTTP;
|
||||
public static function getName()
|
||||
{
|
||||
return 'delete';
|
||||
return 'deleteKey';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http;
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
|
@ -10,12 +10,12 @@ use Utopia\Database\Validator\UID;
|
|||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
|
||||
class Get extends Action
|
||||
class GetKey extends Action
|
||||
{
|
||||
use HTTP;
|
||||
public static function getName()
|
||||
{
|
||||
return 'get';
|
||||
return 'getKey';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http;
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
|
@ -11,12 +11,12 @@ use Utopia\Database\Validator\UID;
|
|||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
|
||||
class XList extends Action
|
||||
class ListKeys extends Action
|
||||
{
|
||||
use HTTP;
|
||||
public static function getName()
|
||||
{
|
||||
return 'list';
|
||||
return 'listKeys';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -12,12 +12,12 @@ use Utopia\Platform\Action;
|
|||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class Update extends Action
|
||||
class UpdateKey extends Action
|
||||
{
|
||||
use HTTP;
|
||||
public static function getName()
|
||||
{
|
||||
return 'update';
|
||||
return 'updateKeys';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class UpdateKey extends Action
|
||||
{
|
||||
use HTTP;
|
||||
public static function getName()
|
||||
{
|
||||
return 'updateKey';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setHttpMethod(Action::HTTP_REQUEST_METHOD_PUT)
|
||||
->setHttpPath('/v1/projects/:projectId/development-keys/:keyId')
|
||||
->desc('Update key')
|
||||
->groups(['api', 'projects'])
|
||||
->label('scope', 'projects.write')
|
||||
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
|
||||
->label('sdk.namespace', 'projects')
|
||||
->label('sdk.method', 'updateDevelopmentKey')
|
||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||
->label('sdk.response.model', Response::MODEL_KEY)
|
||||
->param('projectId', '', new UID(), 'Project unique ID.')
|
||||
->param('keyId', '', new UID(), 'Key unique ID.')
|
||||
->param('name', null, new Text(128), 'Key name. Max length: 128 chars.')
|
||||
->param('expire', null, new DatetimeValidator(), 'Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format.', true)
|
||||
->inject('response')
|
||||
->inject('dbForConsole')
|
||||
->callback(fn ($projectId, $keyId, $name, $expire, $response, $dbForConsole) => $this->action($projectId, $keyId, $name, $expire, $response, $dbForConsole));
|
||||
}
|
||||
public function action(string $projectId, string $keyId, string $name, ?string $expire, Response $response, Database $dbForConsole)
|
||||
{
|
||||
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
$key = $dbForConsole->findOne('developmentKeys', [
|
||||
Query::equal('$id', [$keyId]),
|
||||
Query::equal('projectInternalId', [$project->getInternalId()]),
|
||||
]);
|
||||
|
||||
if ($key === false || $key->isEmpty()) {
|
||||
throw new Exception(Exception::KEY_NOT_FOUND);
|
||||
}
|
||||
|
||||
$key
|
||||
->setAttribute('name', $name)
|
||||
->setAttribute('expire', $expire ?? $key->getAttribute('expire'));
|
||||
|
||||
$dbForConsole->updateDocument('developmentKeys', $key->getId(), $key);
|
||||
|
||||
$dbForConsole->purgeCachedDocument('projects', $project->getId());
|
||||
|
||||
$response->dynamic($key, Response::MODEL_KEY);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules;
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys;
|
||||
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Services\Http;
|
||||
use Utopia\Platform\Module;
|
||||
use Utopia\Platform\Module as Base;
|
||||
|
||||
class DevelopmentKeys extends Module
|
||||
class Module extends Base
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace Appwrite\Platform\Modules\DevelopmentKeys\Services;
|
||||
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\Create;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\Delete;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\Get;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\Update;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\XList;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys\CreateKey;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys\DeleteKey;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys\GetKey;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys\ListKeys;
|
||||
use Appwrite\Platform\Modules\DevelopmentKeys\Http\DevelopmentKeys\UpdateKey;
|
||||
use Utopia\Platform\Service;
|
||||
|
||||
class Http extends Service
|
||||
|
|
@ -14,10 +14,10 @@ class Http extends Service
|
|||
public function __construct()
|
||||
{
|
||||
$this->type = Service::TYPE_HTTP;
|
||||
$this->addAction(Create::getName(), new Create());
|
||||
$this->addAction(Update::getName(), new Update());
|
||||
$this->addAction(Get::getName(), new Get());
|
||||
$this->addAction(XList::getName(), new XList());
|
||||
$this->addAction(Delete::getName(), new Delete());
|
||||
$this->addAction(CreateKey::getName(), new CreateKey());
|
||||
$this->addAction(UpdateKey::getName(), new UpdateKey());
|
||||
$this->addAction(GetKey::getName(), new GetKey());
|
||||
$this->addAction(ListKeys::getName(), new ListKeys());
|
||||
$this->addAction(DeleteKey::getName(), new DeleteKey());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ trait ProjectsDevelopmentKeys
|
|||
$developmentKey = $response['body']['secret'];
|
||||
|
||||
//
|
||||
for($i = 0; $i < 11; $i++) {
|
||||
for ($i = 0; $i < 11; $i++) {
|
||||
$res = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $id,
|
||||
|
|
|
|||
Loading…
Reference in a new issue