wbeforexl

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package wbeforexl provides a simple xlistd.List implementation that can be used to check on a white list before checking on a blacklist.

This package is a work in progress and makes no API stability promises.

Index

Examples

Constants

View Source
const ComponentClass = "wbefore"

ComponentClass registered.

Variables

This section is empty.

Functions

func Builder

func Builder(defaultCfg Config) xlistd.BuildListFn

Builder returns a builder function.

Types

type Config

type Config struct {
	ForceValidation bool
	Reason          string
}

Config options.

type List

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

List implements a composite RBL that checks a whtelist before checking the blacklist. This means that if the checked resource exists in the whitelist, then it returns immediately with a negative result. If not in the whitelist, then returns the response of the blacklist.

Example
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/luids-io/api/xlist"
	"github.com/luids-io/xlist/pkg/xlistd/components/mockxl"
	"github.com/luids-io/xlist/pkg/xlistd/components/wbeforexl"
)

func main() {
	resources := []xlist.Resource{xlist.IPv4}
	white := &mockxl.List{
		Identifier:   "whitelist",
		ResourceList: resources,
		Results:      []bool{true, false},
	}
	black := &mockxl.List{
		Identifier:   "blacklist",
		ResourceList: resources,
		Results:      []bool{true},
	}

	//constructs wbefore rbl
	rbl := wbeforexl.New("test", white, black, resources, wbeforexl.Config{Reason: "hello"})
	//in the first check, whitelist returns true -> return false
	resp, err := rbl.Check(context.Background(), "10.10.10.10", xlist.IPv4)
	if err != nil && resp.Result {
		log.Fatalln("this should not happen")
	}
	fmt.Println("check 1:", resp.Result)

	//in the second check, whitelist returns false -> blacklist is checked
	// and blacklist allways returns true -> return true
	resp, err = rbl.Check(context.Background(), "10.10.10.10", xlist.IPv4)
	if err != nil && !resp.Result {
		log.Fatalln("this should not happen")
	}
	fmt.Println("check 2:", resp.Result, resp.Reason)

}
Output:

check 1: false
check 2: true hello

func New

func New(id string, white, black xlistd.List, resources []xlist.Resource, cfg Config) *List

New constructs a new "white before" RBL, it receives the resource list that RBL supports.

func (*List) Check

func (l *List) Check(ctx context.Context, name string, resource xlist.Resource) (xlist.Response, error)

Check implements xlist.Checker interface.

func (*List) Class

func (l *List) Class() string

Class implements xlistd.List interface.

func (*List) ID

func (l *List) ID() string

ID implements xlistd.List interface.

func (*List) Ping

func (l *List) Ping() error

Ping implements xlistd.Ping interface.

func (*List) Resources

func (l *List) Resources(ctx context.Context) ([]xlist.Resource, error)

Resources implements xlist.Checker interface.

Jump to

Keyboard shortcuts

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