Python Flask application to proxy calls to the GitHub API.
10K+
A simple Python Flask REST server to proxy calls to GitHub.
The GitHub API is implemented using agithub and supports authenticated calls (with better rate limiting) using these environment variables:
GITHUB_USERNAME: a valid GitHub usernameGITHUB_PASSWORD: password for the same GitHub accountGITHUB_TOKEN: alternatively an authenticated GitHub token can be used instead of
username and passwordTo get a reference to the ApiClient class use something like:
api = ApiClient(username=os.environ.get('GITHUB_USERNAME'),
password=os.environ.get('GITHUB_PASSWORD'),
token=os.environ.get('GITHUB_TOKEN'))
The api.ApiClient class wraps endpoints with the following methods:
list_repos(username): returns a list of all repositories for the GitHub user
identified by username - regardless of pagination (e.g. from all pages)get_readme_html(owner, repository): returns the HTML README of the
owner/repository GitHub repositoryget_readme_raw(owner, repository): returns the raw plain text README of the
owner/repository GitHub repositoryget_commit_stats(owner, repository): returns a dictionary containing the total number
of commits in the owner/repository GitHub repository plus the author, date and message
of the last commitThe app module is responsible for the REST presentation layer exposing JSON endpoints.
The exposed endpoints are cached using Flask-Cache.
Configuration options:
HTTP_HOST: the host (interface) for Flask to bind to (default: 127.0.0.1)HTTP_PORT: the port to bind to (default: 5000)CORS_ORIGINS: comma separated list of origins to allow cross-domain GET requests from
(default: http://localhost:?.*)To allow connections from other hosts apart from localhost set the HTTP_PORT environment
variable to 0.0.0.0 or as appropriate.
List of endpoints:
/repos/<username>: lists the repositories of the <username> GitHub userApiClient.list_repos(<username>)/repos/<username>/<repository>/readme or/repos/<username>/<repository>/readme/html: an HTML endpoint returning the
rendered README markup for the <username>/<repository> GitHub repository/repos/<username>/<repository>/readme/raw: an plain text endpoint returning the
raw README contents for the <username>/<repository> GitHub repository/repos/<username>/<repository>/commit-stats: returns the commit statistics for the
<username>/<repository> GitHub repositoryApiClient.get_commit_stats(owner, repository)The web application is built as a Docker image too based on Alpine Linux for 3 architectures with the following tags:
latest is auto-built on Docker Hub
while the ARM builds are uploaded from Travis.
To run it:
docker run -d --name="github-proxy" -p 5000:5000 \
-e GITHUB_USERNAME='user' -e GITHUB_PASSWORD='pass' \
-e CORS_ORIGINS='http://site.example.com,*.website.com' \
rycus86/github-proxy:latest
Or with docker-compose (for a Raspberry Pi for example):
version: '2'
services:
github-proxy:
image: rycus86/github-proxy:armhf
read_only: true
expose:
- "5000"
restart: always
environment:
- HTTP_HOST=0.0.0.0
env_file:
- github-secrets.env
This way you can keep the secrets in the env_file instead of passing them to the Docker
client from the command line.
Content type
Image
Digest
Size
18.6 MB
Last updated
about 8 years ago
docker pull rycus86/github-proxy