Skip to content

Commit

Permalink
Add CI build + test checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmunns committed Jun 10, 2024
1 parent 0c32967 commit 6de639c
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 58 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

# Cancel old workflows for PRs (only the most recent workflow can run).
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

# Avoid workflow-level permissions, instead use job-level permissions.
permissions: {}

jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./ci.sh
15 changes: 15 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -euxo pipefail

# Format check first
cargo fmt --all -- --check

# Test all crates
cargo test --all

# Run configuration file checks
cd ./source/river
cargo run -p river -- --config-toml ./assets/example-config.toml --validate-configs
cargo run -p river -- --config-toml ./assets/test-config.toml --validate-configs
cargo run -p river -- --config-kdl ./assets/test-config.kdl --validate-configs
1 change: 0 additions & 1 deletion experiments/kdl-experiment/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use std::{collections::BTreeMap, path::PathBuf};

use pingora::{
Expand Down
7 changes: 1 addition & 6 deletions experiments/kdl-experiment/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#![allow(dead_code)]

use std::{
collections::BTreeMap,
fs::read_to_string,
net::SocketAddr,
path::PathBuf,
};
use std::{collections::BTreeMap, fs::read_to_string, net::SocketAddr, path::PathBuf};

use config::{Config, ListenerConfig, ListenerKind, PathControl, ProxyConfig, TlsConfig};
use kdl::{KdlDocument, KdlEntry, KdlNode};
Expand Down
148 changes: 97 additions & 51 deletions source/river/src/config/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,59 @@ pub enum ListenerKind {
Uds(PathBuf),
}

impl From<ProxyConfig> for super::internal::ProxyConfig {
fn from(other: ProxyConfig) -> Self {
Self {
name: other.name,
listeners: other.listeners.into_iter().map(Into::into).collect(),
upstream: other.connector.into(),
path_control: other.path_control.into(),
}
}
}

impl From<PathControl> for super::internal::PathControl {
fn from(value: PathControl) -> Self {
Self {
upstream_request_filters: value.upstream_request_filters,
upstream_response_filters: value.upstream_response_filters,
}
}
}

impl From<ListenerTlsConfig> for super::internal::TlsConfig {
fn from(other: ListenerTlsConfig) -> Self {
Self {
cert_path: other.cert_path,
key_path: other.key_path,
}
}
}

impl From<ListenerConfig> for super::internal::ListenerConfig {
fn from(other: ListenerConfig) -> Self {
Self {
source: other.source.into(),
}
}
}

impl From<ListenerKind> for super::internal::ListenerKind {
fn from(other: ListenerKind) -> Self {
match other {
ListenerKind::Tcp { addr, tls } => super::internal::ListenerKind::Tcp {
addr,
tls: tls.map(Into::into),
},
ListenerKind::Uds(a) => super::internal::ListenerKind::Uds(a),
}
}
}

#[cfg(test)]
pub mod test {
use std::collections::BTreeMap;

use pingora::upstreams::peer::HttpPeer;

use crate::config::{
Expand Down Expand Up @@ -206,7 +257,28 @@ pub mod test {
tls_sni: Some(String::from("onevariable.com")),
},
path_control: crate::config::toml::PathControl {
upstream_request_filters: vec![],
upstream_request_filters: vec![
BTreeMap::from([
("kind".to_string(), "remove-header-key-regex".to_string()),
("pattern".to_string(), ".*(secret|SECRET).*".to_string()),
]),
BTreeMap::from([
("key".to_string(), "x-proxy-friend".to_string()),
("kind".to_string(), "upsert-header".to_string()),
("value".to_string(), "river".to_string()),
]),
],
upstream_response_filters: vec![
BTreeMap::from([
("kind".to_string(), "remove-header-key-regex".to_string()),
("pattern".to_string(), ".*ETag.*".to_string()),
]),
BTreeMap::from([
("key".to_string(), "x-with-love-from".to_string()),
("kind".to_string(), "upsert-header".to_string()),
("value".to_string(), "river".to_string()),
]),
],
},
},
ProxyConfig {
Expand All @@ -223,6 +295,7 @@ pub mod test {
},
path_control: crate::config::toml::PathControl {
upstream_request_filters: vec![],
upstream_response_filters: vec![],
},
},
],
Expand Down Expand Up @@ -259,7 +332,28 @@ pub mod test {
String::from("onevariable.com"),
),
path_control: internal::PathControl {
upstream_request_filters: vec![],
upstream_request_filters: vec![
BTreeMap::from([
("kind".to_string(), "remove-header-key-regex".to_string()),
("pattern".to_string(), ".*(secret|SECRET).*".to_string()),
]),
BTreeMap::from([
("key".to_string(), "x-proxy-friend".to_string()),
("kind".to_string(), "upsert-header".to_string()),
("value".to_string(), "river".to_string()),
]),
],
upstream_response_filters: vec![
BTreeMap::from([
("kind".to_string(), "remove-header-key-regex".to_string()),
("pattern".to_string(), ".*ETag.*".to_string()),
]),
BTreeMap::from([
("key".to_string(), "x-with-love-from".to_string()),
("kind".to_string(), "upsert-header".to_string()),
("value".to_string(), "river".to_string()),
]),
],
},
},
internal::ProxyConfig {
Expand All @@ -273,6 +367,7 @@ pub mod test {
upstream: HttpPeer::new("91.107.223.4:80", false, String::new()),
path_control: internal::PathControl {
upstream_request_filters: vec![],
upstream_response_filters: vec![],
},
},
],
Expand All @@ -287,52 +382,3 @@ pub mod test {
assert_eq!(format!("{sys_snapshot:?}"), format!("{cfg:?}"));
}
}

impl From<ProxyConfig> for super::internal::ProxyConfig {
fn from(other: ProxyConfig) -> Self {
Self {
name: other.name,
listeners: other.listeners.into_iter().map(Into::into).collect(),
upstream: other.connector.into(),
path_control: other.path_control.into(),
}
}
}

impl From<PathControl> for super::internal::PathControl {
fn from(value: PathControl) -> Self {
Self {
upstream_request_filters: value.upstream_request_filters,
upstream_response_filters: value.upstream_response_filters,
}
}
}

impl From<ListenerTlsConfig> for super::internal::TlsConfig {
fn from(other: ListenerTlsConfig) -> Self {
Self {
cert_path: other.cert_path,
key_path: other.key_path,
}
}
}

impl From<ListenerConfig> for super::internal::ListenerConfig {
fn from(other: ListenerConfig) -> Self {
Self {
source: other.source.into(),
}
}
}

impl From<ListenerKind> for super::internal::ListenerKind {
fn from(other: ListenerKind) -> Self {
match other {
ListenerKind::Tcp { addr, tls } => super::internal::ListenerKind::Tcp {
addr,
tls: tls.map(Into::into),
},
ListenerKind::Uds(a) => super::internal::ListenerKind::Uds(a),
}
}
}

0 comments on commit 6de639c

Please sign in to comment.