base

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuditActionCreate = "CREATE"
	AuditActionUpdate = "UPDATE"
	AuditActionList   = "LIST"
	AuditActionGet    = "GET"
	AuditActionSearch = "SEARCH"
	AuditActionDelete = "DELETE"
)
View Source
const (
	FilterActionRead   = "READ"
	FilterActionCreate = "CREATE"
	FilterActionUpdate = "UPDATE"
	FilterActionDelete = "DELETE"

	OperationEqual            = "eq"
	OperationNotEqual         = "ne"
	OperationStartsWith       = "startswith"
	OperationContains         = "contains"
	OperationNotContains      = "notcontains"
	OperationExists           = "exists"
	OperationGreaterThan      = "gt"
	OperationLessThan         = "lt"
	OperationGreaterThanEqual = "ge"
	OperationLessThanEqual    = "le"
	OperationBetween          = "between"
	OperationIn               = "in"
	OperationNotIn            = "notin"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterBase

type FilterBase interface {
	Operations() OperationMap

	// Filter operation, Returns generated conditions and any errors
	Filter(user *types.User, filters map[string][]string, action string) (interface{}, error)
	// contains filtered or unexported methods
}

FilterBase : Interface used to generalize the filter logic across multiple providers

type Filtering

type Filtering struct {
	FilterBase
	ScoutrFilters
}

func (*Filtering) Filter

func (f *Filtering) Filter(user *types.User, filters map[string][]string, action string) (interface{}, error)

func (*Filtering) MultiFilter

func (f *Filtering) MultiFilter(user *types.User, key string, values []string) (interface{}, error)

MultiFilter : Build multi-filter using the IN operator to search a key for 1 or more values

type LocalFiltering

type LocalFiltering struct {
	Filtering
	// contains filtered or unexported fields
}

func (*LocalFiltering) And

func (f *LocalFiltering) And(condition1, condition2 interface{}) bool

func (*LocalFiltering) Contains

func (f *LocalFiltering) Contains(attr string, value interface{}) bool

func (*LocalFiltering) Equals

func (f *LocalFiltering) Equals(attr string, value interface{}) bool

func (*LocalFiltering) Exists

func (f *LocalFiltering) Exists(attr string, value interface{}) bool

func (*LocalFiltering) GreaterThan

func (f *LocalFiltering) GreaterThan(attr string, value interface{}) bool

func (*LocalFiltering) GreaterThanEqual

func (f *LocalFiltering) GreaterThanEqual(attr string, value interface{}) bool

func (*LocalFiltering) In

func (f *LocalFiltering) In(attr string, values interface{}) bool

func (*LocalFiltering) LessThan

func (f *LocalFiltering) LessThan(attr string, value interface{}) bool

func (*LocalFiltering) LessThanEqual

func (f *LocalFiltering) LessThanEqual(attr string, value interface{}) bool

func (*LocalFiltering) NotContains

func (f *LocalFiltering) NotContains(attr string, value interface{}) bool

func (*LocalFiltering) NotEqual

func (f *LocalFiltering) NotEqual(attr string, value interface{}) bool

func (*LocalFiltering) NotIn

func (f *LocalFiltering) NotIn(attr string, values interface{}) bool

func (*LocalFiltering) Or

func (f *LocalFiltering) Or(condition1, condition2 interface{}) bool

func (*LocalFiltering) StartsWith

func (f *LocalFiltering) StartsWith(attr string, value interface{}) bool

type OperationMap

type OperationMap map[string]func(string, interface{}) (interface{}, error)

OperationMap : Map of operator to a callable to perform the filter

type Scoutr

type Scoutr struct {
	ScoutrBase
	Filtering FilterBase
	Config    config.Config
}

Scoutr : Base struct that implements ScoutrBase and sets up some commonly used functions across various cloud providers

func (*Scoutr) BuildParams

func (api *Scoutr) BuildParams(req types.Request) map[string][]string

BuildParams : Takes in a request object and generates a parameters map that can be used in Filter calls

func (*Scoutr) CanAccessEndpoint

func (api *Scoutr) CanAccessEndpoint(method string, path string, user *types.User, request *types.Request) bool

CanAccessEndpoint : Determine if a user has access to a specific endpoint

func (*Scoutr) GetConfig

func (api *Scoutr) GetConfig() config.Config

GetConfig : Return config

func (Scoutr) GetUser

func (api Scoutr) GetUser(id string, userData *types.UserData) (*types.User, error)

GetUser : Fetch a user from the backend, merging any permissions from group memberships

func (Scoutr) InitializeRequest

func (api Scoutr) InitializeRequest(req types.Request) (*types.User, error)

InitializeRequest : Given a request, get the corresponding user and perform user and request validation.

func (*Scoutr) MergePermissions

func (api *Scoutr) MergePermissions(user *types.User, group *types.Group)

MergePermissions : Merge permissions expressed in a group into the user object

func (*Scoutr) PostProcess

func (api *Scoutr) PostProcess(data []types.Record, user *types.User)

PostProcess : Perform post processing on records before returning to user

func (Scoutr) PrepareCreate

func (api Scoutr) PrepareCreate(request types.Request, data map[string]interface{}, validation map[string]types.FieldValidation, requiredFields []string) (*types.User, error)

func (*Scoutr) UserIdentifier

func (api *Scoutr) UserIdentifier(user *types.User) string

UserIdentifier : Generate a user identifier for logs

func (*Scoutr) ValidateFields

func (api *Scoutr) ValidateFields(validation map[string]types.FieldValidation, requiredFields []string, item map[string]interface{}, existingItem map[string]interface{}) error

func (*Scoutr) ValidateRequest

func (api *Scoutr) ValidateRequest(req types.Request, user *types.User) error

ValidateRequest : Validate the user has permissions to perform the request

func (*Scoutr) ValidateUser

func (api *Scoutr) ValidateUser(user *types.User) error

ValidateUser : Validate the user object has all required fields

type ScoutrBase

type ScoutrBase interface {
	ScoutrProvider
	GetConfig() config.Config
	CanAccessEndpoint(string, string, *types.User, *types.Request) bool
}

ScoutrBase : Low level interface that defines all the functions used by a Scoutr provider. Some of these would be implemented by the Scoutr struct

type ScoutrFilters

type ScoutrFilters interface {
	And(condition1 interface{}, condition2 interface{}) interface{}
	Or(condition1 interface{}, condition2 interface{}) interface{}
	Equals(key string, value interface{}) (interface{}, error)
	NotEqual(key string, value interface{}) (interface{}, error)
	StartsWith(key string, value interface{}) (interface{}, error)
	Contains(key string, value interface{}) (interface{}, error)
	NotContains(key string, value interface{}) (interface{}, error)
	Exists(key string, value interface{}) (interface{}, error)
	GreaterThan(key string, value interface{}) (interface{}, error)
	LessThan(key string, value interface{}) (interface{}, error)
	GreaterThanEqual(key string, value interface{}) (interface{}, error)
	LessThanEqual(key string, value interface{}) (interface{}, error)
	Between(key string, values interface{}) (interface{}, error)
	In(key string, values interface{}) (interface{}, error)
	NotIn(key string, values interface{}) (interface{}, error)
}

type ScoutrProvider

type ScoutrProvider interface {
	GetEntitlements([]string) ([]types.User, error)
	GetAuth(string) (*types.User, error)
	GetGroup(string) (*types.Group, error)
	Create(request types.Request, item map[string]interface{}, validation map[string]types.FieldValidation, requiredFields []string) error
	Update(request types.Request, partitionKey map[string]interface{}, item map[string]interface{}, validation map[string]types.FieldValidation, requiredFields []string, auditAction string) (interface{}, error)
	Patch(request types.Request, partitionKey map[string]interface{}, item map[string]interface{}, validation map[string]types.FieldValidation, auditAction string) (interface{}, error)
	Get(request types.Request, id string) (types.Record, error)
	List(request types.Request) ([]types.Record, error)
	ListUniqueValues(request types.Request, uniqueKey string) ([]string, error)
	ListAuditLogs(request types.Request, pathParams map[string]string, queryParams map[string][]string) ([]types.AuditLog, error)
	History(request types.Request, key string, value string, queryParams map[string][]string, actions []string) ([]types.History, error)
	Search(request types.Request, key string, values []string) ([]types.Record, error)
	Delete(request types.Request, partitionKey map[string]interface{}) error
}

Jump to

Keyboard shortcuts

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