1
0
mirror of https://github.com/vbrandl/bind9-api.git synced 2025-07-31 14:23:56 +02:00

4 Commits

Author SHA1 Message Date
Valentin Brandl
c42640a088 Add Dockerfile 2021-06-01 08:31:48 +02:00
Valentin Brandl
bee19e4c78 Document building the project 2020-11-30 16:40:07 +01:00
Valentin Brandl
be5c8c6e62 Fix deprecation 2020-11-30 16:35:31 +01:00
Valentin Brandl
55aa95a41c Fix breaking change in ToHex crate 2020-11-30 16:35:19 +01:00
9 changed files with 51 additions and 16 deletions

14
Cargo.lock generated
View File

@@ -88,7 +88,7 @@ dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -215,7 +215,7 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -233,7 +233,7 @@ dependencies = [
"reqwest 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -356,7 +356,7 @@ dependencies = [
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"publicsuffix 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1334,7 +1334,7 @@ dependencies = [
"mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1467,7 +1467,7 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.52"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2304,7 +2304,7 @@ dependencies = [
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64"
"checksum serde_json 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)" = "a7894c8ed05b7a3a279aeb79025fdec1d3158080b75b98a08faf2806bb799edd"
"checksum serde_json 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "78a7a12c167809363ec3bd7329fc0a3369056996de43c4b37ef3cd54a6ce4867"
"checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a"
"checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
"checksum signal-hook 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "72ab58f1fda436857e6337dcb6a5aaa34f16c5ddc87b3a8b6ef7a212f90b9c5a"

22
Dockerfile Normal file
View File

@@ -0,0 +1,22 @@
FROM lukemathwalker/cargo-chef as planner
WORKDIR app
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM lukemathwalker/cargo-chef as cacher
WORKDIR app
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
FROM rust as builder
WORKDIR app
COPY . .
# Copy over the cached dependencies
COPY --from=cacher /app/target target
COPY --from=cacher $CARGO_HOME $CARGO_HOME
RUN cargo build --release --bin bind9-api
FROM rust as runtime
WORKDIR app
COPY --from=builder /app/target/release/bind9-api /usr/local/bin
ENTRYPOINT ["/usr/local/bin/bind9-api"]

View File

@@ -7,6 +7,19 @@
This is an attempt to implement an API to create, update or delete DNS records
on a BIND9 DNS server.
## Building
To compile the code, you first need to [install Rust](https://rustup.rs/). Then
you can run
```
cargo build --release
```
in the project root. The server and client binary will be located in
`./target/release/bind9-api` and `./target/release/bind9-api-client`
respectively.
## Server
The server will wait for incoming requests and uses the `nsupdate` command to

View File

@@ -17,5 +17,5 @@ pretty_env_logger = "0.4.0"
reqwest = "0.9.24"
serde = "1.0.104"
serde_derive = "1.0.104"
serde_json = "1.0.52"
serde_json = "1.0.50"
toml = "0.5.6"

View File

@@ -106,7 +106,7 @@ fn call_api<D: serde::Serialize>(
let data_s = serde_json::to_string(&data)?;
info!("body: {}", data_s);
let signature = crypto::sign(config.secret.as_bytes(), data_s.as_bytes());
let signature = crypto::bytes_to_hex_str(&signature)?;
let signature = crypto::bytes_to_hex_str(&signature);
let client = reqwest::Client::new();
let url = format!("{}/record", config.host);
Ok(if method == Method::POST {

View File

@@ -55,10 +55,8 @@ use ring::{digest, hmac};
type Result<T> = std::result::Result<T, Error>;
/// Converts a byte slice to a lowercase hex string.
pub fn bytes_to_hex_str(bytes: &[u8]) -> Result<String> {
let mut output = String::new();
bytes.write_hex(&mut output)?;
Ok(output)
pub fn bytes_to_hex_str(bytes: &[u8]) -> String {
bytes.encode_hex::<String>()
}
/// Converts a hey string to a vec of bytes.

1
recipe.json Normal file

File diff suppressed because one or more lines are too long

View File

@@ -15,4 +15,4 @@ futures = "0.1.29"
log = "0.4.8"
pretty_env_logger = "0.4.0"
serde = "1.0.104"
serde_json = "1.0.52"
serde_json = "1.0.50"

View File

@@ -104,7 +104,7 @@ pub struct Validated<T>(T);
impl<T: 'static + ::serde::de::DeserializeOwned> FromRequest<Arc<Config>> for Validated<T> {
type Config = ();
type Result = Box<Future<Item = Self, Error = Error>>;
type Result = Box<dyn Future<Item = Self, Error = Error>>;
fn from_request(req: &HttpRequest<Arc<Config>>, _: &Self::Config) -> Self::Result {
let state = req.state().clone();
@@ -134,7 +134,8 @@ impl<T> Deref for Validated<T> {
}
fn extract_signature<S>(req: &HttpRequest<S>) -> Result<Vec<u8>> {
Ok(req.headers()
Ok(req
.headers()
.get(::data::TOKEN_HEADER)
.as_ref()
.ok_or_else(|| ErrorUnauthorized(ParseError::Header))?