cfapi

package
v0.0.0-...-f85c0f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ChangeNew       = "new"
	ChangeUpdated   = "updated"
	ChangeUnchanged = "unchanged"
)
View Source
const (
	TimeLayout = time.RFC3339
)

Variables

View Source
var (
	ErrUnauthorized = errors.New("unauthorized")
	ErrBadRequest   = errors.New("incorrect request parameters")
	ErrNotFound     = errors.New("not found")
	ErrAPINoSuccess = errors.New("API call failed")
)
View Source
var ErrTunnelNameConflict = errors.New("tunnel with name already exists")
View Source
var (

	// Flags contains all filter flags.
	IpRouteFilterFlags = []cli.Flag{
		&filterIpRouteDeleted,
		&filterIpRouteTunnelID,
		&filterSubsetIpRoute,
		&filterSupersetIpRoute,
		&filterIpRouteComment,
		&filterIpRouteByVnet,
	}
)
View Source
var (
	VnetFilterFlags = []cli.Flag{
		&filterVnetId,
		&filterVnetByName,
		&filterDefaultVnet,
		&filterDeletedVnet,
	}
)

Functions

This section is empty.

Types

type ActiveClient

type ActiveClient struct {
	ID          uuid.UUID    `json:"id"`
	Features    []string     `json:"features"`
	Version     string       `json:"version"`
	Arch        string       `json:"arch"`
	RunAt       time.Time    `json:"run_at"`
	Connections []Connection `json:"conns"`
}

type CIDR

type CIDR net.IPNet

CIDR is just a newtype wrapper around net.IPNet. It adds JSON unmarshalling.

func (CIDR) MarshalJSON

func (c CIDR) MarshalJSON() ([]byte, error)

func (CIDR) String

func (c CIDR) String() string

func (*CIDR) UnmarshalJSON

func (c *CIDR) UnmarshalJSON(data []byte) error

UnmarshalJSON parses a JSON string into net.IPNet

type Change

type Change = string

type CleanupParams

type CleanupParams struct {
	// contains filtered or unexported fields
}

func NewCleanupParams

func NewCleanupParams() *CleanupParams

func (*CleanupParams) ForClient

func (cp *CleanupParams) ForClient(clientID uuid.UUID)

type Client

type Connection

type Connection struct {
	ColoName           string    `json:"colo_name"`
	ID                 uuid.UUID `json:"id"`
	IsPendingReconnect bool      `json:"is_pending_reconnect"`
	OriginIP           net.IP    `json:"origin_ip"`
	OpenedAt           time.Time `json:"opened_at"`
}

type DNSRoute

type DNSRoute struct {
	// contains filtered or unexported fields
}

func (*DNSRoute) MarshalJSON

func (dr *DNSRoute) MarshalJSON() ([]byte, error)

func (*DNSRoute) RecordType

func (dr *DNSRoute) RecordType() string

func (*DNSRoute) String

func (dr *DNSRoute) String() string

func (*DNSRoute) UnmarshalResult

func (dr *DNSRoute) UnmarshalResult(body io.Reader) (HostnameRouteResult, error)

type DNSRouteResult

type DNSRouteResult struct {
	CName Change `json:"cname"`
	Name  string `json:"name"`
	// contains filtered or unexported fields
}

func (*DNSRouteResult) SuccessSummary

func (res *DNSRouteResult) SuccessSummary() string

type DetailedRoute

type DetailedRoute struct {
	ID       uuid.UUID `json:"id"`
	Network  CIDR      `json:"network"`
	TunnelID uuid.UUID `json:"tunnel_id"`
	// Optional field. When unset, it means the DetailedRoute belongs to the default virtual network.
	VNetID     *uuid.UUID `json:"virtual_network_id,omitempty"`
	Comment    string     `json:"comment"`
	CreatedAt  time.Time  `json:"created_at"`
	DeletedAt  time.Time  `json:"deleted_at"`
	TunnelName string     `json:"tunnel_name"`
}

DetailedRoute is just a Route with some extra fields, e.g. TunnelName.

func (*DetailedRoute) IsZero

func (r *DetailedRoute) IsZero() bool

IsZero checks if DetailedRoute is the zero value.

func (DetailedRoute) TableString

func (r DetailedRoute) TableString() string

