Sign inSign up

mycfsg/api-proxy-gzip

By mycfsg

Updated almost 7 years ago

See https://gitlab.com/mycf.sg/api-proxy-gzip

Image
0

2.4K

mycfsg/api-proxy-gzip repository overview

Canonical documentation at: https://gitlab.com/mycf.sg/api-proxy-gzip

Note: Following is a clone of the README.md as of 10th September 2019

ProxyGzip

A proxy service that assists in compressing your requests via gzip.

Note: As of 22nd February 2019, this component is actively maintained but inactively upgraded

Why this exists

Some policies enforce analysis of ingoing and outgoing through decoding of body data. A method needed to be devised to re-encode this data upon exiting the internal network before hitting the final destination.

This is it.

Usage

How it works

This server takes in any request and transforms the request so that:

  1. The body data is compressed with gzip
  2. The Content-Length header will be set to the length of the gzipped content
  3. The Content-Encoding header will be set to "gzip"
  4. The Content-Type header will be derived from your data, or if the CONTENT_TYPE environment variable is set, that
  5. All other headers sent are re-constructed from the original client request and forwarded to the next hop server AS-IS

The transformed request is then forwarded to the next hop server and a response is received. This response is processed such that:

  1. The next hop response headers will be reflected in the response to the client AS-IS
  2. The client request headers will be reflected in the response headers prefixed with pgz-request-*
  3. The proxy server configuration will be reflected in the response headers prefixed with pgz-config-*

Configuration

Application Environment Variables

Use the following variables to configure the application.

Environment VariableDescriptionExample
ADDRNetwork interface for proxy server to listen on"0.0.0.0"
APP_IDID of the application to reflect in the logs"goproygzip"
CONTENT_TYPEForces the proxied Content-Type header to whatever you want. Useful for when the MIME type cannot automatically be detected"application/some-custom-format"
FLUENTD_HOSTHostname of the FluentD service"somefluentd"
FLUENTD_PORTPort which the FluentD service is listening on"24224"
FORWARD_TOURL to forward to. When this is left empty, the service will simply be an echo server that echoes what it will sent to the next hop server if FORWARD_TO had been specified."https://my.api.somewhere.com"
LOG_FORMATSets the logs to the format you desire for development/production."text", or "json"
PORTPort for proxy server to listen on"1337"

Deployment

Docker Compose

See the example file.

Kubernetes

See the example manifests.

Response Interpretation

Status Code

The status code will reflect the status code of the next hop response.

Headers

Headers prefixed with pgz-config- display the configuration of the ProxyGzip server.

Headers prefixed with pgz-request- display headers from the client's request.

Headers not prefixed are headers from the next hop server.

Contributing

  • Development tooling is performed via the Makefile.
  • Dependency management is done via Go Modules (from Go 1.11)
  • Non-collabs: Fork, make changes on your fork's master branch, and then issue a pull request back for changes
  • Collabs: Make changes on a branch other than master, issue a merge request
  • For quickening the process/if this repo seems dead, ping the maintainers

Running locally

make

(Manually) Getting dependencies in

The make start/make recipe already does this for you before running the application

make deps

Running tests

make test

Binary generation (compilation)

# compiles for all operating systems and architectures
make compile

# for windows
make compile.windows

# for macos
make compile.macos

# for linux
make compile.linux

Bundling Docker image for production

make package

Publish Docker image

make release

Continuous Integration Configuration

Available pipelines

Currently, there exists integrations for:

  • GitLab CI (for GitLab hosting)
  • TraviS CI (for GitHub hosting)
Environment setup
Generating SSH Deploy Keys

Run the following to generate a set of keys to use for your deploy keys:

make ssh.keys

You can find the keys in the ./bin directory as id_rsa (the private key) and id_rsa.pub (the public key). There should also be a Base 64 encoded version of the private key named id_rsa.b64 which you can copy the contents and paste into the relevant x_SSH_DEPLOY_KEY in the Pipeline Environment Variables table below.

Inserting SSH Deploy Keys - GitHub

Go to your repository and click on Settings > Deploy keys and hit the Add deploy key button on the top right of the page. Paste the contents of id_rsa.pub there as the key. Note: do not base64 encode this one.

Inserting SSH Deploy Keys - GitLab

Go to your repository's side menu in Settings > Repository > Deploy Keys and add the contents of id_rsa.pub there as the key. Note: do not base64 encode this one.

Pipeline Environment Variables

Before running the CI pipeline, you need to input the following build pipeline variables:

Environment VariableDescriptionExample
BINARY_FILENAMEFilename for the binary"proxy-gzip"
DOCKER_REGISTRY_HOSTNAMEHostname for the Docker registry"docker.io"
DOCKER_REGISTRY_USERNAMEOptional: Username for the Docker registry (if not present, the job will be skipped)"username"
DOCKER_REGSITRY_PASSWORDOptional: Password for the Docker registry (if not present, the job will be skipped)"password123"
DOCKER_IMAGE_NAMESPACEdocker.io/THIS/image:tag"zephinzer"
DOCKER_IMAGE_NAMEdocker.io/namespace/THIS:tag"proxy-gzip"
GITHUB_REPOSITORY_URLWhen present, bumps the patch version and Optional: SSH URL of the GitHub repository to release to, if not present, releasing to GitHub will be skipped"[email protected]:zephinzer/go-proxy-gzip.git"
GITHUB_SSH_DEPLOY_KEYBase64 encoded deploy key for the GitHub repository Optional: Only in play when GITHUB_REPOSITORY_URL is specified.""
GITHUB_OAUTH_TOKENOptional: When specified, deploys the built binaries to GitHub under releases.""
GITLAB_REPOSITORY_URLOptional: SSH URL of the GitLab repository to release to, if not present, releasing to GitLab will be skipped"[email protected]:zephinzer/go-proxy-gzip.git"
GITLAB_SSH_DEPLOY_KEYBase64 encoded deploy key for the GitHub repository Optional: Only in play when GITLAB_REPOSITORY_URL is specified.""
VERSION_BUMPOptional: One of "patch", "minor", or "major". Only of use if either the GitHub or GitLab URL is specified. Indicates whether the semver version bump should be a patch, minor, or major one accordingly"patch"

TODOS

  • Healthchecks to verify next hop server is alive
  • Healthchecks to verify self-health
  • Distributed tracing
  • Logs collation

(help anyone?)

License

This project is licensed under the MIT license.

Cheers

Tag summary

Content type

Image

Digest

Size

6.6 MB

Last updated

almost 7 years ago

docker pull mycfsg/api-proxy-gzip