Skip to content

Commit b86f768

Browse files
committed
Merge branch '0.16.x' of github.com:appwrite/appwrite into feat-audits-label-desc-decoupling
2 parents 342c4a3 + 36b45fd commit b86f768

34 files changed

Lines changed: 552 additions & 186 deletions

File tree

‎CHANGES.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Queries have been improved to allow even more flexibility, and introduced to new endpoints. See the Queries V2 section in the document for more information [#3702](https://github.com/appwrite/appwrite/pull/3702)
1111
- Compound indexes are now more flexible [#151](https://github.com/utopia-php/database/pull/151)
1212
- `createExecution` parameter `async` default value was changed from `true` to `false` [#3781](https://github.com/appwrite/appwrite/pull/3781)
13+
- `time` attribute in Execution response model has been reanamed to `duration` to be more consistent with other response models. [#3801](https://github.com/appwrite/appwrite/pull/3801)
1314

1415
## Features
1516
- Added the UI to see the Parent ID of all resources within the UI. [#3653](https://github.com/appwrite/appwrite/pull/3653)

‎app/config/collections.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,7 @@
26732673
'filters' => [],
26742674
],
26752675
[
2676-
'$id' => ID::custom('time'),
2676+
'$id' => ID::custom('duration'),
26772677
'type' => Database::VAR_FLOAT,
26782678
'format' => '',
26792679
'size' => 0,
@@ -2732,9 +2732,9 @@
27322732
'orders' => [Database::ORDER_ASC],
27332733
],
27342734
[
2735-
'$id' => ID::custom('_key_time'),
2735+
'$id' => ID::custom('_key_duration'),
27362736
'type' => Database::INDEX_KEY,
2737-
'attributes' => ['time'],
2737+
'attributes' => ['duration'],
27382738
'lengths' => [],
27392739
'orders' => [Database::ORDER_ASC],
27402740
],

‎app/controllers/api/avatars.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
->action(function (string $name, int $width, int $height, string $background, Response $response, Document $user) {
361361

362362
$themes = [
363-
['background' => '#F2F2F8'], // Default
363+
['background' => '#FFA1CE'], // Default (Pink)
364364
['background' => '#FDC584'], // Orange
365365
['background' => '#94DBD1'], // Green
366366
['background' => '#A1C4FF'], // Blue

‎app/controllers/api/databases.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
15851585

15861586
$oldAttributes[] = [
15871587
'key' => '$id',
1588-
'type' => 'string',
1588+
'type' => Database::VAR_STRING,
15891589
'status' => 'available',
15901590
'required' => true,
15911591
'array' => false,
@@ -1595,7 +1595,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
15951595

15961596
$oldAttributes[] = [
15971597
'key' => '$createdAt',
1598-
'type' => 'string',
1598+
'type' => Database::VAR_DATETIME,
15991599
'status' => 'available',
16001600
'signed' => false,
16011601
'required' => false,
@@ -1606,7 +1606,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att
16061606

16071607
$oldAttributes[] = [
16081608
'key' => '$updatedAt',
1609-
'type' => 'string',
1609+
'type' => Database::VAR_DATETIME,
16101610
'status' => 'available',
16111611
'signed' => false,
16121612
'required' => false,

‎app/controllers/api/functions.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@
10061006
'statusCode' => 0,
10071007
'response' => '',
10081008
'stderr' => '',
1009-
'time' => 0.0,
1009+
'duration' => 0.0,
10101010
'search' => implode(' ', [$functionId, $executionId]),
10111011
])));
10121012

@@ -1093,11 +1093,11 @@
10931093
$execution->setAttribute('response', $executionResponse['response']);
10941094
$execution->setAttribute('stdout', $executionResponse['stdout']);
10951095
$execution->setAttribute('stderr', $executionResponse['stderr']);
1096-
$execution->setAttribute('time', $executionResponse['time']);
1096+
$execution->setAttribute('duration', $executionResponse['duration']);
10971097
} catch (\Throwable $th) {
10981098
$interval = (new \DateTime())->diff(new \DateTime($execution->getCreatedAt()));
10991099
$execution
1100-
->setAttribute('time', (float)$interval->format('%s.%f'))
1100+
->setAttribute('duration', (float)$interval->format('%s.%f'))
11011101
->setAttribute('status', 'failed')
11021102
->setAttribute('statusCode', $th->getCode())
11031103
->setAttribute('stderr', $th->getMessage());
@@ -1111,7 +1111,7 @@
11111111
->setParam('functionId', $function->getId())
11121112
->setParam('executions.{scope}.compute', 1)
11131113
->setParam('executionStatus', $execution->getAttribute('status', ''))
1114-
->setParam('executionTime', $execution->getAttribute('time')); // ms
1114+
->setParam('executionTime', $execution->getAttribute('duration')); // ms
11151115

11161116
$roles = Authorization::getRoles();
11171117
$isPrivilegedUser = Auth::isPrivilegedUser($roles);

‎app/executor.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ function (string $runtimeId, array $vars, string $data, $timeout, $activeRuntime
503503

504504
$ch = \curl_init();
505505
$body = \json_encode([
506-
'env' => $vars,
506+
'variables' => $vars,
507507
'payload' => $data,
508508
'timeout' => $timeout
509509
]);
@@ -574,7 +574,7 @@ function (string $runtimeId, array $vars, string $data, $timeout, $activeRuntime
574574
'response' => \mb_strcut($res, 0, 1000000), // Limit to 1MB
575575
'stdout' => \mb_strcut($stdout, 0, 1000000), // Limit to 1MB
576576
'stderr' => \mb_strcut($stderr, 0, 1000000), // Limit to 1MB
577-
'time' => $executionTime,
577+
'duration' => $executionTime,
578578
];
579579

580580
/** Update swoole table */

‎app/tasks/maintenance.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function renewCertificates($dbForConsole)
108108
$time = DateTime::now();
109109

110110
$certificates = $dbForConsole->find('certificates', [
111-
Query::lessThanEqual('attempts', 5), // Maximum 5 attempts
111+
Query::lessThan('attempts', 5), // Maximum 5 attempts
112112
Query::lessThanEqual('renewDate', $time), // includes 60 days cooldown (we have 30 days to renew)
113113
Query::limit(200), // Limit 200 comes from LetsEncrypt (300 orders per 3 hours, keeping some for new domains)
114114
]);

‎app/views/console/databases/collection.phtml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ $permissions = $this->getParam('permissions', null);
508508
<li data-state="/console/databases/collection/settings?id={{router.params.id}}&databaseId={{router.params.databaseId}}&project={{router.params.project}}">
509509
<h2>Settings</h2>
510510

511-
<div class="row responsive margin-top-negative">
511+
<div class="row responsive">
512512
<div class="col span-8 margin-bottom">
513513
<form id="<?php echo $permissions->getParam('form') ?>"></form>
514514

‎app/workers/certificates.php‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Utopia\Database\Database;
99
use Utopia\Database\Document;
1010
use Utopia\Database\DateTime;
11+
use Utopia\Database\ID;
1112
use Utopia\Database\Query;
1213
use Utopia\Domains\Domain;
1314

@@ -100,8 +101,11 @@ public function run(): void
100101
throw new Exception('Renew isn\'t required.');
101102
}
102103

104+
// Prepare folder name for certbot. Using this helps prevent miss-match in LetsEncrypt configuration when renewing certificate
105+
$folder = ID::unique();
106+
103107
// Generate certificate files using Let's Encrypt
104-
$letsEncryptData = $this->issueCertificate($domain->get(), $email);
108+
$letsEncryptData = $this->issueCertificate($folder, $domain->get(), $email);
105109

106110
// Command succeeded, store all data into document
107111
// We store stderr too, because it may include warnings
@@ -111,7 +115,7 @@ public function run(): void
111115
]));
112116

113117
// Give certificates to Traefik
114-
$this->applyCertificateFiles($domain->get(), $letsEncryptData);
118+
$this->applyCertificateFiles($folder, $domain->get(), $letsEncryptData);
115119

116120
// Update certificate info stored in database
117121
$certificate->setAttribute('renewDate', $this->getRenewDate($domain->get()));
@@ -125,6 +129,9 @@ public function run(): void
125129
$attempts = $certificate->getAttribute('attempts', 0) + 1;
126130
$certificate->setAttribute('attempts', $attempts);
127131

132+
// Store cuttent time as renew date to ensure another attempt in next maintenance cycle
133+
$certificate->setAttribute('renewDate', DateTime::now());
134+
128135
// Send email to security email
129136
$this->notifyError($domain->get(), $e->getMessage(), $attempts);
130137
} finally {
@@ -259,18 +266,20 @@ private function isRenewRequired(string $domain): bool
259266
/**
260267
* LetsEncrypt communication to issue certificate (using certbot CLI)
261268
*
269+
* @param string $folder Folder into which certificates should be generated
262270
* @param string $domain Domain to generate certificate for
263271
*
264272
* @return array Named array with keys 'stdout' and 'stderr', both string
265273
*/
266-
private function issueCertificate(string $domain, string $email): array
274+
private function issueCertificate(string $folder, string $domain, string $email): array
267275
{
268276
$stdout = '';
269277
$stderr = '';
270278

271279
$staging = (App::isProduction()) ? '' : ' --dry-run';
272280
$exit = Console::execute("certbot certonly --webroot --noninteractive --agree-tos{$staging}"
273281
. " --email " . $email
282+
. " --cert-name " . $folder
274283
. " -w " . APP_STORAGE_CERTIFICATES
275284
. " -d {$domain}", '', $stdout, $stderr);
276285

@@ -290,9 +299,9 @@ private function issueCertificate(string $domain, string $email): array
290299
*
291300
* @param string $domain Domain which certificate was generated for
292301
*
293-
* @return int
302+
* @return string
294303
*/
295-
private function getRenewDate(string $domain): int
304+
private function getRenewDate(string $domain): string
296305
{
297306
$certPath = APP_STORAGE_CERTIFICATES . '/' . $domain . '/cert.pem';
298307
$certData = openssl_x509_parse(file_get_contents($certPath));
@@ -305,11 +314,12 @@ private function getRenewDate(string $domain): int
305314
* Method to take files from Let's Encrypt, and put it into Traefik.
306315
*
307316
* @param string $domain Domain which certificate was generated for
317+
* @param string $folder Folder in which certificates were generated
308318
* @param array $letsEncryptData Let's Encrypt logs to use for additional info when throwing error
309319
*
310320
* @return void
311321
*/
312-
private function applyCertificateFiles(string $domain, array $letsEncryptData): void
322+
private function applyCertificateFiles(string $folder, string $domain, array $letsEncryptData): void
313323
{
314324
// Prepare folder in storage for domain
315325
$path = APP_STORAGE_CERTIFICATES . '/' . $domain;
@@ -319,20 +329,20 @@ private function applyCertificateFiles(string $domain, array $letsEncryptData):
319329
}
320330
}
321331

322-
// Move generated files from certbot into our storage
323-
if (!@\rename('/etc/letsencrypt/live/' . $domain . '/cert.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/cert.pem')) {
332+
// Move generated files
333+
if (!@\rename('/etc/letsencrypt/live/' . $folder . '/cert.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/cert.pem')) {
324334
throw new Exception('Failed to rename certificate cert.pem. Let\'s Encrypt log: ' . $letsEncryptData['stderr'] . ' ; ' . $letsEncryptData['stdout']);
325335
}
326336

327-
if (!@\rename('/etc/letsencrypt/live/' . $domain . '/chain.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/chain.pem')) {
337+
if (!@\rename('/etc/letsencrypt/live/' . $folder . '/chain.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/chain.pem')) {
328338
throw new Exception('Failed to rename certificate chain.pem. Let\'s Encrypt log: ' . $letsEncryptData['stderr'] . ' ; ' . $letsEncryptData['stdout']);
329339
}
330340

331-
if (!@\rename('/etc/letsencrypt/live/' . $domain . '/fullchain.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/fullchain.pem')) {
341+
if (!@\rename('/etc/letsencrypt/live/' . $folder . '/fullchain.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/fullchain.pem')) {
332342
throw new Exception('Failed to rename certificate fullchain.pem. Let\'s Encrypt log: ' . $letsEncryptData['stderr'] . ' ; ' . $letsEncryptData['stdout']);
333343
}
334344

335-
if (!@\rename('/etc/letsencrypt/live/' . $domain . '/privkey.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/privkey.pem')) {
345+
if (!@\rename('/etc/letsencrypt/live/' . $folder . '/privkey.pem', APP_STORAGE_CERTIFICATES . '/' . $domain . '/privkey.pem')) {
336346
throw new Exception('Failed to rename certificate privkey.pem. Let\'s Encrypt log: ' . $letsEncryptData['stderr'] . ' ; ' . $letsEncryptData['stdout']);
337347
}
338348

‎app/workers/functions.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private function execute(
248248
'statusCode' => 0,
249249
'response' => '',
250250
'stderr' => '',
251-
'time' => 0.0,
251+
'duration' => 0.0,
252252
'search' => implode(' ', [$functionId, $executionId]),
253253
]));
254254

@@ -301,11 +301,11 @@ private function execute(
301301
->setAttribute('response', $executionResponse['response'])
302302
->setAttribute('stdout', $executionResponse['stdout'])
303303
->setAttribute('stderr', $executionResponse['stderr'])
304-
->setAttribute('time', $executionResponse['time']);
304+
->setAttribute('duration', $executionResponse['duration']);
305305
} catch (\Throwable $th) {
306306
$interval = (new \DateTime())->diff(new \DateTime($execution->getCreatedAt()));
307307
$execution
308-
->setAttribute('time', (float)$interval->format('%s.%f'))
308+
->setAttribute('duration', (float)$interval->format('%s.%f'))
309309
->setAttribute('status', 'failed')
310310
->setAttribute('statusCode', $th->getCode())
311311
->setAttribute('stderr', $th->getMessage());
@@ -367,7 +367,7 @@ private function execute(
367367
->setParam('functionId', $function->getId())
368368
->setParam('executions.{scope}.compute', 1)
369369
->setParam('executionStatus', $execution->getAttribute('status', ''))
370-
->setParam('executionTime', $execution->getAttribute('time'))
370+
->setParam('executionTime', $execution->getAttribute('duration'))
371371
->setParam('networkRequestSize', 0)
372372
->setParam('networkResponseSize', 0)
373373
->submit();

0 commit comments

Comments
 (0)