tailscale

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package tailscale provides the interface and client to interact with the tailscale API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Client  *http.Client
	Tailnet string
	Token   string
	// contains filtered or unexported fields
}

Client is a client that interacts with the TSTag service.

func (*Client) GetTags

func (c *Client) GetTags(ip net.IP) (tags []string, err error)

GetTags returns the tags for the given device that is identified by the IP address.

func (*Client) Refresh

func (c *Client) Refresh(ctx context.Context) error

Refresh refreshes the data from the tailscale.

func (*Client) Run

func (c *Client) Run(ctx context.Context, refreshInterval time.Duration)

Run starts the client and refreshes the data from the TSTag service.

type Device

type Device struct {
	Name      string
	Addresses []net.IP
	Tags      []string
}

Device represents a device in the TSTag network.

func (Device) Equal added in v0.7.0

func (d Device) Equal(other Device) bool

Equal returns true if two devices are identical.

type Interface

type Interface interface {
	// Run starts the client and refreshes the data from the TSTag service.
	Run(ctx context.Context, refreshInterval time.Duration)
	// Refresh refreshes the data from the tailscale.
	Refresh(ctx context.Context) error
	// GetTags returns the tags for the given device that is identified by the IP address.
	GetTags(ip net.IP) (tags []string, err error)
}

Interface is an interface that provides the information about the IP address from the TSTag service.

type InterfaceMock added in v0.8.0

type InterfaceMock struct {
	// GetTagsFunc mocks the GetTags method.
	GetTagsFunc func(ip net.IP) ([]string, error)

	// RefreshFunc mocks the Refresh method.
	RefreshFunc func(ctx context.Context) error

	// RunFunc mocks the Run method.
	RunFunc func(ctx context.Context, refreshInterval time.Duration)
	// contains filtered or unexported fields
}

InterfaceMock is a mock implementation of Interface.

func TestSomethingThatUsesInterface(t *testing.T) {

	// make and configure a mocked Interface
	mockedInterface := &InterfaceMock{
		GetTagsFunc: func(ip net.IP) ([]string, error) {
			panic("mock out the GetTags method")
		},
		RefreshFunc: func(ctx context.Context) error {
			panic("mock out the Refresh method")
		},
		RunFunc: func(ctx context.Context, refreshInterval time.Duration)  {
			panic("mock out the Run method")
		},
	}

	// use mockedInterface in code that requires Interface
	// and then make assertions.

}

func (*InterfaceMock) GetTags added in v0.8.0

func (mock *InterfaceMock) GetTags(ip net.IP) ([]string, error)

GetTags calls GetTagsFunc.

func (*InterfaceMock) GetTagsCalls added in v0.8.0

func (mock *InterfaceMock) GetTagsCalls() []struct {
	IP net.IP
}

GetTagsCalls gets all the calls that were made to GetTags. Check the length with:

len(mockedInterface.GetTagsCalls())

func (*InterfaceMock) Refresh added in v0.8.0

func (mock *InterfaceMock) Refresh(ctx context.Context) error

Refresh calls RefreshFunc.

func (*InterfaceMock) RefreshCalls added in v0.8.0

func (mock *InterfaceMock) RefreshCalls() []struct {
	Ctx context.Context
}

RefreshCalls gets all the calls that were made to Refresh. Check the length with:

len(mockedInterface.RefreshCalls())

func (*InterfaceMock) Run added in v0.8.0

func (mock *InterfaceMock) Run(ctx context.Context, refreshInterval time.Duration)

Run calls RunFunc.

func (*InterfaceMock) RunCalls added in v0.8.0

func (mock *InterfaceMock) RunCalls() []struct {
	Ctx             context.Context
	RefreshInterval time.Duration
}

RunCalls gets all the calls that were made to Run. Check the length with:

len(mockedInterface.RunCalls())

type State added in v0.7.0

type State struct {
	Devices []Device
}

State specifies the current state of the tailnet.

func (State) Equal added in v0.7.0

func (s State) Equal(other State) bool

Equal returns true if two states are equal.

Jump to

Keyboard shortcuts

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