1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00

feat: add new attributes for API Keys

This commit is contained in:
Christy Jacob 2022-08-05 15:50:48 +05:30
parent 78d02f50af
commit c96f1e76e2
4 changed files with 44 additions and 0 deletions

View file

@ -972,6 +972,28 @@ $collections = [
'array' => false,
'filters' => [],
],
[
'$id' => 'accessedAt',
'type' => Database::VAR_INTEGER,
'format' => '',
'size' => 0,
'signed' => false,
'required' => false,
'default' => 0,
'array' => false,
'filters' => [],
],
[
'$id' => 'sdks',
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => true,
'default' => null,
'array' => true,
'filters' => [],
],
],
'indexes' => [
[
@ -981,6 +1003,13 @@ $collections = [
'lengths' => [Database::LENGTH_KEY],
'orders' => [Database::ORDER_ASC],
],
[
'$id' => '_key_accessedAt',
'type' => Database::INDEX_KEY,
'attributes' => ['accessedAt'],
'lengths' => [],
'orders' => [],
],
],
],

View file

@ -841,6 +841,8 @@ App::post('/v1/projects/:projectId/keys')
'name' => $name,
'scopes' => $scopes,
'expire' => $expire,
'sdks' => [],
'accessedAt' => 0,
'secret' => \bin2hex(\random_bytes(128)),
]);

View file

@ -281,6 +281,7 @@ App::init()
* Mock user to app and grant API key scopes in addition to default app scopes
*/
if ($key && $user->isEmpty()) {
var_dump($key);
$user = new Document([
'$id' => '',
'status' => true,

View file

@ -58,6 +58,18 @@ class Key extends Model
'default' => '',
'example' => '919c2d18fb5d4...a2ae413da83346ad2',
])
->addRule('accessedAt', [
'type' => self::TYPE_INTEGER,
'description' => 'Most recent access date in Unix timestamp.',
'default' => null,
'example' => '1653990687',
])
->addRule('sdks', [
'type' => self::TYPE_STRING,
'description' => 'List of SDK user agents that used this key.',
'default' => null,
'example' => 'appwrite:flutter',
])
;
}