TableString outputs a table row summarizing the route, to be used when showing the user their routing table.

type GetRouteByIpParams

type GetRouteByIpParams struct {
	Ip net.IP
	// Optional field. If unset, backend will assume the default vnet for the account.
	VNetID *uuid.UUID
}

type HostnameClient

type HostnameClient interface {
	RouteTunnel(tunnelID uuid.UUID, route HostnameRoute) (HostnameRouteResult, error)
}

type HostnameRoute

type HostnameRoute interface {
	json.Marshaler
	RecordType() string
	UnmarshalResult(body io.Reader) (HostnameRouteResult, error)
	String() string
}

HostnameRoute represents a record type that can route to a tunnel

func NewDNSRoute

func NewDNSRoute(userHostname string, overwriteExisting bool) HostnameRoute

func NewLBRoute

func NewLBRoute(lbName, lbPool string) HostnameRoute

type HostnameRouteResult

type HostnameRouteResult interface {
	// SuccessSummary explains what will route to this tunnel when it's provisioned successfully
	SuccessSummary() string
}

type IPRouteClient

type IPRouteClient interface {
	ListRoutes(filter *IpRouteFilter) ([]*DetailedRoute, error)
	AddRoute(newRoute NewRoute) (Route, error)
	DeleteRoute(id uuid.UUID) error
	GetByIP(params GetRouteByIpParams) (DetailedRoute, error)
}

type IpRouteFilter

type IpRouteFilter struct {
	// contains filtered or unexported fields
}

IpRouteFilter which routes get queried.

func NewIPRouteFilter

func NewIPRouteFilter() *IpRouteFilter

func NewIpRouteFilterFromCLI

func NewIpRouteFilterFromCLI(c *cli.Context) (*IpRouteFilter, error)

NewIpRouteFilterFromCLI parses CLI flags to discover which filters should get applied.

func (*IpRouteFilter) CommentIs

func (f *IpRouteFilter) CommentIs(comment string)

func (*IpRouteFilter) Deleted

func (f *IpRouteFilter) Deleted()

func (IpRouteFilter) Encode

func (f IpRouteFilter) Encode() string

func (*IpRouteFilter) ExistedAt

func (f *IpRouteFilter) ExistedAt(existedAt time.Time)

func (*IpRouteFilter) MaxFetchSize

func (f *IpRouteFilter) MaxFetchSize(max uint)

func (*IpRouteFilter) NetworkIsSubsetOf

func (f *IpRouteFilter) NetworkIsSubsetOf(superset net.IPNet)

func (*IpRouteFilter) NetworkIsSupersetOf

func (f *IpRouteFilter) NetworkIsSupersetOf(subset net.IPNet)

func (*IpRouteFilter) NotDeleted

func (f *IpRouteFilter) NotDeleted()

func (*IpRouteFilter) Page

func (f *IpRouteFilter) Page(page int)

func (*IpRouteFilter) TunnelID

func (f *IpRouteFilter) TunnelID(id uuid.UUID)

func (*IpRouteFilter) VNetID

func (f *IpRouteFilter) VNetID(id uuid.UUID)

type LBRoute

type LBRoute struct {
	// contains filtered or unexported fields
}

func (*LBRoute) MarshalJSON

func (lr *LBRoute) MarshalJSON() ([]byte, error)

func (*LBRoute) RecordType

func (lr *LBRoute) RecordType() string

func (*LBRoute) String

func (lb *LBRoute) String() string

func (*LBRoute) UnmarshalResult

func (lr *LBRoute) UnmarshalResult(body io.Reader) (HostnameRouteResult, error)

type LBRouteResult

type LBRouteResult struct {
	LoadBalancer Change `json:"load_balancer"`
	Pool         Change `json:"pool"`
	// contains filtered or unexported fields
}

func (*LBRouteResult) SuccessSummary

func (res *LBRouteResult) SuccessSummary() string

type NewRoute

type NewRoute struct {
	Network  net.IPNet
	TunnelID uuid.UUID
	Comment  string
	// Optional field. If unset, backend will assume the default vnet for the account.
	VNetID *uuid.UUID
}

NewRoute has all the parameters necessary to add a new route to the table.

func (NewRoute) MarshalJSON

func (r NewRoute) MarshalJSON() ([]byte, error)

MarshalJSON handles fields with non-JSON types (e.g. net.IPNet).

