Merge branch '0.7.x' into feat-dart-env
This commit is contained in:
commit
d184e0eae8
|
@ -39,6 +39,7 @@
|
||||||
- New OAuth adapter for PayPal sandbox (@armino-dev - [#420](https://github.com/appwrite/appwrite/issues/410))
|
- New OAuth adapter for PayPal sandbox (@armino-dev - [#420](https://github.com/appwrite/appwrite/issues/410))
|
||||||
- Introducing new permssion types: role:guest, role:member, role:app
|
- Introducing new permssion types: role:guest, role:member, role:app
|
||||||
- Disabled rate-limits on server side integrations
|
- Disabled rate-limits on server side integrations
|
||||||
|
- Refactored migration script
|
||||||
|
|
||||||
### User Interface
|
### User Interface
|
||||||
|
|
||||||
|
@ -105,6 +106,7 @@
|
||||||
- Fixed OAuth redirect when using the self-hosted instance default success URL ([#454](https://github.com/appwrite/appwrite/issues/454))
|
- Fixed OAuth redirect when using the self-hosted instance default success URL ([#454](https://github.com/appwrite/appwrite/issues/454))
|
||||||
- Fixed bug denying authentication with Github OAuth provider
|
- Fixed bug denying authentication with Github OAuth provider
|
||||||
- Fixed a bug making read permission overwrite write permission in some cases
|
- Fixed a bug making read permission overwrite write permission in some cases
|
||||||
|
- Fixed consistent property names in databases by enforcing camel case
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
|
@ -113,6 +115,7 @@
|
||||||
- Now using your `_APP_SYSTEM_EMAIL_ADDRESS` as the email address for issuing and renewing SSL certificates
|
- Now using your `_APP_SYSTEM_EMAIL_ADDRESS` as the email address for issuing and renewing SSL certificates
|
||||||
- Block iframe access to Appwrite console using the `X-Frame-Options` header.
|
- Block iframe access to Appwrite console using the `X-Frame-Options` header.
|
||||||
- Fixed `roles` param input validator
|
- Fixed `roles` param input validator
|
||||||
|
- API Keys are now stored encrypted
|
||||||
|
|
||||||
# Version 0.6.2 (PRE-RELEASE)
|
# Version 0.6.2 (PRE-RELEASE)
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ $collections = [
|
||||||
[
|
[
|
||||||
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||||
'label' => 'Password Update Date',
|
'label' => 'Password Update Date',
|
||||||
'key' => 'password-update',
|
'key' => 'passwordUpdate',
|
||||||
'type' => Database::SYSTEM_VAR_TYPE_NUMERIC,
|
'type' => Database::SYSTEM_VAR_TYPE_NUMERIC,
|
||||||
'default' => '',
|
'default' => '',
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
@ -827,6 +827,7 @@ $collections = [
|
||||||
'type' => Database::SYSTEM_VAR_TYPE_TEXT,
|
'type' => Database::SYSTEM_VAR_TYPE_TEXT,
|
||||||
'default' => '',
|
'default' => '',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
|
'filter' => ['encrypt'],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
@ -2,98 +2,126 @@
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'/' => [
|
'/' => [
|
||||||
|
'key' => 'homepage',
|
||||||
'name' => 'Homepage',
|
'name' => 'Homepage',
|
||||||
'controller' => 'web/home.php',
|
'controller' => 'web/home.php',
|
||||||
'sdk' => false,
|
'sdk' => false,
|
||||||
|
'docs' => false,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'console/' => [
|
'console/' => [
|
||||||
|
'key' => 'console',
|
||||||
'name' => 'Console',
|
'name' => 'Console',
|
||||||
'controller' => 'web/console.php',
|
'controller' => 'web/console.php',
|
||||||
'sdk' => false,
|
'sdk' => false,
|
||||||
|
'docs' => false,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/account' => [
|
'v1/account' => [
|
||||||
|
'key' => 'account',
|
||||||
'name' => 'Account',
|
'name' => 'Account',
|
||||||
'description' => '/docs/services/account.md',
|
'description' => '/docs/services/account.md',
|
||||||
'controller' => 'api/account.php',
|
'controller' => 'api/account.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/avatars' => [
|
'v1/avatars' => [
|
||||||
|
'key' => 'avatars',
|
||||||
'name' => 'Avatars',
|
'name' => 'Avatars',
|
||||||
'description' => '/docs/services/avatars.md',
|
'description' => '/docs/services/avatars.md',
|
||||||
'controller' => 'api/avatars.php',
|
'controller' => 'api/avatars.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/database' => [
|
'v1/database' => [
|
||||||
|
'key' => 'database',
|
||||||
'name' => 'Database',
|
'name' => 'Database',
|
||||||
'description' => '/docs/services/database.md',
|
'description' => '/docs/services/database.md',
|
||||||
'controller' => 'api/database.php',
|
'controller' => 'api/database.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/locale' => [
|
'v1/locale' => [
|
||||||
|
'key' => 'locale',
|
||||||
'name' => 'Locale',
|
'name' => 'Locale',
|
||||||
'description' => '/docs/services/locale.md',
|
'description' => '/docs/services/locale.md',
|
||||||
'controller' => 'api/locale.php',
|
'controller' => 'api/locale.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/health' => [
|
'v1/health' => [
|
||||||
|
'key' => 'health',
|
||||||
'name' => 'Health',
|
'name' => 'Health',
|
||||||
'description' => '/docs/services/health.md',
|
'description' => '/docs/services/health.md',
|
||||||
'controller' => 'api/health.php',
|
'controller' => 'api/health.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/projects' => [
|
'v1/projects' => [
|
||||||
|
'key' => 'projects',
|
||||||
'name' => 'Projects',
|
'name' => 'Projects',
|
||||||
'controller' => 'api/projects.php',
|
'controller' => 'api/projects.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/storage' => [
|
'v1/storage' => [
|
||||||
|
'key' => 'storage',
|
||||||
'name' => 'Storage',
|
'name' => 'Storage',
|
||||||
'description' => '/docs/services/storage.md',
|
'description' => '/docs/services/storage.md',
|
||||||
'controller' => 'api/storage.php',
|
'controller' => 'api/storage.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/teams' => [
|
'v1/teams' => [
|
||||||
|
'key' => 'teams',
|
||||||
'name' => 'Teams',
|
'name' => 'Teams',
|
||||||
'description' => '/docs/services/teams.md',
|
'description' => '/docs/services/teams.md',
|
||||||
'controller' => 'api/teams.php',
|
'controller' => 'api/teams.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/users' => [
|
'v1/users' => [
|
||||||
|
'key' => 'users',
|
||||||
'name' => 'Users',
|
'name' => 'Users',
|
||||||
'description' => '/docs/services/users.md',
|
'description' => '/docs/services/users.md',
|
||||||
'controller' => 'api/users.php',
|
'controller' => 'api/users.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/functions' => [
|
'v1/functions' => [
|
||||||
'name' => 'Users',
|
'key' => 'functions',
|
||||||
|
'name' => 'Functions',
|
||||||
'description' => '/docs/services/functions.md',
|
'description' => '/docs/services/functions.md',
|
||||||
'controller' => 'api/functions.php',
|
'controller' => 'api/functions.php',
|
||||||
'sdk' => true,
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
'v1/mock' => [
|
'v1/mock' => [
|
||||||
|
'key' => 'mock',
|
||||||
'name' => 'Mock',
|
'name' => 'Mock',
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'controller' => 'mock.php',
|
'controller' => 'mock.php',
|
||||||
'sdk' => false,
|
'sdk' => false,
|
||||||
|
'docs' => false,
|
||||||
'tests' => true,
|
'tests' => true,
|
||||||
],
|
],
|
||||||
'v1/graphql' => [
|
'v1/graphql' => [
|
||||||
|
'key' => 'graphql',
|
||||||
'name' => 'GraphQL',
|
'name' => 'GraphQL',
|
||||||
'description' => 'GraphQL Endpoint',
|
'description' => 'GraphQL Endpoint',
|
||||||
'controller' => 'api/graphql.php',
|
'controller' => 'api/graphql.php',
|
||||||
'sdk' => false,
|
'sdk' => false,
|
||||||
|
'docs' => false,
|
||||||
'tests' => false,
|
'tests' => false,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -100,7 +100,7 @@ App::post('/v1/account')
|
||||||
'emailVerification' => false,
|
'emailVerification' => false,
|
||||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||||
'password' => Auth::passwordHash($password),
|
'password' => Auth::passwordHash($password),
|
||||||
'password-update' => \time(),
|
'passwordUpdate' => \time(),
|
||||||
'registration' => \time(),
|
'registration' => \time(),
|
||||||
'reset' => false,
|
'reset' => false,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
@ -512,7 +512,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||||
'emailVerification' => true,
|
'emailVerification' => true,
|
||||||
'status' => Auth::USER_STATUS_ACTIVATED, // Email should already be authenticated by OAuth2 provider
|
'status' => Auth::USER_STATUS_ACTIVATED, // Email should already be authenticated by OAuth2 provider
|
||||||
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
||||||
'password-update' => \time(),
|
'passwordUpdate' => \time(),
|
||||||
'registration' => \time(),
|
'registration' => \time(),
|
||||||
'reset' => false,
|
'reset' => false,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
@ -1456,7 +1456,7 @@ App::put('/v1/account/recovery')
|
||||||
|
|
||||||
$profile = $projectDB->updateDocument(\array_merge($profile->getArrayCopy(), [
|
$profile = $projectDB->updateDocument(\array_merge($profile->getArrayCopy(), [
|
||||||
'password' => Auth::passwordHash($password),
|
'password' => Auth::passwordHash($password),
|
||||||
'password-update' => \time(),
|
'passwordUpdate' => \time(),
|
||||||
'emailVerification' => true,
|
'emailVerification' => true,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ App::post('/v1/functions')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($name, $execute, $env, $vars, $events, $schedule, $timeout, $response, $projectDB) {
|
->action(function ($name, $execute, $env, $vars, $events, $schedule, $timeout, $response, $projectDB) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
|
||||||
$function = $projectDB->createDocument([
|
$function = $projectDB->createDocument([
|
||||||
'$collection' => Database::SYSTEM_COLLECTION_FUNCTIONS,
|
'$collection' => Database::SYSTEM_COLLECTION_FUNCTIONS,
|
||||||
'$permissions' => [
|
'$permissions' => [
|
||||||
|
@ -91,6 +94,9 @@ App::get('/v1/functions')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) {
|
->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
|
||||||
$results = $projectDB->getCollection([
|
$results = $projectDB->getCollection([
|
||||||
'limit' => $limit,
|
'limit' => $limit,
|
||||||
'offset' => $offset,
|
'offset' => $offset,
|
||||||
|
@ -122,6 +128,9 @@ App::get('/v1/functions/:functionId')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($functionId, $response, $projectDB) {
|
->action(function ($functionId, $response, $projectDB) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
|
|
||||||
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
|
@ -272,13 +281,19 @@ App::put('/v1/functions/:functionId')
|
||||||
->param('timeout', 15, new Range(1, 900), 'Function maximum execution time in seconds.', true)
|
->param('timeout', 15, new Range(1, 900), 'Function maximum execution time in seconds.', true)
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($functionId, $name, $execute, $vars, $events, $schedule, $timeout, $response, $projectDB) {
|
->inject('project')
|
||||||
|
->action(function ($functionId, $name, $execute, $vars, $events, $schedule, $timeout, $response, $projectDB, $project) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
/** @var Appwrite\Database\Document $project */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
|
|
||||||
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
throw new Exception('Function not found', 404);
|
throw new Exception('Function not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$original = $function->getAttribute('schedule', '');
|
||||||
$cron = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? CronExpression::factory($schedule) : null;
|
$cron = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? CronExpression::factory($schedule) : null;
|
||||||
$next = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : null;
|
$next = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : null;
|
||||||
|
|
||||||
|
@ -291,28 +306,23 @@ App::put('/v1/functions/:functionId')
|
||||||
'vars' => $vars,
|
'vars' => $vars,
|
||||||
'events' => $events,
|
'events' => $events,
|
||||||
'schedule' => $schedule,
|
'schedule' => $schedule,
|
||||||
'schedulePrevious' => null,
|
|
||||||
'scheduleNext' => $next,
|
'scheduleNext' => $next,
|
||||||
'timeout' => $timeout,
|
'timeout' => $timeout,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
if ($next) {
|
|
||||||
ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [
|
|
||||||
|
|
||||||
]);
|
|
||||||
|
|
||||||
// ->setParam('projectId', $project->getId())
|
|
||||||
// ->setParam('event', $route->getLabel('event', ''))
|
|
||||||
// ->setParam('payload', [])
|
|
||||||
// ->setParam('functionId', null)
|
|
||||||
// ->setParam('executionId', null)
|
|
||||||
// ->setParam('trigger', 'event')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false === $function) {
|
if (false === $function) {
|
||||||
throw new Exception('Failed saving function to DB', 500);
|
throw new Exception('Failed saving function to DB', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($next && $schedule !== $original) {
|
||||||
|
ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [
|
||||||
|
'projectId' => $project->getId(),
|
||||||
|
'functionId' => $function->getId(),
|
||||||
|
'executionId' => null,
|
||||||
|
'trigger' => 'schedule',
|
||||||
|
]); // Async task rescheduale
|
||||||
|
}
|
||||||
|
|
||||||
$response->dynamic($function, Response::MODEL_FUNCTION);
|
$response->dynamic($function, Response::MODEL_FUNCTION);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -331,7 +341,12 @@ App::patch('/v1/functions/:functionId/tag')
|
||||||
->param('tag', '', new UID(), 'Tag unique ID.')
|
->param('tag', '', new UID(), 'Tag unique ID.')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($functionId, $tag, $response, $projectDB) {
|
->inject('project')
|
||||||
|
->action(function ($functionId, $tag, $response, $projectDB, $project) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
/** @var Appwrite\Database\Document $project */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
$tag = $projectDB->getDocument($tag);
|
$tag = $projectDB->getDocument($tag);
|
||||||
|
|
||||||
|
@ -344,14 +359,23 @@ App::patch('/v1/functions/:functionId/tag')
|
||||||
}
|
}
|
||||||
|
|
||||||
$schedule = $function->getAttribute('schedule', '');
|
$schedule = $function->getAttribute('schedule', '');
|
||||||
$cron = (!empty($function->getAttribute('tag')&& !empty($schedule))) ? CronExpression::factory($schedule) : null;
|
$cron = (empty($function->getAttribute('tag')) && !empty($schedule)) ? CronExpression::factory($schedule) : null;
|
||||||
$next = (!empty($function->getAttribute('tag')&& !empty($schedule))) ? $cron->getNextRunDate()->format('U') : null;
|
$next = (empty($function->getAttribute('tag')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : null;
|
||||||
|
|
||||||
$function = $projectDB->updateDocument(array_merge($function->getArrayCopy(), [
|
$function = $projectDB->updateDocument(array_merge($function->getArrayCopy(), [
|
||||||
'tag' => $tag->getId(),
|
'tag' => $tag->getId(),
|
||||||
'scheduleNext' => $next,
|
'scheduleNext' => $next,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
if ($next) { // Init first schedule
|
||||||
|
ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [
|
||||||
|
'projectId' => $project->getId(),
|
||||||
|
'functionId' => $function->getId(),
|
||||||
|
'executionId' => null,
|
||||||
|
'trigger' => 'schedule',
|
||||||
|
]); // Async task rescheduale
|
||||||
|
}
|
||||||
|
|
||||||
if (false === $function) {
|
if (false === $function) {
|
||||||
throw new Exception('Failed saving function to DB', 500);
|
throw new Exception('Failed saving function to DB', 500);
|
||||||
}
|
}
|
||||||
|
@ -418,6 +442,11 @@ App::post('/v1/functions/:functionId/tags')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->inject('usage')
|
->inject('usage')
|
||||||
->action(function ($functionId, $command, $code, $request, $response, $projectDB, $usage) {
|
->action(function ($functionId, $command, $code, $request, $response, $projectDB, $usage) {
|
||||||
|
/** @var Utopia\Swoole\Request $request */
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
/** @var Appwrite\Event\Event $usage */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
|
|
||||||
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
|
@ -506,6 +535,9 @@ App::get('/v1/functions/:functionId/tags')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $projectDB) {
|
->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $projectDB) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
|
|
||||||
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
|
@ -545,6 +577,9 @@ App::get('/v1/functions/:functionId/tags/:tagId')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($functionId, $tagId, $response, $projectDB) {
|
->action(function ($functionId, $tagId, $response, $projectDB) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
|
|
||||||
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
|
@ -581,6 +616,10 @@ App::delete('/v1/functions/:functionId/tags/:tagId')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->inject('usage')
|
->inject('usage')
|
||||||
->action(function ($functionId, $tagId, $response, $projectDB, $usage) {
|
->action(function ($functionId, $tagId, $response, $projectDB, $usage) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
/** @var Appwrite\Event\Event $usage */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
|
|
||||||
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
|
@ -727,6 +766,9 @@ App::get('/v1/functions/:functionId/executions')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $projectDB) {
|
->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $projectDB) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
|
|
||||||
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
|
@ -766,6 +808,9 @@ App::get('/v1/functions/:functionId/executions/:executionId')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('projectDB')
|
->inject('projectDB')
|
||||||
->action(function ($functionId, $executionId, $response, $projectDB) {
|
->action(function ($functionId, $executionId, $response, $projectDB) {
|
||||||
|
/** @var Appwrite\Utopia\Response $response */
|
||||||
|
/** @var Appwrite\Database\Database $projectDB */
|
||||||
|
|
||||||
$function = $projectDB->getDocument($functionId);
|
$function = $projectDB->getDocument($functionId);
|
||||||
|
|
||||||
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
|
|
|
@ -324,7 +324,7 @@ App::post('/v1/teams/:teamId/memberships')
|
||||||
'emailVerification' => false,
|
'emailVerification' => false,
|
||||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||||
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
'password' => Auth::passwordHash(Auth::passwordGenerator()),
|
||||||
'password-update' => \time(),
|
'passwordUpdate' => \time(),
|
||||||
'registration' => \time(),
|
'registration' => \time(),
|
||||||
'reset' => false,
|
'reset' => false,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
|
|
@ -62,7 +62,7 @@ App::post('/v1/users')
|
||||||
'emailVerification' => false,
|
'emailVerification' => false,
|
||||||
'status' => Auth::USER_STATUS_UNACTIVATED,
|
'status' => Auth::USER_STATUS_UNACTIVATED,
|
||||||
'password' => Auth::passwordHash($password),
|
'password' => Auth::passwordHash($password),
|
||||||
'password-update' => \time(),
|
'passwordUpdate' => \time(),
|
||||||
'registration' => \time(),
|
'registration' => \time(),
|
||||||
'reset' => false,
|
'reset' => false,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
|
|
@ -216,6 +216,7 @@ App::get('/specs/:format')
|
||||||
|
|
||||||
$routes = [];
|
$routes = [];
|
||||||
$models = [];
|
$models = [];
|
||||||
|
$services = [];
|
||||||
|
|
||||||
$keys = [
|
$keys = [
|
||||||
APP_PLATFORM_CLIENT => [
|
APP_PLATFORM_CLIENT => [
|
||||||
|
@ -317,6 +318,20 @@ App::get('/specs/:format')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (Config::getParam('services', []) as $key => $service) {
|
||||||
|
if(!isset($service['docs']) // Skip service if not part of the public API
|
||||||
|
|| !isset($service['sdk'])
|
||||||
|
|| !$service['docs']
|
||||||
|
|| !$service['sdk']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$services[] = [
|
||||||
|
'name' => $service['key'] ?? '',
|
||||||
|
'description' => (!empty($service['description'])) ? file_get_contents(realpath(__DIR__.'/../../..'.$service['description'])) : '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$models = $response->getModels();
|
$models = $response->getModels();
|
||||||
|
|
||||||
foreach ($models as $key => $value) {
|
foreach ($models as $key => $value) {
|
||||||
|
@ -327,11 +342,11 @@ App::get('/specs/:format')
|
||||||
|
|
||||||
switch ($format) {
|
switch ($format) {
|
||||||
case 'swagger2':
|
case 'swagger2':
|
||||||
$format = new Swagger2($utopia, $routes, $models, $keys[$platform], $security[$platform]);
|
$format = new Swagger2($utopia, $services, $routes, $models, $keys[$platform], $security[$platform]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'open-api3':
|
case 'open-api3':
|
||||||
$format = new OpenAPI3($utopia, $routes, $models, $keys[$platform], $security[$platform]);
|
$format = new OpenAPI3($utopia, $services, $routes, $models, $keys[$platform], $security[$platform]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -18,6 +18,7 @@ use Utopia\CLI\Console;
|
||||||
ini_set('memory_limit','512M');
|
ini_set('memory_limit','512M');
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
ini_set('display_startup_errors', 1);
|
ini_set('display_startup_errors', 1);
|
||||||
|
ini_set('default_socket_timeout', -1);
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
$http = new Server("0.0.0.0", App::getEnv('PORT', 80));
|
$http = new Server("0.0.0.0", App::getEnv('PORT', 80));
|
||||||
|
|
|
@ -8,38 +8,37 @@ use Appwrite\Event\Event;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
|
|
||||||
Console::title('Maintenance V1');
|
|
||||||
|
|
||||||
Console::success(APP_NAME.' maintenance process v1 has started');
|
|
||||||
|
|
||||||
function notifyDeleteExecutionLogs(int $interval)
|
|
||||||
{
|
|
||||||
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
|
||||||
'type' => DELETE_TYPE_EXECUTIONS,
|
|
||||||
'timestamp' => time() - $interval
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function notifyDeleteAbuseLogs(int $interval)
|
|
||||||
{
|
|
||||||
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
|
||||||
'type' => DELETE_TYPE_ABUSE,
|
|
||||||
'timestamp' => time() - $interval
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function notifyDeleteAuditLogs(int $interval)
|
|
||||||
{
|
|
||||||
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
|
||||||
'type' => DELETE_TYPE_AUDIT,
|
|
||||||
'timestamp' => time() - $interval
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$cli
|
$cli
|
||||||
->task('maintenance')
|
->task('maintenance')
|
||||||
->desc('Schedules maintenance tasks and publishes them to resque')
|
->desc('Schedules maintenance tasks and publishes them to resque')
|
||||||
->action(function () {
|
->action(function () {
|
||||||
|
Console::title('Maintenance V1');
|
||||||
|
Console::success(APP_NAME.' maintenance process v1 has started');
|
||||||
|
|
||||||
|
function notifyDeleteExecutionLogs(int $interval)
|
||||||
|
{
|
||||||
|
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
||||||
|
'type' => DELETE_TYPE_EXECUTIONS,
|
||||||
|
'timestamp' => time() - $interval
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function notifyDeleteAbuseLogs(int $interval)
|
||||||
|
{
|
||||||
|
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
||||||
|
'type' => DELETE_TYPE_ABUSE,
|
||||||
|
'timestamp' => time() - $interval
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function notifyDeleteAuditLogs(int $interval)
|
||||||
|
{
|
||||||
|
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
||||||
|
'type' => DELETE_TYPE_AUDIT,
|
||||||
|
'timestamp' => time() - $interval
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
// # of days in seconds (1 day = 86400s)
|
// # of days in seconds (1 day = 86400s)
|
||||||
$interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400');
|
$interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400');
|
||||||
$executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_EXECUTION', '1209600');
|
$executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_EXECUTION', '1209600');
|
||||||
|
|
|
@ -5,187 +5,26 @@ global $cli, $register, $projectDB, $console;
|
||||||
use Utopia\Config\Config;
|
use Utopia\Config\Config;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
use Appwrite\Database\Database;
|
use Appwrite\Database\Database;
|
||||||
use Appwrite\Database\Document;
|
|
||||||
use Appwrite\Database\Validator\Authorization;
|
use Appwrite\Database\Validator\Authorization;
|
||||||
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||||
|
use Appwrite\Migration\Version;
|
||||||
$callbacks = [
|
|
||||||
'0.4.0' => function() {
|
|
||||||
Console::log('I got nothing to do.');
|
|
||||||
},
|
|
||||||
|
|
||||||
'0.5.0' => function($project) use ($register, $projectDB) {
|
|
||||||
$db = $register->get('db');
|
|
||||||
|
|
||||||
Console::log('Migrating project: '.$project->getAttribute('name').' ('.$project->getId().')');
|
|
||||||
|
|
||||||
// Update all documents $uid -> $id
|
|
||||||
|
|
||||||
$limit = 30;
|
|
||||||
$sum = 30;
|
|
||||||
$offset = 0;
|
|
||||||
|
|
||||||
while ($sum >= 30) {
|
|
||||||
$all = $projectDB->getCollection([
|
|
||||||
'limit' => $limit,
|
|
||||||
'offset' => $offset,
|
|
||||||
'orderType' => 'DESC',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$sum = \count($all);
|
|
||||||
|
|
||||||
Console::log('Migrating: '.$offset.' / '.$projectDB->getSum());
|
|
||||||
|
|
||||||
foreach($all as $document) {
|
|
||||||
$document = fixDocument($document);
|
|
||||||
|
|
||||||
if(empty($document->getId())) {
|
|
||||||
throw new Exception('Missing ID');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$new = $projectDB->overwriteDocument($document->getArrayCopy());
|
|
||||||
} catch (\Throwable $th) {
|
|
||||||
var_dump($document);
|
|
||||||
Console::error('Failed to update document: '.$th->getMessage());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($new->getId() !== $document->getId()) {
|
|
||||||
throw new Exception('Duplication Error');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$offset = $offset + $limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$schema = $_SERVER['_APP_DB_SCHEMA'] ?? '';
|
|
||||||
|
|
||||||
try {
|
|
||||||
$statement = $db->prepare("
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `template.database.unique` (
|
|
||||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
|
||||||
`key` varchar(128) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `index1` (`key`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `{$schema}`.`app_{$project->getId()}.database.unique` LIKE `template.database.unique`;
|
|
||||||
ALTER TABLE `{$schema}`.`app_{$project->getId()}.audit.audit` DROP COLUMN IF EXISTS `userType`;
|
|
||||||
ALTER TABLE `{$schema}`.`app_{$project->getId()}.audit.audit` DROP INDEX IF EXISTS `index_1`;
|
|
||||||
ALTER TABLE `{$schema}`.`app_{$project->getId()}.audit.audit` ADD INDEX IF NOT EXISTS `index_1` (`userId` ASC);
|
|
||||||
");
|
|
||||||
|
|
||||||
$statement->closeCursor();
|
|
||||||
|
|
||||||
$statement->execute();
|
|
||||||
}
|
|
||||||
catch (\Exception $e) {
|
|
||||||
Console::error('Failed to alter table for project: '.$project->getId().' with message: '.$e->getMessage().'/');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function fixDocument(Document $document) {
|
|
||||||
$providers = Config::getParam('providers');
|
|
||||||
|
|
||||||
if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_PROJECTS){
|
|
||||||
foreach($providers as $key => $provider) {
|
|
||||||
if(!empty($document->getAttribute('usersOauth'.\ucfirst($key).'Appid'))) {
|
|
||||||
$document
|
|
||||||
->setAttribute('usersOauth2'.\ucfirst($key).'Appid', $document->getAttribute('usersOauth'.\ucfirst($key).'Appid', ''))
|
|
||||||
->removeAttribute('usersOauth'.\ucfirst($key).'Appid')
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($document->getAttribute('usersOauth'.\ucfirst($key).'Secret'))) {
|
|
||||||
$document
|
|
||||||
->setAttribute('usersOauth2'.\ucfirst($key).'Secret', $document->getAttribute('usersOauth'.\ucfirst($key).'Secret', ''))
|
|
||||||
->removeAttribute('usersOauth'.\ucfirst($key).'Secret')
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_WEBHOOKS){
|
|
||||||
$document->setAttribute('security', ($document->getAttribute('security')) ? true : false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_TASKS){
|
|
||||||
$document->setAttribute('security', ($document->getAttribute('security')) ? true : false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_USERS) {
|
|
||||||
foreach($providers as $key => $provider) {
|
|
||||||
if(!empty($document->getAttribute('oauth'.\ucfirst($key)))) {
|
|
||||||
$document
|
|
||||||
->setAttribute('oauth2'.\ucfirst($key), $document->getAttribute('oauth'.\ucfirst($key), ''))
|
|
||||||
->removeAttribute('oauth'.\ucfirst($key))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($document->getAttribute('oauth'.\ucfirst($key).'AccessToken'))) {
|
|
||||||
$document
|
|
||||||
->setAttribute('oauth2'.\ucfirst($key).'AccessToken', $document->getAttribute('oauth'.\ucfirst($key).'AccessToken', ''))
|
|
||||||
->removeAttribute('oauth'.\ucfirst($key).'AccessToken')
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($document->getAttribute('confirm', null) !== null) {
|
|
||||||
$document
|
|
||||||
->setAttribute('emailVerification', $document->getAttribute('confirm', $document->getAttribute('emailVerification', false)))
|
|
||||||
->removeAttribute('confirm')
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_PLATFORMS) {
|
|
||||||
if($document->getAttribute('url', null) !== null) {
|
|
||||||
$document
|
|
||||||
->setAttribute('hostname', \parse_url($document->getAttribute('url', $document->getAttribute('hostname', '')), PHP_URL_HOST))
|
|
||||||
->removeAttribute('url')
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$document
|
|
||||||
->setAttribute('$id', $document->getAttribute('$uid', $document->getAttribute('$id')))
|
|
||||||
->removeAttribute('$uid')
|
|
||||||
;
|
|
||||||
|
|
||||||
foreach($document as &$attr) { // Handle child documents
|
|
||||||
if($attr instanceof Document) {
|
|
||||||
$attr = fixDocument($attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(\is_array($attr)) {
|
|
||||||
foreach($attr as &$child) {
|
|
||||||
if($child instanceof Document) {
|
|
||||||
$child = fixDocument($child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $document;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cli
|
$cli
|
||||||
->task('migrate')
|
->task('migrate')
|
||||||
->action(function () use ($register, $callbacks) {
|
->action(function () use ($register) {
|
||||||
Console::success('Starting Data Migration');
|
Console::success('Starting Data Migration');
|
||||||
|
|
||||||
$consoleDB = new Database();
|
$consoleDB = new Database();
|
||||||
$consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register));
|
$consoleDB
|
||||||
$consoleDB->setNamespace('app_console'); // Main DB
|
->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register))
|
||||||
$consoleDB->setMocks(Config::getParam('collections', []));
|
->setNamespace('app_console') // Main DB
|
||||||
|
->setMocks(Config::getParam('collections', []));
|
||||||
|
|
||||||
$projectDB = new Database();
|
$projectDB = new Database();
|
||||||
$projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register));
|
$projectDB
|
||||||
$projectDB->setMocks(Config::getParam('collections', []));
|
->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register))
|
||||||
|
->setMocks(Config::getParam('collections', []));
|
||||||
|
|
||||||
$console = $consoleDB->getDocument('console');
|
$console = $consoleDB->getDocument('console');
|
||||||
|
|
||||||
|
@ -197,13 +36,14 @@ $cli
|
||||||
$projects = [$console];
|
$projects = [$console];
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
while ($sum >= 30) {
|
$migration = new Version\V06($register->get('db')); //TODO: remove hardcoded version and move to dynamic migration
|
||||||
foreach($projects as $project) {
|
|
||||||
|
|
||||||
$projectDB->setNamespace('app_'.$project->getId());
|
|
||||||
|
|
||||||
|
while ($sum > 0) {
|
||||||
|
foreach ($projects as $project) {
|
||||||
try {
|
try {
|
||||||
$callbacks['0.5.0']($project, $projectDB);
|
$migration
|
||||||
|
->setProject($project, $projectDB)
|
||||||
|
->execute();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
throw $th;
|
throw $th;
|
||||||
Console::error('Failed to update project ("'.$project->getId().'") version with error: '.$th->getMessage());
|
Console::error('Failed to update project ("'.$project->getId().'") version with error: '.$th->getMessage());
|
||||||
|
@ -221,9 +61,11 @@ $cli
|
||||||
$sum = \count($projects);
|
$sum = \count($projects);
|
||||||
$offset = $offset + $limit;
|
$offset = $offset + $limit;
|
||||||
$count = $count + $sum;
|
$count = $count + $sum;
|
||||||
|
|
||||||
Console::log('Fetched '.$count.'/'.$consoleDB->getSum().' projects...');
|
if ($sum > 0) {
|
||||||
|
Console::log('Fetched '.$count.'/'.$consoleDB->getSum().' projects...');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::success('Data Migration Completed');
|
Console::success('Data Migration Completed');
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||||
use Appwrite\Database\Validator\Authorization;
|
use Appwrite\Database\Validator\Authorization;
|
||||||
use Appwrite\Event\Event;
|
use Appwrite\Event\Event;
|
||||||
|
use Cron\CronExpression;
|
||||||
use Swoole\Runtime;
|
use Swoole\Runtime;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
|
@ -27,7 +28,7 @@ $environments = Config::getParam('environments');
|
||||||
$warmupStart = \microtime(true);
|
$warmupStart = \microtime(true);
|
||||||
|
|
||||||
Co\run(function() use ($environments) { // Warmup: make sure images are ready to run fast 🚀
|
Co\run(function() use ($environments) { // Warmup: make sure images are ready to run fast 🚀
|
||||||
Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||||
|
|
||||||
foreach($environments as $environment) {
|
foreach($environments as $environment) {
|
||||||
go(function() use ($environment) {
|
go(function() use ($environment) {
|
||||||
|
@ -79,14 +80,6 @@ $stdout = \explode("\n", $stdout);
|
||||||
\parse_str($value, $container);
|
\parse_str($value, $container);
|
||||||
|
|
||||||
if(isset($container['name'])) {
|
if(isset($container['name'])) {
|
||||||
// $labels = [];
|
|
||||||
// $temp = explode(',', $container['labels'] ?? []);
|
|
||||||
|
|
||||||
// foreach($temp as &$label) {
|
|
||||||
// $label = explode('=', $label);
|
|
||||||
// $labels[$label[0] || 0] = $label[1] || '';
|
|
||||||
// }
|
|
||||||
|
|
||||||
$container = [
|
$container = [
|
||||||
'name' => $container['name'],
|
'name' => $container['name'],
|
||||||
'online' => (\substr($container['status'], 0, 2) === 'Up'),
|
'online' => (\substr($container['status'], 0, 2) === 'Up'),
|
||||||
|
@ -142,6 +135,7 @@ class FunctionsV1
|
||||||
$executionId = $this->args['executionId'] ?? '';
|
$executionId = $this->args['executionId'] ?? '';
|
||||||
$trigger = $this->args['trigger'] ?? '';
|
$trigger = $this->args['trigger'] ?? '';
|
||||||
$event = $this->args['event'] ?? '';
|
$event = $this->args['event'] ?? '';
|
||||||
|
$scheduleOriginal = $this->args['scheduleOriginal'] ?? '';
|
||||||
$payload = (!empty($this->args['payload'])) ? json_encode($this->args['payload']) : '';
|
$payload = (!empty($this->args['payload'])) ? json_encode($this->args['payload']) : '';
|
||||||
|
|
||||||
$database = new Database();
|
$database = new Database();
|
||||||
|
@ -190,9 +184,7 @@ class FunctionsV1
|
||||||
|
|
||||||
Console::success('Triggered function: '.$event);
|
Console::success('Triggered function: '.$event);
|
||||||
|
|
||||||
Swoole\Coroutine\run(function () use ($projectId, $database, $function, $event, $payload) {
|
$this->execute('event', $projectId, '', $database, $function, $event, $payload);
|
||||||
$this->execute('event', $projectId, '', $database, $function, $event, $payload);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -210,6 +202,45 @@ class FunctionsV1
|
||||||
* On failure add error count
|
* On failure add error count
|
||||||
* If error count bigger than allowed change status to pause
|
* If error count bigger than allowed change status to pause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Reschedule
|
||||||
|
Authorization::disable();
|
||||||
|
$function = $database->getDocument($functionId);
|
||||||
|
Authorization::reset();
|
||||||
|
|
||||||
|
if (empty($function->getId()) || Database::SYSTEM_COLLECTION_FUNCTIONS != $function->getCollection()) {
|
||||||
|
throw new Exception('Function not found ('.$functionId.')');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($scheduleOriginal && $scheduleOriginal !== $function->getAttribute('schedule')) { // Schedule has changed from previous run, ignore this run.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cron = CronExpression::factory($function->getAttribute('schedule'));
|
||||||
|
$next = (int) $cron->getNextRunDate()->format('U');
|
||||||
|
|
||||||
|
$function
|
||||||
|
->setAttribute('scheduleNext', $next)
|
||||||
|
->setAttribute('schedulePrevious', \time())
|
||||||
|
;
|
||||||
|
|
||||||
|
Authorization::disable();
|
||||||
|
|
||||||
|
$function = $database->updateDocument(array_merge($function->getArrayCopy(), [
|
||||||
|
'scheduleNext' => $next,
|
||||||
|
]));
|
||||||
|
|
||||||
|
Authorization::reset();
|
||||||
|
|
||||||
|
ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [
|
||||||
|
'projectId' => $projectId,
|
||||||
|
'functionId' => $function->getId(),
|
||||||
|
'executionId' => null,
|
||||||
|
'trigger' => 'schedule',
|
||||||
|
'scheduleOriginal' => $function->getAttribute('schedule', ''),
|
||||||
|
]); // Async task rescheduale
|
||||||
|
|
||||||
|
$this->execute($trigger, $projectId, $executionId, $database, $function);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -222,9 +253,7 @@ class FunctionsV1
|
||||||
throw new Exception('Function not found ('.$functionId.')');
|
throw new Exception('Function not found ('.$functionId.')');
|
||||||
}
|
}
|
||||||
|
|
||||||
Swoole\Coroutine\run(function () use ($trigger, $projectId, $executionId, $database, $function) {
|
$this->execute($trigger, $projectId, $executionId, $database, $function);
|
||||||
$this->execute($trigger, $projectId, $executionId, $database, $function);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -278,8 +307,8 @@ class FunctionsV1
|
||||||
'time' => 0,
|
'time' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if(false === $execution) {
|
if(false === $execution || ($execution instanceof Document && $execution->isEmpty())) {
|
||||||
throw new Exception('Failed to create execution');
|
throw new Exception('Failed to create or read execution');
|
||||||
}
|
}
|
||||||
|
|
||||||
Authorization::reset();
|
Authorization::reset();
|
||||||
|
|
|
@ -57,6 +57,11 @@ class Database
|
||||||
*/
|
*/
|
||||||
static protected $filters = [];
|
static protected $filters = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
static protected $statusFilters = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -214,7 +219,7 @@ class Database
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Document|bool
|
* @return Document
|
||||||
*
|
*
|
||||||
* @throws AuthorizationException
|
* @throws AuthorizationException
|
||||||
* @throws StructureException
|
* @throws StructureException
|
||||||
|
@ -448,6 +453,26 @@ class Database
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable Attribute decoding
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function disableFilters(): void
|
||||||
|
{
|
||||||
|
self::$statusFilters = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable Attribute decoding
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function enableFilters(): void
|
||||||
|
{
|
||||||
|
self::$statusFilters = true;
|
||||||
|
}
|
||||||
|
|
||||||
public function encode(Document $document):Document
|
public function encode(Document $document):Document
|
||||||
{
|
{
|
||||||
$collection = $this->getDocument($document->getCollection(), true , false);
|
$collection = $this->getDocument($document->getCollection(), true , false);
|
||||||
|
@ -550,6 +575,10 @@ class Database
|
||||||
*/
|
*/
|
||||||
static protected function decodeAttribute(string $name, $value)
|
static protected function decodeAttribute(string $name, $value)
|
||||||
{
|
{
|
||||||
|
if (!self::$statusFilters) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset(self::$filters[$name])) {
|
if (!isset(self::$filters[$name])) {
|
||||||
return $value;
|
return $value;
|
||||||
throw new Exception('Filter not found');
|
throw new Exception('Filter not found');
|
||||||
|
|
119
src/Appwrite/Migration/Migration.php
Normal file
119
src/Appwrite/Migration/Migration.php
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Migration;
|
||||||
|
|
||||||
|
use Appwrite\Database\Document;
|
||||||
|
use Appwrite\Database\Database;
|
||||||
|
use PDO;
|
||||||
|
use Swoole\Runtime;
|
||||||
|
use Utopia\CLI\Console;
|
||||||
|
use Utopia\Exception;
|
||||||
|
|
||||||
|
abstract class Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var PDO
|
||||||
|
*/
|
||||||
|
protected PDO $db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected int $limit = 50;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Document
|
||||||
|
*/
|
||||||
|
protected Document $project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Database
|
||||||
|
*/
|
||||||
|
protected Database $projectDB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migration constructor.
|
||||||
|
*
|
||||||
|
* @param PDO $pdo
|
||||||
|
*/
|
||||||
|
public function __construct(PDO $db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set project for migration.
|
||||||
|
*
|
||||||
|
* @param Document $project
|
||||||
|
* @param Database $projectDB
|
||||||
|
*
|
||||||
|
* @return Migration
|
||||||
|
*/
|
||||||
|
public function setProject(Document $project, Database $projectDB): Migration
|
||||||
|
{
|
||||||
|
$this->project = $project;
|
||||||
|
$this->projectDB = $projectDB;
|
||||||
|
$this->projectDB->setNamespace('app_' . $project->getId());
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates through every document.
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
*/
|
||||||
|
public function forEachDocument(callable $callback): void
|
||||||
|
{
|
||||||
|
$sum = $this->limit;
|
||||||
|
$offset = 0;
|
||||||
|
|
||||||
|
while ($sum >= $this->limit) {
|
||||||
|
$all = $this->projectDB->getCollection([
|
||||||
|
'limit' => $this->limit,
|
||||||
|
'offset' => $offset,
|
||||||
|
'orderType' => 'DESC',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$sum = \count($all);
|
||||||
|
Runtime::setHookFlags(SWOOLE_HOOK_ALL);
|
||||||
|
|
||||||
|
Console::log('Migrating: ' . $offset . ' / ' . $this->projectDB->getSum());
|
||||||
|
\Co\run(function () use ($all, $callback) {
|
||||||
|
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||||
|
|
||||||
|
foreach ($all as $document) {
|
||||||
|
go(function () use ($document, $callback) {
|
||||||
|
|
||||||
|
$old = $document->getArrayCopy();
|
||||||
|
$new = call_user_func($callback, $document);
|
||||||
|
|
||||||
|
if (empty($new->getId())) {
|
||||||
|
throw new Exception('Missing ID');
|
||||||
|
}
|
||||||
|
if (!array_diff($new->getArrayCopy(), $old)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$new = $this->projectDB->overwriteDocument($document->getArrayCopy());
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Console::error('Failed to update document: ' . $th->getMessage());
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ($document && $new->getId() !== $document->getId()) {
|
||||||
|
throw new Exception('Duplication Error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$offset += $this->limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes migration for set project.
|
||||||
|
*/
|
||||||
|
abstract public function execute(): void;
|
||||||
|
}
|
14
src/Appwrite/Migration/Version/V04.php
Normal file
14
src/Appwrite/Migration/Version/V04.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Migration\Version;
|
||||||
|
|
||||||
|
use Utopia\CLI\Console;
|
||||||
|
use Appwrite\Migration\Migration;
|
||||||
|
|
||||||
|
class V04 extends Migration
|
||||||
|
{
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
Console::log('I got nothing to do.');
|
||||||
|
}
|
||||||
|
}
|
126
src/Appwrite/Migration/Version/V05.php
Normal file
126
src/Appwrite/Migration/Version/V05.php
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Migration\Version;
|
||||||
|
|
||||||
|
use Appwrite\Migration\Migration;
|
||||||
|
use Utopia\Config\Config;
|
||||||
|
use Utopia\CLI\Console;
|
||||||
|
use Appwrite\Database\Database;
|
||||||
|
use Appwrite\Database\Document;
|
||||||
|
|
||||||
|
class V05 extends Migration
|
||||||
|
{
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
$db = $this->db;
|
||||||
|
$project = $this->project;
|
||||||
|
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
|
||||||
|
|
||||||
|
// Update all documents $uid -> $id
|
||||||
|
|
||||||
|
$this->forEachDocument([$this, 'fixDocument']);
|
||||||
|
|
||||||
|
$schema = $_SERVER['_APP_DB_SCHEMA'] ?? '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$statement = $db->prepare("
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `template.database.unique` (
|
||||||
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`key` varchar(128) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `index1` (`key`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `{$schema}`.`app_{$project->getId()}.database.unique` LIKE `template.database.unique`;
|
||||||
|
ALTER TABLE `{$schema}`.`app_{$project->getId()}.audit.audit` DROP COLUMN IF EXISTS `userType`;
|
||||||
|
ALTER TABLE `{$schema}`.`app_{$project->getId()}.audit.audit` DROP INDEX IF EXISTS `index_1`;
|
||||||
|
ALTER TABLE `{$schema}`.`app_{$project->getId()}.audit.audit` ADD INDEX IF NOT EXISTS `index_1` (`userId` ASC);
|
||||||
|
");
|
||||||
|
|
||||||
|
$statement->closeCursor();
|
||||||
|
|
||||||
|
$statement->execute();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Console::error('Failed to alter table for project: ' . $project->getId() . ' with message: ' . $e->getMessage() . '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function fixDocument(Document $document)
|
||||||
|
{
|
||||||
|
$providers = Config::getParam('providers');
|
||||||
|
|
||||||
|
switch ($document->getAttribute('$collection')) {
|
||||||
|
case Database::SYSTEM_COLLECTION_PROJECTS:
|
||||||
|
foreach ($providers as $key => $provider) {
|
||||||
|
if (!empty($document->getAttribute('usersOauth' . \ucfirst($key) . 'Appid'))) {
|
||||||
|
$document
|
||||||
|
->setAttribute('usersOauth2' . \ucfirst($key) . 'Appid', $document->getAttribute('usersOauth' . \ucfirst($key) . 'Appid', ''))
|
||||||
|
->removeAttribute('usersOauth' . \ucfirst($key) . 'Appid');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($document->getAttribute('usersOauth' . \ucfirst($key) . 'Secret'))) {
|
||||||
|
$document
|
||||||
|
->setAttribute('usersOauth2' . \ucfirst($key) . 'Secret', $document->getAttribute('usersOauth' . \ucfirst($key) . 'Secret', ''))
|
||||||
|
->removeAttribute('usersOauth' . \ucfirst($key) . 'Secret');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$document->setAttribute('security', $document->getAttribute('security') ? true : false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Database::SYSTEM_COLLECTION_TASKS:
|
||||||
|
$document->setAttribute('security', $document->getAttribute('security') ? true : false);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Database::SYSTEM_COLLECTION_USERS:
|
||||||
|
foreach ($providers as $key => $provider) {
|
||||||
|
if (!empty($document->getAttribute('oauth' . \ucfirst($key)))) {
|
||||||
|
$document
|
||||||
|
->setAttribute('oauth2' . \ucfirst($key), $document->getAttribute('oauth' . \ucfirst($key), ''))
|
||||||
|
->removeAttribute('oauth' . \ucfirst($key));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($document->getAttribute('oauth' . \ucfirst($key) . 'AccessToken'))) {
|
||||||
|
$document
|
||||||
|
->setAttribute('oauth2' . \ucfirst($key) . 'AccessToken', $document->getAttribute('oauth' . \ucfirst($key) . 'AccessToken', ''))
|
||||||
|
->removeAttribute('oauth' . \ucfirst($key) . 'AccessToken');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($document->getAttribute('confirm', null) !== null) {
|
||||||
|
$document
|
||||||
|
->setAttribute('emailVerification', $document->getAttribute('confirm', $document->getAttribute('emailVerification', false)))
|
||||||
|
->removeAttribute('confirm');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Database::SYSTEM_COLLECTION_PLATFORMS:
|
||||||
|
if ($document->getAttribute('url', null) !== null) {
|
||||||
|
$document
|
||||||
|
->setAttribute('hostname', \parse_url($document->getAttribute('url', $document->getAttribute('hostname', '')), PHP_URL_HOST))
|
||||||
|
->removeAttribute('url');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$document
|
||||||
|
->setAttribute('$id', $document->getAttribute('$uid', $document->getAttribute('$id')))
|
||||||
|
->removeAttribute('$uid');
|
||||||
|
|
||||||
|
foreach ($document as &$attr) { // Handle child documents
|
||||||
|
if ($attr instanceof Document) {
|
||||||
|
$attr = $this->fixDocument($attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\is_array($attr)) {
|
||||||
|
foreach ($attr as &$child) {
|
||||||
|
if ($child instanceof Document) {
|
||||||
|
$child = $this->fixDocument($child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
}
|
60
src/Appwrite/Migration/Version/V06.php
Normal file
60
src/Appwrite/Migration/Version/V06.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Migration\Version;
|
||||||
|
|
||||||
|
|
||||||
|
use Utopia\App;
|
||||||
|
use Utopia\CLI\Console;
|
||||||
|
use Appwrite\Database\Database;
|
||||||
|
use Appwrite\Database\Document;
|
||||||
|
use Appwrite\Migration\Migration;
|
||||||
|
use Appwrite\OpenSSL\OpenSSL;
|
||||||
|
|
||||||
|
class V06 extends Migration
|
||||||
|
{
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
$project = $this->project;
|
||||||
|
Console::log('Migrating project: ' . $project->getAttribute('name') . ' (' . $project->getId() . ')');
|
||||||
|
|
||||||
|
$this->projectDB->disableFilters();
|
||||||
|
$this->forEachDocument([$this, 'fixDocument']);
|
||||||
|
$this->projectDB->enableFilters();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function fixDocument(Document $document)
|
||||||
|
{
|
||||||
|
switch ($document->getAttribute('$collection')) {
|
||||||
|
case Database::SYSTEM_COLLECTION_USERS:
|
||||||
|
if ($document->getAttribute('password-update', null)) {
|
||||||
|
$document
|
||||||
|
->setAttribute('passwordUpdate', $document->getAttribute('password-update', $document->getAttribute('passwordUpdate', '')))
|
||||||
|
->removeAttribute('password-update');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Database::SYSTEM_COLLECTION_KEYS:
|
||||||
|
if ($document->getAttribute('secret', null)) {
|
||||||
|
$json = \json_decode($document->getAttribute('secret'));
|
||||||
|
if ($json->{'data'} || $json->{'method'} || $json->{'iv'} || $json->{'tag'} || $json->{'version'})
|
||||||
|
{
|
||||||
|
Console::log('Secret already encrypted. Skipped: ' . $document->getId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||||
|
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||||
|
$tag = null;
|
||||||
|
|
||||||
|
$document->setAttribute('secret', json_encode([
|
||||||
|
'data' => OpenSSL::encrypt($document->getAttribute('secret'), OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag),
|
||||||
|
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||||
|
'iv' => bin2hex($iv),
|
||||||
|
'tag' => bin2hex($tag),
|
||||||
|
'version' => '1',
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,11 @@ abstract class Format
|
||||||
*/
|
*/
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $services;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Route[]
|
* @var Route[]
|
||||||
*/
|
*/
|
||||||
|
@ -53,14 +58,16 @@ abstract class Format
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param App $app
|
* @param App $app
|
||||||
|
* @param array $services
|
||||||
* @param Route[] $routes
|
* @param Route[] $routes
|
||||||
* @param Model[] $models
|
* @param Model[] $models
|
||||||
* @param array $keys
|
* @param array $keys
|
||||||
* @param array $security
|
* @param array $security
|
||||||
*/
|
*/
|
||||||
public function __construct(App $app, array $routes, array $models, array $keys, array $security)
|
public function __construct(App $app, array $services, array $routes, array $models, array $keys, array $security)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
|
$this->services = $services;
|
||||||
$this->routes = $routes;
|
$this->routes = $routes;
|
||||||
$this->models = $models;
|
$this->models = $models;
|
||||||
$this->keys = $keys;
|
$this->keys = $keys;
|
||||||
|
|
|
@ -56,6 +56,7 @@ class OpenAPI3 extends Format
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'paths' => [],
|
'paths' => [],
|
||||||
|
'tags' => $this->services,
|
||||||
'components' => [
|
'components' => [
|
||||||
'schemas' => [],
|
'schemas' => [],
|
||||||
'securitySchemes' => $this->keys,
|
'securitySchemes' => $this->keys,
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Swagger2 extends Format
|
||||||
'produces' => ['application/json'],
|
'produces' => ['application/json'],
|
||||||
'securityDefinitions' => $this->keys,
|
'securityDefinitions' => $this->keys,
|
||||||
'paths' => [],
|
'paths' => [],
|
||||||
|
'tags' => $this->services,
|
||||||
'definitions' => [],
|
'definitions' => [],
|
||||||
'externalDocs' => [
|
'externalDocs' => [
|
||||||
'description' => $this->getParam('docs.description'),
|
'description' => $this->getParam('docs.description'),
|
||||||
|
|
|
@ -561,8 +561,9 @@ class FunctionsCustomServerTest extends Scope
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
sleep(count($envs) * 30);
|
sleep(count($envs) * 20);
|
||||||
fwrite(STDERR, ".");
|
fwrite(STDERR, ".");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for SUCCESS
|
* Test for SUCCESS
|
||||||
*/
|
*/
|
||||||
|
|
39
tests/unit/Migration/MigrationTest.php
Normal file
39
tests/unit/Migration/MigrationTest.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Tests;
|
||||||
|
|
||||||
|
use Appwrite\Database\Document;
|
||||||
|
use Appwrite\Migration\Migration;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use ReflectionMethod;
|
||||||
|
|
||||||
|
abstract class MigrationTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var PDO
|
||||||
|
*/
|
||||||
|
protected \PDO $pdo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Migration
|
||||||
|
*/
|
||||||
|
protected Migration $migration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ReflectionMethod
|
||||||
|
*/
|
||||||
|
protected ReflectionMethod $method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs every document fix twice, to prevent corrupted data on multiple migrations.
|
||||||
|
*
|
||||||
|
* @param Document $document
|
||||||
|
*/
|
||||||
|
protected function fixDocument(Document $document)
|
||||||
|
{
|
||||||
|
return $this->method->invokeArgs($this->migration, [
|
||||||
|
$this->method->invokeArgs($this->migration, [$document])
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
86
tests/unit/Migration/MigrationV05Test.php
Normal file
86
tests/unit/Migration/MigrationV05Test.php
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Tests;
|
||||||
|
|
||||||
|
use ReflectionClass;
|
||||||
|
use Appwrite\Migration\Version\V05;
|
||||||
|
use Appwrite\Database\Database;
|
||||||
|
use Appwrite\Database\Document;
|
||||||
|
use Utopia\Config\Config;
|
||||||
|
|
||||||
|
class MigrationV05Test extends MigrationTest
|
||||||
|
{
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
Config::load('providers', __DIR__ . '/../../../app/config/providers.php');
|
||||||
|
|
||||||
|
$this->pdo = new \PDO('sqlite::memory:');
|
||||||
|
$this->migration = new V05($this->pdo);
|
||||||
|
$reflector = new ReflectionClass('Appwrite\Migration\Version\V05');
|
||||||
|
$this->method = $reflector->getMethod('fixDocument');
|
||||||
|
$this->method->setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMigration()
|
||||||
|
{
|
||||||
|
$document = $this->fixDocument(new Document([
|
||||||
|
'$uid' => 'unique',
|
||||||
|
'$collection' => Database::SYSTEM_COLLECTION_PROJECTS,
|
||||||
|
'usersOauthGithubAppid' => 123,
|
||||||
|
'usersOauthGithubSecret' => 456
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('$uid', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('$id', null), 'unique');
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('usersOauthGithubAppid', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('usersOauth2GithubAppid', null), 123);
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('usersOauthGithubSecret', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('usersOauth2GithubSecret', null), 456);
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('security', true), false);
|
||||||
|
|
||||||
|
$document = $this->fixDocument(new Document([
|
||||||
|
'$uid' => 'unique',
|
||||||
|
'$collection' => Database::SYSTEM_COLLECTION_TASKS
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('$uid', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('$id', null), 'unique');
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('security', true), false);
|
||||||
|
|
||||||
|
$document = $this->fixDocument(new Document([
|
||||||
|
'$uid' => 'unique',
|
||||||
|
'$collection' => Database::SYSTEM_COLLECTION_USERS,
|
||||||
|
'oauthGithub' => 'id',
|
||||||
|
'oauthGithubAccessToken' => 'token',
|
||||||
|
'confirm' => false
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('$uid', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('$id', null), 'unique');
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('confirm', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('emailVerification', true), false);
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('oauthGithub', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('oauth2Github', null), 'id');
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('oauthGithubAccessToken', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('oauth2GithubAccessToken', null), 'token');
|
||||||
|
|
||||||
|
$document = $this->fixDocument(new Document([
|
||||||
|
'$uid' => 'unique',
|
||||||
|
'$collection' => Database::SYSTEM_COLLECTION_PLATFORMS,
|
||||||
|
'url' => 'https://appwrite.io'
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('$uid', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('$id', null), 'unique');
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('url', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('hostname', null), 'appwrite.io');
|
||||||
|
}
|
||||||
|
}
|
48
tests/unit/Migration/MigrationV06Test.php
Normal file
48
tests/unit/Migration/MigrationV06Test.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Tests;
|
||||||
|
|
||||||
|
use ReflectionClass;
|
||||||
|
use Appwrite\Migration\Version\V06;
|
||||||
|
use Appwrite\Database\Database;
|
||||||
|
use Appwrite\Database\Document;
|
||||||
|
|
||||||
|
class MigrationV06Test extends MigrationTest
|
||||||
|
{
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->pdo = new \PDO('sqlite::memory:');
|
||||||
|
|
||||||
|
$this->migration = new V06($this->pdo);
|
||||||
|
$reflector = new ReflectionClass('Appwrite\Migration\Version\V06');
|
||||||
|
$this->method = $reflector->getMethod('fixDocument');
|
||||||
|
$this->method->setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMigration()
|
||||||
|
{
|
||||||
|
$document = $this->fixDocument(new Document([
|
||||||
|
'$id' => uniqid(),
|
||||||
|
'$collection' => Database::SYSTEM_COLLECTION_USERS,
|
||||||
|
'password-update' => 123
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertEquals($document->getAttribute('password-update', null), null);
|
||||||
|
$this->assertEquals($document->getAttribute('passwordUpdate', null), 123);
|
||||||
|
|
||||||
|
$document = $this->fixDocument(
|
||||||
|
new Document([
|
||||||
|
'$id' => uniqid(),
|
||||||
|
'$collection' => Database::SYSTEM_COLLECTION_KEYS,
|
||||||
|
'secret' => 123
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$encrypted = json_decode($document->getAttribute('secret', null));
|
||||||
|
$this->assertObjectHasAttribute('data', $encrypted);
|
||||||
|
$this->assertObjectHasAttribute('method', $encrypted);
|
||||||
|
$this->assertObjectHasAttribute('iv', $encrypted);
|
||||||
|
$this->assertObjectHasAttribute('tag', $encrypted);
|
||||||
|
$this->assertObjectHasAttribute('version', $encrypted);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue