Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
eyarz opened this issue Nov 2, 2021 · 5 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers up for grabs Looking for a contributor to take this task
Projects

Comments

@eyarz
Copy link
Member

eyarz commented Nov 2, 2021

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 eyarz added enhancement New feature or request good first issue Good for newcomers labels Nov 2, 2021
@eyarz eyarz added the up for grabs Looking for a contributor to take this task label Nov 16, 2021
@kevholmes
Copy link
Contributor

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.

@myishay myishay removed their assignment Nov 23, 2021
@dimabru
Copy link
Contributor

dimabru commented Nov 23, 2021

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.

@eyarz eyarz added this to To do in Datree via automation Nov 23, 2021
@kevholmes
Copy link
Contributor

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.

@dimabru
Copy link
Contributor

dimabru commented Nov 23, 2021

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

@kevholmes
Copy link
Contributor

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.

@datreeio datreeio deleted a comment from helper-uttam Nov 24, 2021
@datreeio datreeio deleted a comment from helper-uttam Nov 24, 2021
@noaabarki noaabarki added the WIP Working in progress (will be deployed soon) label Apr 18, 2022
@eyarz eyarz removed the WIP Working in progress (will be deployed soon) label Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers up for grabs Looking for a contributor to take this task
Projects
Datree
To Do
Development

No branches or pull requests

5 participants