-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the project structure and make it more coherent. Fix #138
- Loading branch information
Showing
48 changed files
with
438 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
export * from './configure'; | ||
export * from './devices'; | ||
export * from './logout'; | ||
export * from './passwords'; | ||
export * from './secureNotes'; | ||
export * from './sync'; | ||
export * from './teamDevices'; | ||
export * from './teamLogs'; | ||
export * from './teamMembers'; | ||
export * from './teamReport'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Database } from 'better-sqlite3'; | ||
import winston from 'winston'; | ||
import { deactivateDevices } from '../endpoints'; | ||
import { connectAndPrepare, connect, reset } from '../modules/database'; | ||
import { Secrets, DeviceConfiguration } from '../types'; | ||
import { askConfirmReset } from '../utils'; | ||
|
||
export const runLogout = async () => { | ||
const resetConfirmation = await askConfirmReset(); | ||
if (!resetConfirmation) { | ||
return; | ||
} | ||
|
||
let db: Database; | ||
let secrets: Secrets | undefined; | ||
let deviceConfiguration: DeviceConfiguration | null | undefined; | ||
try { | ||
({ db, secrets, deviceConfiguration } = await connectAndPrepare({ | ||
autoSync: false, | ||
failIfNoDB: true, | ||
})); | ||
} catch (error) { | ||
let errorMessage = 'unknown error'; | ||
if (error instanceof Error) { | ||
errorMessage = error.message; | ||
} | ||
winston.debug(`Unable to read device configuration during logout: ${errorMessage}`); | ||
|
||
db = connect(); | ||
db.serialize(); | ||
} | ||
if (secrets && deviceConfiguration) { | ||
await deactivateDevices({ | ||
deviceIds: [deviceConfiguration.accessKey], | ||
login: deviceConfiguration.login, | ||
secrets, | ||
}); | ||
} | ||
reset({ db, secrets }); | ||
console.log('The local Dashlane local storage has been reset and you have been logged out'); | ||
db.close(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 12 additions & 1 deletion
13
src/middleware/getSecureNotes.ts → src/command-handlers/secureNotes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 20 additions & 1 deletion
21
src/middleware/getAuditLogs.ts → src/command-handlers/teamLogs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/middleware/getTeamMembers.ts → src/command-handlers/teamMembers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/middleware/getTeamReport.ts → src/command-handlers/teamReport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Command } from 'commander'; | ||
import { configureDisableAutoSync, configureSaveMasterPassword } from '../command-handlers'; | ||
|
||
export const configureCommands = (params: { program: Command }) => { | ||
const { program } = params; | ||
|
||
const configureGroup = program.command('configure').alias('c').description('Configure the CLI'); | ||
|
||
configureGroup | ||
.command('disable-auto-sync <boolean>') | ||
.description('Disable automatic synchronization which is done once per hour (default: false)') | ||
.action(configureDisableAutoSync); | ||
|
||
configureGroup | ||
.command('save-master-password <boolean>') | ||
.description('Should the encrypted master password be saved and the OS keychain be used (default: true)') | ||
.action(configureSaveMasterPassword); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Command } from 'commander'; | ||
import { listAllDevices, removeAllDevices } from '../command-handlers'; | ||
|
||
export const devicesCommands = (params: { program: Command }) => { | ||
const { program } = params; | ||
|
||
const devicesGroup = program.command('devices').alias('d').description('Operations on devices'); | ||
|
||
devicesGroup | ||
.command('list') | ||
.option('--json', 'Output in JSON format') | ||
.description('Lists all registered devices that can access your account') | ||
.action(listAllDevices); | ||
|
||
devicesGroup | ||
.command('remove') | ||
.option('--all', 'remove all devices including this one (dangerous)') | ||
.option('--others', 'remove all other devices') | ||
.argument('[device ids...]', 'ids of the devices to remove') | ||
.description('De-registers a list of devices. De-registering the CLI will implies doing a "dcli logout"') | ||
.action(removeAllDevices); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Command } from 'commander'; | ||
import { devicesCommands } from './devices'; | ||
import { teamCommands } from './team'; | ||
import { configureCommands } from './configure'; | ||
import { runSync, runOtp, runPassword, runSecureNote, runLogout } from '../command-handlers'; | ||
|
||
export const rootCommands = (params: { program: Command }) => { | ||
const { program } = params; | ||
|
||
program | ||
.command('sync') | ||
.alias('s') | ||
.description('Manually synchronize the local vault with Dashlane') | ||
.action(runSync); | ||
|
||
program | ||
.command('password') | ||
.alias('p') | ||
.description('Retrieve a password from the local vault and copy it to the clipboard') | ||
.option( | ||
'-o, --output <type>', | ||
'How to print the passwords among `clipboard, password, json`. The JSON option outputs all the matching credentials', | ||
'clipboard' | ||
) | ||
.argument( | ||
'[filters...]', | ||
'Filter credentials based on any parameter using <param>=<value>; if <param> is not specified in the filter, will default to url and title' | ||
) | ||
.action(runPassword); | ||
|
||
program | ||
.command('otp') | ||
.alias('o') | ||
.description('Retrieve an OTP code from local vault and copy it to the clipboard') | ||
.option('--print', 'Prints just the OTP code, instead of copying it to the clipboard') | ||
.argument( | ||
'[filters...]', | ||
'Filter credentials based on any parameter using <param>=<value>; if <param> is not specified in the filter, will default to url and title' | ||
) | ||
.action(runOtp); | ||
|
||
program | ||
.command('note') | ||
.alias('n') | ||
.description('Retrieve a secure note from the local vault and open it') | ||
.argument('[filter]', 'Filter notes based on their title') | ||
.action(runSecureNote); | ||
|
||
devicesCommands({ program }); | ||
|
||
teamCommands({ program }); | ||
|
||
configureCommands({ program }); | ||
|
||
program.command('logout').description('Logout and clean your local database and OS keychain').action(runLogout); | ||
}; |
Oops, something went wrong.