Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more complex filtering using Validators #867

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cli/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ project_name = "${projectName}"
# serve_static = "dist"


###############################################################################
# Filter Options
# WARNING: This option might have performance implications
# 'enable_subscribe_validator_filter' will filter results failing validation from
# the result set, instead of throwing an exception
#------------------------------------------------------------------------------
# enable_subscribe_validator_filter = false


###############################################################################
# Data Options
# WARNING: these should probably not be enabled on a publically accessible
Expand Down
1 change: 1 addition & 0 deletions cli/src/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ const processConfig = (parsed) => {

const start_horizon_server = (http_servers, opts) =>
new horizon_server.Server(http_servers, {
enable_subscribe_validator_filter: opts.enable_subscribe_validator_filter,
auto_create_collection: opts.auto_create_collection,
auto_create_index: opts.auto_create_index,
permissions: opts.permissions,
Expand Down
4 changes: 4 additions & 0 deletions cli/src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const make_default_options = () => ({
cert_file: './horizon-cert.pem',
schema_file: null,

// Enable subscribe validator filtering instead of exception throwing
enable_subscribe_validator_filter: false,

auto_create_collection: false,
auto_create_index: false,

Expand All @@ -59,6 +62,7 @@ const yes_no_options = [ 'debug',
'secure',
'permissions',
'start_rethinkdb',
'enable_subscribe_validator_filter',
'auto_create_index',
'auto_create_collection',
'allow_unauthenticated',
Expand Down
6 changes: 5 additions & 1 deletion server/src/endpoint/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ const run = (raw_request, context, ruleset, metadata, send, done) => {
send({ state: 'synced' });
} else if ((item.old_val && !ruleset.validate(context, item.old_val)) ||
(item.new_val && !ruleset.validate(context, item.new_val))) {
throw new Error('Operation not permitted.');
if (metadata._subscribe_validator_filter_enabled) {
console.log('Filtering record from result set')
} else {
throw new Error('Operation not permitted.');
}
} else {
send({ data: [ item ] });
}
Expand Down
2 changes: 2 additions & 0 deletions server/src/metadata/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ class Metadata {
constructor(project_name,
conn,
clients,
enable_subscribe_validator_filter,
auto_create_collection,
auto_create_index) {
this._db = project_name;
this._conn = conn;
this._clients = clients;
this._subscribe_validator_filter_enabled = enable_subscribe_validator_filter;
this._auto_create_collection = auto_create_collection;
this._auto_create_index = auto_create_index;
this._closed = false;
Expand Down
3 changes: 3 additions & 0 deletions server/src/reql_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const default_pass = '';

class ReqlConnection {
constructor(host, port, db,
enable_subscribe_validator_filter,
auto_create_collection, auto_create_index,
user, pass, connect_timeout,
interruptor) {
Expand All @@ -22,6 +23,7 @@ class ReqlConnection {
timeout: connect_timeout || null,
};

this._subscribe_validator_filter_enabled = enable_subscribe_validator_filter;
this._auto_create_collection = auto_create_collection;
this._auto_create_index = auto_create_index;
this._clients = new Set();
Expand Down Expand Up @@ -83,6 +85,7 @@ class ReqlConnection {
return new Metadata(this._rdb_options.db,
conn,
this._clients,
this._subscribe_validator_filter_enabled,
this._auto_create_collection,
this._auto_create_index).ready();
}).then((metadata) => {
Expand Down
2 changes: 2 additions & 0 deletions server/src/schema/server_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const server = Joi.object({
rdb_host: Joi.string().hostname().default('localhost'),
rdb_port: Joi.number().greater(0).less(65536).default(28015),

enable_subscribe_validator_filter: Joi.boolean().default(false),

auto_create_collection: Joi.boolean().default(false),
auto_create_index: Joi.boolean().default(false),

Expand Down
2 changes: 2 additions & 0 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Server {
this._name = opts.project_name;
this._max_connections = opts.max_connections;
this._permissions_enabled = opts.permissions;
this._subscribe_validator_filter_enabled = opts.enable_subscribe_validator_filter;
this._auth_methods = { };
this._request_handlers = new Map();
this._http_handlers = new Map();
Expand All @@ -84,6 +85,7 @@ class Server {
this._reql_conn = new ReqlConnection(opts.rdb_host,
opts.rdb_port,
opts.project_name,
opts.enable_subscribe_validator_filter,
opts.auto_create_collection,
opts.auto_create_index,
opts.rdb_user || null,
Expand Down