Skip to content

Instantly share code, notes, and snippets.

View vdel26's full-sized avatar

Victor Delgado vdel26

View GitHub Profile
@vdel26
vdel26 / nginx.lua
Created September 8, 2014 15:29
detect 409 from 3scale
function error_authorization_failed(service)
ngx.status = 409
ngx.header.content_type = service.auth_failed_headers
ngx.print("Limit exceeded")
ngx.exit(ngx.HTTP_OK)
end
function authrep(params, service)
ngx.var.cached_key = ngx.var.cached_key .. ":" .. ngx.var.usage
local api_keys = ngx.shared.api_keys
@vdel26
vdel26 / nginx.conf
Last active August 29, 2015 14:05
Bypass 3scale depending on incoming IP
upstream backend_api {
# service name:API ;
server api.domain.com:80 max_fails=5 fail_timeout=30;
}
#### add this anywhere inside your http block
geo $match {
default 0;
## set IPs or IP groups that will be sent directly to your API
---
THEME_ACCT: vdel26
COMMON_GIT_MIRROR: 'github.com'
##
# deploying from an edx fork
#
# GIT_ACCT: vdel26
# edx_platform_repo: https://{{ COMMON_GIT_MIRROR }}/{{ GIT_ACCT }}/edx-platform.git
# edx_platform_version: release
@vdel26
vdel26 / nginx.lua
Last active August 29, 2015 14:04
Use prebuilt cache in case 3scale cannot be reached
local whitelist = require "whitelist"
function authrep(params, service)
ngx.var.cached_key = ngx.var.cached_key .. ":" .. ngx.var.usage
local api_keys = ngx.shared.api_keys
local is_known = api_keys:get(ngx.var.cached_key)
if is_known ~= 200 then
local res = ngx.location.capture("/threescale_authrep", { share_all_vars = true })
@vdel26
vdel26 / nginx.conf
Last active August 29, 2015 14:04
Error 404 and report if app plan doesn't match
location = /threescale_report {
internal;
set $provider_key "PROVIDERKEY";
proxy_pass http://threescale_backend/transactions.xml;
proxy_set_header Host "su1.3scale.net";
}
@vdel26
vdel26 / heroku-blog-post.md
Last active August 29, 2015 14:02
API Management with 3scale as an Heroku add-on for your application

API Management with 3scale as an Heroku add-on for your application

Hosting your API in a platform as a service like Heroku is a popular option nowadays since it frees you from all the infrastructure administration tasks and allows you to focus on development. It is also a really good way to launch your API when you are not sure what the usage will be like, as Heroku will handle scaling your application server for you.

If that is your case, now you can add 3scale to secure and manage your API right from your Heroku dashboard, by using 3scale Heroku add-on.

Provisioning the add-on for your Heroku app is as simple as doing a simple call from the command line:

heroku addons:add threescale
@vdel26
vdel26 / Makefile
Last active May 19, 2016 16:44
Makefile for working with a remote Nginx
#### SETTINGS
NGINXDIR = /usr/local/openresty/nginx/
NGXCONF = nginx_dummycustomer.conf
USER = ubuntu
REMOTE = ec2-54-224-138-186.compute-1.amazonaws.com
REMOTEDIR = /home/$(USER)/dummycustomer/
PRIVATEKEY = /Users/victordg/.ssh/aws/vdg-3scale.pem
####
@vdel26
vdel26 / aws-metadata
Created March 10, 2014 16:57
AWS metadata from within the instance
# curl -s http://169.254.169.254/latest/meta-data/
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
hostname
instance-action
instance-id
instance-type
kernel-id
@vdel26
vdel26 / nginx_basicauth.lua
Last active November 13, 2022 18:22
Extracting Basic Auth token
--[[
Authorization logic
]]--
function get_auth_params(where, method)
local params = {}
if where == "headers" then
params = ngx.req.get_headers()
elseif where == "basicauth" then
@vdel26
vdel26 / nginx
Last active September 24, 2025 21:37
Openresty init.d script
#!/bin/sh
#
# chkconfig: 2345 55 25
# Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx
# For Debian, run: update-rc.d -f nginx defaults
# For CentOS, run: chkconfig --add nginx
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all