mirror of
https://github.com/containers/gvisor-tap-vsock.git
synced 2025-09-26 21:01:42 +08:00
Add documentation for REST api and client package
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Package client provides go bindings for gvisor-tap-vsock HTTP API
|
||||
// This API is accessible over the endpoint specified with the `--services` or `--listen` arguments to `gvproxy`
|
||||
package client
|
||||
|
||||
import (
|
||||
@@ -17,6 +19,7 @@ type Client struct {
|
||||
base string
|
||||
}
|
||||
|
||||
// New returns a new instance of a Client. client will be used for the HTTP communication, and base specifies the base path the HTTP API is available at.
|
||||
func New(client *http.Client, base string) *Client {
|
||||
return &Client{
|
||||
client: client,
|
||||
@@ -24,6 +27,12 @@ func New(client *http.Client, base string) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
// List lists all the forwarded ports between host and guest
|
||||
//
|
||||
// Request:
|
||||
// GET /services/forwarder/all
|
||||
// Response:
|
||||
// [{"local":"127.0.0.1:2223","remote":"192.168.127.2:22","protocol":"tcp"}]
|
||||
func (c *Client) List() ([]types.ExposeRequest, error) {
|
||||
res, err := c.client.Get(fmt.Sprintf("%s%s", c.base, "/services/forwarder/all"))
|
||||
if err != nil {
|
||||
@@ -41,6 +50,13 @@ func (c *Client) List() ([]types.ExposeRequest, error) {
|
||||
return ports, nil
|
||||
}
|
||||
|
||||
// Expose forwards a new port between host and guest
|
||||
//
|
||||
// Request:
|
||||
// POST /services/forwarder/expose
|
||||
// {"local":"127.0.0.1:2224","remote":"192.168.127.2:22","protocol":"tcp"}
|
||||
// Response:
|
||||
// HTTP Status Code
|
||||
func (c *Client) Expose(req *types.ExposeRequest) error {
|
||||
bin, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
@@ -61,6 +77,13 @@ func (c *Client) Expose(req *types.ExposeRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unexpose stops forwarding a port between host and guest
|
||||
//
|
||||
// Request:
|
||||
// POST /services/forwarder/unexpose
|
||||
// {"local":"127.0.0.1:2224","protocol":"tcp"}
|
||||
// Response:
|
||||
// HTTP Status Code
|
||||
func (c *Client) Unexpose(req *types.UnexposeRequest) error {
|
||||
bin, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
@@ -81,6 +104,12 @@ func (c *Client) Unexpose(req *types.UnexposeRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListDNS shows the configuration of the built-in DNS server
|
||||
//
|
||||
// Request:
|
||||
// GET /services/dns/all
|
||||
// Response:
|
||||
// [{"Name":"containers.internal.","Records":[{"Name":"gateway","IP":"192.168.127.1","Regexp":null},{"Name":"host","IP":"192.168.127.254","Regexp":null}],"DefaultIP":""},{"Name":"docker.internal.","Records":[{"Name":"gateway","IP":"192.168.127.1","Regexp":null},{"Name":"host","IP":"192.168.127.254","Regexp":null}],"DefaultIP":""}]
|
||||
func (c *Client) ListDNS() ([]types.Zone, error) {
|
||||
res, err := c.client.Get(fmt.Sprintf("%s%s", c.base, "/services/dns/all"))
|
||||
if err != nil {
|
||||
@@ -98,6 +127,13 @@ func (c *Client) ListDNS() ([]types.Zone, error) {
|
||||
return dnsZone, nil
|
||||
}
|
||||
|
||||
// AddDNS adds a new DNS zone to the built-in DNS server
|
||||
//
|
||||
// Request:
|
||||
// POST /services/dns/add
|
||||
// {"Name":"test.internal.","Records":[{"Name":"gateway","IP":"192.168.127.1"}]}
|
||||
// Response:
|
||||
// HTTP Status Code
|
||||
func (c *Client) AddDNS(req *types.Zone) error {
|
||||
bin, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
@@ -118,6 +154,12 @@ func (c *Client) AddDNS(req *types.Zone) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListDHCPLeases shows the configuration of the built-in DNS server
|
||||
//
|
||||
// Request:
|
||||
// GET /services/dhcp/leases
|
||||
// Response:
|
||||
// {"192.168.127.1":"5a:94:ef:e4:0c:dd","192.168.127.2":"5a:94:ef:e4:0c:ee"}
|
||||
func (c *Client) ListDHCPLeases() (map[string]string, error) {
|
||||
res, err := c.client.Get(fmt.Sprintf("%s%s", c.base, "/services/dhcp/leases"))
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user