Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 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 @@ -2,6 +2,7 @@

members = [
"cincinnati",
"commons",
"graph-builder",
"policy-engine",
]
6 changes: 6 additions & 0 deletions commons/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "commons"
version = "0.1.0"
authors = ["Stefan Junker <[email protected]>"]

[dependencies]
12 changes: 12 additions & 0 deletions commons/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// Strip any leading and trailing slashes
pub fn parse_path_namespace(path_namespace: &str) -> String {
path_namespace.to_string().trim_matches('/').to_string()
}

#[cfg(test)]
mod tests {
#[test]
fn test_parse_path_namespace() {
assert_eq!(super::parse_path_namespace("//a/b/c/"), "a/b/c");
}
}
1 change: 1 addition & 0 deletions graph-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = ["Alex Crawford <[email protected]>"]
[dependencies]
actix-web = "^0.7.8"
cincinnati = { path = "../cincinnati" }
commons = { path = "../commons" }
env_logger = "^0.6.0"
itertools = "^0.7.8"
failure = "^0.1.1"
Expand Down
9 changes: 9 additions & 0 deletions graph-builder/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use commons::parse_path_namespace;
use std::net::IpAddr;
use std::num::ParseIntError;
use std::path::PathBuf;
Expand Down Expand Up @@ -51,6 +52,14 @@ pub struct Options {
/// Credentials file for authentication against the image registry
#[structopt(long = "credentials-file", parse(from_os_str))]
pub credentials_path: Option<PathBuf>,

/// Path namespace prefix for all paths. Shall be given without leading and trailing slashes.
#[structopt(
long = "path-namespace",
default_value = "",
parse(from_str = "parse_path_namespace")
)]
pub path_namespace: String,
}

fn parse_duration(src: &str) -> Result<Duration, ParseIntError> {
Expand Down
1 change: 1 addition & 0 deletions graph-builder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern crate cincinnati;
extern crate commons;
extern crate dkregistry;
extern crate env_logger;
extern crate flate2;
Expand Down
3 changes: 2 additions & 1 deletion graph-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn main() -> Result<(), Error> {

let state = graph::State::new();
let addr = (opts.address, opts.port);
let graph_path = format!("/{}/v1/graph", opts.path_namespace);

{
let state = state.clone();
Expand All @@ -52,7 +53,7 @@ fn main() -> Result<(), Error> {
server::new(move || {
App::with_state(state.clone())
.middleware(Logger::default())
.route("/v1/graph", Method::GET, graph::index)
.route(&graph_path, Method::GET, graph::index)
})
.bind(addr)?
.run();
Expand Down
1 change: 1 addition & 0 deletions policy-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = ["Alex Crawford <[email protected]>"]
actix = "^0.7.6"
actix-web = "^0.7.8"
cincinnati = { path = "../cincinnati" }
commons = { path = "../commons" }
env_logger = "^0.6.0"
failure = "^0.1.1"
futures = "^0.1.23"
Expand Down
9 changes: 9 additions & 0 deletions policy-engine/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Command-line options for policy-engine.

use commons::parse_path_namespace;
use hyper::Uri;
use std::net::IpAddr;

Expand Down Expand Up @@ -28,4 +29,12 @@ pub struct Options {
/// Port to which the metrics server will bind.
#[structopt(long = "metrics_port", default_value = "9081")]
pub metrics_port: u16,

/// Path namespace prefix for all paths. Must be given without leading and ending '/'
#[structopt(
long = "path-namespace",
default_value = "",
parse(from_str = "parse_path_namespace")
)]
pub path_namespace: String,
}
5 changes: 4 additions & 1 deletion policy-engine/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
extern crate actix;
extern crate actix_web;
extern crate cincinnati;
extern crate commons;
extern crate env_logger;
#[macro_use]
extern crate failure;
Expand Down Expand Up @@ -56,10 +57,12 @@ fn main() -> Result<(), Error> {
let state = graph::State {
upstream: opts.upstream,
};

let graph_path = format!("/{}/v1/graph", opts.path_namespace);
server::new(move || {
App::with_state(state.clone())
.middleware(Logger::default())
.route("/v1/graph", Method::GET, graph::index)
.route(&graph_path, Method::GET, graph::index)
})
.bind((opts.address, opts.port))?
.start();
Expand Down