type NewVirtualNetwork

type NewVirtualNetwork struct {
	Name      string `json:"name"`
	Comment   string `json:"comment"`
	IsDefault bool   `json:"is_default"`
}

type Pagination

type Pagination struct {
	Count      int `json:"count,omitempty"`
	Page       int `json:"page,omitempty"`
	PerPage    int `json:"per_page,omitempty"`
	TotalCount int `json:"total_count,omitempty"`
}

type RESTClient

type RESTClient struct {
	// contains filtered or unexported fields
}

func NewRESTClient

func NewRESTClient(baseURL, accountTag, zoneTag, authToken, userAgent string, log *zerolog.Logger) (*RESTClient, error)

func (*RESTClient) AddRoute

func (r *RESTClient) AddRoute(newRoute NewRoute) (Route, error)

AddRoute calls the Tunnelstore POST endpoint for a given route.

func (*RESTClient) CleanupConnections

func (r *RESTClient) CleanupConnections(tunnelID uuid.UUID, params *CleanupParams) error

func (*RESTClient) CreateTunnel

func (r *RESTClient) CreateTunnel(name string, tunnelSecret []byte) (*TunnelWithToken, error)

func (*RESTClient) CreateVirtualNetwork

func (r *RESTClient) CreateVirtualNetwork(newVnet NewVirtualNetwork) (VirtualNetwork, error)

func (*RESTClient) DeleteRoute

func (r *RESTClient) DeleteRoute(id uuid.UUID) error

DeleteRoute calls the Tunnelstore DELETE endpoint for a given route.

func (*RESTClient) DeleteTunnel

func (r *RESTClient) DeleteTunnel(tunnelID uuid.UUID, cascade bool) error

func (*RESTClient) DeleteVirtualNetwork

func (r *RESTClient) DeleteVirtualNetwork(id uuid.UUID, force bool) error

func (*RESTClient) GetByIP

func (r *RESTClient) GetByIP(params GetRouteByIpParams) (DetailedRoute, error)

GetByIP checks which route will proxy a given IP.

func (*RESTClient) GetManagementToken

func (r *RESTClient) GetManagementToken(tunnelID uuid.UUID) (token string, err error)

func (*RESTClient) GetTunnel

func (r *RESTClient) GetTunnel(tunnelID uuid.UUID) (*Tunnel, error)

func (*RESTClient) GetTunnelToken

func (r *RESTClient) GetTunnelToken(tunnelID uuid.UUID) (token string, err error)

func (*RESTClient) ListActiveClients

func (r *RESTClient) ListActiveClients(tunnelID uuid.UUID) ([]*ActiveClient, error)

func (*RESTClient) ListRoutes

func (r *RESTClient) ListRoutes(filter *IpRouteFilter) ([]*DetailedRoute, error)

ListRoutes calls the Tunnelstore GET endpoint for all routes under an account. Due to pagination on the server side it will call the endpoint multiple times if needed.

func (*RESTClient) ListTunnels

func (r *RESTClient) ListTunnels(filter *TunnelFilter) ([]*Tunnel, error)

func (*RESTClient) ListVirtualNetworks

func (r *RESTClient) ListVirtualNetworks(filter *VnetFilter) ([]*VirtualNetwork, error)

func (*RESTClient) RouteTunnel

func (r *RESTClient) RouteTunnel(tunnelID uuid.UUID, route HostnameRoute) (HostnameRouteResult, error)

func (*RESTClient) UpdateVirtualNetwork

func (r *RESTClient) UpdateVirtualNetwork(id uuid.UUID, updates UpdateVirtualNetwork) error

type Route

type Route struct {
	Network  CIDR      `json:"network"`
	TunnelID uuid.UUID `json:"tunnel_id"`
	// Optional field. When unset, it means the Route belongs to the default virtual network.
	VNetID    *uuid.UUID `json:"virtual_network_id,omitempty"`
	Comment   string     `json:"comment"`
	CreatedAt time.Time  `json:"created_at"`
	DeletedAt time.Time  `json:"deleted_at"`
}

Route is a mapping from customer's IP space to a tunnel. Each route allows the customer to route eyeballs in their corporate network to certain private IP ranges. Each Route represents an IP range in their network, and says that eyeballs can reach that route using the corresponding tunnel.

