Socket
Socket
Sign inDemoInstall

github.com/graphikdb/eval

Package Overview
Dependencies
14
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/graphikdb/eval


Version published

Readme

Source

trigger

https://graphikdb.github.io/trigger/

GoDoc

a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

  • Full Text Search Expression Macros/Functions(startsWith, endsWith, contains)
  • RegularExp Expression Macros/Functions(matches)
  • Geographic Expression Macros/Functions(geoDistance)
  • Cryptographic Expression Macros/Functions(encrypt, decrypt, sha1, sha256, sha3)
  • JWT Expression Macros/Functions(parseClaims, parseHeader, parseSignature)
  • Collection Expression Macros/Functions(in, map, filter, exists)
  • String Manipulation Expression Macros/Functions(replace, join, titleCase, lowerCase, upperCase, trimSpace, trimPrefix, trimSuffix, render)
  • URL Introspection Expression Macros/Functions(parseHost, parseScheme, parseQuery, parsePath)

Use Case:

Since this expression language requires just input data(map[string]interface) and an expression string, Go programs may use it to embed flexible logic that may be changed at runtime without having to recompile.

  • Authorization Middleware/Policy Evaluation/Rule Engine

  • Database or API "triggers" for mutating data before its commited

  • Search Engine(filter something based on a decision)

Examples

restrict access based on domain
	decision, err := trigger.NewDecision("this.email.endsWith('acme.com')")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	err = decision.Eval(map[string]interface{}{
		"email": "bob@gmail.com",
	})
	fmt.Println(err == trigger.ErrDecisionDenied) 
    // Output: true 
create a trigger based on signup event that adds updated_at timestamp & hashes a password
	// create a trigger based on the new decision that hashes a password and creates an updated_at timestamp
	// this would in theory be applied to a newly created user after signup
	trigg, err := trigger.NewArrowTrigger(`
	this.event == 'signup' && has(this.email) =>
	{
		'updated_at': now(),
		'password': this.password.sha1()
	}
`)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	user := map[string]interface{}{
		"event": "signup",
		"name":  "bob",
		"email": "bob@acme.com",
		"password": "123456",
	}
	data, err := trigg.Trigger(user)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(data["updated_at"].(int64) > 0, data["password"])
	// Output: true 7c4a8d09ca3762af61e59520943dc26494f8941b

CEL Macro Extensions

Additional details on the standard CEL spec/library may be found here

functionnotationdescription
nownow() int64current timestamp in unix secods
uuiduuid() stringrandom uuidv4 string
sha1sha1(string) stringsha1 hash of the input string
sha256sha256(string) stringsha256 hash of the input string
sha3sha3(string) stringsha3 hash of the input string
base64Encodebase64Encode(string) stringbase64 encoded version of the input
base64Decodebase64Decode(string) stringbase64 decoded version of the input
jsonEncodejsonEncode(string) stringjson encoded version of the input
jsonDecodejsonDecode(string) stringjson decoded version of the input
replacereplace(text string, old string, new string) stringfull string replacement of the old value with the new value
joinjoin(arr list(string), sep string) stringjoins the array into a single string with the given separator
titleCasetitleCase(string) stringconverts the input into title case string
lowerCaselowerCase(string) stringconverts the input into lower case string
upperCaseupperCase(string) stringconverts the input into upper case string
trimSpacetrimSpace(string) stringremoves white spaces from the input string
trimPrefixtrimPrefix(string) stringremoves prefix from the input string
trimSuffixtrimSuffix(string) stringremoves suffix from the input string
geoDistancegeoDistance(this list(float64), that list(float64)) float64haversine distance between two coordinates [lat,lng]
renderrender(tmplate string, data map[string]interface) stringrenders the input template with the provided data map
parseClaimsparseClaims(jwt string) map[string]interface)returns the payload of the jwt as a map
parseHeaderparseHeader(jwt string) map[string]interfacereturns the header of the jwt as a map
parseSignatureparseSignature(jwt string) stringreturns the signature of the jwt as a string
typeOftypeOf(any) stringreturns the go type of the input
encryptencrypt(secret string, msg string) stringaes encrypt a message with a given secret
decryptdecrypt(secret string, msg string) stringaes decrypt a message with a given secret

FAQs

Last updated on 16 Jan 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc