Forum Discussion

mzs's avatar
mzs
New Member
22 hours ago

Disabling interactive prompt to set up account in op CLI?

I have a developer environment setup script that tries to get some optional secrets from the 1Password CLI. Some developers aren't signed in, or don't want to expose their 1Password on the CLI; I don't want to force it on them.

On a machine where the CLI has been installed, but has not been set up with an account, a command like this:

somevar=$(op item get --vault "test vault" "test item" --fields credential --reveal)

... gets stuck on this interactive prompt:

No accounts configured for use with 1Password CLI. You can either: - Turn on the 1Password desktop app integration to sign in with the accounts you've added to the app: https://developer.1password.com/docs/cli/app-integration/ for details. - Add an account manually with 'op account add' and sign in by entering your password on the command line. See 'op account add --help' for details. - Authenticate using a 1Password service account by setting the 'OP_SERVICE_ACCOUNT_TOKEN' environment variable to your service account token. Learn more: https://developer.1password.com/docs/service-accounts/ - Use 1Password CLI with a Connect server by setting the 'OP_CONNECT_HOST' and 'OP_CONNECT_TOKEN' environment variables to your Connect host and token, respectively. Learn more: https://developer.1password.com/docs/connect/ Do you want to add an account manually now? [Y/n]

That blocks the script. How can I disable that, so the op command just exits with a failure code if it hasn't been set up? I tried `</dev/null` and `2</dev/null`, no dice.

Secondly, how can I reliably check if the CLI is logged in, either via `eval $(op signin)` or the desktop integration?

`op whoami` works with `eval $(op signin)`, but not with the desktop integration: it reports `account is not signed in`

The best I could find was `op vault list`, which exits with code 0 if the user is logged in either way, but it seems a bit wasteful.

Thanks!

No RepliesBe the first to reply