parse

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

TODO(nklaassen): evaluate the risks and utility of allowing traits to be used as regular expressions. The only thing blocking this today is that all trait values are lists and the regex must be a single value. It could be possible to write: `{{regexp.match(email.local(head(external.trait_name)))}}`

Index

Constants

View Source
const (
	// EmailLocalFnName is a name for email.local function
	EmailLocalFnName = "email.local"
	// RegexpMatchFnName is a name for regexp.match function.
	RegexpMatchFnName = "regexp.match"
	// RegexpNotMatchFnName is a name for regexp.not_match function.
	RegexpNotMatchFnName = "regexp.not_match"
	// RegexpReplaceFnName is a name for regexp.replace function.
	RegexpReplaceFnName = "regexp.replace"
)

Variables

This section is empty.

Functions

func EmailLocal

func EmailLocal(inputs []string) ([]string, error)

EmailLocal returns a new list which is a result of getting the local part of each email from the input list.

func RegexpReplace

func RegexpReplace(inputs []string, match string, replacement string) ([]string, error)

RegexpReplace returns a new list which is the result of replacing each instance of [match] with [replacement] for each item in the input list.

Types

type MatchExpression

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

MatchExpression is a match expression.

func NewMatcher

func NewMatcher(value string) (*MatchExpression, error)

NewMatcher parses a matcher expression. Currently supported expressions: - string literal: `foo` - wildcard expression: `*` or `foo*bar` - regexp expression: `^foo$` - regexp function calls:

  • positive match: `{{regexp.match("foo.*")}}`
  • negative match: `{{regexp.not_match("foo.*")}}`

These expressions do not support variable interpolation (e.g. `{{internal.logins}}`), like Expression does.

func (*MatchExpression) Match

func (e *MatchExpression) Match(in string) bool

type Matcher

type Matcher interface {
	Match(in string) bool
}

Matcher matches strings against some internal criteria (e.g. a regexp)

func NewAnyMatcher

func NewAnyMatcher(in []string) (Matcher, error)

NewAnyMatcher returns a matcher function based on incoming values

type MatcherFn

type MatcherFn func(in string) bool

MatcherFn converts function to a matcher interface

func (MatcherFn) Match

func (fn MatcherFn) Match(in string) bool

Match matches string against a regexp

type TraitsTemplateExpression

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

TraitsTemplateExpression can interpolate user trait values into a string template to produce some values.

func NewTraitsTemplateExpression

func NewTraitsTemplateExpression(value string) (*TraitsTemplateExpression, error)

NewTraitsTemplateExpression parses expressions like {{external.foo}} or {{internal.bar}}, or a literal value like "prod". Call Interpolate on the returned Expression to get the final value based on user traits.

func (*TraitsTemplateExpression) Interpolate

func (e *TraitsTemplateExpression) Interpolate(varValidation func(namespace, name string) error, traits map[string][]string) ([]string, error)

Interpolate interpolates the variable adding prefix and suffix if present. The returned error is trace.NotFound in case the expression contains a variable and this variable is not found on any trait, nil in case of success, and BadParameter otherwise.

Jump to

Keyboard shortcuts

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