mirror of
https://github.com/vbrandl/bind9-api.git
synced 2025-08-31 12:07:00 +02:00
Compare commits
1 Commits
docker
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
|
20d1ea9758 |
837
Cargo.lock
generated
837
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
22
Dockerfile
22
Dockerfile
@@ -1,22 +0,0 @@
|
|||||||
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,19 +7,6 @@
|
|||||||
This is an attempt to implement an API to create, update or delete DNS records
|
This is an attempt to implement an API to create, update or delete DNS records
|
||||||
on a BIND9 DNS server.
|
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
|
## Server
|
||||||
|
|
||||||
The server will wait for incoming requests and uses the `nsupdate` command to
|
The server will wait for incoming requests and uses the `nsupdate` command to
|
||||||
|
@@ -14,7 +14,7 @@ hyper = "0.12.35"
|
|||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
openssl-probe = "0.1.2"
|
openssl-probe = "0.1.2"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
reqwest = "0.9.24"
|
reqwest = "0.9.22"
|
||||||
serde = "1.0.104"
|
serde = "1.0.104"
|
||||||
serde_derive = "1.0.104"
|
serde_derive = "1.0.104"
|
||||||
serde_json = "1.0.50"
|
serde_json = "1.0.50"
|
||||||
|
@@ -106,7 +106,7 @@ fn call_api<D: serde::Serialize>(
|
|||||||
let data_s = serde_json::to_string(&data)?;
|
let data_s = serde_json::to_string(&data)?;
|
||||||
info!("body: {}", data_s);
|
info!("body: {}", data_s);
|
||||||
let signature = crypto::sign(config.secret.as_bytes(), data_s.as_bytes());
|
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 client = reqwest::Client::new();
|
||||||
let url = format!("{}/record", config.host);
|
let url = format!("{}/record", config.host);
|
||||||
Ok(if method == Method::POST {
|
Ok(if method == Method::POST {
|
||||||
|
@@ -55,8 +55,10 @@ use ring::{digest, hmac};
|
|||||||
type Result<T> = std::result::Result<T, Error>;
|
type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
/// Converts a byte slice to a lowercase hex string.
|
/// Converts a byte slice to a lowercase hex string.
|
||||||
pub fn bytes_to_hex_str(bytes: &[u8]) -> String {
|
pub fn bytes_to_hex_str(bytes: &[u8]) -> Result<String> {
|
||||||
bytes.encode_hex::<String>()
|
let mut output = String::new();
|
||||||
|
bytes.write_hex(&mut output)?;
|
||||||
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a hey string to a vec of bytes.
|
/// Converts a hey string to a vec of bytes.
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -6,7 +6,7 @@ description = "Web API to create, update and remove DNS entries in bind9"
|
|||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "0.7.19"
|
actix-web = "1.0.4"
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
crypto = { path = "../crypto" }
|
crypto = { path = "../crypto" }
|
||||||
data = { path = "../data" }
|
data = { path = "../data" }
|
||||||
|
@@ -104,7 +104,7 @@ pub struct Validated<T>(T);
|
|||||||
|
|
||||||
impl<T: 'static + ::serde::de::DeserializeOwned> FromRequest<Arc<Config>> for Validated<T> {
|
impl<T: 'static + ::serde::de::DeserializeOwned> FromRequest<Arc<Config>> for Validated<T> {
|
||||||
type Config = ();
|
type Config = ();
|
||||||
type Result = Box<dyn Future<Item = Self, Error = Error>>;
|
type Result = Box<Future<Item = Self, Error = Error>>;
|
||||||
|
|
||||||
fn from_request(req: &HttpRequest<Arc<Config>>, _: &Self::Config) -> Self::Result {
|
fn from_request(req: &HttpRequest<Arc<Config>>, _: &Self::Config) -> Self::Result {
|
||||||
let state = req.state().clone();
|
let state = req.state().clone();
|
||||||
@@ -134,8 +134,7 @@ impl<T> Deref for Validated<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn extract_signature<S>(req: &HttpRequest<S>) -> Result<Vec<u8>> {
|
fn extract_signature<S>(req: &HttpRequest<S>) -> Result<Vec<u8>> {
|
||||||
Ok(req
|
Ok(req.headers()
|
||||||
.headers()
|
|
||||||
.get(::data::TOKEN_HEADER)
|
.get(::data::TOKEN_HEADER)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or_else(|| ErrorUnauthorized(ParseError::Header))?
|
.ok_or_else(|| ErrorUnauthorized(ParseError::Header))?
|
||||||
|
Reference in New Issue
Block a user