1
0
Fork 0
mirror of synced 2024-10-01 17:58:02 +13:00

add encrypt param

This commit is contained in:
Bishwajeet Parhi 2023-05-30 12:30:10 +05:30
parent f45905e545
commit 69504bfaac

View file

@ -1103,13 +1103,14 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string
->param('key', '', new Key(), 'Attribute Key.')
->param('size', null, new Range(1, APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH, Range::TYPE_INTEGER), 'Attribute size for text attributes, in number of characters.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('default', null, new Text(0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
->param('array', false, new Boolean(), 'Is attribute an array?', true)
->inject('response')
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?int $size, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?int $size, bool $required, ?bool $encrypt, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
// Ensure attribute default is within required size
$validator = new Text($size);
@ -1117,6 +1118,17 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string
throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, $validator->getDescription());
}
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
'type' => Database::VAR_STRING,
@ -1124,6 +1136,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string
'required' => $required,
'default' => $default,
'array' => $array,
'filters' => $filters,
]), $response, $dbForProject, $database, $events);
$response
@ -1152,13 +1165,25 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/email'
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('default', null, new Email(), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
->param('array', false, new Boolean(), 'Is attribute an array?', true)
->inject('response')
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, bool $encrypt, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
@ -1168,6 +1193,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/email'
'default' => $default,
'array' => $array,
'format' => APP_DATABASE_ATTRIBUTE_EMAIL,
'filters' => $filters
]), $response, $dbForProject, $database, $events);
$response
@ -1197,13 +1223,14 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum')
->param('key', '', new Key(), 'Attribute Key.')
->param('elements', [], new ArrayList(new Text(APP_LIMIT_ARRAY_ELEMENT_SIZE, min: 0), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of elements in enumerated type. Uses length of longest element to determine size. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' elements are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('default', null, new Text(0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
->param('array', false, new Boolean(), 'Is attribute an array?', true)
->inject('response')
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, bool $encrypt, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
// use length of longest string as attribute size
$size = 0;
@ -1219,6 +1246,17 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum')
throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Default value not found in elements');
}
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
'type' => Database::VAR_STRING,
@ -1228,6 +1266,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum')
'array' => $array,
'format' => APP_DATABASE_ATTRIBUTE_ENUM,
'formatOptions' => ['elements' => $elements],
'filters' => $filters
]), $response, $dbForProject, $database, $events);
$response
@ -1256,13 +1295,25 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/ip')
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('default', null, new IP(), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
->param('array', false, new Boolean(), 'Is attribute an array?', true)
->inject('response')
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, bool $encrypt, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
@ -1272,6 +1323,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/ip')
'default' => $default,
'array' => $array,
'format' => APP_DATABASE_ATTRIBUTE_IP,
'filters' => $filters,
]), $response, $dbForProject, $database, $events);
$response
@ -1300,13 +1352,25 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/url')
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('default', null, new URL(), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
->param('array', false, new Boolean(), 'Is attribute an array?', true)
->inject('response')
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, bool $encrypt, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
@ -1316,6 +1380,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/url')
'default' => $default,
'array' => $array,
'format' => APP_DATABASE_ATTRIBUTE_URL,
'filters' => $filters,
]), $response, $dbForProject, $database, $events);
$response
@ -1344,6 +1409,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/intege
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('min', null, new Integer(), 'Minimum value to enforce on new documents', true)
->param('max', null, new Integer(), 'Maximum value to enforce on new documents', true)
->param('default', null, new Integer(), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
@ -1352,7 +1418,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/intege
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, bool $encrypt, ?int $min, ?int $max, ?int $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
// Ensure attribute default is within range
$min = (is_null($min)) ? PHP_INT_MIN : \intval($min);
@ -1370,6 +1436,17 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/intege
$size = $max > 2147483647 ? 8 : 4; // Automatically create BigInt depending on max value
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
'type' => Database::VAR_INTEGER,
@ -1382,6 +1459,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/intege
'min' => $min,
'max' => $max,
],
'filters' => $filters,
]), $response, $dbForProject, $database, $events);
$formatOptions = $attribute->getAttribute('formatOptions', []);
@ -1417,6 +1495,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/float'
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('min', null, new FloatValidator(), 'Minimum value to enforce on new documents', true)
->param('max', null, new FloatValidator(), 'Maximum value to enforce on new documents', true)
->param('default', null, new FloatValidator(), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
@ -1425,7 +1504,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/float'
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?float $min, ?float $max, ?float $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, bool $encrypt, ?float $min, ?float $max, ?float $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
// Ensure attribute default is within range
$min = (is_null($min)) ? -PHP_FLOAT_MAX : \floatval($min);
@ -1446,6 +1525,17 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/float'
throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, $validator->getDescription());
}
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
'type' => Database::VAR_FLOAT,
@ -1458,6 +1548,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/float'
'min' => $min,
'max' => $max,
],
'filters' => $filters,
]), $response, $dbForProject, $database, $events);
$formatOptions = $attribute->getAttribute('formatOptions', []);
@ -1493,13 +1584,25 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/boolea
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('default', null, new Boolean(), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
->param('array', false, new Boolean(), 'Is attribute an array?', true)
->inject('response')
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?bool $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, bool $encrypt, ?bool $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
@ -1508,6 +1611,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/boolea
'required' => $required,
'default' => $default,
'array' => $array,
'filters' => $filters
]), $response, $dbForProject, $database, $events);
$response
@ -1536,13 +1640,27 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/dateti
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('encrypt', false, new Boolean(), 'Encrypt attribue? Encrypting an attribute means that the attribute can not be queried.', true)
->param('default', null, new DatetimeValidator(), 'Default value for the attribute in ISO 8601 format. Cannot be set when attribute is required.', true)
->param('array', false, new Boolean(), 'Is attribute an array?', true)
->inject('response')
->inject('dbForProject')
->inject('database')
->inject('events')
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
->action(function (string $databaseId, string $collectionId, string $key, ?bool $required, bool $encrypt, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {
$filters = [];
switch ($encrypt) {
case true:
$filters[] = 'encrypt';
break;
case false:
$filters[] = 'decrypt';
break;
}
$filters[] = 'datetime';
$attribute = createAttribute($databaseId, $collectionId, new Document([
'key' => $key,
@ -1551,7 +1669,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/dateti
'required' => $required,
'default' => $default,
'array' => $array,
'filters' => ['datetime']
'filters' => $filters,
]), $response, $dbForProject, $database, $events);
$response