Fix builds, add docs.

This commit is contained in:
Syfaro 2021-07-28 15:56:54 -04:00
parent 2ef64e6d70
commit 04e494ee31
2 changed files with 28 additions and 1 deletions

View File

@ -34,4 +34,4 @@ docker:
- mkdir -p /kaniko/.docker - mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json
script: 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

View File

@ -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 futures::TryStreamExt;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// A search result, containing the searched information and all of the results.
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SearchResults { pub struct SearchResults {
/// Searched hash.
pub hash: i64, pub hash: i64,
/// Searched distance.
pub distance: u64, pub distance: u64,
/// Search results.
pub hashes: Vec<SearchResult>, pub hashes: Vec<SearchResult>,
} }
/// A single search result, containing information about the match.
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SearchResult { pub struct SearchResult {
/// Result hash.
pub hash: i64, pub hash: i64,
/// Distance between search and this result.
pub distance: u64, pub distance: u64,
} }
/// The BKApi client.
#[derive(Clone)]
pub struct BKApiClient { pub struct BKApiClient {
/// Endpoint to search for results.
pub endpoint: String, pub endpoint: String,
client: reqwest::Client, client: reqwest::Client,
} }
impl BKApiClient { 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<E>(endpoint: E) -> Self pub fn new<E>(endpoint: E) -> Self
where where
E: Into<String>, E: Into<String>,
@ -31,6 +54,7 @@ impl BKApiClient {
} }
} }
/// Search for a hash with a given maximum distance.
#[tracing::instrument(err, skip(self))] #[tracing::instrument(err, skip(self))]
pub async fn search(&self, hash: i64, distance: u64) -> Result<SearchResults, reqwest::Error> { pub async fn search(&self, hash: i64, distance: u64) -> Result<SearchResults, reqwest::Error> {
let results = self let results = self
@ -50,6 +74,9 @@ impl BKApiClient {
Ok(results) 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))] #[tracing::instrument(err, skip(self))]
pub async fn search_many( pub async fn search_many(
&self, &self,