Skip to content

Commit b60fb2c

Browse files
chore: move stuff to libs/core
1 parent 83ea1a2 commit b60fb2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+7256
-17
lines changed

cel-rust

Submodule cel-rust deleted from d84558a
File renamed without changes.
File renamed without changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Release-plz
2+
3+
permissions:
4+
pull-requests: write
5+
contents: write
6+
7+
on:
8+
push:
9+
branches:
10+
- master
11+
12+
jobs:
13+
14+
# Release unpublished packages.
15+
release-plz-release:
16+
name: Release-plz release
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
- name: Install Rust toolchain
22+
uses: dtolnay/rust-toolchain@stable
23+
- name: Run release-plz
24+
uses: MarcoIeni/[email protected]
25+
with:
26+
command: release
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
30+
31+
# Create a PR with the new versions and changelog, preparing the next release.
32+
release-plz-pr:
33+
name: Release-plz PR
34+
runs-on: ubuntu-latest
35+
concurrency:
36+
group: release-plz-${{ github.ref }}
37+
cancel-in-progress: false
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 0
43+
- name: Install Rust toolchain
44+
uses: dtolnay/rust-toolchain@stable
45+
- name: Run release-plz
46+
uses: MarcoIeni/[email protected]
47+
with:
48+
command: release-pr
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: Swatinem/rust-cache@v2
19+
- name: Format
20+
run: cargo fmt --all -- --check
21+
- name: Build minimal
22+
run: cargo build --verbose --no-default-features
23+
- name: Build with default features
24+
run: cargo build --verbose
25+
- name: Build with all features
26+
run: cargo build --verbose --all-features
27+
- name: Clippy
28+
run: cargo clippy --all-features --all-targets -- -D warnings
29+
- name: Run tests
30+
run: |
31+
cargo test --verbose
32+
cargo test --verbose --features json
33+
cargo test --verbose --features regex
34+
cargo test --verbose --features chrono

libs/core/cel-rust/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

libs/core/cel-rust/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[workspace]
2+
members = ["parser", "interpreter", "example"]
3+
resolver = "2"
4+
5+
[profile.bench]
6+
lto = true
7+
codegen-units = 1
8+
opt-level = 3

libs/core/cel-rust/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2022 Tom Forbes and Contributors
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
19+
OR OTHER DEALINGS IN THE SOFTWARE.

libs/core/cel-rust/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Common Expression Language (Rust)
2+
3+
[![Rust](https://github.com/clarkmcc/cel-rust/actions/workflows/rust.yml/badge.svg)](https://github.com/clarkmcc/cel-rust/actions/workflows/rust.yml)
4+
5+
The [Common Expression Language (CEL)](https://github.com/google/cel-spec) is a non-Turing complete language designed
6+
for simplicity, speed, safety, and
7+
portability. CEL's C-like syntax looks nearly identical to equivalent expressions in C++, Go, Java, and TypeScript. CEL
8+
is ideal for lightweight expression evaluation when a fully sandboxed scripting language is too resource intensive.
9+
10+
```java
11+
// Check whether a resource name starts with a group name.
12+
resource.name.startsWith("/groups/" + auth.claims.group)
13+
```
14+
15+
```go
16+
// Determine whether the request is in the permitted time window.
17+
request.time - resource.age < duration("24h")
18+
```
19+
20+
```typescript
21+
// Check whether all resource names in a list match a given filter.
22+
auth.claims.email_verified && resources.all(r, r.startsWith(auth.claims.email))
23+
```
24+
25+
## Getting Started
26+
27+
This project includes a CEL-parser and an interpreter which means that it can be used to evaluate CEL-expressions. The
28+
library aims to be very simple to use, while still being fast, safe, and customizable.
29+
30+
```rust
31+
fn main() {
32+
let program = Program::compile("add(2, 3) == 5").unwrap();
33+
let mut context = Context::default();
34+
context.add_function("add", |a: i64, b: i64| a + b);
35+
let value = program.execute(&context).unwrap();
36+
assert_eq!(value, true.into());
37+
}
38+
```
39+
40+
### Examples
41+
42+
Check out these other examples to learn how to use this library:
43+
44+
- [Simple](./example/src/simple.rs) - A simple example of how to use the library.
45+
- [Variables](./example/src/variables.rs) - Passing variables and using them in your program.
46+
- [Functions](./example/src/functions.rs) - Defining and using custom functions in your program.
47+
- [Concurrent Execution](./example/src/threads.rs) - Executing the same program concurrently.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[package]
2+
name = "example"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[features]
7+
axum = ["dep:axum", "dep:tokio", "dep:thiserror"]
8+
json = ["dep:serde_json", "cel-interpreter/json"]
9+
chrono = ["dep:chrono", "cel-interpreter/chrono"]
10+
11+
[dependencies]
12+
cel-interpreter = { path = "../interpreter", default-features = false }
13+
14+
chrono = { version = "0.4", optional = true }
15+
16+
serde = { version = "1.0", features = ["derive"] }
17+
serde_json = { version = "1.0", optional = true }
18+
19+
axum = { version = "0.7.5", default-features = false, features = [
20+
"http1",
21+
"json",
22+
"tokio",
23+
], optional = true }
24+
tokio = { version = "1.38.0", default-features = false, features = [
25+
"macros",
26+
"net",
27+
"rt-multi-thread",
28+
], optional = true }
29+
thiserror = { version = "1.0", optional = true }
30+
31+
[[bin]]
32+
name = "example-simple"
33+
path = "src/simple.rs"
34+
35+
[[bin]]
36+
name = "example-variables"
37+
path = "src/variables.rs"
38+
39+
[[bin]]
40+
name = "example-functions"
41+
path = "src/functions.rs"
42+
required-features = ["chrono"]
43+
44+
[[bin]]
45+
name = "example-threads"
46+
path = "src/threads.rs"
47+
48+
[[bin]]
49+
name = "example-serde"
50+
path = "src/serde.rs"
51+
52+
[[bin]]
53+
name = "example-axum"
54+
path = "src/axum.rs"
55+
required-features = ["axum"]
56+
57+
[[bin]]
58+
name = "example-json"
59+
path = "src/json.rs"
60+
required-features = ["json"]

0 commit comments

Comments
 (0)