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

NSFS | NC | Use avj compile and Reuse validate Function #7887

Merged
merged 1 commit into from
Mar 17, 2024
Merged
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
19 changes: 13 additions & 6 deletions src/manage_nsfs/nsfs_schema_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ schema_utils.strictify(account_schema, {
additionalProperties: false
});

const validate_account = ajv.compile(account_schema);
const validate_bucket = ajv.compile(bucket_schema);
const validate_nsfs_config = ajv.compile(nsfs_config_schema);

// NOTE - DO NOT strictify nsfs_config_schema
// we might want to use it in the future for adding additional properties

Expand All @@ -44,9 +48,10 @@ schema_utils.strictify(account_schema, {
* @param {object} account
*/
function validate_account_schema(account) {
const valid = ajv.validate(account_schema, account);
const valid = validate_account(account);
if (!valid) {
const err_msg = ajv.errors[0].message ? create_schema_err_msg(ajv.errors[0]) : undefined;
const first_err = validate_account.errors[0];
const err_msg = first_err.message ? create_schema_err_msg(first_err) : undefined;
throw new RpcError('INVALID_SCHEMA', err_msg);
}
}
Expand All @@ -56,9 +61,10 @@ function validate_account_schema(account) {
* @param {object} bucket
*/
function validate_bucket_schema(bucket) {
const valid = ajv.validate(bucket_schema, bucket);
const valid = validate_bucket(bucket);
if (!valid) {
const err_msg = ajv.errors[0].message ? create_schema_err_msg(ajv.errors[0]) : undefined;
const first_err = validate_bucket.errors[0];
const err_msg = first_err.message ? create_schema_err_msg(first_err) : undefined;
throw new RpcError('INVALID_SCHEMA', err_msg);
}
}
Expand All @@ -68,9 +74,10 @@ function validate_bucket_schema(bucket) {
* @param {object} config
*/
function validate_nsfs_config_schema(config) {
const valid = ajv.validate(nsfs_config_schema, config);
const valid = validate_nsfs_config(config);
if (!valid) {
const err_msg = ajv.errors[0].message ? create_schema_err_msg(ajv.errors[0]) : undefined;
const first_err = validate_nsfs_config.errors[0];
const err_msg = first_err.message ? create_schema_err_msg(first_err) : undefined;
throw new RpcError('INVALID_SCHEMA', err_msg);
}
}
Expand Down