pkg

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AppLongName  = "Tailscale IPs"
	AppShortName = "tips"
)
View Source
const (
	// These two buckets contain FULL data.
	DevicesBucket = "bucket:devices.full"
	StatsBucket   = "bucket:stats"

	StatsKey = "key:stats"
)
View Source
const (
	NoHdr       = "No"
	MachineHdr  = "Machine"
	AddressHdr  = "Address"
	TagsHdr     = "Tags"
	UserHdr     = "User"
	VersionHdr  = "Version"
	LastSeenHdr = "LastSeen"
	ExitNodeHdr = "Exit Node"
)
View Source
const (
	// PrimaryFilterAll basically means glob: *, but since this expands in the terminal we use @
	PrimaryFilterAll = "@"
)

Variables

View Source
var (
	AppVersion = "0.0.1"
	UserAgent  = fmt.Sprintf("%s/%s", AppShortName, AppVersion)
)
View Source
var (
	// CtxKeyConfig holds all config settings that were resolved from the environment/config file/cli flags
	CtxKeyConfig    = contextKey("configuration")
	CtxKeyUserQuery = contextKey("user-query")
)

Functions

func CtxAsBool

func CtxAsBool(ctx context.Context, key contextKey) bool

func CtxAsInt

func CtxAsInt(ctx context.Context, key contextKey) int

func CtxAsString

func CtxAsString(ctx context.Context, key contextKey) string

func ExecuteClusterRemoteCmd

func ExecuteClusterRemoteCmd(ctx context.Context, w io.Writer, hosts []RemoteCmdHost, remoteCmd string)

func NewClient

func NewClient(ctx context.Context) *tailscale.Client

func NewOauthClient

func NewOauthClient(ctx context.Context) *tailscale.Client

func ParseColumns

func ParseColumns(s string) mapset.Set[string]

func ParseFilter

func ParseFilter(filter string) map[string]mapset.Set[string]

func RenderASCIITableView

func RenderASCIITableView(ctx context.Context, tableView *GeneralTableView, w io.Writer) error

func RenderIPs

func RenderIPs(ctx context.Context, tableView *GeneralTableView, w io.Writer) error

func RenderJson

func RenderJson(ctx context.Context, tableView *GeneralTableView, w io.Writer) error

func RenderLogLine

func RenderLogLine(ctx context.Context, w io.Writer, idx int, isStdErr bool, hostname, alias, line string)

func RenderRemoteSummary

func RenderRemoteSummary(ctx context.Context, w io.Writer, success, errors uint32, elapsed time.Duration) error

func RenderTableView

func RenderTableView(ctx context.Context, tableView *GeneralTableView, w io.Writer) error

Types

type CachedRepository

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

func NewCachedRepo

func NewCachedRepo(innerRepo InnerRepo) *CachedRepository

func (*CachedRepository) DevicesResource

func (c *CachedRepository) DevicesResource(ctx context.Context) ([]*WrappedDevice, error)

type ConfigCtx

type ConfigCtx struct {
	Basic         bool
	CacheTimeout  time.Duration
	Columns       mapset.Set[string]
	Concurrency   int
	Filters       map[string]mapset.Set[string]
	IPsOutput     bool
	IPsDelimiter  string
	JsonOutput    bool
	NoCache       bool
	NoColor       bool
	PrefixFilter  *PrefixFilter
	RemoteCmd     string
	Slice         *SliceCfg
	SortOrder     []SortSpec
	Tailnet       string
	CachedElapsed time.Duration
	TailscaleAPI  TailscaleAPICfgCtx
	TailscaleCLI  TailscaleCLICfgCtx
	Page          int

	TestMode bool
}

func CtxAsConfig

func CtxAsConfig(ctx context.Context, key contextKey) *ConfigCtx

func NewConfigCtx

func NewConfigCtx() *ConfigCtx

func (*ConfigCtx) IsRemoteCommand

func (c *ConfigCtx) IsRemoteCommand() bool

type ContextView

type ContextView struct {
	Query      string
	APIElapsed time.Duration
	CLIElapsed time.Duration
}

type DB2

type DB2[T Indexer] struct {
	// contains filtered or unexported fields
}

func NewDB2

func NewDB2[T Indexer](tailnetScope string) *DB2[T]

func (*DB2[T]) Close

func (d *DB2[T]) Close() error

func (*DB2[T]) Erase

func (d *DB2[T]) Erase() error

func (*DB2[T]) Exists

func (d *DB2[T]) Exists(ctx context.Context) (bool, error)

func (*DB2[T]) File

func (d *DB2[T]) File() string

func (*DB2[T]) IndexOpaqueItems

func (d *DB2[T]) IndexOpaqueItems(ctx context.Context, bucketName string, items []T) error

func (*DB2[T]) LookupOpaqueItem

func (d *DB2[T]) LookupOpaqueItem(ctx context.Context, bucketName, primaryKey string) (*T, error)

