allocator

package
v0.0.0-...-1ea0709 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package allocator implements santa allocations

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	CanAllocateSelf: false,
	Timeout:         time.Second * 5,
}

Functions

This section is empty.

Types

type Allocation

type Allocation struct {
	Aliases     map[string]string `json:"aliases"`     // name -> password
	Allocations map[string]string `json:"allocations"` // name -> name
	Created     time.Time
}

Allocation holds the aliases and allocations for a particular derangment.

func (*Allocation) PrintAliases

func (a *Allocation) PrintAliases()

func (*Allocation) PrintNameToName

func (a *Allocation) PrintNameToName()

func (*Allocation) PrintNameToPassword

func (a *Allocation) PrintNameToPassword()

func (*Allocation) String

func (a *Allocation) String() string

type AllocationStore

type AllocationStore struct {
	Allocation         string            `json:"allocation"` // base64 encoded version of Allocation
	AllocatedPasswords map[string]string `json:"allocated_passwords"`
	Created            time.Time         `json:"created"`
	Name               string            `json:"allocation_name"`
}

AllocationStore is a struct which models how marshalled allocations should be stored as to hide the specific allocation and aliases but show allocated passwords

type Allocator

type Allocator struct {
	Names     Set // using maps here to dedupe the list
	Passwords Set
	Config    Config
	// contains filtered or unexported fields
}

Allocator creates a new allocation given a particular config

func New

func New(config *Config) (*Allocator, error)

creates a new instance of an Allocator takes a config which is used to setup the allocator

func (*Allocator) Allocate

func (a *Allocator) Allocate() (*Allocation, error)

Allocate will allocate the names to a password and then the password to a name to create anonymity

func (*Allocator) OutputToFile

func (a *Allocator) OutputToFile(allocation *Allocation, fileName string, fileType string) error

OutputToFile writes an instance of Allocation to fileName with either "json" or "yaml" as the fileType

type Config

type Config struct {
	Names struct {
		File string   `yaml:"file"`
		Data []string `yaml:"data"`
	}
	Passwords struct {
		File string   `yaml:"file"`
		Data []string `yaml:"data"`
	}
	CanAllocateSelf bool          `yaml:"canAllocateSelf"`
	Timeout         time.Duration `yaml:"timeout,omitempty"`
	Rules           []Rule        `yaml:"rules"`
	Name            string        `yaml:"allocation_name"`
}

Config is the configuration for an allocator

func LoadConfigFromYaml

func LoadConfigFromYaml(yamlData []byte) (*Config, error)

LoadConfigFromYaml receives yamlData and unmarshals it into a Config

type Rule

type Rule struct {
	Name      string   `yaml:"name"`
	CannotGet []string `yaml:"cannotGet"`
}

Rule holds information about constraints for an individual name

type Set

type Set map[string]struct{}

Set is a makeshift set using a map for deduping purposes

Jump to

Keyboard shortcuts

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