Skip to content

Commit

Permalink
flag name change
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed May 2, 2024
1 parent e8f2402 commit ceee60a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 56 deletions.
12 changes: 6 additions & 6 deletions bin/vaultclient
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function action(cmd, fn, args) {
const secretKey = config.secretKeyValue;
let host = args.parent.host || process.env.VAULT_HOST || 'localhost';
const token = config.sessionToken;
const disableValidation = args.disableValidation || false;
const parameterValidation = args.parameterValidation || true;
const client = new vaultclient.Client(host,
Number.parseInt(args.parent.port ? args.parent.port :
process.env.VAULT_PORT, 10),
Expand All @@ -103,7 +103,7 @@ function action(cmd, fn, args) {
null,
null,
token,
disableValidation);
parameterValidation);
fn(client, args);
} catch (err) {
//process.stderr.write(err.message + '\n');
Expand Down Expand Up @@ -217,23 +217,23 @@ program
.command('update-account-quota')
.option('--account-name [NAME]', 'Name of the account')
.option('--quota <QUOTA>', 'Maximum quota for the account', parseInt)
.option('--disable-validation', 'Disable validation of quota')
.option('--parameter-validation', 'Disable validation of quota')
.action(action.bind(null, 'update-account-quota', (client, args) => {
client.updateAccountQuota(args.accountName ,args.quota, handleVaultResponse);
client.updateAccountQuota(args.accountName, args.quota, handleVaultResponse);
}));

program
.command('delete-account-quota')
.option('--account-name [NAME]', 'Name of the account')
.option('--disable-validation', 'Disable validation of quota')
.option('--parameter-validation', 'Disable validation of quota')
.action(action.bind(null, 'delete-account-quota', (client, args) => {
client.deleteAccountQuota(args.accountName, handleVaultResponse);
}));

program
.command('get-account-quota')
.option('--account-name [NAME]', 'Name of the account')
.option('--disable-validation', 'Disable validation of quota')
.option('--parameter-validation', 'Disable validation of quota')
.action(action.bind(null, 'get-account-quota', (client, args) => {
client.getAccountQuota(args.accountName, handleVaultResponse);
}));
Expand Down
6 changes: 3 additions & 3 deletions lib/IAMClient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ declare class VaultClient {
* for the Logger object
* @param {string} [path] - prefix requests with this path
* @param {string} [sessionToken] - session token for v4 signature
* @param {boolean} [disableValidation] - flag that will disable param validation
* @param {boolean} [parameterValidation] - flag that will enable param validation
*/
constructor(host: string, port?: number, useHttps?: boolean, key?: string, cert?: string, ca?: string, ignoreCa?: boolean, accessKey?: string, secretKeyValue?: string, logApi?: werelogs.API, path?: string, sessionToken?: string, disableValidation?: boolean);
constructor(host: string, port?: number, useHttps?: boolean, key?: string, cert?: string, ca?: string, ignoreCa?: boolean, accessKey?: string, secretKeyValue?: string, logApi?: werelogs.API, path?: string, sessionToken?: string, parameterValidation?: boolean);
serverHost: string;
serverPort: number;
_key: string;
Expand All @@ -32,7 +32,7 @@ declare class VaultClient {
log: any;
_path: string;
useAuthenticatedAdminRoutes: boolean;
disableValidation: boolean;
parameterValidation: boolean;
setCustomEndpointForSignature(host: any, path: any): void;
_host: any;
__path: any;
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.

36 changes: 13 additions & 23 deletions lib/IAMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class VaultClient {
* for the Logger object
* @param {string} [path] - prefix requests with this path
* @param {string} [sessionToken] - session token for v4 signature
* @param {boolean} [disableValidation] - flag that will disable param validation
* @param {boolean} [parameterValidation] - flag that will enable param validation
*/
constructor(host, port, useHttps, key, cert, ca, ignoreCa,
accessKey, secretKeyValue, logApi, path, sessionToken, disableValidation) {
accessKey, secretKeyValue, logApi, path, sessionToken, parameterValidation) {
assert(typeof host === 'string' && host !== '', 'host is required');
assert(port === undefined || typeof port === 'number',
'port must be a number');
Expand Down Expand Up @@ -77,7 +77,7 @@ class VaultClient {
this.log = new this.logApi.Logger('VaultClient');
this._path = path;
this.useAuthenticatedAdminRoutes = false;
this.disableValidation = disableValidation || false;
this.parameterValidation = parameterValidation !== undefined ? !!parameterValidation : true;
}

setCustomEndpointForSignature(host, path) {
Expand Down Expand Up @@ -292,23 +292,17 @@ class VaultClient {
* @returns {undefined}
*/
updateAccountQuota(accountName, quota, callback) {
const disableValidation = this.disableValidation;
const data = {
Action: 'UpdateAccountQuota',
Version: '2010-05-08',
quotaMax: quota,
};
if (disableValidation) {
if (accountName) {
data.AccountName = accountName;
}
} else {
const quotaIsValid = typeof quota === 'number' && !Number.isNaN(Number.parseInt(quota, 10)) && quota > 0;
assert(quotaIsValid, 'Quota must be a strictly positive number');
if (accountName) {
assert(typeof accountName === 'string', 'the account name, if set, should be a string');
data.AccountName = accountName;
}
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);
}
Expand All @@ -326,11 +320,9 @@ class VaultClient {
Version: '2010-05-08',
};

const disableValidation = this.disableValidation;
if (accountName) {
if (!disableValidation) {
assert(typeof accountName === 'string', 'the account name, if set, should be a string');
}
assert(!this.parameterValidation || typeof accountName === 'string',
'the account name, if set, should be a string');
data.AccountName = accountName;
}
this.request('POST', '/', true, callback, data);
Expand All @@ -348,12 +340,10 @@ class VaultClient {
Action: 'GetAccountQuota',
Version: '2010-05-08',
};
const disableValidation = this.disableValidation;

if (accountName) {
if (!disableValidation) {
assert(typeof accountName === 'string',
assert(!this.parameterValidation || typeof accountName === 'string',
'the account name, if set, should be a string');
}
data.AccountName = accountName;
}
this.request('POST', '/', true, callback, data);
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/deleteAccountQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ describe('IAMClient - deleteAccountQuota', () => {
let client;
let lastRequestData;

const createClient = disableValidation => {
client = new IAMClient('127.0.0.1', 8500, undefined, undefined,
undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, disableValidation);
const createClient = parameterValidation => {
client = new IAMClient('127.0.0.1', 8500, undefined, undefined, undefined,
undefined, undefined, undefined, undefined, undefined, undefined, undefined, parameterValidation);
lastRequestData = null;
client.request = (method, path, iamAuthenticate, callback, data, reqUid, contentType) => {
lastRequestData = { method, path, iamAuthenticate, data, reqUid, contentType };
Expand All @@ -17,7 +17,7 @@ describe('IAMClient - deleteAccountQuota', () => {
};

it('should call the request method with the correct parameters when options are provided', () => {
client = createClient(false);
client = createClient(true);
const accountName = 'exampleAccount';
client.deleteAccountQuota(accountName, () => {});

Expand All @@ -32,7 +32,7 @@ describe('IAMClient - deleteAccountQuota', () => {
});

it('should call the request method with the correct params when wrong options are provided and ci is true', () => {
client = createClient(true);
client = createClient(false);
const accountName = 123;

client.deleteAccountQuota(accountName, () => {});
Expand All @@ -48,7 +48,7 @@ describe('IAMClient - deleteAccountQuota', () => {
});

it('should call the request method with the correct parameters when options are not provided', () => {
client = createClient(false);
client = createClient(true);
client.deleteAccountQuota(undefined, () => {});

assert.strictEqual(lastRequestData.method, 'POST');
Expand All @@ -61,7 +61,7 @@ describe('IAMClient - deleteAccountQuota', () => {
});

it('should throw an error if accountName is not a string', () => {
client = createClient(false);
client = createClient(true);
const accountName = 123;
assert.throws(() => {
client.deleteAccountQuota(accountName, () => {});
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/getAccountQuota.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ describe('GetAccountQuota', () => {
let client;
let lastRequestData;

const createClient = disableValidation => {
client = new IAMClient('127.0.0.1', 8500, undefined, undefined,
undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, disableValidation);
const createClient = parameterValidation => {
client = new IAMClient('127.0.0.1', 8500, undefined, undefined, undefined,
undefined, undefined, undefined, undefined, undefined, undefined, undefined, parameterValidation);
lastRequestData = null;
client.request = (method, path, iamAuthenticate, callback, data, reqUid, contentType) => {
lastRequestData = { method, path, iamAuthenticate, data, reqUid, contentType };
Expand All @@ -17,7 +17,7 @@ describe('GetAccountQuota', () => {
};

it('should call the request method with the correct parameters when options are provided', () => {
client = createClient(false);
client = createClient(true);
const accountName = 'exampleAccount';
const callback = () => {};
client.getAccountQuota(accountName, callback);
Expand All @@ -33,7 +33,7 @@ describe('GetAccountQuota', () => {
});

it('should call the request method with default parameters when options are not provided', () => {
client = createClient(false);
client = createClient(true);
const callback = () => {};
client.getAccountQuota(undefined, callback);
const expectedData = {
Expand All @@ -47,7 +47,7 @@ describe('GetAccountQuota', () => {
});

it('should throw an error if accountName is not a string', () => {
client = createClient(false);
client = createClient(true);
const accountName = 123;
const callback = () => {};
assert.throws(() => {
Expand All @@ -56,7 +56,7 @@ describe('GetAccountQuota', () => {
});

it('should not throw an error if accountName is not a string and ci is true', () => {
client = createClient(true);
client = createClient(false);
const accountName = 123;
const callback = () => {};
client.getAccountQuota(accountName, callback);
Expand Down
Loading

0 comments on commit ceee60a

Please sign in to comment.