access

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 4 Imported by: 3

README

access-go

Access functionality in Go shared across SWAN repositories.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllowedHttp

func GetAllowedHttp(
	w http.ResponseWriter,
	r *http.Request,
	a Access) bool

GetAllowedHttp of the Access.GetAllowedHttp method for use my implementing structures.

Types

type Access

type Access interface {

	// GetAllowed returns true if the accessKey is allowed access to the service
	// network, otherwise false. If false is returned then the error will
	// provide the reason.
	GetAllowed(accessKey string) (bool, error)

	// Returns true if the request is allowed to access the handler, otherwise
	// false. Removes the accessKey parameter from the form to prevent it being
	// used by other methods. If false is returned then no further action is
	// needed as the method will have responded to the request already.
	GetAllowedHttp(w http.ResponseWriter, r *http.Request) bool
}

Access interface for validating entitlement to access the network.

type Cache

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

func NewCache

func NewCache(
	size int,
	refresh func(string, *State) error,
	onEvicted func(key string, state *State)) (*Cache, error)

NewAccessProxy creates a new access proxy instance.

func (*Cache) GetAllowed

func (a *Cache) GetAllowed(accessKey string) (bool, error)

GetAllowed returns true if the accessKey is allowed access to the service network, otherwise false. If false is returned then the error will provide the reason.

func (*Cache) GetAllowedHttp

func (a *Cache) GetAllowedHttp(w http.ResponseWriter, r *http.Request) bool

GetAllowedHttp validates the access key in the request and handles any failures.

func (*Cache) Len

func (a *Cache) Len() int

type Fixed

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

Fixed is a implementation of common.Access for testing where a list of provided keys returns true, and all others return false.

func NewFixed

func NewFixed(validKeys []string) *Fixed

NewFixed creates a new instance of the AccessFixed structure with the fixed list of keys provided the allowed keys.

func (*Fixed) GetAllowed

func (a *Fixed) GetAllowed(accessKey string) (bool, error)

GetAllowed validates access key is allowed.

func (*Fixed) GetAllowedHttp

func (a *Fixed) GetAllowedHttp(w http.ResponseWriter, r *http.Request) bool

GetAllowedHttp validates the access key in the request and handles any failures.

type State

type State struct {
	Allowed     bool      // True if the key was allowed access when last checked, otherwise false
	Count       int       // The number of times the key has been used
	NextRefresh time.Time // The time after which the state needs to be checked again
}

State for access associated with a key

Jump to

Keyboard shortcuts

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