mirror of
https://github.com/vbrandl/bind9-api.git
synced 2025-07-31 14:23:56 +02:00
Compare commits
4 Commits
dependabot
...
docker
Author | SHA1 | Date | |
---|---|---|---|
|
c42640a088 | ||
|
bee19e4c78 | ||
|
be5c8c6e62 | ||
|
55aa95a41c |
32
Cargo.lock
generated
32
Cargo.lock
generated
@@ -87,7 +87,7 @@ dependencies = [
|
||||
"percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"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.106 (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.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)",
|
||||
@@ -214,7 +214,7 @@ dependencies = [
|
||||
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"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.106 (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.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -231,8 +231,8 @@ dependencies = [
|
||||
"openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pretty_env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"reqwest 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.106 (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.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@@ -355,7 +355,7 @@ dependencies = [
|
||||
"idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"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.106 (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.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)",
|
||||
@@ -455,8 +455,8 @@ name = "data"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.106 (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)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1333,7 +1333,7 @@ dependencies = [
|
||||
"mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"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.106 (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.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)",
|
||||
@@ -1449,15 +1449,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.106"
|
||||
version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.106"
|
||||
version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -1472,7 +1472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1482,7 +1482,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -1843,7 +1843,7 @@ name = "toml"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2302,8 +2302,8 @@ dependencies = [
|
||||
"checksum security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9636f8989cbf61385ae4824b98c1aaa54c994d7d8b41f11c601ed799f0549a56"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
|
||||
"checksum serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c"
|
||||
"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.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"
|
||||
|
22
Dockerfile
Normal file
22
Dockerfile
Normal 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"]
|
13
README.md
13
README.md
@@ -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
|
||||
|
@@ -15,7 +15,7 @@ log = "0.4.8"
|
||||
openssl-probe = "0.1.2"
|
||||
pretty_env_logger = "0.4.0"
|
||||
reqwest = "0.9.24"
|
||||
serde = "1.0.106"
|
||||
serde = "1.0.104"
|
||||
serde_derive = "1.0.104"
|
||||
serde_json = "1.0.50"
|
||||
toml = "0.5.6"
|
||||
|
@@ -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 {
|
||||
|
@@ -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.
|
||||
|
@@ -6,5 +6,5 @@ license = "MIT/Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
failure = "0.1.7"
|
||||
serde = "1.0.106"
|
||||
serde = "1.0.104"
|
||||
serde_derive = "1.0.104"
|
||||
|
1
recipe.json
Normal file
1
recipe.json
Normal file
File diff suppressed because one or more lines are too long
@@ -14,5 +14,5 @@ failure = "0.1.7"
|
||||
futures = "0.1.29"
|
||||
log = "0.4.8"
|
||||
pretty_env_logger = "0.4.0"
|
||||
serde = "1.0.106"
|
||||
serde = "1.0.104"
|
||||
serde_json = "1.0.50"
|
||||
|
@@ -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))?
|
||||
|
Reference in New Issue
Block a user