mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-05 23:53:21 +00:00
Update to commander 7 (#94)
* Upgrade to commander 7.0.0 * Match lint rules for typescript * update jslib
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 06239aea2d...6183a30a52
362
package-lock.json
generated
362
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -161,13 +161,13 @@
|
||||
"electron-notarize": "^1.0.0",
|
||||
"electron-rebuild": "^2.3.4",
|
||||
"electron-reload": "^1.5.0",
|
||||
"mini-css-extract-plugin": "^0.9.0",
|
||||
"file-loader": "^2.0.0",
|
||||
"font-awesome": "4.7.0",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-google-webfonts": "^2.0.0",
|
||||
"html-loader": "^0.5.5",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"mini-css-extract-plugin": "^0.9.0",
|
||||
"node-abi": "^2.9.0",
|
||||
"node-loader": "^0.6.0",
|
||||
"node-sass": "^4.13.1",
|
||||
@@ -200,7 +200,7 @@
|
||||
"bootstrap": "4.3.1",
|
||||
"browser-hrtime": "^1.1.8",
|
||||
"chalk": "2.4.1",
|
||||
"commander": "2.18.0",
|
||||
"commander": "7.0.0",
|
||||
"core-js": "2.6.2",
|
||||
"duo_web_sdk": "git+https://github.com/duosecurity/duo_web_sdk.git",
|
||||
"electron-log": "4.3.0",
|
||||
|
||||
@@ -10,7 +10,7 @@ import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
|
||||
export class ClearCacheCommand {
|
||||
constructor(private configurationService: ConfigurationService, private i18nService: I18nService) { }
|
||||
|
||||
async run(cmd: program.Command): Promise<Response> {
|
||||
async run(cmd: program.OptionValues): Promise<Response> {
|
||||
try {
|
||||
await this.configurationService.clearStatefulSettings(true);
|
||||
const res = new MessageResponse(this.i18nService.t('syncCacheCleared'), null);
|
||||
|
||||
@@ -33,13 +33,13 @@ export class ConfigCommand {
|
||||
constructor(private environmentService: EnvironmentService, private i18nService: I18nService,
|
||||
private configurationService: ConfigurationService) { }
|
||||
|
||||
async run(setting: string, value: string, cmd: program.Command): Promise<Response> {
|
||||
async run(setting: string, value: string, options: program.OptionValues): Promise<Response> {
|
||||
setting = setting.toLowerCase();
|
||||
if (value == null || value === '') {
|
||||
if (cmd.secretfile) {
|
||||
value = await NodeUtils.readFirstLine(cmd.secretfile);
|
||||
} else if (cmd.secretenv && process.env[cmd.secretenv]) {
|
||||
value = process.env[cmd.secretenv];
|
||||
if (options.secretfile) {
|
||||
value = await NodeUtils.readFirstLine(options.secretfile);
|
||||
} else if (options.secretenv && process.env[options.secretenv]) {
|
||||
value = process.env[options.secretenv];
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { StringResponse } from 'jslib/cli/models/response/stringResponse';
|
||||
export class LastSyncCommand {
|
||||
constructor(private configurationService: ConfigurationService) { }
|
||||
|
||||
async run(object: string, cmd: program.Command): Promise<Response> {
|
||||
async run(object: string): Promise<Response> {
|
||||
try {
|
||||
switch (object.toLowerCase()) {
|
||||
case 'groups':
|
||||
|
||||
@@ -10,7 +10,7 @@ import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
|
||||
export class SyncCommand {
|
||||
constructor(private syncService: SyncService, private i18nService: I18nService) { }
|
||||
|
||||
async run(cmd: program.Command): Promise<Response> {
|
||||
async run(): Promise<Response> {
|
||||
try {
|
||||
const result = await this.syncService.sync(false, false);
|
||||
const groupCount = result[0] != null ? result[0].length : 0;
|
||||
|
||||
@@ -12,7 +12,7 @@ import { TestResponse } from '../models/response/testResponse';
|
||||
export class TestCommand {
|
||||
constructor(private syncService: SyncService, private i18nService: I18nService) { }
|
||||
|
||||
async run(cmd: program.Command): Promise<Response> {
|
||||
async run(cmd: program.OptionValues): Promise<Response> {
|
||||
try {
|
||||
const result = await ConnectorUtils.simulate(this.syncService, this.i18nService, cmd.last || false);
|
||||
const res = new TestResponse(result);
|
||||
|
||||
@@ -104,12 +104,12 @@ export class Program extends BaseProgram {
|
||||
writeLn(' bwdc login --sso');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (email: string, password: string, cmd: program.Command) => {
|
||||
.action(async (email: string, password: string, options: program.OptionValues) => {
|
||||
await this.exitIfAuthed();
|
||||
const command = new LoginCommand(this.main.authService, this.main.apiService, this.main.i18nService,
|
||||
this.main.environmentService, this.main.passwordGenerationService, this.main.cryptoFunctionService,
|
||||
this.main.platformUtilsService, 'connector');
|
||||
const response = await command.run(email, password, cmd);
|
||||
const response = await command.run(email, password, options);
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
@@ -122,11 +122,11 @@ export class Program extends BaseProgram {
|
||||
writeLn(' bwdc logout');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (cmd) => {
|
||||
.action(async () => {
|
||||
await this.exitIfNotAuthed();
|
||||
const command = new LogoutCommand(this.main.authService, this.main.i18nService,
|
||||
async () => await this.main.logout());
|
||||
const response = await command.run(cmd);
|
||||
const response = await command.run();
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
@@ -141,10 +141,10 @@ export class Program extends BaseProgram {
|
||||
writeLn(' bwdc test --last');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (cmd) => {
|
||||
.action(async (options: program.OptionValues) => {
|
||||
await this.exitIfNotAuthed();
|
||||
const command = new TestCommand(this.main.syncService, this.main.i18nService);
|
||||
const response = await command.run(cmd);
|
||||
const response = await command.run(options);
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
@@ -157,10 +157,10 @@ export class Program extends BaseProgram {
|
||||
writeLn(' bwdc sync');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (cmd) => {
|
||||
.action(async () => {
|
||||
await this.exitIfNotAuthed();
|
||||
const command = new SyncCommand(this.main.syncService, this.main.i18nService);
|
||||
const response = await command.run(cmd);
|
||||
const response = await command.run();
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
@@ -178,10 +178,10 @@ export class Program extends BaseProgram {
|
||||
writeLn(' bwdc last-sync users');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (object: string, cmd: program.Command) => {
|
||||
.action(async (object: string) => {
|
||||
await this.exitIfNotAuthed();
|
||||
const command = new LastSyncCommand(this.main.configurationService);
|
||||
const response = await command.run(object, cmd);
|
||||
const response = await command.run(object);
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
@@ -214,10 +214,10 @@ export class Program extends BaseProgram {
|
||||
writeLn(' bwdc config onelogin.secret <secret>');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (setting, value, cmd) => {
|
||||
.action(async (setting: string, value: string, options: program.OptionValues) => {
|
||||
const command = new ConfigCommand(this.main.environmentService, this.main.i18nService,
|
||||
this.main.configurationService);
|
||||
const response = await command.run(setting, value, cmd);
|
||||
const response = await command.run(setting, value, options);
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
@@ -244,9 +244,9 @@ export class Program extends BaseProgram {
|
||||
writeLn(' bwdc clear-cache');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (cmd) => {
|
||||
.action(async (options: program.OptionValues) => {
|
||||
const command = new ClearCacheCommand(this.main.configurationService, this.main.i18nService);
|
||||
const response = await command.run(cmd);
|
||||
const response = await command.run(options);
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
@@ -266,10 +266,10 @@ export class Program extends BaseProgram {
|
||||
writeLn(' bwdc update --raw');
|
||||
writeLn('', true);
|
||||
})
|
||||
.action(async (cmd) => {
|
||||
.action(async () => {
|
||||
const command = new UpdateCommand(this.main.platformUtilsService, this.main.i18nService,
|
||||
'directory-connector', 'bwdc', false);
|
||||
const response = await command.run(cmd);
|
||||
const response = await command.run();
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
||||
|
||||
@@ -377,7 +377,7 @@ export class AzureDirectoryService extends BaseDirectoryService implements Direc
|
||||
|
||||
private init() {
|
||||
this.client = graph.Client.init({
|
||||
authProvider: (done) => {
|
||||
authProvider: done => {
|
||||
if (this.dirConfig.applicationId == null || this.dirConfig.key == null ||
|
||||
this.dirConfig.tenant == null) {
|
||||
done(this.i18nService.t('dirConfigIncomplete'), null);
|
||||
@@ -407,7 +407,7 @@ export class AzureDirectoryService extends BaseDirectoryService implements Direc
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Content-Length': Buffer.byteLength(data),
|
||||
},
|
||||
}, (res) => {
|
||||
}, res => {
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', (chunk: string) => {
|
||||
const d = JSON.parse(chunk);
|
||||
@@ -420,7 +420,7 @@ export class AzureDirectoryService extends BaseDirectoryService implements Direc
|
||||
done('Unknown error (' + res.statusCode + ').', null);
|
||||
}
|
||||
});
|
||||
}).on('error', (err) => {
|
||||
}).on('error', err => {
|
||||
done(err, null);
|
||||
});
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ export abstract class BaseDirectoryService {
|
||||
return users;
|
||||
}
|
||||
|
||||
return users.filter((u) => {
|
||||
return users.filter(u => {
|
||||
if (u.deleted) {
|
||||
return true;
|
||||
}
|
||||
@@ -81,11 +81,11 @@ export abstract class BaseDirectoryService {
|
||||
return true;
|
||||
}
|
||||
|
||||
return groups.filter((g) => g.userMemberExternalIds.has(u.externalId)).length > 0;
|
||||
return groups.filter(g => g.userMemberExternalIds.has(u.externalId)).length > 0;
|
||||
});
|
||||
}
|
||||
|
||||
protected forceGroup(force: boolean, users: UserEntry[]): boolean {
|
||||
return force || (users != null && users.filter((u) => !u.deleted && !u.disabled).length > 0);
|
||||
return force || (users != null && users.filter(u => !u.deleted && !u.disabled).length > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class KeytarSecureStorageService implements StorageService {
|
||||
constructor(private serviceName: string) { }
|
||||
|
||||
get<T>(key: string): Promise<T> {
|
||||
return getPassword(this.serviceName, key).then((val) => {
|
||||
return getPassword(this.serviceName, key).then(val => {
|
||||
return JSON.parse(val) as T;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export class LdapDirectoryService implements DirectoryService {
|
||||
if (this.syncConfig.groups) {
|
||||
let groupForce = force;
|
||||
if (!groupForce && users != null) {
|
||||
const activeUsers = users.filter((u) => !u.deleted && !u.disabled);
|
||||
const activeUsers = users.filter(u => !u.deleted && !u.disabled);
|
||||
groupForce = activeUsers.length > 0;
|
||||
}
|
||||
groups = await this.getGroups(groupForce);
|
||||
@@ -303,18 +303,18 @@ export class LdapDirectoryService implements DirectoryService {
|
||||
return;
|
||||
}
|
||||
|
||||
res.on('error', (resErr) => {
|
||||
res.on('error', resErr => {
|
||||
reject(resErr);
|
||||
});
|
||||
|
||||
res.on('searchEntry', (entry) => {
|
||||
res.on('searchEntry', entry => {
|
||||
const e = processEntry(entry);
|
||||
if (e != null) {
|
||||
entries.push(e);
|
||||
}
|
||||
});
|
||||
|
||||
res.on('end', (result) => {
|
||||
res.on('end', result => {
|
||||
resolve(entries);
|
||||
});
|
||||
});
|
||||
@@ -381,7 +381,7 @@ export class LdapDirectoryService implements DirectoryService {
|
||||
if (err != null) {
|
||||
reject(err.message);
|
||||
} else {
|
||||
this.client.bind(user, pass, (err2) => {
|
||||
this.client.bind(user, pass, err2 => {
|
||||
if (err2 != null) {
|
||||
reject(err2.message);
|
||||
} else {
|
||||
@@ -391,7 +391,7 @@ export class LdapDirectoryService implements DirectoryService {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.client.bind(user, pass, (err) => {
|
||||
this.client.bind(user, pass, err => {
|
||||
if (err != null) {
|
||||
reject(err.message);
|
||||
} else {
|
||||
@@ -404,7 +404,7 @@ export class LdapDirectoryService implements DirectoryService {
|
||||
|
||||
private async unbind(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.unbind((err) => {
|
||||
this.client.unbind(err => {
|
||||
if (err != null) {
|
||||
reject(err);
|
||||
} else {
|
||||
|
||||
@@ -122,7 +122,7 @@ export class OktaDirectoryService extends BaseDirectoryService implements Direct
|
||||
entries.push(entry);
|
||||
}
|
||||
// throttle some to avoid rate limiting
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
}
|
||||
});
|
||||
return entries;
|
||||
@@ -164,7 +164,7 @@ export class OktaDirectoryService extends BaseDirectoryService implements Direct
|
||||
|
||||
private async apiGetCall(url: string): Promise<[any, Map<string, string | string[]>]> {
|
||||
const u = new URL(url);
|
||||
return new Promise((resolve) => {
|
||||
return new Promise(resolve => {
|
||||
https.get({
|
||||
hostname: u.hostname,
|
||||
path: u.pathname + u.search,
|
||||
@@ -173,10 +173,10 @@ export class OktaDirectoryService extends BaseDirectoryService implements Direct
|
||||
Authorization: 'SSWS ' + this.dirConfig.token,
|
||||
Accept: 'application/json',
|
||||
},
|
||||
}, (res) => {
|
||||
}, res => {
|
||||
let body = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
res.on('data', chunk => {
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ export class OneLoginDirectoryService extends BaseDirectoryService implements Di
|
||||
const setFilter = this.createCustomSet(this.syncConfig.userFilter);
|
||||
this.logService.info('Querying users.');
|
||||
this.allUsers = await this.apiGetMany('users' + (query != null ? '?' + query : ''));
|
||||
this.allUsers.forEach((user) => {
|
||||
this.allUsers.forEach(user => {
|
||||
const entry = this.buildUser(user);
|
||||
if (entry != null && !this.filterOutResult(setFilter, entry.email)) {
|
||||
entries.push(entry);
|
||||
@@ -109,7 +109,7 @@ export class OneLoginDirectoryService extends BaseDirectoryService implements Di
|
||||
const query = this.createDirectoryQuery(this.syncConfig.groupFilter);
|
||||
this.logService.info('Querying groups.');
|
||||
const roles = await this.apiGetMany('roles' + (query != null ? '?' + query : ''));
|
||||
roles.forEach((role) => {
|
||||
roles.forEach(role => {
|
||||
const entry = this.buildGroup(role);
|
||||
if (entry != null && !this.filterOutResult(setFilter, entry.name)) {
|
||||
entries.push(entry);
|
||||
@@ -125,7 +125,7 @@ export class OneLoginDirectoryService extends BaseDirectoryService implements Di
|
||||
entry.name = group.name;
|
||||
|
||||
if (this.allUsers != null) {
|
||||
this.allUsers.forEach((user) => {
|
||||
this.allUsers.forEach(user => {
|
||||
if (user.role_id != null && user.role_id.indexOf(entry.referenceId) > -1) {
|
||||
entry.userMemberExternalIds.add(user.id);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ export class SyncService {
|
||||
}
|
||||
|
||||
private filterUnsupportedUsers(users: UserEntry[]): UserEntry[] {
|
||||
return users == null ? null : users.filter((u) => u.email == null || u.email.length <= 50);
|
||||
return users == null ? null : users.filter(u => u.email == null || u.email.length <= 50);
|
||||
}
|
||||
|
||||
private flattenUsersToGroups(levelGroups: GroupEntry[], allGroups: GroupEntry[]): Set<string> {
|
||||
@@ -113,9 +113,9 @@ export class SyncService {
|
||||
return allUsers;
|
||||
}
|
||||
for (const group of levelGroups) {
|
||||
const childGroups = allGroups.filter((g) => group.groupMemberReferenceIds.has(g.referenceId));
|
||||
const childGroups = allGroups.filter(g => group.groupMemberReferenceIds.has(g.referenceId));
|
||||
const childUsers = this.flattenUsersToGroups(childGroups, allGroups);
|
||||
childUsers.forEach((id) => group.userMemberExternalIds.add(id));
|
||||
childUsers.forEach(id => group.userMemberExternalIds.add(id));
|
||||
allUsers = new Set([...allUsers, ...group.userMemberExternalIds]);
|
||||
}
|
||||
return allUsers;
|
||||
|
||||
23
tslint.json
23
tslint.json
@@ -49,6 +49,27 @@
|
||||
"check-separator",
|
||||
"check-type"
|
||||
],
|
||||
"max-classes-per-file": false
|
||||
"max-classes-per-file": false,
|
||||
"ordered-imports": true,
|
||||
"arrow-parens": [
|
||||
true,
|
||||
"ban-single-arg-parens"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"trailing-comma": [
|
||||
true,
|
||||
{
|
||||
"multiline": {
|
||||
"objects": "always",
|
||||
"arrays": "always",
|
||||
"functions": "ignore",
|
||||
"typeLiterals": "ignore"
|
||||
},
|
||||
"singleline": "never"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user