1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-15 07:43:27 +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:
Matt Gibson
2021-02-08 13:32:02 -06:00
committed by GitHub
parent 9a1caf1e7e
commit e5d0b3a372
17 changed files with 397 additions and 92 deletions

2
jslib

Submodule jslib updated: 06239aea2d...6183a30a52

362
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -161,13 +161,13 @@
"electron-notarize": "^1.0.0", "electron-notarize": "^1.0.0",
"electron-rebuild": "^2.3.4", "electron-rebuild": "^2.3.4",
"electron-reload": "^1.5.0", "electron-reload": "^1.5.0",
"mini-css-extract-plugin": "^0.9.0",
"file-loader": "^2.0.0", "file-loader": "^2.0.0",
"font-awesome": "4.7.0", "font-awesome": "4.7.0",
"gulp": "^4.0.0", "gulp": "^4.0.0",
"gulp-google-webfonts": "^2.0.0", "gulp-google-webfonts": "^2.0.0",
"html-loader": "^0.5.5", "html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.9.0",
"node-abi": "^2.9.0", "node-abi": "^2.9.0",
"node-loader": "^0.6.0", "node-loader": "^0.6.0",
"node-sass": "^4.13.1", "node-sass": "^4.13.1",
@@ -200,7 +200,7 @@
"bootstrap": "4.3.1", "bootstrap": "4.3.1",
"browser-hrtime": "^1.1.8", "browser-hrtime": "^1.1.8",
"chalk": "2.4.1", "chalk": "2.4.1",
"commander": "2.18.0", "commander": "7.0.0",
"core-js": "2.6.2", "core-js": "2.6.2",
"duo_web_sdk": "git+https://github.com/duosecurity/duo_web_sdk.git", "duo_web_sdk": "git+https://github.com/duosecurity/duo_web_sdk.git",
"electron-log": "4.3.0", "electron-log": "4.3.0",

View File

