Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active May 23, 2021 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haproxytechblog/671e7b4199f503c70a826a9b81341df1 to your computer and use it in GitHub Desktop.
Save haproxytechblog/671e7b4199f503c70a826a9b81341df1 to your computer and use it in GitHub Desktop.
Announcing HAProxy Data Plane API 2.2
$ curl -u dataplaneapi:mypassword \
-H 'Content-Type: application/json' \
-d '{
"name": "consul-server",
"address": "consul.local",
"port": 8500,
"enabled": true,
"retry_timeout": 10
}' http://localhost:5555/v2/service_discovery/consul
$ curl -u dataplaneapi:mypassword \
-F 'file_upload=@cert.pem' \
http://localhost:5555/v2/services/haproxy/storage/ssl_certificates
{"description":"managed SSL file","file":"/etc/haproxy/certs/cert.pem","storage_name":"cert.pem"}
$ curl -u dataplaneapi:mypassword \
-H 'Content-Type: text/plain' \
-XPUT \
-d "$(cat cert.pem)" \
http://localhost:5555/v2/services/haproxy/storage/ssl_certificates/cert.pem?force_reload=true
static.example.com be_static
www.example.com be_static
$ curl -u dataplaneapi:mypassword \
-F 'file_upload=@hosts.map' \
http://localhost:5555/v2/services/haproxy/storage/maps
$ curl -u dataplaneapi:mypassword \
-H 'Content-Type: application/json' \
-d '{ "name":"%[req.hdr(host),lower,map(/etc/haproxy/maps/hosts.map,be_static)]", "index":0 }' \
'http://localhost:5555/v2/services/haproxy/configuration/backend_switching_rules?frontend=fe_main&version=1'
$ curl -u dataplaneapi:mypassword \
http://localhost:5555/v2/services/haproxy/storage/maps
[
{
"description": "pattern loaded from file '/etc/haproxy/maps/hosts.map' used by map at file '/etc/haproxy/haproxy.cfg' line 60",
"file": "/etc/haproxy/maps/hosts.map",
"id": "4"
}
]
$ curl -u dataplaneapi:mypassword \
-F 'file_upload=@iprep.conf' \
http://localhost:5555/v2/services/haproxy/spoe/spoe_files
# Create empty mirror.conf
$ touch mirror.conf
# Upload empty file
$ curl -u dataplaneapi:mypassword \
-F 'file_upload=@mirror.conf' \ http://localhost:5555/v2/services/haproxy/spoe/spoe_files
# SPOE Scope [mirror]
$ curl -u dataplaneapi:mypassword \
-H 'Content-Type: application/json'
-d '"[mirror]"' \ 'http://localhost:5555/v2/services/haproxy/spoe/spoe_scopes?spoe=mirror.conf&version=1'
# SPOE Agent
$ curl -u dataplaneapi:mypassword \
-H 'Content-Type: application/json' \
-d '{
"log":[
{
"global":true,
"index":0
}
],
"messages":"mirror",
"use-backend":"mirroragents",
"name":"mirror",
"hello_timeout":500,
"idle_timeout":5000,
"processing_timeout":5000
}' \
'http://localhost:5555/v2/services/haproxy/spoe/spoe_agents?spoe=mirror.conf&scope=[mirror]&version=2'
# SPOE Message
$ curl -u dataplaneapi:mypassword \
-H 'Content-Type: application/json' \
-d '{
"name":"mirror",
"args":"arg_method=method arg_path=url arg_ver=req.ver arg_hdrs=req.hdrs_bin arg_body=req.body",
"event":{
"name":"on-frontend-http-request"
}
}' \ 'http://localhost:5555/v2/services/haproxy/spoe/spoe_messages?spoe=mirror.conf&scope=[mirror]&version=3'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment