dispatch

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dispatch defines an interface for all password spraying implementations For example, a webhook worker client will send tasks to via HTTP requests. Additionally, this package provides a registration mechanism similar to database/sql. Make sure to "blank import" each dispatch.

import (
    "github.com/praetorian-inc/trident/pkg/dispatch"

    _ "github.com/praetorian-inc/trident/pkg/dispatch/clients/webhook"
)

var req event.AuthRequest
// ...
worker, err := dispatch.Open("webhook", map[string]string{"url":"https://example.org"})
if err != nil {
    // handle error
}
resp, err := worker.Submit(req)
// ...

See https://golang.org/doc/effective_go.html#blank_import for more information on "blank imports".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, driver Driver)

Register makes a client driver available at the provided name. If register is called twice or if the driver is nil, if panics. Register() is typically called in the client implementation's init() function to allow for easy importing of each client.

Types

type Dispatcher

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

Dispatcher creates a data pipeline which accepts tasks, sends them to a worker, and publishes the result. This pipeline can be visualized as:

PubSub Subscription --> WorkerClient --> PubSub Topic

func NewDispatcher

func NewDispatcher(ctx context.Context, opts Options, wc WorkerClient) (*Dispatcher, error)

NewDispatcher creates a dispatcher based on the provided options and worker.

func (*Dispatcher) Listen

func (d *Dispatcher) Listen(ctx context.Context) error

Listen listens for task messages on the Pub/Sub subscription. Tasks are sent to the worker and results are then published to the Pub/Sub topic.

type Driver

type Driver interface {
	New(opts map[string]string) (WorkerClient, error)
}

Driver is an interface which wraps the creation of a WorkerClient.

type Options

type Options struct {

	// ProjectID is the Google Cloud Platform project ID
	ProjectID string

	// SubscriptionID is the Pub/Sub subscription used by the dispatcher to
	// listen for incoming tasks.
	SubscriptionID string

	// ResultTopicID is the Pub/Sub topic ID used by the dispatcher to publish
	// results..
	ResultTopicID string
}

Options is used to configure a Dispatcher

type WorkerClient

type WorkerClient interface {
	Submit(event.AuthRequest) (*event.AuthResponse, error)
}

WorkerClient is an interface that wraps the Submit function, which simply accepts and AuthRequest, performs work, and returns an AuthResponse.

func Open

func Open(name string, opts WorkerOptions) (WorkerClient, error)

Open opens a worker client specified by the client driver name (e.g. webhook) and configures that client via the provided opts argument. Each WorkerClient should document its configuration options in its New() method.

type WorkerOptions

type WorkerOptions map[string]string

WorkerOptions is a tyoe alias for simple marshaling/unmarshaling of worker configuration options.

func (*WorkerOptions) UnmarshalJSON

func (opts *WorkerOptions) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the encoding/json.Unmarshaler interface.

func (*WorkerOptions) UnmarshalText

func (opts *WorkerOptions) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.Textunmarshaler interface.

Directories

Path Synopsis
clients

Jump to

Keyboard shortcuts

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