mirror of
https://github.com/vbrandl/bind9-api.git
synced 2025-07-30 17:56:40 +02:00
Compare commits
4 Commits
dependabot
...
docker
Author | SHA1 | Date | |
---|---|---|---|
|
c42640a088 | ||
|
bee19e4c78 | ||
|
be5c8c6e62 | ||
|
55aa95a41c |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -446,7 +446,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proptest 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proptest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -1107,7 +1107,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proptest"
|
||||
version = "0.9.6"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bit-set 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -2266,7 +2266,7 @@ dependencies = [
|
||||
"checksum pretty_env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d"
|
||||
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
||||
"checksum proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c5c2380ae88876faae57698be9e9775e3544decad214599c3a6266cca6ac802"
|
||||
"checksum proptest 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)" = "01c477819b845fe023d33583ebf10c9f62518c8d79a0960ba5c36d6ac8a55a5b"
|
||||
"checksum proptest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bf6147d103a7c9d7598f4105cf049b15c99e2ecd93179bf024f0fd349be5ada4"
|
||||
"checksum publicsuffix 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5afecba86dcf1e4fd610246f89899d1924fe12e1e89f555eb7c7f710f3c5ad1d"
|
||||
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
|
||||
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
|
||||
|
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
|
||||
|
@@ -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 {
|
||||
|
@@ -10,4 +10,4 @@ hex = "0.4.0"
|
||||
ring = "0.13.5"
|
||||
|
||||
[dev-dependencies]
|
||||
proptest = "0.9.6"
|
||||
proptest = "0.9.5"
|
||||
|
@@ -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
1
recipe.json
Normal file
File diff suppressed because one or more lines are too long
@@ -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