Code Monkey home page Code Monkey logo

pre-commit-opa's Introduction

pre-commit-opa

Python application

Pre-commit git hooks for Open Policy Agent (OPA) and Rego development

Using pre-commit-opa with pre-commit

Add the pre-commit-opa repo to the .pre-commit-config.yaml file in your git root directory, and add any number of the available hooks:

repos:
- repo: https://github.com/anderseknert/pre-commit-opa
  rev: v1.4.1
  hooks:
  - id: opa-fmt
  - id: opa-check
  - id: opa-test
  - id: conftest-test
  - id: conftest-verify

Once saved, run pre-commit install to install git pre-commit hooks.

Hooks available

opa-fmt

Runs opa fmt on any rego files in the repository.

Note that any files changed by this hook will need to be re-added (git add) to be included in the commit.

opa-check

Runs opa check on any rego files in the repository.

opa-test

If rego files are present in commit, runs opa test in git root directory.

Since it doesn't make sense to only provide opa test with the files changed (as these might not include tests), the default is to run opa test . in the project root directory. If you keep your policies, tests and data in a specific directory, you'll likely want to change this by pointing out the location of that, like:

- id: opa-test
  args: ['my/policies', 'my/other/policies/']

conftest-fmt

Runs conftest fmt on any Rego files in the repository.

Note that any files changed by this hook will need to be re-added (git add) to be included in the commit.

conftest-test

Runs conftest test on any configuration file format supported by conftest.

Just like with opa-test you'll likely want to specify the location of your conftest policies, and possibly what type of files changed should trigger the hook:

- id: conftest-test
  args: ['--policy', 'conftest/policy']
  files: conftest/.*\.yaml$

conftest-verify

If rego files are present in commit, runs conftest verify in git root directory.

Just like with conftest-test you'll likely want to specify the location of your conftest policies, and possibly what type of files changed should trigger the hook:

- id: conftest-verify
  args: ['--policy', 'conftest/policy']
  files: conftest/.*\.yaml$

pre-commit-opa's People

Contributors

anderseknert avatar artis3n avatar bplotnick avatar dependabot-preview[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pre-commit-opa's Issues

Opa check seems to run only against stages rego files

Describe the bug

opa-check fails with pre commit hook however, running opa check . manually works.

My situation

  • a.rego is already committed.
  • b.rego is staged and it imports a.rego
  • opa-check fails when I try to commit

My speculation
I'm relatively new to pre-commit however I have a feeling that opa check via opa-check is running only against the staged files, which means opa check b.rego and it will fail because it doesn't include a.rego which is necessary.

Either opa check a.rego b.rego or opa check *.rego or opa check . should succeed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.