Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
81d8e54
[RM-5352] Regula run initial implementation
jason-fugue Apr 24, 2021
9ca8ae3
[RM-5352] Recurse dirs
jason-fugue Apr 24, 2021
2af6258
[RM-5352] Ugly hack to make includes work
jason-fugue Apr 24, 2021
16e44b1
[RM-5352] Generate RegulaInput in order of filenames
jason-fugue Apr 24, 2021
655319c
[RM-5352] Remove problematic rwildcard from make
jason-fugue Apr 24, 2021
cf2ffde
[RM-5352] Small osFs implementation
jason-fugue Apr 24, 2021
c88aa3e
[RM-5352] Add install make target
jason-fugue Apr 25, 2021
7c068be
[RM-5352] Override input type detection
jason-fugue Apr 25, 2021
f5f3b36
[RM-5352] Implement severity and non-zero exit code
jason-fugue Apr 25, 2021
22eb0cb
[RM-5352] Use cwd as default
jason-fugue Apr 25, 2021
63e8b0f
[RM-5352] Skip severity check if no failures
jason-fugue Apr 25, 2021
b495486
[RM-5352] Load input from stdin
jason-fugue Apr 26, 2021
1859041
[RM-5352] pkg/loader improvements
jason-fugue Apr 26, 2021
093c6b5
[RM-5352] Add table output format
jason-fugue Apr 26, 2021
ab1bc93
[RM-5352] Add JUnit reporter
jason-fugue Apr 27, 2021
d5d21fb
[RM-5352] Add directory loading concept
jason-fugue Apr 27, 2021
41d0931
[RM-5352] Add TAP reporter
jason-fugue Apr 27, 2021
b13cabe
[RM-5352] Implement gitignore functionality
jason-fugue Apr 28, 2021
51f5013
[RM-5352] Better type detector implementation
jason-fugue Apr 28, 2021
e3f31ce
[RM-5352] Better detector implementation
jason-fugue Apr 28, 2021
0481d35
[RM-5352] Remove generic yaml and json detectors
jason-fugue Apr 28, 2021
35e9887
[RM-5352] Better loader behavior
jason-fugue Apr 28, 2021
0dfef24
[RM-5352] Started fixing linting errors
jason-fugue Apr 28, 2021
3262a01
[RM-5352] Add license and some inline docs
jason-fugue Apr 28, 2021
2b0781e
[RM-5352] Simplify lines that set noIgnore
jason-fugue Apr 28, 2021
07d929a
[RM-5352] Better interfaces
jason-fugue Apr 29, 2021
eaa545c
[RM-5352] Fix bug with gitignore behavior
jason-fugue Apr 29, 2021
d55fd3d
[RM-5352] In-progress: adding tests
jason-fugue Apr 30, 2021
4657aef
[RM-5352] About to clean up
jason-fugue Apr 30, 2021
b2c9551
[RM-5352] Working test and repl, but needs to be cleaned up
jason-fugue May 3, 2021
ff9e1be
[RM-5352] Some cleanup to repl and test
jason-fugue May 3, 2021
6fbfd87
[RM-5352] Update rule tests to use regula_load function
jason-fugue May 3, 2021
14e15fd
[RM-5352] Run regula rego tests with go test
jason-fugue May 3, 2021
ff68e22
[RM-5352] Fix copy and paste issue in test messages
jason-fugue May 3, 2021
64d6648
[RM-5352] Update and include examples tests in go test
jason-fugue May 4, 2021
f6f83e0
[RM-5352] Replace git2go with go-git
jason-fugue May 4, 2021
44388b5
[RM-5352] Apply gitignore while finding gitignores
jason-fugue May 4, 2021
417b8e9
[RM-5352] Preparing for release
jason-fugue May 5, 2021
bc3d33a
[RM-5352] Started on a gitignore optimization
jason-fugue May 5, 2021
90dc0ab
[RM-5352] Ignore non-input paths in gitignore search
jason-fugue May 5, 2021
2f5acf3
[RM-5352] Got the gitignore support feeling fast
jason-fugue May 5, 2021
afafadd
[RM-5352] Cleaned up ReadPatterns a little
jason-fugue May 6, 2021
d8c5c8f
[RM-5352] Better banner for REPL
jason-fugue May 6, 2021
9cee229
[RM-5352] Include OPA version in regula --version
jason-fugue May 6, 2021
c093357
[RM-5352] Fix REPL help text and use homedir for .regula-history
jason-fugue May 6, 2021
1ad7f66
[RM-5352] Handle error from rego.RunRules()
jason-fugue May 7, 2021
5cd43ae
[RM-5352] Fix stdin detection with docker w/o -it flags
jason-fugue May 11, 2021
d2cec3e
[RM-5352] Added some tests to pkg/loader
jason-fugue May 11, 2021
c70b49b
[RM-5352] Roll back OPA dep to v0.25.2 for old dedupe behavior
jason-fugue May 12, 2021
fe1651b
[RM-5352] Bump OPA back to 0.28.0
jason-fugue May 13, 2021
b5ce219
[RM-5352] Better errors for regula_load in repl
jason-fugue May 13, 2021
37c61e4
[RM-5352] Exclude regula dir in .gitignore
jason-fugue May 13, 2021
4b748e6
[RM-5352] Move test_helper lib to fugue.regula.tests
jason-fugue May 13, 2021
4b0dad5
[RM-5352] Account for multiple configs in mock_input()
jason-fugue May 18, 2021
00e3f0c
[RM-5352] Remove TAP13 reporter enum
jason-fugue May 18, 2021
b225cc8
[RM-5431] HCL Support in Regula CLI
jaspervdj-luminal May 18, 2021
1f6a9f5
[RM-5431] Sneakily implement Data for renderContext
jaspervdj-luminal May 20, 2021
f759cf4
[RM-5431] PR suggestions
jaspervdj-luminal May 20, 2021
07087cd
[RM-5431] Silence warning
jaspervdj-luminal May 20, 2021
a0ae1a6
[RM-5431] Don't relativize filepaths
jaspervdj-luminal May 22, 2021
472608e
[RM-5431] Support local references, add tf tests
jaspervdj-luminal May 24, 2021
f7ee849
[RM-5431] Improve file() support, add tests
jaspervdj-luminal May 24, 2021
48b02d7
[RM-5431] Parse .terraform/modules/modules.json
jaspervdj-luminal May 24, 2021
370b898
[RM-5431] Detector fixes
jaspervdj-luminal May 24, 2021
6eb16b8
Draft of markdown generation from rules metadata
curtis-fugue May 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.cfn linguist-language=YAML
*.tfplan linguist-language=JSON
12 changes: 5 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ on: [pull_request, push]
jobs:
test:
runs-on: ubuntu-latest
name: OPA test
name: Test
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- run: |
go get github.com/open-policy-agent/opa
go install github.com/open-policy-agent/opa
- run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- run: opa test lib rules examples tests
- run: ./scripts/check-naming.sh
with:
go-version: '^1.16'
- run: make test
- run: cd rego && ./scripts/check-naming.sh
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
.terraform/
.DS_Store
venv/
pkg/rego/lib
pkg/rego/rules
regula
regula-*
!regula/
.vscode/
.scratch/
.regula-history
build/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "providers/terraform-provider-google"]
path = providers/terraform-provider-google
url = https://github.com/hashicorp/terraform-provider-google.git
[submodule "providers/terraform-provider-aws"]
path = providers/terraform-provider-aws
url = https://github.com/hashicorp/terraform-provider-aws.git
[submodule "pkg/loader/tf_test/example-terraform-modules"]
path = pkg/loader/tf_test/example-terraform-modules
url = https://github.com/jaspervdj-luminal/example-terraform-modules.git
42 changes: 11 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
FROM python:3.9.2-alpine3.13

