datree icon indicating copy to clipboard operation
datree copied to clipboard

inject the account token from the pre-commit config to the docker image

Open eyarz opened this issue 3 years ago • 5 comments

Is your feature request related to a problem? Please describe. when running Datree's pre-commit, there is no ("native") way to pass the account token to the docker image

Describe the solution you'd like A way to inject the account token from the pre-commit config

Describe alternatives you've considered pass the account token as env variable to the docker image

eyarz avatar Nov 02 '21 16:11 eyarz

Would you consider a PR to add in a --token flag to the CLI that accepts this parameter rather than an environment variable? Through this approach a user could configure their .pre-commit-config.yaml file like so:

repos:
- repo: https://github.com/datreeio/datree
  rev: 0.14.49
  hooks:
  - id: datree-docker
    args: ['--token abcd123456789']

If you're open to that approach I could mock something up to quickly test if this solution will work with the existing pre-commit-hooks.yaml file and the existing args being passed in using the docker_image language type in pre-commit.

kevholmes avatar Nov 23 '21 03:11 kevholmes

Hi @kevholmes , We actually have support for env variable. If you use DATREE_TOKEN (https://hub.datree.io/account-token#lz-how-it-works) you can set a token in runtime, which will work similarly to --token flag. Using datree config set token <token> will also do the trick.

The issue here is adding this behavior to the docker run functionality, allowing docker to have the local token in the pre-commit step. One of the solutions can be doing docker run -e DATREE_TOKEN=$LOCAL_TOKEN with a script running beforehand updating LOCAL_TOKEN with the token located in ~/.datree/config.yaml if exists.

dimabru avatar Nov 23 '21 10:11 dimabru

Hey @dimabru,

Yeah, that's my issue with using the env var solution, there's not really any support for that with the docker_image type in pre-commit. We can pass in extra command line args for the cli invocation of datree but there's no documented way to use environment variables in such a way with pre-commit. I could try to write a test script up where we attempt to pass in an env-var through pre-commit but I do not believe it supports any kind of env var awareness.

kevholmes avatar Nov 23 '21 14:11 kevholmes

I see. Can we achieve the same solution running datree config set token $TOKEN && datree test ...? I'm trying to avoid multiple touch-points for token insertion. This can add complexity to debugging if we place the same token in multiple places with ambiguity regarding variable precedence.

This is not a constraint though, if adding a token flag is the best solution we can certainly do that and update docs for clarity

dimabru avatar Nov 23 '21 15:11 dimabru

I'll mock something up to see if we can get $TOKEN into the datree docker img that pre-commit runs. It's not something that I've run into in the documentation so it might be supported just undocumented. It makes sense to try and exhaust our potential solutions before adding more complexity to the app.

kevholmes avatar Nov 23 '21 15:11 kevholmes