internal

package
v5.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConfigFile             = "./config.json"
	DefaultVerbosity              = 5
	DestinationTypeGoogleContacts = "GoogleContacts"
	DestinationTypeGoogleGroups   = "GoogleGroups"
	DestinationTypeGoogleSheets   = "GoogleSheets"
	DestinationTypeGoogleUsers    = "GoogleUsers"
	DestinationTypeRestAPI        = "RestAPI"
	DestinationTypeWebHelpDesk    = "WebHelpDesk"
	SourceTypeGoogleSheets        = "GoogleSheets"
	SourceTypeRestAPI             = "RestAPI"
)
View Source
const (
	VerbosityLow    = 0
	VerbosityMedium = 5
	VerbosityHigh   = 10
)

Variables

View Source
var LogLevels = map[syslog.Priority]string{
	syslog.LOG_EMERG:   "Emerg",
	syslog.LOG_ALERT:   "Alert",
	syslog.LOG_CRIT:    "Critical",
	syslog.LOG_ERR:     "Error",
	syslog.LOG_WARNING: "Warning",
	syslog.LOG_NOTICE:  "Notice",
	syslog.LOG_INFO:    "Info",
	syslog.LOG_DEBUG:   "Debug",
}

Functions

func AddStringToSlice added in v5.5.0

func AddStringToSlice(newString string, slice []string) []string

func GetDestinationAttributes

func GetDestinationAttributes(attrMap []AttributeMap) []string

func GetSourceAttributes

func GetSourceAttributes(attrMap []AttributeMap) []string

func InArray

func InArray(needle interface{}, haystack interface{}) (exists bool, index int)

This function will search element inside array with any type. Will return boolean and index for matched element. True and index more than 0 if element is exist. needle is element to search, haystack is slice of value to be search.

func IsStringInSlice added in v5.5.0

func IsStringInSlice(needle string, haystack []string) bool

IsStringInSlice iterates over a slice of strings, looking for the given string. If found, true is returned. Otherwise, false is returned.

func RunSyncSet

func RunSyncSet(logger *log.Logger, source Source, destination Destination, config AppConfig) error

RunSyncSet calls a number of functions to do the following ...

  • it gets the list of people from the source
  • it remaps their attributes to match the keys used in the destination
  • it gets the list of people from the destination
  • it generates the lists of people to change, update and delete
  • if dryRun is true, it prints those lists, but otherwise makes the associated changes

Types

type AppConfig

type AppConfig struct {
	Runtime      RuntimeConfig
	Source       SourceConfig
	Destination  DestinationConfig
	Alert        alert.Config
	AttributeMap []AttributeMap
	SyncSets     []SyncSet
}

func LoadConfig

func LoadConfig(configFile string) (AppConfig, error)

LoadConfig looks for a config file if one is provided. Otherwise, it looks for a config file based on the CONFIG_PATH env var. If that is not set, it gets the default config file ("./config.json").

func (*AppConfig) MaxSyncSetNameLength

func (a *AppConfig) MaxSyncSetNameLength() int

type AttributeMap

type AttributeMap struct {
	Source        string
	Destination   string
	Required      bool
	CaseSensitive bool
	Expression    string // regular expression
	Replace       string // replace string
}

type BatchTimer

type BatchTimer struct {
	Counter         int
	SecondsPerBatch int
	BatchSize       int
	// contains filtered or unexported fields
}

BatchTimer is intended as a time limited batch enforcer To create one, call its Init method. Then, to use it call its WaitOnBatch method after every call to

the associated go routine

func NewBatchTimer

func NewBatchTimer(batchSize, secondsPerBatch int) BatchTimer

Init sets the startTime to the current time,

sets the endTime based on secondsPerBatch into the future

func (*BatchTimer) Init

func (b *BatchTimer) Init(batchSize, secondsPerBatch int)

Init sets the startTime to the current time,

sets the endTime based on secondsPerBatch into the future

func (*BatchTimer) WaitOnBatch

func (b *BatchTimer) WaitOnBatch()

WaitOnBatch increments the Counter and then

if fewer than BatchSize have been dealt with, just returns without doing anything
Otherwise, sleeps until the batch time has expired (i.e. current time is past endTime).
If this last process occurs, then it ends by resetting the batch's times and counter.

type ChangeResults

type ChangeResults struct {
	Created uint64
	Updated uint64
	Deleted uint64
}

type ChangeSet

type ChangeSet struct {
	Create []Person
	Update []Person
	Delete []Person
}

func GenerateChangeSet

func GenerateChangeSet(logger *log.Logger, sourcePeople, destinationPeople []Person, config AppConfig) ChangeSet

GenerateChangeSet builds the three slice attributes of a ChangeSet (Create, Update and Delete) based on whether they are in the slice

of destination Person instances.

It skips all source Person instances that have DisableChanges set to true

type Destination

type Destination interface {
	ForSet(syncSetJson json.RawMessage) error
	ListUsers(desiredAttrs []string) ([]Person, error)
	ApplyChangeSet(changes ChangeSet, activityLog chan<- EventLogItem) ChangeResults
}

type DestinationConfig

type DestinationConfig struct {
	Type          string
	ExtraJSON     json.RawMessage
	DisableAdd    bool
	DisableUpdate bool
	DisableDelete bool
}

type EmptyDestination

type EmptyDestination struct{}

func (*EmptyDestination) ApplyChangeSet

func (e *EmptyDestination) ApplyChangeSet(changes ChangeSet, eventLog chan<- EventLogItem) ChangeResults

func (*EmptyDestination) ForSet

func (e *EmptyDestination) ForSet(syncSetJson json.RawMessage) error

func (*EmptyDestination) ListUsers

func (e *EmptyDestination) ListUsers(desiredAttrs []string) ([]Person, error)

type EmptySource

type EmptySource struct{}

func (*EmptySource) ForSet

func (e *EmptySource) ForSet(syncSetJson json.RawMessage) error

func (*EmptySource) ListUsers

func (e *EmptySource) ListUsers(desiredAttrs []string) ([]Person, error)

type EventLogItem

type EventLogItem struct {
	Message string
	Level   syslog.Priority
}

func (EventLogItem) String

func (l EventLogItem) String() string

type Person

type Person struct {
	CompareValue   string
	ID             string
	Attributes     map[string]string
	DisableChanges bool
}

func RemapToDestinationAttributes

func RemapToDestinationAttributes(logger *log.Logger, sourcePersons []Person, attributeMap []AttributeMap) ([]Person, error)

RemapToDestinationAttributes returns a slice of Person instances that each have only the desired attributes based on the destination attribute keys. If a required attribute is missing for a Person, then their disableChanges value is set to true.

type RuntimeConfig

type RuntimeConfig struct {
	DryRunMode bool
	Verbosity  int
}

type Source

type Source interface {
	ForSet(syncSetJson json.RawMessage) error
	ListUsers(desiredAttrs []string) ([]Person, error)
}

type SourceConfig

type SourceConfig struct {
	Type      string
	ExtraJSON json.RawMessage
}

type SyncSet

type SyncSet struct {
	Name        string
	Source      json.RawMessage
	Destination json.RawMessage
}

Jump to

Keyboard shortcuts

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