client

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotFound : error returned when a headscale user is not found
	ErrUserNotFound = errors.New("Headscale : User not found")
	ErrUnauthorized = errors.New("Headscale : Unauthorized")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	APIURL string
	APIKey string
	HTTP   *http.Client
}

Client : struct that define a Headscale Client

func NewClient

func NewClient() *Client

NewClient returns a Headscale client and instantiatethe http client

func (*Client) CreatePreAuthKey

func (c *Client) CreatePreAuthKey(ctx context.Context, preAuthKeyConfig PreAuthKeyConfig) (status PreAuthKeyStatus, preAuthKey PreAuthKeyResponse, err error)

CreatePreAuthKey creates a preAuthKey from a PreAuthKeyConfig

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, name string) (status UserStatus, user UserConfig, err error)

CreateUser create a new Headscale user and return its status

func (*Client) DeleteUser

func (c *Client) DeleteUser(ctx context.Context, name string) (status UserStatus, err error)

DeleteUser delete a headscale user from the control plance and return deletion status

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, name string) (status UserStatus, user UserConfig, err error)

GetUser : return a Headscale user and its status

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context) (users []UserConfig, err error)

ListUsers list all exisint users from Headscale controle plane

type PreAuthKeyConfig

type PreAuthKeyConfig struct {
	User       string    `json:"name"`
	Reusable   bool      `json:"reusable"`
	Ephemeral  bool      `json:"ephemeral"`
	Expiration time.Time `json:"expiration"`
	Tags       []string  `json:"acl_tags"`
}

PreAuthKeyConfig is used to create a preAuthKey

type PreAuthKeyResponse

type PreAuthKeyResponse struct {
	PreAuthKey struct {
		User       string    `json:"user"`
		ID         string    `json:"id"`
		Key        string    `json:"key"`
		Reusable   bool      `json:"reusable"`
		Ephemeral  bool      `json:"ephemeral"`
		Used       bool      `json:"used"`
		Expiration time.Time `json:"expiration"`
		CreatedAt  time.Time `json:"createdAt"`
		ACLTags    []string  `json:"aclTags"`
	} `json:"preAuthKey"`
}

PreAuthKeyResponse stores the HEadscale response

type PreAuthKeyStatus

type PreAuthKeyStatus uint8

PreAuthKeyStatus defines the status of a Headscale preauthkey

const (
	PreAuthKeyCreated PreAuthKeyStatus = iota
	PreAuthKeyExists  PreAuthKeyStatus = iota
	PreAuthKeyDeleted PreAuthKeyStatus = iota
	PreAuthKeyUnknown PreAuthKeyStatus = iota
	PreAuthKeyError   PreAuthKeyStatus = iota
)

Instantiate the PreAuthKeyStatus enum

type UserConfig

type UserConfig struct {
	ID        uint32    `json:"id,string"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"createdAt"`
}

UserConfig : struct that defines a Headscale users

type UserCreationResponse

type UserCreationResponse struct {
	User UserConfig `json:"user"`
}

type UserStatus

type UserStatus uint8

UserStatus : defined the status of a Headscale user

const (
	UserCreated UserStatus = iota
	UserExists  UserStatus = iota
	UserDeleted UserStatus = iota
	UserUnknown UserStatus = iota
	UserError   UserStatus = iota
)

Defined UserStatus enum values

Jump to

Keyboard shortcuts

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