Skip to content

Commit

Permalink
Fixes #14554: Update relay component
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Apr 1, 2019
1 parent 8d9092f commit 46dae9c
Show file tree
Hide file tree
Showing 33 changed files with 1,287 additions and 477 deletions.
1 change: 1 addition & 0 deletions relay/sources/relayd/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
rudder-relayd.iml
/target/
**/*.rs.bk
/tests/tmp/
299 changes: 218 additions & 81 deletions relay/sources/relayd/Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions relay/sources/relayd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "relayd"
version = "0.0.1"
# TODO automate version number
version = "5.1.0-alpha1"
authors = ["Rudder developpers <dev@rudder.io>"]
edition = "2018"

Expand All @@ -17,8 +18,7 @@ path = "src/relayd.rs"
## Good
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
regex = "1.1"
lazy_static = "1.2"
nom = "4.2"
clap = "2.32"
diesel = { version = "1.4", features = ["postgres", "chrono", "r2d2"] }
# Compile dev and release with trace logs enabled
Expand Down
40 changes: 18 additions & 22 deletions relay/sources/relayd/Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
DESTDIR = $(CURDIR)/target

build:
cargo build
# fmt, build, test, audit, clean, etc.
%:
cargo $@

test:
cargo test

audit:
cargo audit

format:
cargo fmt
outdated:
# only check on our dependencies
cargo outdated --root-deps-only

lint:
RUSTFLAGS="-D warnings" cargo clippy --all-targets --all-features --examples --tests -- -D clippy::all

install: clean lint audit
cargo install --path=. --root=$(DESTDIR)
cargo install --bin relayd --path=. --root=$(DESTDIR)

yum-dependencies:
yum install pkgconf-pkg-config libpqxx openssl-devel

apt-dependencies:
apt install pkg-config libpq-dev libssl-dev

build-env:
curl https://sh.rustup.rs -sSf | sh
rustup component add clippy
cargo install cargo-update
cargo install cargo-audit

Expand All @@ -28,20 +31,13 @@ build-env-update:
rustup update
cargo install-update -a

deps-update:
cargo update
cargo outdated -d 1
deps-update: update outdated
# done

dev-env: build-env
rustup component add rustfmt
rustup component add clippy
cargo install cargo-fix
cargo install cargo-tree
cargo install cargo-outdated

clean:
cargo clean

veryclean: clean
rm -rf ~/.rustup
rm -rf ~/.cargo
rustup self uninstall
rm -rf ~/.rustup ~/.cargo
32 changes: 31 additions & 1 deletion relay/sources/relayd/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# protocol-v2-poc

## Install

### Dependencies

Dependencies are:

* pkg-config (only for dev)
* openssl
* libpq

To install build dependencies on Debian/Ubuntu:

```bash
make apt-dependencies
```

To install build dependencies on RHEL/Fedora:

```bash
make yum-dependencies
```

### Installation

To install:

```bash
make DESTDIR=/target/directory install
```

## Development environment

This project requires Rust 1.32 or later (for Rust 2018 support
Expand Down Expand Up @@ -33,4 +63,4 @@ cargo install cargo-benchcmp # to compare benchmarks results

## Development database

Schema for the database is: `webapp/sources/rudder/rudder-core/src/main/resources/reportsSchema.sql`
Schema for the database is in: `webapp/sources/rudder/rudder-core/src/main/resources/reportsSchema.sql`
30 changes: 30 additions & 0 deletions relay/sources/relayd/fuzz/fuzz_targets/report.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// Copyright 2019 Normation SAS
//
// This file is part of Rudder.
//
// Rudder is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In accordance with the terms of section 7 (7. Additional Terms.) of
// the GNU General Public License version 3, the copyright holders add
// the following Additional permissions:
// Notwithstanding to the terms of section 5 (5. Conveying Modified Source
// Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
// Public License version 3, when you create a Related Module, this
// Related Module is not considered as a part of the work and may be
// distributed under the license agreement of your choice.
// A "Related Module" means a set of sources files including their
// documentation that, without modification of the Source Code, enables
// supplementary functions or services in addition to those offered by
// the Software.
//
// Rudder is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rudder. If not, see <http://www.gnu.org/licenses/>.

#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate relayd;
Expand Down
30 changes: 30 additions & 0 deletions relay/sources/relayd/fuzz/fuzz_targets/runinfo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// Copyright 2019 Normation SAS
//
// This file is part of Rudder.
//
// Rudder is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In accordance with the terms of section 7 (7. Additional Terms.) of
// the GNU General Public License version 3, the copyright holders add
// the following Additional permissions:
// Notwithstanding to the terms of section 5 (5. Conveying Modified Source
// Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
// Public License version 3, when you create a Related Module, this
// Related Module is not considered as a part of the work and may be
// distributed under the license agreement of your choice.
// A "Related Module" means a set of sources files including their
// documentation that, without modification of the Source Code, enables
// supplementary functions or services in addition to those offered by
// the Software.
//
// Rudder is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rudder. If not, see <http://www.gnu.org/licenses/>.

#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate relayd;
Expand Down
30 changes: 30 additions & 0 deletions relay/sources/relayd/fuzz/fuzz_targets/runlog.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// Copyright 2019 Normation SAS
//
// This file is part of Rudder.
//
// Rudder is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In accordance with the terms of section 7 (7. Additional Terms.) of
// the GNU General Public License version 3, the copyright holders add
// the following Additional permissions:
// Notwithstanding to the terms of section 5 (5. Conveying Modified Source
// Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
// Public License version 3, when you create a Related Module, this
// Related Module is not considered as a part of the work and may be
// distributed under the license agreement of your choice.
// A "Related Module" means a set of sources files including their
// documentation that, without modification of the Source Code, enables
// supplementary functions or services in addition to those offered by
// the Software.
//
// Rudder is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rudder. If not, see <http://www.gnu.org/licenses/>.

#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate relayd;
Expand Down
30 changes: 30 additions & 0 deletions relay/sources/relayd/src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// Copyright 2019 Normation SAS
//
// This file is part of Rudder.
//
// Rudder is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In accordance with the terms of section 7 (7. Additional Terms.) of
// the GNU General Public License version 3, the copyright holders add
// the following Additional permissions:
// Notwithstanding to the terms of section 5 (5. Conveying Modified Source
// Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
// Public License version 3, when you create a Related Module, this
// Related Module is not considered as a part of the work and may be
// distributed under the license agreement of your choice.
// A "Related Module" means a set of sources files including their
// documentation that, without modification of the Source Code, enables
// supplementary functions or services in addition to those offered by
// the Software.
//
// Rudder is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rudder. If not, see <http://www.gnu.org/licenses/>.

extern crate relayd;

use clap::{crate_version, App, Arg};
Expand Down
33 changes: 32 additions & 1 deletion relay/sources/relayd/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// Copyright 2019 Normation SAS
//
// This file is part of Rudder.
//
// Rudder is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In accordance with the terms of section 7 (7. Additional Terms.) of
// the GNU General Public License version 3, the copyright holders add
// the following Additional permissions:
// Notwithstanding to the terms of section 5 (5. Conveying Modified Source
// Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
// Public License version 3, when you create a Related Module, this
// Related Module is not considered as a part of the work and may be
// distributed under the license agreement of your choice.
// A "Related Module" means a set of sources files including their
// documentation that, without modification of the Source Code, enables
// supplementary functions or services in addition to those offered by
// the Software.
//
// Rudder is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rudder. If not, see <http://www.gnu.org/licenses/>.

use crate::stats::Stats;
use futures::Future;
use slog::slog_info;
Expand All @@ -11,10 +41,11 @@ pub fn api(
shutdown: impl Future<Item = ()> + Send + 'static,
stats: Arc<RwLock<Stats>>,
) -> impl Future<Item = (), Error = ()> {
// TODO remove unwrap
let stats_simple =
warp::path("stats").map(move || warp::reply::json(&(*stats.clone().read().unwrap())));
let routes = warp::get2().and(stats_simple);
let (addr, server) = warp::serve(routes).bind_with_graceful_shutdown(listen, shutdown);
info!("Started stats API on {}", addr);
info!("Started stats API on {}", addr; "component" => "statistics");
server
}
49 changes: 31 additions & 18 deletions relay/sources/relayd/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
// Copyright 2019 Normation SAS
//
// This file is part of Rudder.
//
// Rudder is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In accordance with the terms of section 7 (7. Additional Terms.) of
// the GNU General Public License version 3, the copyright holders add
// the following Additional permissions:
// Notwithstanding to the terms of section 5 (5. Conveying Modified Source
// Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
// Public License version 3, when you create a Related Module, this
// Related Module is not considered as a part of the work and may be
// distributed under the license agreement of your choice.
// A "Related Module" means a set of sources files including their
// documentation that, without modification of the Source Code, enables
// supplementary functions or services in addition to those offered by
// the Software.
//
// Rudder is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rudder. If not, see <http://www.gnu.org/licenses/>.

use crate::configuration::DEFAULT_CONFIGURATION_FILE;
use clap::{crate_version, App, Arg};
use slog::Level;
use std::path::PathBuf;

#[derive(Debug)]
pub struct CliConfiguration {
pub configuration_file: PathBuf,
pub verbosity: Level,
}

pub fn parse() -> CliConfiguration {
let matches = App::new("relayd")
.version(crate_version!())
.author("Rudder team")
.author("Rudder team <dev@rudder.io>")
.about("Rudder relay server")
.arg(
Arg::with_name("config")
Expand All @@ -23,27 +51,12 @@ pub fn parse() -> CliConfiguration {
.help("Sets a custom config file")
.takes_value(true),
)
.arg(
Arg::with_name("verbosity")
.short("v")
.long("verbosity")
.default_value("info")
.possible_values(&["error", "warn", "info", "debug", "trace"])
.value_name("VERBOSITY")
.help("Sets the level of verbosity")
.takes_value(true),
)
.get_matches();

CliConfiguration {
configuration_file: matches
.value_of("config")
.expect("No configuration file specified")
.into(),
verbosity: matches
.value_of("verbosity")
.expect("Missing verbosity level")
.parse::<Level>()
.expect("Unknown verbosity level"),
}
}

0 comments on commit 46dae9c

Please sign in to comment.