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

VLTCLT-54 : quota to bigInt relative changes #450

Open
wants to merge 12 commits into
base: development/8.4
Choose a base branch
from
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
"new-parens": "off",
"no-multi-spaces": "off",
"quote-props": "off"
},
"globals": {
"BigInt": "readonly"
}
}
4 changes: 2 additions & 2 deletions bin/vaultclient
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ program
.command('create-account')
.option('--name <NAME>')
.option('--email <EMAIL>')
.option('--quota <Quota>', 'Maximum quota for the account', parseInt)
.option('--quota <Quota>', 'Maximum quota for the account', BigInt)
.option('--accountid <ExternalAccountID>')
.option('--canonicalid <ExternalCanonicalID>')
.action(action.bind(null, 'create-account', (client, args) => {
Expand Down Expand Up @@ -216,7 +216,7 @@ program
program
.command('update-account-quota')
.option('--account-name <NAME>', 'Name of the account')
.option('--quota <QUOTA>', 'Maximum quota for the account', parseInt)
.option('--quota <QUOTA>', 'Maximum quota for the account', parseBigInt)
.option('--parameter-validation', 'Disable validation of quota')
.action(action.bind(null, 'update-account-quota', (client, args) => {
client.updateAccountQuota(args.accountName, args.quota, handleVaultResponse);
Expand Down
8 changes: 4 additions & 4 deletions lib/IAMClient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ declare class VaultClient {
* @param {string} accountName - account name
* @param {object} options - additional creation params
* @param {string} options.email - account email
* @param {string} [options.quota] - maximum quota for the account
* @param {bigint | number} [options.quota] - maximum quota for the account
* @param {VaultClient~requestCallback} callback - callback
* @returns {undefined}
*/
createAccount(accountName: string, options: {
email: string;
quota?: string;
quota?: bigint | number;
}, callback: any): undefined;
/**
* Create a password for an account
Expand Down Expand Up @@ -97,11 +97,11 @@ declare class VaultClient {
* Update Quota of an account
*
* @param {string} accountName - account name
* @param {number} quota - maximum quota for the account
* @param {bigint | number} quota - maximum quota for the account
* @param {VaultClient~requestCallback} callback - callback
* @returns {undefined}
*/
updateAccountQuota(accountName: string, quota: number, callback: any): undefined;
updateAccountQuota(accountName: string, quota: bigint | number, callback: any): undefined;
/**
* Delete Quota of an account
*
Expand Down
2 changes: 1 addition & 1 deletion lib/IAMClient.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 53 additions & 15 deletions lib/IAMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class VaultClient {
* @param {string} accountName - account name
* @param {object} options - additional creation params
* @param {string} options.email - account email
* @param {string} [options.quota] - maximum quota for the account
* @param {bigint | number} [options.quota] - maximum quota for the account
* @param {VaultClient~requestCallback} callback - callback
* @returns {undefined}
*/
Expand All @@ -146,11 +146,13 @@ class VaultClient {
} = options;

if (quota) {
const conv = Number.isNaN(Number.parseInt(quota, 10));
assert(typeof quota === 'number'
&& !conv
&& quota >= 0, 'Quota must be a non-negative number');
data.quotaMax = quota;
// ensure quota is a number or a bigint
assert(typeof quota === 'bigint' || typeof quota === 'number',
'Quota must be a number or a bigint');
// ensure quota is a non-negative number
assert(!this.parameterValidation || quota >= 0,
'Quota must be a non-negative number');
data.quotaMax = quota.toString();
}
if (externalAccountId) {
const conv = Number.isNaN(Number.parseInt(externalAccountId, 10));
Expand All @@ -176,13 +178,18 @@ class VaultClient {
data.disableSeed = disableSeed;
}

this.request('POST', '/', true, (err, result) => {
this.request('POST', '/', true, (err, result, ...params) => {
if (err) {
return callback(err);
}
if (result && result.account && result.account.data) {
// eslint-disable-next-line no-param-reassign
result.account.data.quotaMax = BigInt(result.account.data.quotaMax || 0);
}
return callback(null, {
account: result.account.data,
});
account: result && result.account && result.account.data ?
result.account.data : null,
}, ...params);
}, data);
}

Expand Down Expand Up @@ -287,24 +294,36 @@ class VaultClient {
* Update Quota of an account
*
* @param {string} accountName - account name
* @param {number} quota - maximum quota for the account
* @param {bigint | number} quota - maximum quota for the account
* @param {VaultClient~requestCallback} callback - callback
* @returns {undefined}
*/
updateAccountQuota(accountName, quota, callback) {
const quotaIsValid = (typeof quota === 'bigint' || typeof quota === 'number') && quota > 0;
assert(!this.parameterValidation || quotaIsValid, 'Quota must be a strictly positive bigint');
const data = {
Action: 'UpdateAccountQuota',
Version: '2010-05-08',
quotaMax: quota,
quotaMax: quota.toString(),
};
const quotaIsValid = typeof quota === 'number' && !Number.isNaN(Number.parseInt(quota, 10)) && quota > 0;
assert(!this.parameterValidation || quotaIsValid, 'Quota must be a strictly positive number');
if (accountName) {
assert(!this.parameterValidation || typeof accountName === 'string',
'the account name, if set, should be a string');
data.AccountName = accountName;
}
this.request('POST', '/', true, callback, data);
this.request('POST', '/', true, (err, response, ...params) => {
if (err) {
return callback(err);
}
if (response && response.quota) {
// eslint-disable-next-line no-param-reassign
response.quota = BigInt(response.quota || 0);
} else if (response && !response.quota) {
// eslint-disable-next-line no-param-reassign
response.quota = BigInt(0);
}
return callback(null, response, ...params);
}, data);
}

/**
Expand Down Expand Up @@ -346,7 +365,19 @@ class VaultClient {
'the account name, if set, should be a string');
data.AccountName = accountName;
}
this.request('POST', '/', true, callback, data);
this.request('POST', '/', true, (err, response, ...params) => {
if (err) {
return callback(err);
}
if (response && response.quota) {
// eslint-disable-next-line no-param-reassign
response.quota = BigInt(response.quota || 0);
} else if (response && !response.quota) {
// eslint-disable-next-line no-param-reassign
response.quota = BigInt(0);
}
return callback(null, response, ...params);
}, data);
}

/**
Expand Down Expand Up @@ -830,6 +861,13 @@ class VaultClient {
if (err) {
return callback(err);
}
if (data && data.accountQuota && data.accountQuota.quota) {
// eslint-disable-next-line no-param-reassign
data.accountQuota.quota = BigInt(data.accountQuota.quota || 0);
} else if (data && data.accountQuota && !data.accountQuota.quota) {
// eslint-disable-next-line no-param-reassign
data.accountQuota.quota = BigInt(0);
}
return callback(null, {
message: {
message: 'Authentication successful',
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "8.4.1",
"version": "8.4.2",
"description": "Client library and binary for Vault, the user directory and key management service",
"main": "index.js",
"repository": "scality/vaultclient",
Expand All @@ -29,6 +29,7 @@
"eslint-config-scality": "scality/Guidelines#8.2.0",
"eslint-plugin-import": "^2.18.0",
"mocha": "6.1.4",
"sinon": "^19.0.2",
"typescript": "^4.7.3"
},
"scripts": {
Expand All @@ -37,6 +38,6 @@
"lint_yml": "yamllint $(git ls-files '*.yml')",
"lint_md": "mdlint $(git ls-files '*.md')",
"test": "mocha --exit tests/unit",
"gen-types": "rm -f lib/IAMClient.d.ts && rm -f lib/constants.d.ts && tsc --declaration --emitDeclarationOnly"
"gen-types": "rm -f lib/IAMClient.d.ts.map && rm -f lib/IAMClient.d.ts.map && rm -f lib/IAMClient.d.ts && rm -f lib/constants.d.ts && tsc --declaration --emitDeclarationOnly"
}
}
Loading
Loading