Repository navigation
Bitwarden Extension: Add Support for Apple Silicon Macs, Add Lock Vault command - #263
Conversation
PSalant726
left a comment
There was a problem hiding this comment.
IMO, this is a step backwards. It makes the preference more confusing for non-developers, and setting a custom PATH could have unforeseen user-specific side effects when executing commands via the extension. I think if you want to support M1 macs by default, changing the setting's default value is all that should be done here.
As an alternative solution to support both homebrew default installation paths: you could have the Bitwarden constructor run a bw status command using the old default path, and if the CLI isn't found, try again with the new default. Then, the installation path could be saved as state on the Bitwarden instance that gets created.
|
Thanks for the feedback, your raised valid points |
|
@PSalant726 Please look at this second iteration. I reverted back the cli path pref, but without a default value. Instead, bw dynamically find the command if this setting is not set (and looks at both the I'm not sure why but I'm unable to rerequest a review. |
pernielsentikaer
left a comment
There was a problem hiding this comment.
Hi @pomdtr 👋 💪
I tested this extension on M1 and I can confirm that everything works as expected, didn't have the bitwarden-cli, but was guided and it was an easy setup.
A few NITs and suggestions:
- package.json line 29/37 (Add linebreak for better readability)
"description": "The client_id value seen in the My Account section of a Bitwarden web vault.\r\nMore info: https://bitwarden.com/help/article/personal-api-key/",
- hooks.ts line 8/12 (Corrected language)
const toast = await showToast(ToastStyle.Animated, "Logging in...", "It may take some time");
showToast(ToastStyle.Failure, "An error occurred during login!", "Please check your credentials");
- api.ts line 46 (Redundant return await)
return execa(this.cliPath, args, {env: this.env});
- It could be cool with a way to "log out" of the vault again to ensure security if needed.
Request a new review when you are ready, feel free to contact me here or at Slack if you have any questions.
|
@pernielsentikaer I added the ability to lock the vault using a second command. |
|
I found a few word translations that can be corrected for the next version @pomdtr 💪 package.json hooks.ts Tried your extension directly from the store and it worked very well! 💯 |
| { | ||
| "name": "lock-vault", | ||
| "title": "Lock Vault", | ||
| "subtitle": "Bitwarden", | ||
| "description": "Lock the vault.", | ||
| "mode": "no-view" |
There was a problem hiding this comment.
Not a problem for this PR, but in the future I'd prefer if a new command were added in it's own PR. It keeps changes cleaner and much simpler to review.
Since the change are on this PR, I would just reiterate that the concept of authentication (including locking and unlocking), is not limited to just vault actions. If we later plan to add commands related to the Bitwarden Send functionality, then we should drop the word "vault" from this command.
| import which from "which"; | ||
| import { VaultStatus } from "./types"; | ||
|
|
||
| const PATH = "/usr/local/bin:/opt/homebrew/bin" |
There was a problem hiding this comment.
I haven't tested this extensively, but it's possible that setting a custom PATH value could have unforeseen per-user side effects. I'm not sure how the PATH variable is handled in shell sessions launched by Raycast.
There was a problem hiding this comment.
I would prefer to check a set of expected bw cli path, but the bw cli does not work if /usr/local/bin is not in path :/
| constructor() { | ||
| const { cliPath, clientId, clientSecret } = getPreferenceValues() | ||
| this.cliPath = cliPath ? cliPath : which.sync('bw', {path: PATH}) | ||
| if (!existsSync(this.cliPath)) { |
There was a problem hiding this comment.
Doesn't the previous line guarantee that this.cliPath will exist?
There was a problem hiding this comment.
No, because it could be:
- an empty string
- a faulty path (if the user provides a wrong path.
| return JSON.parse(stdout).status | ||
| } | ||
|
|
||
| private async exec(args: string[]): Promise<execa.ExecaChildProcess> { |
There was a problem hiding this comment.
Is the async keyword necessary here if no await exists within the function body?
| 1. The Bitwarden CLI is [correctly installed](https://bitwarden.com/help/article/cli/#download-and-install) | ||
| 1. The path of the installation matches the Bitwarden CLI Installation Path extension setting | ||
| > Currently set to: \`${path}\` | ||
| 1. If you did not install bitwarden using brew, please check that path of the installation matches the \`Bitwarden CLI Installation Path\` extension setting |
There was a problem hiding this comment.
| 1. If you did not install bitwarden using brew, please check that path of the installation matches the \`Bitwarden CLI Installation Path\` extension setting | |
| 1. If you did not install the Bitwarden CLI using homebrew, verify that the installation path matches the \`Bitwarden CLI Installation Path\` extension setting. |
| @@ -0,0 +1 @@ | |||
| export const SESSION_KEY = "sessionToken"; | |||
There was a problem hiding this comment.
Can this be stored on the Bitwarden instance, instead of in it's own file?
| toast.hide(); | ||
| } catch (error) { | ||
| showToast(ToastStyle.Failure, "An error occurred during login!", "Please check your crendentials"); | ||
| showToast(ToastStyle.Failure, "An error occurred during login!", "Please check your credentials"); |
There was a problem hiding this comment.
| showToast(ToastStyle.Failure, "An error occurred during login!", "Please check your credentials"); | |
| showToast(ToastStyle.Failure, "An error occurred during login!", "Invalid credentials"); |
| for (const item of state?.items || []) { | ||
| item.favorite ? favoriteItems.push(item) : regularItems.push(item); | ||
| } |
There was a problem hiding this comment.
We don't need to map over both the favorites and regular items below. We can DRY things up and slightly improve the latency by doing it here:
| for (const item of state?.items || []) { | |
| item.favorite ? favoriteItems.push(item) : regularItems.push(item); | |
| } | |
| for (const item of state?.items || []) { | |
| const listItem = <ItemListItem | |
| key={item.id} | |
| item={item} | |
| folder={item.folderId ? folderMap[item.folderId] : undefined} | |
| refreshItems={refreshItems} | |
| /> | |
| item.favorite ? favoriteItems.push(listItem) : regularItems.push(listItem); | |
| } |
There was a problem hiding this comment.
You are right, this is much better.
…lt command (raycast#263) * Add support apple silicon macs * Update pref title * search bw cli in brew directories by default * extract PATH to a global var * fix @pernielsentikaer comments * Update troubleshooting guide * Add ability to lock the vault * Group favorites to the top * Update extensions/bitwarden/src/hooks.ts Co-authored-by: Petr Nikolaev <[email protected]>
Description
Search the bitwarden cli in multiple dirs, including the default brew install dir for M1 macs
Type of change
Bug fix / improvement for my extension
Screencast