stripe-cli: listen fails when run non-interactively

Issue

I am trying to run stripe listen non-interactively in one docker container to proxy events to a different docker container, so that I can validate my webhooks in an automated test.

I run:

stripe listen --device-name my-test --api-key sk_test_XXXX

The output is:

your device name has not been configured. Use `stripe configure` to set your device name

but if I then run:

stripe configure

it outputs:

unknown command "configure" for "stripe"

So, the issue is:

  1. I don’t know what a device is, but according to stripe listen --help I should be able to set this with --device-name. The first command should succeed as is.
  2. The error output should not refer to a nonexistent command.

If I populate ~/.config/stripe/config.toml directly instead of using command-line flags, stripe listen works great. (While undocumented, this might be a better idea regardless, because then I don’t need to worry about my API key being in an error message if the command fails.)

Environment

Ubuntu 18.04 running under Docker, Stripe CLI 0.2.3 installed via https://github.com/stripe/stripe-cli/releases/download/v0.2.3/stripe_0.2.3_linux_amd64.deb.

Postscript

stripe listen is great. I’ve been wanting something like this for a long time.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

For those who may stumble upon this in the future, the solution is to create a .env file with your docker-compose.yml.

.env file

STRIPE_SECRET_KEY=sk_test_***
STRIPE_DEVICE_NAME=my-laptop

docker-compose.yml

version: '3'
services:
  stripe:
    image: stripe/stripe-cli
    command: listen --api-key ${STRIPE_SECRET_KEY} --device-name ${STRIPE_DEVICE_NAME}

Then run $ docker-compose up stripe

If you have ${...} anywhere in your docker-compose file, it looks in .env for the value.

Hope this helps.

Hey @aminnaggar, thanks for the report. I think support for setting the API key via an environment variable is broken in the current version (0.8.0). We will investigate and report back here soon. Sorry for the inconvenience!

UPDATE 2021

For those looking to setup stripe cli webhooks with their docker-compose test environment, here’s my setup:

.env file

STRIPE_PRIVATE_KEY=sk_test_***

docker-compose.yml

version: '3'
services:
  stripe:
    image: stripe/stripe-cli
    command: listen --api-key ${STRIPE_PRIVATE_KEY} --forward-to server:3000 -a

  server:
    ...

Then run $ docker-compose up

Take note that the server service is a node server, accessible at localhost:3000. The stripe service accesses it in the docker-compose network through server:3000.

Lastly, the -a flag allows us to listen to events triggered from the stripe test environment. You can remove the -a flag if you want to only listen to events triggered locally.

Hope this helps.

Hey great work on providing a docker image for this. I’m running into the same issue as @Freezystem before me. I’m tryin to run this non-interactively, and I’m getting

stripe_1 | your API key has not been configured. Use stripe login to set your API key

this is my configuration

  # stripe config from docker-compose.yml
  stripe:
    image: stripe/stripe-cli:v0.8.0
    command: listen --forward-to http://localhost:3030/webhooks/stripe
    environment:
      - STRIPE_SECRET_KEY=sk_test_***
      - STRIPE_DEVICE_NAME=my-laptop

What am I missing? Cheers

Hey all, closing this issue since it looks like we resolved the underlying issues with the listen command. If you’re still having issues please open a new issue!

For setting --device-name, there was a bug there that I fixed in version 0.5.4 if you want to give that a shot! Sorry for the delay there

@Freezystem Done! https://hub.docker.com/r/stripe/stripe-cli

Also, we’d love to hear about how you’re using the CLI in your CI exactly! If you have a few minutes to send us a message using the form at https://stri.pe/cli-feedback, we’d really appreciate it.

@ob-stripe excellent, works great.

@madeleineth You could create the configuration file manually in your container (it’s read from ${XDG_CONFIG_HOME}/stripe/config.toml, or $HOME/.config/stripe/config.toml if XDG_CONFIG_HOME is not set), or you can set the API key and device name via environment variables: STRIPE_SECRET_KEY and STRIPE_DEVICE_NAME respectively.

Out of curiosity, would you find it helpful if we provided Docker images for the CLI?