Skip to content

Commit

Permalink
Merge branch 'main' into hawken/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
drewvolz committed Jan 25, 2025
2 parents dfd1bd9 + ed61e39 commit e9acbd2
Show file tree
Hide file tree
Showing 19 changed files with 386 additions and 26 deletions.
29 changes: 29 additions & 0 deletions .config/mise/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[env]
_.file = '.env'

[tasks.build]
run = "cargo build"

[tasks.check]
depends = ["clippy", "format-check", "test"]

[tasks.clippy]
run = "cargo clippy --workspace --all-features --all-targets"

[tasks.diff]
run = "git diff --exit-code -- types/bindings/index.d.ts"

[tasks.format]
run = "cargo fmt --all"

[tasks.format-check]
run = "cargo fmt --all -- --check"

[tasks.start]
run = "cargo run --bin ccc-server"

[tasks.test]
run = "cargo test --workspace --all-features --all-targets --no-fail-fast"

[tasks.e2e]
run = "cargo run --bin e2e"
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BON_APPETIT_AUTH=
14 changes: 8 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ jobs:
run: |
rustup toolchain install ${{ matrix.rust }}
rustup default ${{ matrix.rust }}
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: jdx/mise-action@5083fe46898c414b2475087cc79da59e7da859e8 # v2
- name: Run rustfmt
run: |
rustup component add rustfmt
cargo fmt --all -- --check
mise run format-check
- name: Run clippy
run: |
rustup component add clippy
cargo clippy --workspace --all-features --all-targets
mise run clippy
test:
name: Test the code
runs-on: ubuntu-latest
Expand All @@ -39,10 +40,11 @@ jobs:
run: |
rustup toolchain install ${{ matrix.rust }}
rustup default ${{ matrix.rust }}
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: jdx/mise-action@5083fe46898c414b2475087cc79da59e7da859e8 # v2
- name: Run cargo test
run: |
cargo test --workspace --all-features --all-targets --no-fail-fast
mise run test
- name: Ensure index.d.ts is up-to-date after tests were run
run: |
git diff --exit-code -- types/bindings/index.d.ts
mise run diff
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
.env
.DS_STORE
74 changes: 73 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ccc-handlers = { path = "./ccc-handlers" }
ccc-proxy = { path = "./ccc-proxy" }
ccc-routes = { path = "./ccc-routes" }
ccc-types = { path = "./ccc-types" }
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4.5.3", features = ["derive"] }
http = "1.1.0"
phf = { version = "0.11.2", features = ["macros"] }
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# ccc-server-next
next generation of cautious-computing-context

## Environment

Config is managed with [mise](https://mise.jdx.dev)

Install

```sh
brew install mise
echo 'eval "$(mise activate zsh)"' >> ~/.zshrc
source ~/.zshrc
mise trust
```

Build and run
```sh
mise use -g rust
mise run build
mise run start
```

**`Bonappetit`**: You'll need to have authorization setup to get bonappetit requests working. Copy `.env.sample` to `.env` and set the token to get this working.
1 change: 1 addition & 0 deletions ccc-handlers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ thiserror = { workspace = true }
tracing = { workspace = true }
serde_urlencoded = { workspace = true }
phf = { workspace = true }
chrono = { workspace = true }
20 changes: 17 additions & 3 deletions ccc-handlers/src/bonapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ where

let (base_url, entity) = get_query_base_url_and_entity(&query_type);

let bon_app_auth =
std::env::var("BON_APPETIT_AUTH").expect("BON_APPETIT_AUTH credential not set");
let auth_header_value = format!("Basic {}", bon_app_auth);

let request = ccc_proxy::global_proxy()
.client()
.request(Method::GET, base_url)
.query(&[(entity, entity_id)])
.header("Authorization", auth_header_value)
.build()
.map_err(ProxyError::ProxiedRequest)
.map_err(BonAppProxyError::GenericProxy)?;
Expand Down Expand Up @@ -70,9 +75,18 @@ use QueryType::*;
#[inline]
const fn get_query_base_url_and_entity(query_type: &QueryType) -> (&str, &str) {
match query_type {
Cafe => ("https://legacy.cafebonappetit.com/api/2/cafes", "cafe"),
Menu => ("https://legacy.cafebonappetit.com/api/2/menus", "cafe"),
ItemNutrition => ("https://legacy.cafebonappetit.com/api/2/items", "item"),
Cafe => (
"https://cafemanager-api.cafebonappetit.com/api/2/cafes",
"cafe",
),
Menu => (
"https://cafemanager-api.cafebonappetit.com/api/2/menus",
"cafe",
),
ItemNutrition => (
"https://cafemanager-api.cafebonappetit.com/api/2/items",
"item",
),
}
}

Expand Down
1 change: 1 addition & 0 deletions ccc-handlers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

pub mod bonapp;
pub mod github;
pub mod streams;
Loading

0 comments on commit e9acbd2

Please sign in to comment.