|
| 1 | +.DEFAULT_GOAL := help |
| 2 | + |
| 3 | +.PHONY: clean build fmt test |
| 4 | + |
| 5 | +ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) |
| 6 | + |
| 7 | +BUILD_FLAGS ?= |
| 8 | +VERSION = "0.0.1" |
| 9 | +BRANCH = $(shell git rev-parse --abbrev-ref HEAD) |
| 10 | +REVISION = $(shell git describe --tags --always --dirty) |
| 11 | +BUILD_DATE = $(shell date +'%Y.%m.%d-%H:%M:%S') |
| 12 | +LDFLAGS ?= -w -s |
| 13 | +BINARY = reverse-http |
| 14 | + |
| 15 | +TEST_AGENT_ID = 4711 |
| 16 | +TEST_AUTH = ha-tls |
| 17 | +TEST_STORE_TYPE = none |
| 18 | + |
| 19 | +default: help |
| 20 | + |
| 21 | +.PHONY: help |
| 22 | +help: |
| 23 | + @grep -E '^[a-zA-Z%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
| 24 | + |
| 25 | +build: ## Build executable |
| 26 | + @CGO_ENABLED=0 GO111MODULE=on go build -mod=vendor -o $(BINARY) $(BUILD_FLAGS) -ldflags "$(LDFLAGS)" . |
| 27 | + |
| 28 | +test: ## Test |
| 29 | + @GO111MODULE=on go test -count=1 -mod=vendor -v ./... |
| 30 | + |
| 31 | +fmt: ## Go format |
| 32 | + go fmt ./... |
| 33 | + |
| 34 | +vet: ## Go vet |
| 35 | + go vet ./... |
| 36 | + |
| 37 | +clean: ## Clean |
| 38 | + @rm -rf $(BINARY) |
| 39 | + |
| 40 | +lint: ## Lint |
| 41 | + @golangci-lint run |
| 42 | + |
| 43 | +.PHONY: deps |
| 44 | +deps: ## Get dependencies |
| 45 | + GO111MODULE=on go get ./... |
| 46 | + |
| 47 | +.PHONY: vendor |
| 48 | +vendor: ## Go vendor |
| 49 | + GO111MODULE=on go mod vendor |
| 50 | + |
| 51 | +.PHONY: tidy |
| 52 | +tidy: ## Go tidy |
| 53 | + GO111MODULE=on go mod tidy |
| 54 | + |
| 55 | +##### Testing |
| 56 | + |
| 57 | +docker-compose.build: |
| 58 | + docker-compose -f $(ROOT_DIR)/docker-compose.${TEST_AUTH}.yml build |
| 59 | + |
| 60 | +docker-compose.up: |
| 61 | + docker-compose -f $(ROOT_DIR)/docker-compose.${TEST_AUTH}.yml up --remove-orphans |
| 62 | + |
| 63 | +docker-compose.down: |
| 64 | + docker-compose -f $(ROOT_DIR)/docker-compose.${TEST_AUTH}.yml down --remove-orphans |
| 65 | + |
| 66 | +docker-compose.run: docker-compose.build docker-compose.up |
| 67 | + |
| 68 | +start-proxy: build |
| 69 | + @export QUIC_GO_LOG_LEVEL_=debug && ${ROOT_DIR}/reverse-http proxy --store.type="${TEST_STORE_TYPE}" --agent-server.listen-address=":4242" \ |
| 70 | + --http-proxy.listen-address=":3128" --agent-server.tls.file.key=tests/cfssl/certs/proxy-key.pem --agent-server.tls.file.cert=tests/cfssl/certs/proxy.pem |
| 71 | + |
| 72 | +start-proxy-tls: build |
| 73 | + @export QUIC_GO_LOG_LEVEL_=debug && ${ROOT_DIR}/reverse-http proxy --store.type="${TEST_STORE_TYPE}" --agent-server.listen-address=":4242" \ |
| 74 | + --http-proxy.listen-address=":3128" --agent-server.tls.file.key=tests/cfssl/certs/proxy-key.pem --agent-server.tls.file.cert=tests/cfssl/certs/proxy.pem \ |
| 75 | + --http-proxy.tls.enable --http-proxy.tls.file.key=tests/cfssl/certs/proxy-key.pem --http-proxy.tls.file.cert=tests/cfssl/certs/proxy.pem |
| 76 | + |
| 77 | +start-proxy2: build |
| 78 | + @${ROOT_DIR}/reverse-http proxy --store.type="memcached" --agent-server.listen-address=":4243" --http-proxy.listen-address=":3127" \ |
| 79 | + --store.http-proxy-address="localhost:3127" --agent-server.tls.file.key=tests/cfssl/certs/proxy-key.pem --agent-server.tls.file.cert=tests/cfssl/certs/proxy.pem |
| 80 | + |
| 81 | +start-agent: build |
| 82 | + @export QUIC_GO_LOG_LEVEL_=debug && ${ROOT_DIR}/reverse-http agent --auth.noauth.agent-id="4711" --agent-client.server-address="localhost:4242" --agent-client.tls.file.root-ca=tests/cfssl/certs/ca.pem |
| 83 | + |
| 84 | +start-agent2: build |
| 85 | + @${ROOT_DIR}/reverse-http agent --auth.noauth.agent-id="4712" --agent-client.server-address="localhost:4243" --agent-client.tls.insecure-skip-verify |
| 86 | + |
| 87 | +start-lb: build |
| 88 | + @${ROOT_DIR}/reverse-http lb --http-proxy.listen-address=":3129" --store.type="${TEST_STORE_TYPE}" |
| 89 | + |
| 90 | +curl-proxy: |
| 91 | + curl -x "http://${TEST_AGENT_ID}:noauth@localhost:3128" https://httpbin.org/ip |
| 92 | + |
| 93 | +curl-proxy-tls: |
| 94 | + curl -x "https://${TEST_AGENT_ID}:noauth@localhost:3128" https://httpbin.org/ip --proxy-cacert tests/cfssl/certs/ca.pem |
| 95 | + |
| 96 | +curl-lb: |
| 97 | + curl -x "http://${TEST_AGENT_ID}:noauth@localhost:3129" https://httpbin.org/ip |
| 98 | + |
| 99 | +jwt-keys: build |
| 100 | + @${ROOT_DIR}/reverse-http auth key private --out=${ROOT_DIR}/tests/jwt/auth-key-private.pem |
| 101 | + @${ROOT_DIR}/reverse-http auth key public --out=${ROOT_DIR}/tests/jwt/auth-key-public.pem --in=${ROOT_DIR}/tests/jwt/auth-key-private.pem |
| 102 | + @${ROOT_DIR}/reverse-http auth jwt token --duration=87600h --agent-id="4711" --role "client" --out ${ROOT_DIR}/tests/jwt/auth-client-jwt-4711.b64 --in=${ROOT_DIR}/tests/jwt/auth-key-private.pem |
| 103 | + @${ROOT_DIR}/reverse-http auth jwt token --duration=87600h --agent-id="4711" --role "agent" --out ${ROOT_DIR}/tests/jwt/auth-agent-jwt-4711.b64 --in=${ROOT_DIR}/tests/jwt/auth-key-private.pem |
| 104 | + @${ROOT_DIR}/reverse-http auth jwt token --duration=87600h --agent-id="4712" --role "client" --out ${ROOT_DIR}/tests/jwt/auth-client-jwt-4712.b64 --in=${ROOT_DIR}/tests/jwt/auth-key-private.pem |
| 105 | + @${ROOT_DIR}/reverse-http auth jwt token --duration=87600h --agent-id="4712" --role "agent" --out ${ROOT_DIR}/tests/jwt/auth-agent-jwt-4712.b64 --in=${ROOT_DIR}/tests/jwt/auth-key-private.pem |
| 106 | + |
| 107 | +start-proxy-jwt: build |
| 108 | + @${ROOT_DIR}/reverse-http proxy --auth.type="jwt" --auth.jwt.public-key=tests/jwt/auth-key-public.pem \ |
| 109 | + --agent-server.listen-address=":4242" --http-proxy.listen-address=":3128" --agent-server.tls.file.key=tests/cfssl/certs/proxy-key.pem --agent-server.tls.file.cert=tests/cfssl/certs/proxy.pem |
| 110 | + |
| 111 | +start-agent-jwt: build |
| 112 | + @$(eval JWT_TOKEN=$(shell cat tests/jwt/auth-agent-jwt-${TEST_AGENT_ID}.b64)) |
| 113 | + @${ROOT_DIR}/reverse-http agent --auth.type="jwt" --agent-client.server-address="localhost:4242" --agent-client.tls.file.root-ca=tests/cfssl/certs/ca.pem --auth.jwt.token="file:tests/jwt/auth-agent-jwt-${TEST_AGENT_ID}.b64" |
| 114 | + |
| 115 | +curl-proxy-jwt: |
| 116 | + @$(eval JWT_TOKEN=$(shell cat tests/jwt/auth-client-jwt-${TEST_AGENT_ID}.b64)) |
| 117 | + curl -x "http://${TEST_AGENT_ID}:${JWT_TOKEN}@localhost:3128" https://httpbin.org/ip |
0 commit comments