package
0.1.1
Repository: https://github.com/nanopack/portal.git
Documentation: pkg.go.dev

# README

portal logo
Build Status

Portal

An api-driven, in-kernel layer 2/3 load balancer.

Routes:

RouteDescriptionpayloadoutput
Get /servicesList all servicesniljson array of service objects
Post /servicesAdd a servicejson service objectjson service object
Put /servicesReset the list of servicesjson array of service objectsjson array of service objects
Put /services/:service_idReset the specified serviceniljson service object
Get /services/:service_idGet information about a serviceniljson service object
Delete /services/:service_idDelete a servicenilsuccess message or an error
Get /services/:service_id/serversList all servers on a serviceniljson array of server objects
Post /services/:service_id/serversAdd new server to a servicejson server objectjson server object
Put /services/:service_id/serversReset the list of servers on a servicejson array of server objectsjson array of server objects
Get /services/:service_id/servers/:server_idGet information about a server on a serviceniljson server object
Delete /services/:service_id/servers/:server_idDelete a server from a servicenilsuccess message or an error
Delete /routesDelete a routesubdomain, domain, and path (json or query)success message or an error
Get /routesList all routesniljson array of route objects
Post /routesAdd new routejson route objectjson route object
Put /routesReset the list of routesjson array of route objectsjson array of route objects
Delete /certsDelete a certjson cert objectsuccess message or an error
Get /certsList all certsniljson array of cert objects
Post /certsAdd new certjson cert objectjson cert object
Put /certsReset the list of certsjson array of cert objectsjson array of cert objects
Delete /vipsDelete a vipjson vip objectsuccess message or an error
Get /vipsList all vipsniljson array of vip objects
Post /vipsAdd new vipjson vip objectjson vip object
Put /vipsReset the list of vipsjson array of vip objectsjson array of vip objects

Usage Example:

add service

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services -d \
'{"host":"127.0.0.3", "port":1234, "type":"tcp", "scheduler": "rr", "persistence":0, "netmask":""}'
{"id":"tcp-127_0_0_3-1234","host":"127.0.0.3","port":1234,"type":"tcp","scheduler":"rr","persistence":0,"netmask":""}

list services

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services
[{"id":"tcp-127_0_0_3-1234","host":"127.0.0.3","port":1234,"type":"tcp","scheduler":"rr","persistence":0,"netmask":""}]

get service

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services/tcp-127_0_0_3-1234
{"id":"tcp-127_0_0_3-1234","host":"127.0.0.3","port":1234,"type":"tcp","scheduler":"rr","persistence":0,"netmask":""}

add server

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services/tcp-127_0_0_3-1234/servers \
-d '{"host":"192.168.0.1", "port":8080, "forwarder": "m", "weight": 5, "upper_threshold": 10, "lower_threshold": 1}'
{"id":"192_168_0_1-8080","host":"192.168.0.1","port":8080,"forwarder":"m","weight":5,"upper_threshold":10,"lower_threshold":1}

list servers

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services/tcp-127_0_0_3-1234/servers
[{"id":"192_168_0_1-8080","host":"192.168.0.1","port":8080,"forwarder":"m","weight":5,"upper_threshold":10,"lower_threshold":1}]

get server

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services/tcp-127_0_0_3-1234/servers/192_168_0_1-8080
{"id":"192_168_0_1-8080","host":"192.168.0.1","port":8080,"forwarder":"m","weight":5,"upper_threshold":10,"lower_threshold":1}

delete server

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services/tcp-127_0_0_3-1234/servers/192_168_0_1-8080 -X DELETE
{"msg":"Success"}

list servers

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services/tcp-127_0_0_3-1234/servers
[]

delete service

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services/tcp-127_0_0_3-1234 -X DELETE
{"msg":"Success"}

list services

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services
[]

reset services

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services -d \
'[{"host":"127.0.0.3", "port":1234, "type":"tcp", "scheduler": "rr", "persistence":0, "netmask":"", "servers":[
{"host":"192.168.0.3", "port":8080, "forwarder": "m", "weight": 5, "upper_threshold": 10, "lower_threshold": 1},
{"host":"192.168.0.4", "port":8080, "forwarder": "m", "weight": 4, "upper_threshold": 10, "lower_threshold": 1}]}]' \
-X PUT
[{"id":"tcp-127_0_0_3-1234","host":"127.0.0.3","port":1234,"type":"tcp","scheduler":"rr","persistence":0,"netmask":"","servers":[{"id":"192_168_0_3-8080","host":"192.168.0.3","port":8080,"forwarder":"m","weight":5,"upper_threshold":10,"lower_threshold":1},{"id":"192_168_0_4-8080","host":"192.168.0.4","port":8080,"forwarder":"m","weight":4,"upper_threshold":10,"lower_threshold":1}]}]