type Tunnel

type Tunnel struct {
	ID          uuid.UUID    `json:"id"`
	Name        string       `json:"name"`
	CreatedAt   time.Time    `json:"created_at"`
	DeletedAt   time.Time    `json:"deleted_at"`
	Connections []Connection `json:"connections"`
}

type TunnelClient

type TunnelClient interface {
	CreateTunnel(name string, tunnelSecret []byte) (*TunnelWithToken, error)
	GetTunnel(tunnelID uuid.UUID) (*Tunnel, error)
	GetTunnelToken(tunnelID uuid.UUID) (string, error)
	GetManagementToken(tunnelID uuid.UUID) (string, error)
	DeleteTunnel(tunnelID uuid.UUID, cascade bool) error
	ListTunnels(filter *TunnelFilter) ([]*Tunnel, error)
	ListActiveClients(tunnelID uuid.UUID) ([]*ActiveClient, error)
	CleanupConnections(tunnelID uuid.UUID, params *CleanupParams) error
}

type TunnelFilter

type TunnelFilter struct {
	// contains filtered or unexported fields
}

func NewTunnelFilter

func NewTunnelFilter() *TunnelFilter

func (*TunnelFilter) ByExistedAt

func (f *TunnelFilter) ByExistedAt(existedAt time.Time)

func (*TunnelFilter) ByName

func (f *TunnelFilter) ByName(name string)

func (*TunnelFilter) ByNamePrefix

func (f *TunnelFilter) ByNamePrefix(namePrefix string)

func (*TunnelFilter) ByTunnelID

func (f *TunnelFilter) ByTunnelID(tunnelID uuid.UUID)

func (*TunnelFilter) ExcludeNameWithPrefix

func (f *TunnelFilter) ExcludeNameWithPrefix(excludePrefix string)

func (*TunnelFilter) MaxFetchSize

func (f *TunnelFilter) MaxFetchSize(max uint)

func (*TunnelFilter) NoDeleted

func (f *TunnelFilter) NoDeleted()

func (*TunnelFilter) Page

func (f *TunnelFilter) Page(page int)

type TunnelWithToken

type TunnelWithToken struct {
	Tunnel
	Token string `json:"token"`
}

type UpdateVirtualNetwork

type UpdateVirtualNetwork struct {
	Name      *string `json:"name,omitempty"`
	Comment   *string `json:"comment,omitempty"`
	IsDefault *bool   `json:"is_default_network,omitempty"`
}

type VirtualNetwork

type VirtualNetwork struct {
	ID        uuid.UUID `json:"id"`
	Comment   string    `json:"comment"`
	Name      string    `json:"name"`
	IsDefault bool      `json:"is_default_network"`
	CreatedAt time.Time `json:"created_at"`
	DeletedAt time.Time `json:"deleted_at"`
}

func (VirtualNetwork) TableString

func (virtualNetwork VirtualNetwork) TableString() string

type VnetClient

type VnetClient interface {
	CreateVirtualNetwork(newVnet NewVirtualNetwork) (VirtualNetwork, error)
	ListVirtualNetworks(filter *VnetFilter) ([]*VirtualNetwork, error)
	DeleteVirtualNetwork(id uuid.UUID, force bool) error
	UpdateVirtualNetwork(id uuid.UUID, updates UpdateVirtualNetwork) error
}

type VnetFilter

type VnetFilter struct {
	// contains filtered or unexported fields
}

VnetFilter which virtual networks get queried.

func NewFromCLI

func NewFromCLI(c *cli.Context) (*VnetFilter, error)

NewFromCLI parses CLI flags to discover which filters should get applied to list virtual networks.

func NewVnetFilter

func NewVnetFilter() *VnetFilter

func (*VnetFilter) ByDefaultStatus

func (f *VnetFilter) ByDefaultStatus(isDefault bool)

func (*VnetFilter) ById

func (f *VnetFilter) ById(vnetId uuid.UUID)

func (*VnetFilter) ByName

func (f *VnetFilter) ByName(name string)

func (VnetFilter) Encode

func (f VnetFilter) Encode() string

func (*VnetFilter) MaxFetchSize

func (f *VnetFilter) MaxFetchSize(max uint)

func (*VnetFilter) WithDeleted

func (f *VnetFilter) WithDeleted(isDeleted bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL