diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 49c8d71..b3f6831 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,4 +34,4 @@ docker: - mkdir -p /kaniko/.docker - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json script: - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE:latest --cache=true + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/bkapi/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE:latest --cache=true diff --git a/bkapi-client/src/lib.rs b/bkapi-client/src/lib.rs index 472f8d6..99b232d 100644 --- a/bkapi-client/src/lib.rs +++ b/bkapi-client/src/lib.rs @@ -1,26 +1,49 @@ +#![deny(missing_docs)] + +//! A client for BKApi. +//! +//! Provides basic types and a HTTP client for searching a BKApi instance. + use futures::TryStreamExt; use serde::{Deserialize, Serialize}; +/// A search result, containing the searched information and all of the results. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SearchResults { + /// Searched hash. pub hash: i64, + /// Searched distance. pub distance: u64, + /// Search results. pub hashes: Vec, } +/// A single search result, containing information about the match. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SearchResult { + /// Result hash. pub hash: i64, + /// Distance between search and this result. pub distance: u64, } +/// The BKApi client. +#[derive(Clone)] pub struct BKApiClient { + /// Endpoint to search for results. pub endpoint: String, client: reqwest::Client, } impl BKApiClient { + /// Create a new BKApi client. + /// + /// Endpoint should be the full path to the `/search` endpoint. + /// + /// ```rust + /// let bkapi = BKApiClient::new("http://bkapi:3000/search"); + /// ``` pub fn new(endpoint: E) -> Self where E: Into, @@ -31,6 +54,7 @@ impl BKApiClient { } } + /// Search for a hash with a given maximum distance. #[tracing::instrument(err, skip(self))] pub async fn search(&self, hash: i64, distance: u64) -> Result { let results = self @@ -50,6 +74,9 @@ impl BKApiClient { Ok(results) } + /// Search for multiple hashes given a single maximum distance. + /// + /// Results are returned in the same order as given hashes. #[tracing::instrument(err, skip(self))] pub async fn search_many( &self,