func (*DB2[T]) Open

func (d *DB2[T]) Open() error

func (*DB2[T]) SearchOpaqueItems

func (d *DB2[T]) SearchOpaqueItems(ctx context.Context, bucketName string, query DBQuery) ([]T, error)

SearchOpaqueItems can generically search with 3 different ways. 1. Using one or more primary keys, in which case this is a direct lookup (not technically a search) 2. Using the * (all/everything) construct, this is just a full table scan really. 3. Using a prefix scan, this is a seek to a segment of the index and should be fast assuming good selectivity.

func (*DB2[T]) TailnetScope

func (d *DB2[T]) TailnetScope() string

type DB2Stats

type DB2Stats struct {
	DevicesCount  int `json:"devices_count"`
	EnrichedCount int `json:"enriched_count"`
}

type DBQuery added in v0.0.4

type DBQuery struct {
	PrefixFilters *PrefixFilter
	PrimaryKeys   []string
}

type DevicesTable

type DevicesTable struct {
	TailnetView
	Devices *DevicesView
}

type DevicesView

type DevicesView struct {
}

DevicesView has everything needed to be rendered.

type GeneralTableView

type GeneralTableView struct {
	ContextView
	TailnetView
	SelfView
	Headers []string
	Rows    [][]string
}

func ProcessDevicesTable

func ProcessDevicesTable(ctx context.Context, devList []*WrappedDevice) (*GeneralTableView, error)

ProcessDevicesTable will apply sorting (if required), slicing (if required) and the massage/transformation of data to produce a final `*DevicesTable` that has everything required to render.

type Indexer

type Indexer interface {
	Key() string
}

type InnerRepo

type InnerRepo interface {
	DevicesResource(ctx context.Context) ([]*WrappedDevice, error)
}

type MockedDeviceRepo

type MockedDeviceRepo struct {
}

func NewMockedDeviceRepo

func NewMockedDeviceRepo() *MockedDeviceRepo

func (*MockedDeviceRepo) DevicesResource

func (r *MockedDeviceRepo) DevicesResource(ctx context.Context) ([]*WrappedDevice, error)

type PrefixFilter added in v0.0.4

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

func ParsePrefixFilter added in v0.0.4

func ParsePrefixFilter(s string) *PrefixFilter

func (*PrefixFilter) Count added in v0.0.4

func (p *PrefixFilter) Count() int

func (*PrefixFilter) IsAll added in v0.0.4

func (p *PrefixFilter) IsAll() bool

func (*PrefixFilter) PrefixAt added in v0.0.4

func (p *PrefixFilter) PrefixAt(idx int) string

type RemoteCmdHost

type RemoteCmdHost struct {
	Original string
	Alias    string
}

type RemoteDeviceRepo

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

func NewRemoteDeviceRepo

func NewRemoteDeviceRepo(client *tailscale.Client) *RemoteDeviceRepo

func (*RemoteDeviceRepo) DevicesResource

func (r *RemoteDeviceRepo) DevicesResource(ctx context.Context) ([]*WrappedDevice, error)

type SelfView

type SelfView struct {
	Index   int
	DNSName string
}

type SliceCfg

type SliceCfg struct {
	From *int
	To   *int
}

func ParseSlice

func ParseSlice(s string, page int) *SliceCfg

func (*SliceCfg) IsDefined

func (s *SliceCfg) IsDefined() bool

type SortDirection

type SortDirection int
const (
	Ascending SortDirection = iota
	Descending
)

type SortSpec

type SortSpec struct {
	Field     string
	Direction SortDirection
}

func ParseSortString

func ParseSortString(sortString string) []SortSpec

Parse the sort string and return a slice of SortSpec

type TailnetView

type TailnetView struct {
	Tailnet       string
	TotalMachines int
}

TailnetView has everything known about a Tailnet

type TailscaleAPICfgCtx

type TailscaleAPICfgCtx struct {
	Timeout time.Duration

	// ApiKey for regular authentication
	ApiKey string

	// OAuthClientID for OAuth based login.
	OAuthClientID string
	// OAuthClientSecret for Oauth based login.
	OAuthClientSecret string

	// ElapsedTime records the time this API call took. It's meant to be mutated during the API call and populated then.
	ElapsedTime time.Duration
}

type TailscaleCLICfgCtx

type TailscaleCLICfgCtx struct {
}

type WrappedDevice

type WrappedDevice struct {
	tailscale.Device
	EnrichedInfo *tailscale_cli.DeviceInfo `json:"enrichedInfo"`
}

WrappedDevice is a type that wraps the core `tailscale.Device` type. It also holds the joined `tailscale_cli.DeviceInfo` that may or may not be present when fetched from within the tailnet. It also implements the `Indexer` interface, so it may be stored in the DB.

func (*WrappedDevice) Key

func (w *WrappedDevice) Key() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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