Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

api_key_vault_cmd configuration option for shell command to get api key from vault fails with ENOENT #387

Closed
vorburger opened this issue Dec 2, 2023 · 4 comments · Fixed by #386
Assignees

Comments

@vorburger
Copy link

The api_key_vault_cmd configuration option which according to https://github.com/wakatime/wakatime-cli/blob/develop/USAGE.md can be used to specify a "shell command to get api key from vault" fails for me, on Linux, for example for a simple test like this in .wakatime.cfg:

api_key_vault_cmd = /usr/bin/echo hi

I'm getting this in the VSC Developer Tools:

ERR spawn /usr/bin/echo hi ENOENT: Error: spawn /usr/bin/echo hi ENOENT
	at ChildProcess._handle.onexit (node:internal/child_process:283:19)
	at onErrorNT (node:internal/child_process:476:16)
	at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

I'm intentionally opening this as a separate bug from #295 which seems to be Windows with specific restricted policy.

This is with WakaTime.vscode-wakatime@24.4.0 (from code --list-extensions --show-versions).

@kisaragi-hiu
Copy link
Contributor

kisaragi-hiu commented Apr 9, 2024

First, this package vscode-wakatime is treating the option's entire string as one program to run:

public async getApiKeyFromVaultCmd(): Promise<string> {
try {
const apiKeyCmd = await this.getSettingAsync<string>('settings', 'api_key_vault_cmd');
if (!apiKeyCmd) return '';
const options = Desktop.buildOptions();
const proc = child_process.spawn(apiKeyCmd, options);

child_process.spawn treats the first argument as the program's executable name, and only treats it a shell command (ie. interpreted by sh with sh syntax) if the shell option was true, which it isn't.

Second, that line in the documentation is quite misleading, at least in regards to wakatime-cli's behavior. In reality the string is not a shell command, it is a space-separated list of an executable and its arguments. This extension should probably mimick this behavior.

Edit: I thought this was wakatime/vscode-wakatime. Corrected.

Edit: Oh, it was moved.

@gandarez gandarez transferred this issue from wakatime/vscode-wakatime Apr 9, 2024
@gandarez
Copy link
Member

gandarez commented Apr 9, 2024

Hi @vorburger that's not the way it should be used api_key_vault_cmd = /usr/bin/echo hi. So, instead you might replace with

api_key_vault_cmd = pass any_defined_key

@kisaragi-hiu
Copy link
Contributor

@gandarez with vscode-wakatime, that will not work - not even the pass command would work. vscode-wakatime treats the whole value as one executable name (including the spaces).

This is a problem in vscode-wakatime, specifically here:

  public async getApiKeyFromVaultCmd(): Promise<string> {
    try {
      const apiKeyCmd = await this.getSettingAsync<string>('settings', 'api_key_vault_cmd');
      if (!apiKeyCmd) return '';

      const options = Desktop.buildOptions();
      const proc = child_process.spawn(apiKeyCmd, options);

where it treats the whole string as one executable. I've filed #386 to fix it.

The /usr/bin/echo hi is just fact a placeholder to refer to some command returning a proper API key.

@gandarez
Copy link
Member

gandarez commented Apr 9, 2024

I see. Let's just wait for @alanhamlett input.

@gandarez gandarez reopened this Apr 9, 2024
@gandarez gandarez transferred this issue from wakatime/wakatime-cli Apr 9, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants