From c96f1e76e2296a7dabc5750484a809d57ec8ef5c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 5 Aug 2022 15:50:48 +0530 Subject: [PATCH] feat: add new attributes for API Keys --- app/config/collections.php | 29 ++++++++++++++++++++++ app/controllers/api/projects.php | 2 ++ app/controllers/general.php | 1 + src/Appwrite/Utopia/Response/Model/Key.php | 12 +++++++++ 4 files changed, 44 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index ecbe92c333..2f0949910c 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -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' => [], + ], ], ], diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 214af8e440..7eca6cfdc3 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -841,6 +841,8 @@ App::post('/v1/projects/:projectId/keys') 'name' => $name, 'scopes' => $scopes, 'expire' => $expire, + 'sdks' => [], + 'accessedAt' => 0, 'secret' => \bin2hex(\random_bytes(128)), ]); diff --git a/app/controllers/general.php b/app/controllers/general.php index c87d53c290..87edbdcff4 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -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, diff --git a/src/Appwrite/Utopia/Response/Model/Key.php b/src/Appwrite/Utopia/Response/Model/Key.php index 5c79c28b55..263725996a 100644 --- a/src/Appwrite/Utopia/Response/Model/Key.php +++ b/src/Appwrite/Utopia/Response/Model/Key.php @@ -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', + ]) ; }