@@ -10,7 +10,7 @@ import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
export class ClearCacheCommand { export class ClearCacheCommand {
constructor(private configurationService: ConfigurationService, private i18nService: I18nService) { } constructor(private configurationService: ConfigurationService, private i18nService: I18nService) { }
async run(cmd: program.Command): Promise<Response> { async run(cmd: program.OptionValues): Promise<Response> {
try { try {
await this.configurationService.clearStatefulSettings(true); await this.configurationService.clearStatefulSettings(true);
const res = new MessageResponse(this.i18nService.t('syncCacheCleared'), null); const res = new MessageResponse(this.i18nService.t('syncCacheCleared'), null);

View File

@@ -33,13 +33,13 @@ export class ConfigCommand {
constructor(private environmentService: EnvironmentService, private i18nService: I18nService, constructor(private environmentService: EnvironmentService, private i18nService: I18nService,
private configurationService: ConfigurationService) { } 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(); setting = setting.toLowerCase();
if (value == null || value === '') { if (value == null || value === '') {
if (cmd.secretfile) { if (options.secretfile) {
value = await NodeUtils.readFirstLine(cmd.secretfile); value = await NodeUtils.readFirstLine(options.secretfile);
} else if (cmd.secretenv && process.env[cmd.secretenv]) { } else if (options.secretenv && process.env[options.secretenv]) {
value = process.env[cmd.secretenv]; value = process.env[options.secretenv];
} }
} }
try { try {

View File

@@ -8,7 +8,7 @@ import { StringResponse } from 'jslib/cli/models/response/stringResponse';
export class LastSyncCommand { export class LastSyncCommand {
constructor(private configurationService: ConfigurationService) { } constructor(private configurationService: ConfigurationService) { }
async run(object: string, cmd: program.Command): Promise<Response> { async run(object: string): Promise<Response> {
try { try {
switch (object.toLowerCase()) { switch (object.toLowerCase()) {
case 'groups': case 'groups':

View File

@@ -10,7 +10,7 @@ import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
export class SyncCommand { export class SyncCommand {
constructor(private syncService: SyncService, private i18nService: I18nService) { } constructor(private syncService: SyncService, private i18nService: I18nService) { }
async run(cmd: program.Command): Promise<Response> { async run(): Promise<Response> {
try { try {
const result = await this.syncService.sync(false, false); const result = await this.syncService.sync(false, false);
const groupCount = result[0] != null ? result[0].length : 0; const groupCount = result[0] != null ? result[0].length : 0;

View File

@@ -12,7 +12,7 @@ import { TestResponse } from '../models/response/testResponse';
export class TestCommand { export class TestCommand {
constructor(private syncService: SyncService, private i18nService: I18nService) { } constructor(private syncService: SyncService, private i18nService: I18nService) { }
async run(cmd: program.Command): Promise<Response> { async run(cmd: program.OptionValues): Promise<Response> {
try { try {
const result = await ConnectorUtils.simulate(this.syncService, this.i18nService, cmd.last || false); const result = await ConnectorUtils.simulate(this.syncService, this.i18nService, cmd.last || false);
const res = new TestResponse(result); const res = new TestResponse(result);

View File

@@ -104,12 +104,12 @@ export class Program extends BaseProgram {
writeLn(' bwdc login --sso'); writeLn(' bwdc login --sso');
writeLn('', true); writeLn('', true);
}) })
.action(async (email: string, password: string, cmd: program.Command) => { .action(async (email: string, password: string, options: program.OptionValues) => {
await this.exitIfAuthed(); await this.exitIfAuthed();
const command = new LoginCommand(this.main.authService, this.main.apiService, this.main.i18nService, const command = new LoginCommand(this.main.authService, this.main.apiService, this.main.i18nService,
this.main.environmentService, this.main.passwordGenerationService, this.main.cryptoFunctionService, this.main.environmentService, this.main.passwordGenerationService, this.main.cryptoFunctionService,
this.main.platformUtilsService, 'connector'); this.main.platformUtilsService, 'connector');
const response = await command.run(email, password, cmd); const response = await command.run(email, password, options);
this.processResponse(response); this.processResponse(response);
}); });
@@ -122,11 +122,11 @@ export class Program extends BaseProgram {
writeLn(' bwdc logout'); writeLn(' bwdc logout');
writeLn('', true); writeLn('', true);
}) })
.action(async (cmd) => { .action(async () => {
await this.exitIfNotAuthed(); await this.exitIfNotAuthed();
const command = new LogoutCommand(this.main.authService, this.main.i18nService, const command = new LogoutCommand(this.main.authService, this.main.i18nService,
async () => await this.main.logout()); async () => await this.main.logout());
const response = await command.run(cmd); const response = await command.run();
this.processResponse(response); this.processResponse(response);
}); });
@@ -141,10 +141,10 @@ export class Program extends BaseProgram {
writeLn(' bwdc test --last'); writeLn(' bwdc test --last');
writeLn('', true); writeLn('', true);
}) })
.action(async (cmd) => { .action(async (options: program.OptionValues) => {
await this.exitIfNotAuthed(); await this.exitIfNotAuthed();
const command = new TestCommand(this.main.syncService, this.main.i18nService); 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); this.processResponse(response);
}); });
@@ -157,10 +157,10 @@ export class Program extends BaseProgram {
writeLn(' bwdc sync'); writeLn(' bwdc sync');
writeLn('', true); writeLn('', true);
}) })
.action(async (cmd) => { .action(async () => {
await this.exitIfNotAuthed(); await this.exitIfNotAuthed();
const command = new SyncCommand(this.main.syncService, this.main.i18nService); const command = new SyncCommand(this.main.syncService, this.main.i18nService);
const response = await command.run(cmd); const response = await command.run();
this.processResponse(response); this.processResponse(response);
}); });
@@ -178,10 +178,10 @@ export class Program extends BaseProgram {
writeLn(' bwdc last-sync users'); writeLn(' bwdc last-sync users');
writeLn('', true); writeLn('', true);
}) })
.action(async (object: string, cmd: program.Command) => { .action(async (object: string) => {
await this.exitIfNotAuthed(); await this.exitIfNotAuthed();
const command = new LastSyncCommand(this.main.configurationService); const command = new LastSyncCommand(this.main.configurationService);
const response = await command.run(object, cmd); const response = await command.run(object);
this.processResponse(response); this.processResponse(response);
}); });
@@ -214,10 +214,10 @@ export class Program extends BaseProgram {
writeLn(' bwdc config onelogin.secret <secret>'); writeLn(' bwdc config onelogin.secret <secret>');
writeLn('', true); 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, const command = new ConfigCommand(this.main.environmentService, this.main.i18nService,
this.main.configurationService); this.main.configurationService);
const response = await command.run(setting, value, cmd); const response = await command.run(setting, value, options);
this.processResponse(response); this.processResponse(response);
}); });
@@ -244,9 +244,9 @@ export class Program extends BaseProgram {
writeLn(' bwdc clear-cache'); writeLn(' bwdc clear-cache');
writeLn('', true); writeLn('', true);
}) })
.action(async (cmd) => { .action(async (options: program.OptionValues) => {
const command = new ClearCacheCommand(this.main.configurationService, this.main.i18nService); 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); this.processResponse(response);
}); });
@@ -266,10 +266,10 @@ export class Program extends BaseProgram {
writeLn(' bwdc update --raw'); writeLn(' bwdc update --raw');
writeLn('', true); writeLn('', true);
}) })
.action(async (cmd) => { .action(async () => {
const command = new UpdateCommand(this.main.platformUtilsService, this.main.i18nService, const command = new UpdateCommand(this.main.platformUtilsService, this.main.i18nService,
'directory-connector', 'bwdc', false); 'directory-connector', 'bwdc', false);
const response = await command.run(cmd); const response = await command.run();
this.processResponse(response); this.processResponse(response);
}); });

View File

@@ -377,7 +377,7 @@ export class AzureDirectoryService extends BaseDirectoryService implements Direc
private init() { private init() {
this.client = graph.Client.init({ this.client = graph.Client.init({
authProvider: (done) => { authProvider: done => {
if (this.dirConfig.applicationId == null || this.dirConfig.key == null || if (this.dirConfig.applicationId == null || this.dirConfig.key == null ||
this.dirConfig.tenant == null) { this.dirConfig.tenant == null) {
done(this.i18nService.t('dirConfigIncomplete'), 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-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data), 'Content-Length': Buffer.byteLength(data),
}, },
}, (res) => { }, res => {
res.setEncoding('utf8'); res.setEncoding('utf8');
res.on('data', (chunk: string) => { res.on('data', (chunk: string) => {
const d = JSON.parse(chunk); const d = JSON.parse(chunk);
@@ -420,7 +420,7 @@ export class AzureDirectoryService extends BaseDirectoryService implements Direc
done('Unknown error (' + res.statusCode + ').', null); done('Unknown error (' + res.statusCode + ').', null);
} }
}); });
}).on('error', (err) => { }).on('error', err => {
done(err, null); done(err, null);
}); });

View File

@@ -73,7 +73,7 @@ export abstract class BaseDirectoryService {
return users; return users;
} }
return users.filter((u) => { return users.filter(u => {
if (u.deleted) { if (u.deleted) {
return true; return true;
} }
@@ -81,11 +81,11 @@ export abstract class BaseDirectoryService {
return true; 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 { 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);
} }
} }

View File

@@ -10,7 +10,7 @@ export class KeytarSecureStorageService implements StorageService {
constructor(private serviceName: string) { } constructor(private serviceName: string) { }
get<T>(key: string): Promise<T> { 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; return JSON.parse(val) as T;
}); });
} }

View File

@@ -53,7 +53,7 @@ export class LdapDirectoryService implements DirectoryService {
if (this.syncConfig.groups) { if (this.syncConfig.groups) {
let groupForce = force; let groupForce = force;
if (!groupForce && users != null) { 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; groupForce = activeUsers.length > 0;
} }
groups = await this.getGroups(groupForce); groups = await this.getGroups(groupForce);
@@ -303,18 +303,18 @@ export class LdapDirectoryService implements DirectoryService {
return; return;
} }
res.on('error', (resErr) => { res.on('error', resErr => {
reject(resErr); reject(resErr);
}); });
res.on('searchEntry', (entry) => { res.on('searchEntry', entry => {
const e = processEntry(entry); const e = processEntry(entry);
if (e != null) { if (e != null) {
entries.push(e); entries.push(e);
} }
}); });
res.on('end', (result) => { res.on('end', result => {
resolve(entries); resolve(entries);
}); });
}); });
@@ -381,7 +381,7 @@ export class LdapDirectoryService implements DirectoryService {
if (err != null) { if (err != null) {
reject(err.message); reject(err.message);
} else { } else {
this.client.bind(user, pass, (err2) => { this.client.bind(user, pass, err2 => {
if (err2 != null) { if (err2 != null) {
reject(err2.message); reject(err2.message);
} else { } else {
@@ -391,7 +391,7 @@ export class LdapDirectoryService implements DirectoryService {
} }
}); });
} else { } else {
this.client.bind(user, pass, (err) => { this.client.bind(user, pass, err => {
if (err != null) { if (err != null) {
reject(err.message); reject(err.message);
} else { } else {
@@ -404,7 +404,7 @@ export class LdapDirectoryService implements DirectoryService {
private async unbind(): Promise<any> { private async unbind(): Promise<any> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.client.unbind((err) => { this.client.unbind(err => {
if (err != null) { if (err != null) {
reject(err); reject(err);
} else { } else {

View File

@@ -122,7 +122,7 @@ export class OktaDirectoryService extends BaseDirectoryService implements Direct
entries.push(entry); entries.push(entry);
} }
// throttle some to avoid rate limiting // throttle some to avoid rate limiting
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise(resolve => setTimeout(resolve, 500));
} }
}); });
return entries; return entries;
@@ -164,7 +164,7 @@ export class OktaDirectoryService extends BaseDirectoryService implements Direct
private async apiGetCall(url: string): Promise<[any, Map<string, string | string[]>]> { private async apiGetCall(url: string): Promise<[any, Map<string, string | string[]>]> {
const u = new URL(url); const u = new URL(url);
return new Promise((resolve) => { return new Promise(resolve => {
https.get({ https.get({
hostname: u.hostname, hostname: u.hostname,
path: u.pathname + u.search, path: u.pathname + u.search,
@@ -173,10 +173,10 @@ export class OktaDirectoryService extends BaseDirectoryService implements Direct
Authorization: 'SSWS ' + this.dirConfig.token, Authorization: 'SSWS ' + this.dirConfig.token,
Accept: 'application/json', Accept: 'application/json',
}, },
}, (res) => { }, res => {
let body = ''; let body = '';
res.on('data', (chunk) => { res.on('data', chunk => {
body += chunk; body += chunk;
}); });

View File

@@ -72,7 +72,7 @@ export class OneLoginDirectoryService extends BaseDirectoryService implements Di
const setFilter = this.createCustomSet(this.syncConfig.userFilter); const setFilter = this.createCustomSet(this.syncConfig.userFilter);
this.logService.info('Querying users.'); this.logService.info('Querying users.');
this.allUsers = await this.apiGetMany('users' + (query != null ? '?' + query : '')); this.allUsers = await this.apiGetMany('users' + (query != null ? '?' + query : ''));
this.allUsers.forEach((user) => { this.allUsers.forEach(user => {
const entry = this.buildUser(user); const entry = this.buildUser(user);
if (entry != null && !this.filterOutResult(setFilter, entry.email)) { if (entry != null && !this.filterOutResult(setFilter, entry.email)) {
entries.push(entry); entries.push(entry);
@@ -109,7 +109,7 @@ export class OneLoginDirectoryService extends BaseDirectoryService implements Di
const query = this.createDirectoryQuery(this.syncConfig.groupFilter); const query = this.createDirectoryQuery(this.syncConfig.groupFilter);
this.logService.info('Querying groups.'); this.logService.info('Querying groups.');
const roles = await this.apiGetMany('roles' + (query != null ? '?' + query : '')); const roles = await this.apiGetMany('roles' + (query != null ? '?' + query : ''));
roles.forEach((role) => { roles.forEach(role => {
const entry = this.buildGroup(role); const entry = this.buildGroup(role);
if (entry != null && !this.filterOutResult(setFilter, entry.name)) { if (entry != null && !this.filterOutResult(setFilter, entry.name)) {
entries.push(entry); entries.push(entry);
@@ -125,7 +125,7 @@ export class OneLoginDirectoryService extends BaseDirectoryService implements Di
entry.name = group.name; entry.name = group.name;
if (this.allUsers != null) { if (this.allUsers != null) {
this.allUsers.forEach((user) => { this.allUsers.forEach(user => {
if (user.role_id != null && user.role_id.indexOf(entry.referenceId) > -1) { if (user.role_id != null && user.role_id.indexOf(entry.referenceId) > -1) {
entry.userMemberExternalIds.add(user.id); entry.userMemberExternalIds.add(user.id);
} }

View File

@@ -104,7 +104,7 @@ export class SyncService {
} }
private filterUnsupportedUsers(users: UserEntry[]): UserEntry[] { 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> { private flattenUsersToGroups(levelGroups: GroupEntry[], allGroups: GroupEntry[]): Set<string> {
@@ -113,9 +113,9 @@ export class SyncService {
return allUsers; return allUsers;
} }
for (const group of levelGroups) { 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); 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]); allUsers = new Set([...allUsers, ...group.userMemberExternalIds]);
} }
return allUsers; return allUsers;

View File

@@ -49,6 +49,27 @@
"check-separator", "check-separator",
"check-type" "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"
}
]
} }
} }