Using environment variable in pre-commit hook arguments
Asked Answered
A

1

6

I am struggling to use an environment variable into the arguments section of pre-commit hooks config

following is an example spinet to show what I am trying to do

 - repo: https://github.com/returntocorp/semgrep
   rev: "v0.1.2"
   hooks:
     - id: semgrep
       name: semgrep my_custom_rule
       args:
         [
           "--config",
           "https://PRIVATE-TOKEN:{$TOKEN}@gitlab.com/api/proj/packages/test-rule.yml",
           "--error",
         ]

I have already set the value of TOKEN into environment variable. But still in processing the URL is taken as https://PRIVATE-TOKEN:{$TOKEN}@gitlab.com/api/proj/packages/test-rule.yml instead of with actual token value. I want to avoid putting actual token into config for security reasons.

Auctorial answered 18/7, 2022 at 8:3 Comment(0)
T
12

there is no substitution in the configuration -- your best bet is to use a shell or shell script which substitutes variables -- for instance:

    entry: ./run-semgrep

and then perform your custom substitution inside that shell script


disclaimer: I wrote pre-commit

Tejada answered 18/7, 2022 at 14:8 Comment(5)
Ah funny stuff ... you really wrote pre-commit ... Thanks by the way :) :)Distance
This won't work for my use-case: I need to pass an environment variable into a docker volume binding in entry:.Telemetry
@MatthewSchinckel nothing is stopping you from writing a script which calls docker with whatever you needTejada
Yeah, that's my current plan-of-attack.Telemetry
so I'm confused -- you said it won't work for your use case -- and yet I just reiterated what this answer is in a commentTejada

© 2022 - 2024 — McMap. All rights reserved.