internal

package
v6.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 13 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 AddParamsToURL

func AddParamsToURL(inURL string, params [][2]string) (string, error)

AddParamsToURL returns the input url string if there are no params to add Otherwise, it adds each param pair to the url as `params[n][0]=params[n][1]` (in alphabetical order) with the appropriate delimiter ("?" or "&")

func AddStringToSlice

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, haystack any) (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

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 JoinUrlPath

func JoinUrlPath(inURL, path string) string

func LoadConfig

func LoadConfig(configFile string) ([]byte, 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 RunSyncSet

func RunSyncSet(logger *log.Logger, source Source, destination Destination, config Config) 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, otherwise it makes the associated changes

Types

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

NewBatchTimer returns a new BatchTimer with the startTime set to the current time and the endTime set to secondsPerBatch from now

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 Config) 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 Config added in v6.4.0

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

func NewConfig added in v6.4.0

func NewConfig() Config

func ReadConfig added in v6.4.0

func ReadConfig(data []byte) (Config, error)

ReadConfig parses raw json config data into a Config struct

func (*Config) MaxSyncSetNameLength added in v6.4.0

func (c *Config) MaxSyncSetNameLength() int

func (*Config) Validate added in v6.4.0

func (c *Config) Validate() error

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 Filter added in v6.1.0

type Filter struct {
	Attribute  string
	Expression string
	Exclude    bool

	Nullable bool
	// contains filtered or unexported fields
}

func (Filter) Matches added in v6.2.0

func (f Filter) Matches(value string) bool

type Filters added in v6.1.0

type Filters []Filter

func (*Filters) Validate added in v6.1.0

func (f *Filters) Validate() error

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.

func (*Person) Matches added in v6.1.0

func (p *Person) Matches(filters Filters) (bool, error)

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 SyncError added in v6.7.0

type SyncError struct {
	Message   error
	SendAlert bool
}

func (SyncError) Error added in v6.7.0

func (s SyncError) Error() string

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