-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* supports HTTP * support TLS interception e.g. for HTTPS * support CA generation via cli * first draft of plugin API * support commands from plugins * includes Dockerfile * includes basic configuration
- Loading branch information
Showing
44 changed files
with
2,277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
############### | ||
# Directories # | ||
############### | ||
|
||
.git/ | ||
plugins/ | ||
|
||
######### | ||
# Files # | ||
######### | ||
|
||
*.out | ||
main | ||
inetmock | ||
README.md | ||
.dockerignore | ||
.gitignore | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
assets/fakeFiles/* filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
######### | ||
# files # | ||
######### | ||
|
||
**/cov.out | ||
**/cov-raw.out | ||
**/*.so | ||
*.key | ||
*.pem | ||
inetmock | ||
main | ||
|
||
############### | ||
# directories # | ||
############### | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
FROM golang:1.14-buster as build | ||
|
||
# Create appuser. | ||
ARG USER=inetmock | ||
ARG USER_ID=10001 | ||
|
||
ENV CGO_ENABLED=0 | ||
|
||
# Prepare build stage - can be cached | ||
WORKDIR /work | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends make gcc && \ | ||
adduser \ | ||
--disabled-password \ | ||
--gecos "" \ | ||
--home "/nonexistent" \ | ||
--shell "/sbin/nologin" \ | ||
--no-create-home \ | ||
--uid "${USER_ID}" \ | ||
"${USER}" | ||
|
||
# Fetch dependencies | ||
COPY Makefile go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY ./ ./ | ||
|
||
# Build binary and plugins | ||
RUN make CONTAINER=yes | ||
|
||
# Runtime layer | ||
|
||
FROM scratch | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /etc/passwd /etc/group /etc/ | ||
COPY --from=build --chown=$USER /work/inetmock ./ | ||
COPY --from=build --chown=$USER /work/plugins/ ./plugins/ | ||
|
||
USER $USER:$USER | ||
|
||
ENTRYPOINT ["/app/inetmock"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
VERSION = $(shell git describe --dirty --tags --always) | ||
DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) | ||
BUILD_PATH = $(DIR)/main.go | ||
PKGS = $(shell go list ./...) | ||
TEST_PKGS = $(shell find . -type f -name "*_test.go" -printf '%h\n' | sort -u) | ||
GOARGS = GOOS=linux GOARCH=amd64 | ||
GO_BUILD_ARGS = -ldflags="-w -s" | ||
GO_CONTAINER_BUILD_ARGS = -ldflags="-w -s" -a -installsuffix cgo | ||
GO_DEBUG_BUILD_ARGS = -gcflags "all=-N -l" | ||
BINARY_NAME = inetmock | ||
PLUGINS = $(wildcard $(DIR)pkg/plugins/*/.) | ||
DEBUG_PORT = 2345 | ||
DEBUG_ARGS?= --development-logs=true | ||
INETMOCK_PLUGINS_DIRECTORY = $(DIR)plugins | ||
|
||
.PHONY: clean all format deps compile debug test cli-cover-report html-cover-report plugins $(PLUGINS) | ||
|
||
all: clean format compile test plugins | ||
|
||
clean: | ||
@find $(DIR) -type f \( -name "*.out" -or -name "*.so" \) -exec rm -f {} \; | ||
@rm -rf $(DIR)plugins | ||
@rm -f $(DIR)$(BINARY_NAME) $(DIR)main | ||
|
||
format: | ||
@go fmt $(PKGS) | ||
|
||
deps: | ||
@go mod tidy | ||
@go build -v $(BUILD_PATH) | ||
|
||
compile: deps | ||
ifdef DEBUG | ||
@echo 'Compiling for debugging...' | ||
@$(GOARGS) go build $(GO_DEBUG_BUILD_ARGS) -o $(DIR)$(BINARY_NAME) $(BUILD_PATH) | ||
else ifdef CONTAINER | ||
@echo 'Compiling for container usage...' | ||
@$(GOARGS) go build $(GO_CONTAINER_BUILD_ARGS) -o $(DIR)$(BINARY_NAME) $(BUILD_PATH) | ||
else | ||
@echo 'Compiling for normal Linux env...' | ||
@$(GOARGS) go build $(GO_BUILD_ARGS) -o $(DIR)$(BINARY_NAME) $(BUILD_PATH) | ||
endif | ||
|
||
debug: | ||
@export INETMOCK_PLUGINS_DIRECTORY | ||
@dlv exec $(DIR)$(BINARY_NAME) \ | ||
--headless \ | ||
--listen=:2345 \ | ||
--api-version=2 \ | ||
--accept-multiclient \ | ||
-- $(DEBUG_ARGS) | ||
test: | ||
@go test -coverprofile=./cov-raw.out -v $(TEST_PKGS) | ||
@cat ./cov-raw.out | grep -v "generated" > ./cov.out | ||
|
||
cli-cover-report: | ||
@go tool cover -func=cov.out | ||
|
||
html-cover-report: | ||
@go tool cover -html=cov.out -o .coverage.html | ||
|
||
plugins: $(PLUGINS) | ||
$(PLUGINS): | ||
$(MAKE) -C $@ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Git LFS file not shown
Git LFS file not shown
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
endpoints: | ||
plainHttp: | ||
handler: http_mock | ||
listenAddress: 0.0.0.0 | ||
port: 80 | ||
options: | ||
rules: | ||
- pattern: ".*\\.(?i)exe" | ||
target: ./assets/fakeFiles/sample.exe | ||
- pattern: ".*\\.(?i)(jpg|jpeg)" | ||
target: ./assets/fakeFiles/default.jpg | ||
- pattern: ".*\\.(?i)png" | ||
target: ./assets/fakeFiles/default.png | ||
- pattern: ".*\\.(?i)gif" | ||
target: ./assets/fakeFiles/default.gif | ||
- pattern: ".*\\.(?i)ico" | ||
target: ./assets/fakeFiles/default.ico | ||
- pattern: ".*\\.(?i)txt" | ||
target: ./assets/fakeFiles/default.txt | ||
- pattern: ".*" | ||
target: ./assets/fakeFiles/default.html | ||
httpsDowngrade: | ||
handler: tls_interceptor | ||
listenAddress: 0.0.0.0 | ||
port: 443 | ||
options: | ||
ecdsaCurve: P256 | ||
validity: | ||
ca: | ||
notBeforeRelative: 17520h | ||
notAfterRelative: 17520h | ||
domain: | ||
notBeforeRelative: 168h | ||
notAfterRelative: 168h | ||
rootCaCert: | ||
publicKey: ./ca.pem | ||
privateKey: ./ca.key | ||
certCachePath: /tmp/inetmock/ | ||
target: | ||
ipAddress: 127.0.0.1 | ||
port: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module github.com/baez90/inetmock | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/spf13/cobra v0.0.6 | ||
github.com/spf13/pflag v1.0.5 | ||
github.com/spf13/viper v1.4.0 | ||
go.uber.org/zap v1.14.1 | ||
golang.org/x/tools v0.0.0-20191127201027-ecd32218bd7f // indirect | ||
gopkg.in/yaml.v2 v2.2.8 // indirect | ||
) |
Oops, something went wrong.