mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-17 08:43:27 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3335659c8d | ||
|
|
f0282b33f0 | ||
|
|
f69d461463 | ||
|
|
bcf16562fe | ||
|
|
d7412410f2 | ||
|
|
d5907477df | ||
|
|
9acfaff361 | ||
|
|
737274da59 | ||
|
|
7a0e0e6915 | ||
|
|
25847b9c83 | ||
|
|
07dd7bb93e | ||
|
|
bc9936bd92 | ||
|
|
e4428e3387 | ||
|
|
30ef0ce140 | ||
|
|
38c461ebe0 | ||
|
|
ead1776f90 | ||
|
|
0e944b2442 | ||
|
|
3bbd503308 | ||
|
|
a7b13b168e | ||
|
|
1cf8ae1bdf | ||
|
|
7da3c8e252 | ||
|
|
2edf3fb68d | ||
|
|
1e698ba81b | ||
|
|
e9034ea6fe |
29
README.md
29
README.md
@@ -18,7 +18,32 @@ The application is written using Electron with Angular and installs on Windows,
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
# Build/Run
|
## Command-line Interface
|
||||||
|
|
||||||
|
A command-line interface tool is also available for the Bitwarden Directory Connector. The Directory Connector CLI (`bwdc`) is written with TypeScript and Node.js and can also be run on Windows, macOS, and Linux distributions.
|
||||||
|
|
||||||
|
## CLI Documentation
|
||||||
|
|
||||||
|
The Bitwarden Directory Connector CLI is self-documented with `--help` content and examples for every command. You should start exploring the CLI by using the global `--help` option:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bwdc --help
|
||||||
|
```
|
||||||
|
|
||||||
|
This option will list all available commands that you can use with the Directory Connector CLI.
|
||||||
|
|
||||||
|
Additionally, you can run the `--help` option on a specific command to learn more about it:
|
||||||
|
|
||||||
|
```
|
||||||
|
bwdc test --help
|
||||||
|
bwdc config --help
|
||||||
|
```
|
||||||
|
|
||||||
|
**Detailed Documentation**
|
||||||
|
|
||||||
|
We provide detailed documentation and examples for using the Directory Connector CLI in our help center at https://help.bitwarden.com/article/directory-sync/#command-line-interface.
|
||||||
|
|
||||||
|
## Build/Run
|
||||||
|
|
||||||
**Requirements**
|
**Requirements**
|
||||||
|
|
||||||
@@ -48,7 +73,7 @@ You can then run commands from the `./build-cli` folder:
|
|||||||
node ./build-cli/bwdc.js --help
|
node ./build-cli/bwdc.js --help
|
||||||
```
|
```
|
||||||
|
|
||||||
# Contribute
|
## Contribute
|
||||||
|
|
||||||
Code contributions are welcome! Please commit any pull requests against the `master` branch. Learn more about how to contribute by reading the [`CONTRIBUTING.md`](CONTRIBUTING.md) file.
|
Code contributions are welcome! Please commit any pull requests against the `master` branch. Learn more about how to contribute by reading the [`CONTRIBUTING.md`](CONTRIBUTING.md) file.
|
||||||
|
|
||||||
|
|||||||
20
appveyor.yml
20
appveyor.yml
@@ -24,21 +24,23 @@ init:
|
|||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
Install-Product node 10
|
Install-Product node 10
|
||||||
$env:PATH = "C:\Program Files (x86)\Resource Hacker;${env:PATH}"
|
$env:PATH = "C:\Program Files (x86)\Resource Hacker;${env:PATH}"
|
||||||
if(Test-Path -Path $env:WIN_PKG) {
|
}
|
||||||
$env:VER_INFO = "true"
|
if($env:APPVEYOR_REPO_TAG -eq "true") {
|
||||||
}
|
$env:RELEASE_NAME = $env:APPVEYOR_REPO_TAG_NAME.TrimStart("v")
|
||||||
}
|
}
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- ps: |
|
- ps: |
|
||||||
$env:PACKAGE_VERSION = (Get-Content -Raw -Path .\src\package.json | ConvertFrom-Json).version
|
$env:PACKAGE_VERSION = (Get-Content -Raw -Path .\src\package.json | ConvertFrom-Json).version
|
||||||
$env:RELEASE_NAME = "Version ${tagName}"
|
|
||||||
$env:PROD_DEPLOY = "false"
|
$env:PROD_DEPLOY = "false"
|
||||||
if($env:APPVEYOR_REPO_TAG -eq "true" -and $env:APPVEYOR_RE_BUILD -eq "True") {
|
if($env:APPVEYOR_REPO_TAG -eq "true" -and $env:APPVEYOR_RE_BUILD -eq "True") {
|
||||||
$env:PROD_DEPLOY = "true"
|
$env:PROD_DEPLOY = "true"
|
||||||
echo "This is a production deployment."
|
echo "This is a production deployment."
|
||||||
}
|
}
|
||||||
if($isWindows) {
|
if($isWindows) {
|
||||||
|
if(Test-Path -Path $env:WIN_PKG) {
|
||||||
|
$env:VER_INFO = "true"
|
||||||
|
}
|
||||||
choco install reshack --no-progress
|
choco install reshack --no-progress
|
||||||
choco install cloc --no-progress
|
choco install cloc --no-progress
|
||||||
choco install checksum --no-progress
|
choco install checksum --no-progress
|
||||||
@@ -136,17 +138,17 @@ for:
|
|||||||
only:
|
only:
|
||||||
- image: Visual Studio 2017
|
- image: Visual Studio 2017
|
||||||
cache:
|
cache:
|
||||||
- '%LOCALAPPDATA%\electron -> appveyor.yml'
|
- '%LOCALAPPDATA%\electron'
|
||||||
- '%LOCALAPPDATA%\electron-builder -> appveyor.yml'
|
- '%LOCALAPPDATA%\electron-builder'
|
||||||
- 'C:\Users\appveyor\.pkg-cache\ -> package.json'
|
- 'C:\Users\appveyor\.pkg-cache\'
|
||||||
|
|
||||||
-
|
-
|
||||||
matrix:
|
matrix:
|
||||||
only:
|
only:
|
||||||
- image: Ubuntu1804
|
- image: Ubuntu1804
|
||||||
cache:
|
cache:
|
||||||
- '/home/appveyor/.cache/electron -> appveyor.yml'
|
- '/home/appveyor/.cache/electron'
|
||||||
- '/home/appveyor/.cache/electron-builder -> appveyor.yml'
|
- '/home/appveyor/.cache/electron-builder'
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
tag: $(APPVEYOR_REPO_TAG_NAME)
|
tag: $(APPVEYOR_REPO_TAG_NAME)
|
||||||
|
|||||||
2
jslib
2
jslib
Submodule jslib updated: 50e6f24679...a884f77938
19
package-lock.json
generated
19
package-lock.json
generated
@@ -3865,14 +3865,6 @@
|
|||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"nan": "^2.10.0"
|
"nan": "^2.10.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"nan": {
|
|
||||||
"version": "2.10.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
|
|
||||||
"integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==",
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"duo_web_sdk": {
|
"duo_web_sdk": {
|
||||||
@@ -8800,9 +8792,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ldapjs": {
|
"ldapjs": {
|
||||||
"version": "1.0.2",
|
"version": "git+https://git@github.com/kspearrin/node-ldapjs.git#12c07b17e0cf505e7da817599f877932812d3f8f",
|
||||||
"resolved": "https://registry.npmjs.org/ldapjs/-/ldapjs-1.0.2.tgz",
|
"from": "git+https://git@github.com/kspearrin/node-ldapjs.git",
|
||||||
"integrity": "sha1-VE/3Ayt7g8aPBwEyjZKXqmlDQPk=",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"asn1": "0.2.3",
|
"asn1": "0.2.3",
|
||||||
"assert-plus": "^1.0.0",
|
"assert-plus": "^1.0.0",
|
||||||
@@ -9700,9 +9691,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"moment": {
|
"moment": {
|
||||||
"version": "2.22.2",
|
"version": "2.24.0",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
|
||||||
"integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y=",
|
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==",
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"move-concurrently": {
|
"move-concurrently": {
|
||||||
|
|||||||
@@ -207,7 +207,7 @@
|
|||||||
"googleapis": "33.0.0",
|
"googleapis": "33.0.0",
|
||||||
"inquirer": "6.2.0",
|
"inquirer": "6.2.0",
|
||||||
"keytar": "4.4.1",
|
"keytar": "4.4.1",
|
||||||
"ldapjs": "1.0.2",
|
"ldapjs": "git+https://git@github.com/kspearrin/node-ldapjs.git",
|
||||||
"lowdb": "1.0.0",
|
"lowdb": "1.0.0",
|
||||||
"lunr": "2.3.3",
|
"lunr": "2.3.3",
|
||||||
"node-fetch": "2.2.0",
|
"node-fetch": "2.2.0",
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
<strong *ngIf="syncRunning" class="text-success">{{'running' | i18n}}</strong>
|
<strong *ngIf="syncRunning" class="text-success">{{'running' | i18n}}</strong>
|
||||||
<strong *ngIf="!syncRunning" class="text-danger">{{'stopped' | i18n}}</strong>
|
<strong *ngIf="!syncRunning" class="text-danger">{{'stopped' | i18n}}</strong>
|
||||||
</p>
|
</p>
|
||||||
<button #startBtn (click)="start()" [appApiAction]="startPromise" class="btn btn-primary" [disabled]="startBtn.loading">
|
<button #startBtn (click)="start()" [appApiAction]="startPromise" class="btn btn-primary"
|
||||||
|
[disabled]="startBtn.loading">
|
||||||
<i class="fa fa-play fa-fw" [hidden]="startBtn.loading"></i>
|
<i class="fa fa-play fa-fw" [hidden]="startBtn.loading"></i>
|
||||||
<i class="fa fa-spinner fa-fw fa-spin" [hidden]="!startBtn.loading"></i>
|
<i class="fa fa-spinner fa-fw fa-spin" [hidden]="!startBtn.loading"></i>
|
||||||
{{'startSync' | i18n}}
|
{{'startSync' | i18n}}
|
||||||
@@ -23,7 +24,8 @@
|
|||||||
<i class="fa fa-stop fa-fw"></i>
|
<i class="fa fa-stop fa-fw"></i>
|
||||||
{{'stopSync' | i18n}}
|
{{'stopSync' | i18n}}
|
||||||
</button>
|
</button>
|
||||||
<button #syncBtn (click)="sync()" [appApiAction]="syncPromise" class="btn btn-primary" [disabled]="syncBtn.loading">
|
<button #syncBtn (click)="sync()" [appApiAction]="syncPromise" class="btn btn-primary"
|
||||||
|
[disabled]="syncBtn.loading">
|
||||||
<i class="fa fa-refresh fa-fw" [ngClass]="{'fa-spin': syncBtn.loading}"></i>
|
<i class="fa fa-refresh fa-fw" [ngClass]="{'fa-spin': syncBtn.loading}"></i>
|
||||||
{{'syncNow' | i18n}}
|
{{'syncNow' | i18n}}
|
||||||
</button>
|
</button>
|
||||||
@@ -33,7 +35,8 @@
|
|||||||
<h3 class="card-header">{{'testing' | i18n}}</h3>
|
<h3 class="card-header">{{'testing' | i18n}}</h3>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p>{{'testingDesc' | i18n}}</p>
|
<p>{{'testingDesc' | i18n}}</p>
|
||||||
<button #simBtn (click)="simulate()" [appApiAction]="simPromise" class="btn btn-primary" [disabled]="simBtn.loading">
|
<button #simBtn (click)="simulate()" [appApiAction]="simPromise" class="btn btn-primary"
|
||||||
|
[disabled]="simBtn.loading">
|
||||||
<i class="fa fa-spinner fa-fw fa-spin" [hidden]="!simBtn.loading"></i>
|
<i class="fa fa-spinner fa-fw fa-spin" [hidden]="!simBtn.loading"></i>
|
||||||
<i class="fa fa-bug fa-fw" [hidden]="simBtn.loading"></i>
|
<i class="fa fa-bug fa-fw" [hidden]="simBtn.loading"></i>
|
||||||
{{'testNow' | i18n}}
|
{{'testNow' | i18n}}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { StateService } from 'jslib/abstractions/state.service';
|
|||||||
import { SyncService } from '../../services/sync.service';
|
import { SyncService } from '../../services/sync.service';
|
||||||
|
|
||||||
import { GroupEntry } from '../../models/groupEntry';
|
import { GroupEntry } from '../../models/groupEntry';
|
||||||
|
import { SimResult } from '../../models/simResult';
|
||||||
import { UserEntry } from '../../models/userEntry';
|
import { UserEntry } from '../../models/userEntry';
|
||||||
import { ConfigurationService } from '../../services/configuration.service';
|
import { ConfigurationService } from '../../services/configuration.service';
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
|||||||
simEnabledUsers: UserEntry[] = [];
|
simEnabledUsers: UserEntry[] = [];
|
||||||
simDisabledUsers: UserEntry[] = [];
|
simDisabledUsers: UserEntry[] = [];
|
||||||
simDeletedUsers: UserEntry[] = [];
|
simDeletedUsers: UserEntry[] = [];
|
||||||
simPromise: Promise<any>;
|
simPromise: Promise<SimResult>;
|
||||||
simSinceLast: boolean = false;
|
simSinceLast: boolean = false;
|
||||||
syncPromise: Promise<[GroupEntry[], UserEntry[]]>;
|
syncPromise: Promise<[GroupEntry[], UserEntry[]]>;
|
||||||
startPromise: Promise<any>;
|
startPromise: Promise<any>;
|
||||||
@@ -101,22 +102,18 @@ export class DashboardComponent implements OnInit, OnDestroy {
|
|||||||
this.simDisabledUsers = [];
|
this.simDisabledUsers = [];
|
||||||
this.simDeletedUsers = [];
|
this.simDeletedUsers = [];
|
||||||
|
|
||||||
this.simPromise = new Promise(async (resolve, reject) => {
|
try {
|
||||||
try {
|
this.simPromise = ConnectorUtils.simulate(this.syncService, this.i18nService, this.simSinceLast);
|
||||||
const result = await ConnectorUtils.simulate(this.syncService, this.i18nService, this.simSinceLast);
|
const result = await this.simPromise;
|
||||||
this.simGroups = result.groups;
|
this.simGroups = result.groups;
|
||||||
this.simUsers = result.users;
|
this.simUsers = result.users;
|
||||||
this.simEnabledUsers = result.enabledUsers;
|
this.simEnabledUsers = result.enabledUsers;
|
||||||
this.simDisabledUsers = result.disabledUsers;
|
this.simDisabledUsers = result.disabledUsers;
|
||||||
this.simDeletedUsers = result.deletedUsers;
|
this.simDeletedUsers = result.deletedUsers;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.simGroups = null;
|
this.simGroups = null;
|
||||||
this.simUsers = null;
|
this.simUsers = null;
|
||||||
reject(e);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateLastSync() {
|
private async updateLastSync() {
|
||||||
|
|||||||
18
src/bwdc.ts
18
src/bwdc.ts
@@ -31,6 +31,7 @@ import { Program } from './program';
|
|||||||
const packageJson = require('./package.json');
|
const packageJson = require('./package.json');
|
||||||
|
|
||||||
export class Main {
|
export class Main {
|
||||||
|
dataFilePath: string;
|
||||||
logService: ConsoleLogService;
|
logService: ConsoleLogService;
|
||||||
messagingService: NoopMessagingService;
|
messagingService: NoopMessagingService;
|
||||||
storageService: LowdbStorageService;
|
storageService: LowdbStorageService;
|
||||||
@@ -53,21 +54,20 @@ export class Main {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const applicationName = 'Bitwarden Directory Connector';
|
const applicationName = 'Bitwarden Directory Connector';
|
||||||
let p = null;
|
|
||||||
if (process.env.BITWARDENCLI_CONNECTOR_APPDATA_DIR) {
|
if (process.env.BITWARDENCLI_CONNECTOR_APPDATA_DIR) {
|
||||||
p = path.resolve(process.env.BITWARDENCLI_CONNECTOR_APPDATA_DIR);
|
this.dataFilePath = path.resolve(process.env.BITWARDENCLI_CONNECTOR_APPDATA_DIR);
|
||||||
} else if (process.env.BITWARDEN_CONNECTOR_APPDATA_DIR) {
|
} else if (process.env.BITWARDEN_CONNECTOR_APPDATA_DIR) {
|
||||||
p = path.resolve(process.env.BITWARDEN_CONNECTOR_APPDATA_DIR);
|
this.dataFilePath = path.resolve(process.env.BITWARDEN_CONNECTOR_APPDATA_DIR);
|
||||||
} else if (fs.existsSync(path.join(__dirname, 'bitwarden-connector-appdata'))) {
|
} else if (fs.existsSync(path.join(__dirname, 'bitwarden-connector-appdata'))) {
|
||||||
p = path.join(__dirname, 'bitwarden-connector-appdata');
|
this.dataFilePath = path.join(__dirname, 'bitwarden-connector-appdata');
|
||||||
} else if (process.platform === 'darwin') {
|
} else if (process.platform === 'darwin') {
|
||||||
p = path.join(process.env.HOME, 'Library/Application Support/' + applicationName);
|
this.dataFilePath = path.join(process.env.HOME, 'Library/Application Support/' + applicationName);
|
||||||
} else if (process.platform === 'win32') {
|
} else if (process.platform === 'win32') {
|
||||||
p = path.join(process.env.APPDATA, applicationName);
|
this.dataFilePath = path.join(process.env.APPDATA, applicationName);
|
||||||
} else if (process.env.XDG_CONFIG_HOME) {
|
} else if (process.env.XDG_CONFIG_HOME) {
|
||||||
p = path.join(process.env.XDG_CONFIG_HOME, applicationName);
|
this.dataFilePath = path.join(process.env.XDG_CONFIG_HOME, applicationName);
|
||||||
} else {
|
} else {
|
||||||
p = path.join(process.env.HOME, '.config/' + applicationName);
|
this.dataFilePath = path.join(process.env.HOME, '.config/' + applicationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.i18nService = new I18nService('en', './locales');
|
this.i18nService = new I18nService('en', './locales');
|
||||||
@@ -75,7 +75,7 @@ export class Main {
|
|||||||
this.logService = new ConsoleLogService(this.platformUtilsService.isDev(),
|
this.logService = new ConsoleLogService(this.platformUtilsService.isDev(),
|
||||||
(level) => process.env.BWCLI_DEBUG !== 'true' && level <= LogLevelType.Info);
|
(level) => process.env.BWCLI_DEBUG !== 'true' && level <= LogLevelType.Info);
|
||||||
this.cryptoFunctionService = new NodeCryptoFunctionService();
|
this.cryptoFunctionService = new NodeCryptoFunctionService();
|
||||||
this.storageService = new LowdbStorageService(null, p, true);
|
this.storageService = new LowdbStorageService(null, this.dataFilePath, true);
|
||||||
this.secureStorageService = new KeytarSecureStorageService(applicationName);
|
this.secureStorageService = new KeytarSecureStorageService(applicationName);
|
||||||
this.cryptoService = new CryptoService(this.storageService, this.secureStorageService,
|
this.cryptoService = new CryptoService(this.storageService, this.secureStorageService,
|
||||||
this.cryptoFunctionService);
|
this.cryptoFunctionService);
|
||||||
|
|||||||
29
src/commands/lastSync.command.ts
Normal file
29
src/commands/lastSync.command.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import * as program from 'commander';
|
||||||
|
|
||||||
|
import { ConfigurationService } from '../services/configuration.service';
|
||||||
|
|
||||||
|
import { Response } from 'jslib/cli/models/response';
|
||||||
|
import { StringResponse } from 'jslib/cli/models/response/stringResponse';
|
||||||
|
|
||||||
|
export class LastSyncCommand {
|
||||||
|
constructor(private configurationService: ConfigurationService) { }
|
||||||
|
|
||||||
|
async run(object: string, cmd: program.Command): Promise<Response> {
|
||||||
|
try {
|
||||||
|
switch (object.toLowerCase()) {
|
||||||
|
case 'groups':
|
||||||
|
const groupsDate = await this.configurationService.getLastGroupSyncDate();
|
||||||
|
const groupsRes = new StringResponse(groupsDate == null ? null : groupsDate.toISOString());
|
||||||
|
return Response.success(groupsRes);
|
||||||
|
case 'users':
|
||||||
|
const usersDate = await this.configurationService.getLastUserSyncDate();
|
||||||
|
const usersRes = new StringResponse(usersDate == null ? null : usersDate.toISOString());
|
||||||
|
return Response.success(usersRes);
|
||||||
|
default:
|
||||||
|
return Response.badRequest('Unknown object.');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return Response.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "bitwarden-directory-connector",
|
"name": "bitwarden-directory-connector",
|
||||||
"productName": "Bitwarden Directory Connector",
|
"productName": "Bitwarden Directory Connector",
|
||||||
"description": "Sync your user directory to your Bitwarden organization.",
|
"description": "Sync your user directory to your Bitwarden organization.",
|
||||||
"version": "2.5.0",
|
"version": "2.5.3",
|
||||||
"author": "8bit Solutions LLC <hello@bitwarden.com> (https://bitwarden.com)",
|
"author": "8bit Solutions LLC <hello@bitwarden.com> (https://bitwarden.com)",
|
||||||
"homepage": "https://bitwarden.com",
|
"homepage": "https://bitwarden.com",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import * as chk from 'chalk';
|
import * as chk from 'chalk';
|
||||||
import * as program from 'commander';
|
import * as program from 'commander';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
import { Main } from './bwdc';
|
import { Main } from './bwdc';
|
||||||
|
|
||||||
import { ClearCacheCommand } from './commands/clearCache.command';
|
import { ClearCacheCommand } from './commands/clearCache.command';
|
||||||
import { ConfigCommand } from './commands/config.command';
|
import { ConfigCommand } from './commands/config.command';
|
||||||
|
import { LastSyncCommand } from './commands/lastSync.command';
|
||||||
import { SyncCommand } from './commands/sync.command';
|
import { SyncCommand } from './commands/sync.command';
|
||||||
import { TestCommand } from './commands/test.command';
|
import { TestCommand } from './commands/test.command';
|
||||||
|
|
||||||
@@ -14,6 +16,9 @@ import { UpdateCommand } from 'jslib/cli/commands/update.command';
|
|||||||
|
|
||||||
import { BaseProgram } from 'jslib/cli/baseProgram';
|
import { BaseProgram } from 'jslib/cli/baseProgram';
|
||||||
|
|
||||||
|
import { Response } from 'jslib/cli/models/response';
|
||||||
|
import { StringResponse } from 'jslib/cli/models/response/stringResponse';
|
||||||
|
|
||||||
const chalk = chk.default;
|
const chalk = chk.default;
|
||||||
const writeLn = (s: string, finalLine: boolean = false) => {
|
const writeLn = (s: string, finalLine: boolean = false) => {
|
||||||
if (finalLine && process.platform === 'win32') {
|
if (finalLine && process.platform === 'win32') {
|
||||||
@@ -61,8 +66,10 @@ export class Program extends BaseProgram {
|
|||||||
program.on('--help', () => {
|
program.on('--help', () => {
|
||||||
writeLn('\n Examples:');
|
writeLn('\n Examples:');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
|
writeLn(' bwdc login');
|
||||||
writeLn(' bwdc test');
|
writeLn(' bwdc test');
|
||||||
writeLn(' bwdc sync');
|
writeLn(' bwdc sync');
|
||||||
|
writeLn(' bwdc last-sync');
|
||||||
writeLn(' bwdc config server https://bw.company.com');
|
writeLn(' bwdc config server https://bw.company.com');
|
||||||
writeLn(' bwdc update');
|
writeLn(' bwdc update');
|
||||||
writeLn('', true);
|
writeLn('', true);
|
||||||
@@ -143,6 +150,27 @@ export class Program extends BaseProgram {
|
|||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('last-sync <object>')
|
||||||
|
.description('Get the last successful sync date.')
|
||||||
|
.on('--help', () => {
|
||||||
|
writeLn('\n Notes:');
|
||||||
|
writeLn('');
|
||||||
|
writeLn(' Returns empty response if no sync has been performed for the given object.');
|
||||||
|
writeLn('');
|
||||||
|
writeLn(' Examples:');
|
||||||
|
writeLn('');
|
||||||
|
writeLn(' bwdc last-sync groups');
|
||||||
|
writeLn(' bwdc last-sync users');
|
||||||
|
writeLn('', true);
|
||||||
|
})
|
||||||
|
.action(async (object: string, cmd: program.Command) => {
|
||||||
|
await this.exitIfNotAuthed();
|
||||||
|
const command = new LastSyncCommand(this.main.configurationService);
|
||||||
|
const response = await command.run(object, cmd);
|
||||||
|
this.processResponse(response);
|
||||||
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('config <setting> <value>')
|
.command('config <setting> <value>')
|
||||||
.description('Configure settings.')
|
.description('Configure settings.')
|
||||||
@@ -174,6 +202,20 @@ export class Program extends BaseProgram {
|
|||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('data-file')
|
||||||
|
.description('Path to data.json database file.')
|
||||||
|
.on('--help', () => {
|
||||||
|
writeLn('\n Examples:');
|
||||||
|
writeLn('');
|
||||||
|
writeLn(' bwdc data-file');
|
||||||
|
writeLn('', true);
|
||||||
|
})
|
||||||
|
.action(() => {
|
||||||
|
this.processResponse(
|
||||||
|
Response.success(new StringResponse(path.join(this.main.dataFilePath, 'data.json'))));
|
||||||
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('clear-cache')
|
.command('clear-cache')
|
||||||
.description('Clear the sync cache.')
|
.description('Clear the sync cache.')
|
||||||
|
|||||||
@@ -67,45 +67,59 @@ export class GSuiteDirectoryService extends BaseDirectoryService implements Dire
|
|||||||
private async getUsers(): Promise<UserEntry[]> {
|
private async getUsers(): Promise<UserEntry[]> {
|
||||||
const entries: UserEntry[] = [];
|
const entries: UserEntry[] = [];
|
||||||
const query = this.createDirectoryQuery(this.syncConfig.userFilter);
|
const query = this.createDirectoryQuery(this.syncConfig.userFilter);
|
||||||
|
let nextPageToken: string = null;
|
||||||
this.logService.info('Querying users.');
|
|
||||||
let p = Object.assign({ query: query }, this.authParams);
|
|
||||||
const res = await this.service.users.list(p);
|
|
||||||
if (res.status !== 200) {
|
|
||||||
throw new Error('User list API failed: ' + res.statusText);
|
|
||||||
}
|
|
||||||
|
|
||||||
const filter = this.createCustomSet(this.syncConfig.userFilter);
|
const filter = this.createCustomSet(this.syncConfig.userFilter);
|
||||||
if (res.data.users != null) {
|
while (true) {
|
||||||
for (const user of res.data.users) {
|
this.logService.info('Querying users - nextPageToken:' + nextPageToken);
|
||||||
if (this.filterOutResult(filter, user.primaryEmail)) {
|
const p = Object.assign({ query: query, pageToken: nextPageToken }, this.authParams);
|
||||||
continue;
|
const res = await this.service.users.list(p);
|
||||||
}
|
if (res.status !== 200) {
|
||||||
|
throw new Error('User list API failed: ' + res.statusText);
|
||||||
|
}
|
||||||
|
|
||||||
const entry = this.buildUser(user, false);
|
nextPageToken = res.data.nextPageToken;
|
||||||
if (entry != null) {
|
if (res.data.users != null) {
|
||||||
entries.push(entry);
|
for (const user of res.data.users) {
|
||||||
|
if (this.filterOutResult(filter, user.primaryEmail)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const entry = this.buildUser(user, false);
|
||||||
|
if (entry != null) {
|
||||||
|
entries.push(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nextPageToken == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logService.info('Querying deleted users.');
|
nextPageToken = null;
|
||||||
p = Object.assign({ showDeleted: true, query: query }, this.authParams);
|
while (true) {
|
||||||
const delRes = await this.service.users.list(p);
|
this.logService.info('Querying deleted users - nextPageToken:' + nextPageToken);
|
||||||
if (delRes.status !== 200) {
|
const p = Object.assign({ showDeleted: true, query: query, pageToken: nextPageToken }, this.authParams);
|
||||||
throw new Error('Deleted user list API failed: ' + delRes.statusText);
|
const delRes = await this.service.users.list(p);
|
||||||
}
|
if (delRes.status !== 200) {
|
||||||
|
throw new Error('Deleted user list API failed: ' + delRes.statusText);
|
||||||
|
}
|
||||||
|
|
||||||
if (delRes.data.users != null) {
|
nextPageToken = delRes.data.nextPageToken;
|
||||||
for (const user of delRes.data.users) {
|
if (delRes.data.users != null) {
|
||||||
if (this.filterOutResult(filter, user.primaryEmail)) {
|
for (const user of delRes.data.users) {
|
||||||
continue;
|
if (this.filterOutResult(filter, user.primaryEmail)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const entry = this.buildUser(user, true);
|
||||||
|
if (entry != null) {
|
||||||
|
entries.push(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const entry = this.buildUser(user, true);
|
if (nextPageToken == null) {
|
||||||
if (entry != null) {
|
break;
|
||||||
entries.push(entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,56 +142,75 @@ export class GSuiteDirectoryService extends BaseDirectoryService implements Dire
|
|||||||
|
|
||||||
private async getGroups(setFilter: [boolean, Set<string>]): Promise<GroupEntry[]> {
|
private async getGroups(setFilter: [boolean, Set<string>]): Promise<GroupEntry[]> {
|
||||||
const entries: GroupEntry[] = [];
|
const entries: GroupEntry[] = [];
|
||||||
|
let nextPageToken: string = null;
|
||||||
|
|
||||||
this.logService.info('Querying groups.');
|
while (true) {
|
||||||
const res = await this.service.groups.list(this.authParams);
|
this.logService.info('Querying groups - nextPageToken:' + nextPageToken);
|
||||||
if (res.status !== 200) {
|
const p = Object.assign({ pageToken: nextPageToken }, this.authParams);
|
||||||
throw new Error('Group list API failed: ' + res.statusText);
|
const res = await this.service.groups.list(p);
|
||||||
}
|
if (res.status !== 200) {
|
||||||
if (res.data.groups != null) {
|
throw new Error('Group list API failed: ' + res.statusText);
|
||||||
for (const group of res.data.groups) {
|
}
|
||||||
if (!this.filterOutResult(setFilter, group.name)) {
|
|
||||||
const entry = await this.buildGroup(group);
|
nextPageToken = res.data.nextPageToken;
|
||||||
entries.push(entry);
|
if (res.data.groups != null) {
|
||||||
|
for (const group of res.data.groups) {
|
||||||
|
if (!this.filterOutResult(setFilter, group.name)) {
|
||||||
|
const entry = await this.buildGroup(group);
|
||||||
|
entries.push(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nextPageToken == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async buildGroup(group: admin_directory_v1.Schema$Group) {
|
private async buildGroup(group: admin_directory_v1.Schema$Group) {
|
||||||
|
let nextPageToken: string = null;
|
||||||
|
|
||||||
const entry = new GroupEntry();
|
const entry = new GroupEntry();
|
||||||
entry.referenceId = group.id;
|
entry.referenceId = group.id;
|
||||||
entry.externalId = group.id;
|
entry.externalId = group.id;
|
||||||
entry.name = group.name;
|
entry.name = group.name;
|
||||||
|
|
||||||
const p = Object.assign({ groupKey: group.id }, this.authParams);
|
while (true) {
|
||||||
const memRes = await this.service.members.list(p);
|
const p = Object.assign({ groupKey: group.id, pageToken: nextPageToken }, this.authParams);
|
||||||
if (memRes.status !== 200) {
|
const memRes = await this.service.members.list(p);
|
||||||
this.logService.warning('Group member list API failed: ' + memRes.statusText);
|
if (memRes.status !== 200) {
|
||||||
return entry;
|
this.logService.warning('Group member list API failed: ' + memRes.statusText);
|
||||||
}
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
if (memRes.data.members != null) {
|
nextPageToken = memRes.data.nextPageToken;
|
||||||
for (const member of memRes.data.members) {
|
if (memRes.data.members != null) {
|
||||||
if (member.type == null) {
|
for (const member of memRes.data.members) {
|
||||||
continue;
|
if (member.type == null) {
|
||||||
}
|
continue;
|
||||||
if (member.role == null || member.role.toLowerCase() !== 'member') {
|
}
|
||||||
continue;
|
if (member.role == null || member.role.toLowerCase() !== 'member') {
|
||||||
}
|
continue;
|
||||||
if (member.status == null || member.status.toLowerCase() !== 'active') {
|
}
|
||||||
continue;
|
if (member.status == null || member.status.toLowerCase() !== 'active') {
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const type = member.type.toLowerCase();
|
const type = member.type.toLowerCase();
|
||||||
if (type === 'user') {
|
if (type === 'user') {
|
||||||
entry.userMemberExternalIds.add(member.id);
|
entry.userMemberExternalIds.add(member.id);
|
||||||
} else if (type === 'group') {
|
} else if (type === 'group') {
|
||||||
entry.groupMemberReferenceIds.add(member.id);
|
entry.groupMemberReferenceIds.add(member.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nextPageToken == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
|
|||||||
Reference in New Issue
Block a user