/go-infrabin

infrabin written in go

Primary LanguageGoMIT LicenseMIT

go-infrabin

Go Report Card Coverage Status

infrabin written in go.

Warning: go-infrabin exposes sensitive endpoints and should NEVER be used on the public Internet.

Usage

go-infrabin exposes three ports:

  • 8888 as a http rest port
  • 8899 as the http rest admin port, for liveness and readiness probes
  • 50051 as a grpc port

Installation

See the README.

Command line flags

  • --enable-proxy-endpoint: If true allows /proxy and /aws endpoints

Environment variables

  • 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.

Service Endpoints

  • 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: infrabin.Infrabin.Delay rest: GET /delay/<seconds>

    • grpc request
      message DelayRequest {
        int32 duration = 1;
      }
      
    • returns: a JSON response
      {
          "delay": "<seconds>"
      }
  • 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: 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> or 404 if the environment variable does not exist
      {
          "env": {
              "<env_var>": "<env_var_value>"
          }
      }
  • 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
  • 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

Admin Endpoints

  • 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"
      }

Errors

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"
    }

Contributing

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