reset servers

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services/tcp-127_0_0_3-1234/servers -d \
'[{"host":"192.168.0.5", "port":8080, "forwarder": "m", "weight": 5, "upper_threshold": 10, "lower_threshold": 1},
{"host":"192.168.0.6", "port":8080, "forwarder": "m", "weight": 4, "upper_threshold": 10, "lower_threshold": 1}]' \
-X PUT
[{"id":"192_168_0_5-8080","host":"192.168.0.5","port":8080,"forwarder":"m","weight":5,"upper_threshold":10,"lower_threshold":1},{"id":"192_168_0_6-8080","host":"192.168.0.6","port":8080,"forwarder":"m","weight":4,"upper_threshold":10,"lower_threshold":1}]

list services

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/services
[{"id":"tcp-127_0_0_3-1234","host":"127.0.0.3","port":1234,"type":"tcp","scheduler":"rr","persistence":0,"netmask":"","servers":[{"id":"192_168_0_5-8080","host":"192.168.0.5","port":8080,"forwarder":"m","weight":5,"upper_threshold":10,"lower_threshold":1},{"id":"192_168_0_6-8080","host":"192.168.0.6","port":8080,"forwarder":"m","weight":4,"upper_threshold":10,"lower_threshold":1}]}]

add route

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/routes \
       -d '{"domain":"portal.test", "page":"portal works\n"}'
{"subdomain":"","domain":"portal.test","path":"","targets":null,"fwdpath":"","page":"portal works\n"}

delete route

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/routes?domain=portal.test \
       -X DELETE
{"msg":"Success"}
## OR
$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/routes \
       -d '{"domain":"portal.test"}' \
       -X DELETE
{"msg":"Success"}

list routes

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/routes
[]

reset routes

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/routes \
       -d '[{"domain":"portal.test", "page":"portal works\n"}]' \
       -X PUT
[{"subdomain":"","domain":"portal.test","path":"","targets":null,"fwdpath":"","page":"portal works\n"}]

add cert

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/certs \
       -d '{"key":"-----BEGIN PRIVATE KEY-----\nMII.../J8\n-----END PRIVATE KEY-----",
            "cert":"-----BEGIN CERTIFICATE-----\nMII...aI=\n-----END CERTIFICATE-----"}'
{"key":"-----BEGIN PRIVATE KEY-----\nMII.../J8\n-----END PRIVATE KEY-----", "cert":"-----BEGIN CERTIFICATE-----\nMII...aI=\n-----END CERTIFICATE-----"}

delete cert

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/certs \
       -d '{"key":"-----BEGIN PRIVATE KEY-----\nMII.../J8\n-----END PRIVATE KEY-----",
            "cert":"-----BEGIN CERTIFICATE-----\nMII...aI=\n-----END CERTIFICATE-----"}' \
       -X DELETE
{"msg":"Success"}

list certs

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/certs
[]

reset certs

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/certs \
       -d '[{"key":"-----BEGIN PRIVATE KEY-----\nMII.../J8\n-----END PRIVATE KEY-----",
            "cert":"-----BEGIN CERTIFICATE-----\nMII...aI=\n-----END CERTIFICATE-----"}]' \
       -X PUT
[{"key":"-----BEGIN PRIVATE KEY-----\nMII.../J8\n-----END PRIVATE KEY-----", "cert":"-----BEGIN CERTIFICATE-----\nMII...aI=\n-----END CERTIFICATE-----"}]

add vip

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/vips \
       -d '{"ip":"192.168.0.100","interface":"eth0","alias":"eth0:1"}'
[{"ip":"192.168.0.100","interface":"eth0","alias":"eth0:1"}]

delete vip

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/vips \
       -d '{"ip":"192.168.0.100","interface":"eth0"}'
       -X DELETE
{"msg":"Success"}

list vips

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/vips
[]

reset vips

$ curl -k -H "X-AUTH-TOKEN:" https://127.0.0.1:8443/vips \
       -d [{"ip":"192.168.0.100","interface":"eth0","alias":"eth0:1"}]
       -X PUT
[{"ip":"192.168.0.100","interface":"eth0","alias":"eth0:1"}]

portal logo