Coder Social home page Coder Social logo

daichitakahashi / rego-validation-example Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 120 KB

Examples for validation using Policy Language Rego

Makefile 1.41% Go 61.06% JavaScript 9.26% Open Policy Agent 20.34% Python 7.93%
golang nodejs opa open-policy-agent python rego validation wasm webassembly

rego-validation-example's Introduction

rego-validation-example

Examples for validation using Policy Language Rego.

Policies

  • policy/email.rego: validate email address
    • policy/email_test.rego: test code
  • policy/domain.rego: validate domain part of email address
    • policy/domain_test.rego: test code
  • artifact/policy.wasm: bundled WebAssembly(make build)

Examples

Go

Go example handles ".rego" files directly using github.com/open-policy-agent/opa.

$ cd go
$ go test -v .
=== RUN   TestValidEmail
=== RUN   TestValidEmail/[email protected]
=== RUN   TestValidEmail/hoge@[email protected]
=== RUN   TestValidEmail/hoge@example
--- PASS: TestValidEmail (0.00s)
    --- PASS: TestValidEmail/[email protected] (0.00s)
    --- PASS: TestValidEmail/hoge@[email protected] (0.00s)
    --- PASS: TestValidEmail/hoge@example (0.00s)
=== RUN   TestValidDomain
=== RUN   TestValidDomain/example.com
=== RUN   TestValidDomain/example
--- PASS: TestValidDomain (0.00s)
    --- PASS: TestValidDomain/example.com (0.00s)
    --- PASS: TestValidDomain/example (0.00s)
PASS
ok      rego-validation-example/go      0.365s

JavaScript(node.js)

Javascript example uses "policy.wasm" with @open-policy-agent/opa-wasm.

$ cd node
$ npm install
$ node test.mjs
[validation/email]
[email protected] { valid: true }
hogehogeexample.com { valid: false }
hoge@[email protected] { valid: false }
hogehoge@examplecom { valid: false }

[validation/domain]
example.com { valid: true }
examplecom { valid: false }
.example.com { valid: false }

Python(3.10)

Python example uses "policy.wasm" too, with opa-wasm.

$ cd python
$ pip3 install -r requirements.txt
$ python3 test.py
[validation/email]
[email protected] {'valid': True}
hogehogeexample.com {'valid': False}
hoge@[email protected] {'valid': False}
hogehoge@examplecom {'valid': False}

[validation/domain]
example.com {'valid': True}
examplecom {'valid': False}
.example.com {'valid': False}

rego-validation-example's People

Contributors

daichitakahashi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.