# We need bash for the main regula script since it uses arrays.
# We need git to support terraform modules
RUN apk add --update bash git && rm -rf /var/cache/apk/*

# Install OPA.
ARG OPA_VERSION=0.26.0
RUN wget -O '/usr/local/bin/opa' \
"https://github.com/open-policy-agent/opa/releases/download/v${OPA_VERSION}/opa_linux_amd64" &&\
chmod +x '/usr/local/bin/opa'

# Install terraform.
ARG TERRAFORM_VERSION=0.14.7
ENV TF_IN_AUTOMATION=true
RUN wget -O "/tmp/terraform-${TERRAFORM_VERSION}.zip" \
"https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" && \
unzip -d '/usr/local/bin' "/tmp/terraform-${TERRAFORM_VERSION}.zip" &&\
rm "/tmp/terraform-${TERRAFORM_VERSION}.zip"

# Install cfn-flip
ARG CFNFLIP_VERSION=1.2.3
RUN pip install "cfn-flip==${CFNFLIP_VERSION}"

# Update regula files
RUN mkdir -p /opt/regula
COPY lib /opt/regula/lib
COPY rules /opt/regula/rules
COPY bin/regula /usr/local/bin

ENTRYPOINT ["regula", "-d", "/opt/regula"]
FROM golang:1.16-alpine as builder
ARG version
ARG gitcommit
WORKDIR /build
COPY . .
ENV ldflags "-X \"github.com/fugue/regula/pkg/version.Version=${version}\" -X \"github.com/fugue/regula/pkg/version.GitCommit=${gitcommit}\""
RUN go build -ldflags="${ldflags} -s -w"

FROM alpine:latest
COPY --from=builder /build/regula /usr/local/bin
ENTRYPOINT [ "regula" ]
94 changes: 94 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
BINARY = regula
INSTALLED_BINARY = /usr/local/bin/$(BINARY)
GO_SOURCE = $(shell find cmd pkg -type f -name '*.go')
CLI_SOURCE = $(GO_SOURCE) $(wildcard cmd/*.txt) go.mod go.sum
# MOCKS_SOURCE = $(shell grep -L 'go:generate mockgen' $(GO_SOURCE))
MOCKS = $(wildcard pkg/mocks/*.go)
REGO_LIB_SOURCE = $(shell find rego/lib -type f -name '*.rego')
REGO_RULES_SOURCE = $(shell find rego/rules -type f -name '*.rego')
VERSION = $(shell cat VERSION)
GITCOMMIT = $(shell git rev-parse --short HEAD 2> /dev/null || true)
define LDFLAGS
-X \"github.com/fugue/regula/pkg/version.Version=$(VERSION)\" \
-X \"github.com/fugue/regula/pkg/version.GitCommit=$(GITCOMMIT)\"
endef
CLI_BUILD = go build -ldflags="$(LDFLAGS) -s -w"
GO_BIN_DIR= $(shell go env GOPATH)/bin
GOLINT = $(GO_BIN_DIR)/golint
MOCKGEN = $(GO_BIN_DIR)/mockgen
COPIED_REGO_LIB = pkg/rego/lib
COPIED_REGO_RULES = pkg/rego/rules

$(COPIED_REGO_LIB): $(REGO_LIB_SOURCE)
rm -rf ./$(COPIED_REGO_LIB)
cp -R rego/lib $(COPIED_REGO_LIB)

$(COPIED_REGO_RULES): $(REGO_RULES_SOURCE)
rm -rf ./$(COPIED_REGO_RULES)
cp -R rego/rules $(COPIED_REGO_RULES)

$(GOLINT):
go install golang.org/x/lint/golint

$(MOCKGEN):
go install github.com/golang/mock/[email protected]

$(BINARY): $(CLI_SOURCE) $(COPIED_REGO_LIB) $(COPIED_REGO_RULES)
$(CLI_BUILD) -v -o $@

$(BINARY)-linux-amd64: $(SOURCE)
GOOS=linux GOARCH=amd64 $(CLI_BUILD) -o $@

$(BINARY)-darwin-amd64: $(SOURCE)
GOOS=darwin GOARCH=amd64 $(CLI_BUILD) -o $@

$(INSTALLED_BINARY): $(BINARY)
cp $(BINARY) $(INSTALLED_BINARY)

# $(MOCKS): $(MOCKGEN) $(MOCKS_SOURCE)
# PATH=$(GO_BIN_DIR):$(PATH) go generate ./...

release: $(BINARY)-linux-amd64 $(BINARY)-darwin-amd64

.PHONY: install
install: $(INSTALLED_BINARY)

# .PHONY: mocks
# mocks: $(MOCKS)

.PHONY: clean
clean:
rm -f coverage.out
rm -f $(BINARY) $(BINARY)-linux-amd64 $(BINARY)-darwin-amd64

.PHONY: test
test: $(COPIED_REGO_LIB) $(COPIED_REGO_RULES)
go test -v -cover ./...

.PHONY: coverage
coverage:
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out

.PHONY: lint
lint:
$(GOLINT) ./...
go vet ./...

.PHONY: docker
docker: $(COPIED_REGO_LIB) $(COPIED_REGO_RULES)
rm -rf build
mkdir -p build
cp -R pkg build
cp -R cmd build
cp go.mod build
cp go.sum build
cp main.go build
cp Dockerfile build
cd build
docker build \
--build-arg version=$(VERSION) \
--build-arg gitcommit=$(GITCOMMIT) \
--tag fugue/regula:$(VERSION) \
--tag fugue/regula:latest \
.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
171 changes: 0 additions & 171 deletions bin/regula

This file was deleted.

Loading