api

package
v0.0.0-...-580f94b Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package api implements version 3 of the eduVPN api: https://docs.eduvpn.org/server/v3/api.html

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthorizeDisabled = errors.New("cannot authorize as re-authorization is disabled")

ErrAuthorizeDisabled is returned when authorization is disabled but is needed to complete

Functions

This section is empty.

Types

type API

type API struct {

	// Data is the server data
	Data ServerData
	// contains filtered or unexported fields
}

API is the top-level struct that each method is defined on

func NewAPI

func NewAPI(ctx context.Context, clientID string, sd ServerData, cb Callbacks, tokens *eduoauth.Token) (*API, error)

NewAPI creates a new API object by creating an OAuth object

func (*API) Connect

func (a *API) Connect(ctx context.Context, prof profiles.Profile, protos []protocol.Protocol, pTCP bool) (*ConnectData, error)

Connect sends a /connect to an eduVPN server `ctx` is the context used for cancellation protos is the list of protocols supported and wanted by the client

func (*API) Disconnect

func (a *API) Disconnect(ctx context.Context) error

Disconnect disconnects a client from the server by sending a /disconnect API call This cleans up resources such as WireGuard IP allocation

func (*API) Info

func (a *API) Info(ctx context.Context) (*profiles.Info, error)

Info does the /info API call

type Callbacks

type Callbacks interface {
	// TriggerAuth is called when authorization should be triggered
	TriggerAuth(context.Context, string, bool) (string, error)
	// AuthDone is called when authorization has just completed
	AuthDone(string, server.Type)
	// TokensUpdates is called when tokens are updated
	TokensUpdated(string, server.Type, eduoauth.Token)
}

Callbacks is the API callback interface It is used to trigger authorization and forward token updates

type ConnectData

type ConnectData struct {
	// Configuration is the VPN configuration
	Configuration string
	// Protocol tells us what protocol it is, OpenVPN or WireGuard (proxied or not)
	Protocol protocol.Protocol
	// Expires tells us when this configuration expires
	Expires time.Time
	// Proxy is filled when WireGuard is proxied
	Proxy *wireguard.Proxy
}

ConnectData is the data that is returned when the /connect call completes without error

type EndpointCache

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

EndpointCache is a struct that caches well-known API endpoints

func GetEndpointCache

func GetEndpointCache() *EndpointCache

GetEndpointCache returns the global singleton endpoint cache or creates one if it does not exist

func (*EndpointCache) Get

Get() returns a cached or fresh endpoint cache copy

type OAuthLogger

type OAuthLogger struct{}

OAuthLogger is defined here to update the internal logger for the eduoauth library

func (*OAuthLogger) Log

func (ol *OAuthLogger) Log(msg string)

Log logs a message

func (*OAuthLogger) Logf

func (ol *OAuthLogger) Logf(msg string, params ...interface{})

Logf logs a message with parameters

type ServerData

type ServerData struct {
	// ID is the identifier for the server
	ID string
	// Type is the type of server
	Type server.Type
	// BaseWK is the base well-known endpoint
	BaseWK string
	// BaseAuthWK is the base well-known endpoint for authorization. This is only different in case of secure internet
	BaseAuthWK string
	// ProcessAuth processes the OAuth authorization
	ProcessAuth func(string) string
	// SetAuthorizeTime sets the authorization time
	SetAuthorizeTime func(time.Time)
	// DisableAuthorize indicates whether or not new authorization requests should be disabled
	DisableAuthorize bool
}

ServerData is the data for a server that is passed to the API struct

Directories

Path Synopsis
Package endpoints defines a wrapper around the various endpoints returned by an eduVPN server in well-known
Package endpoints defines a wrapper around the various endpoints returned by an eduVPN server in well-known
Package profiles defines a wrapper around the various profiles returned by the /info endpoint
Package profiles defines a wrapper around the various profiles returned by the /info endpoint

Jump to

Keyboard shortcuts

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