infrabin written in go.
Warning: go-infrabin
exposes sensitive endpoints and should NEVER be used on the public Internet.
go-infrabin
exposes three ports:
8888
as a http rest port8899
as the http rest admin port, for liveness and readiness probes50051
as a grpc port
See the README.
--enable-proxy-endpoint
: If true allows/proxy
and/aws
endpoints
INFRABIN_MAX_DELAY
: to change the maximum value for the/delay
endpoint. Default to 120.FAIL_ROOT_HANDLER
: if set, the/
endpoint will return a 503. This is useful when doing a B/G deployment to test the failure and rollback scenario.
-
grpc:
infrabin.Infrabin.Root
rest:GET /
- grpc request
message Empty {}
- returns: a JSON response
{ "hostname": "<hostname>", "kubernetes": { "pod_name": "<pod_name>", "namespace": "<namespace>", "pod_ip": "<pod_ip>", "node_name": "<node_name>" } }
- grpc request
-
grpc:
infrabin.Infrabin.Delay
rest:GET /delay/<seconds>
- grpc request
message DelayRequest { int32 duration = 1; }
- returns: a JSON response
{ "delay": "<seconds>" }
- grpc request
-
grpc:
infrabin.Infrabin.Headers
rest:GET /headers
- grpc request
message HeadersRequest { map<string, string> headers = 1; }
- returns: a JSON response with HTTP headers
{ "headers": "<request headers>" }
- grpc request
-
grpc:
infrabin.Infrabin.Env
rest:GET /env/<env_var>
- grpc request
message EnvRequest { string env_var = 1; }
- returns: a JSON response with the requested
<env_var>
or404
if the environment variable does not exist{ "env": { "<env_var>": "<env_var_value>" } }
- grpc request
-
grpc:
infrabin.Infrabin.Proxy
rest:GET /proxy
- NOTE:
--enable-proxy-endpoint
must be set - grpc request
message ProxyRequest { string method = 1; string url = 2; google.protobuf.Struct body = 3; map<string, string> headers = 4; }
- returns: JSON of proxied request
- NOTE:
-
grpc:
infrabin.Infrabin.AWS
rest:GET /aws/<path>
- NOTE:
--enable-proxy-endpoint
must be set - grpc request
message AWSRequest { string path = 1; }
- returns: JSON of AWS GET call
- NOTE:
- grpc:
infrabin.Infrabin.Liveness
rest:GET /liveness
- grpc request
message Empty {}
- returns: a JSON response if healthy or the status code
503
if unhealthy.{ "liveness": "pass" }
- grpc request
When caling the http endpoint, errors are mapped by grpc-gateway
. They
have the following format:
- returns:
{ "code": 3, "message": "type mismatch, parameter: duration, error: strconv.ParseInt: parsing \"21asd\": invalid syntax" }
To build locally, ensure you have compiled the protocol schemas. You
will need the protoc
binary which can install by following
these instructions or if using Homebrew
brew install protobuf
You will also need to protoc go plugins for protofuf, grpc, and
grpc-gateway. go mod tidy
will fetch the versions specified in
go.mod
, and go install
will install that version.
go get -t -v -d ./...
go install \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
make run
will compile the protocol
buffers, or you can run:
make protoc
To run the tests:
make test
To run the server locally:
make run
To test http:
http localhost:8888/
To test grpc, use your favourite grpc tool like evans:
echo '{}' | evans -r cli call infrabin.Infrabin.Root