Skip to content

A masking library for MongoDB written in Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

jordanvanallen/tuxedo

Repository files navigation

Tuxedo  

Tuxedo is a library for masking and transferring your MongoDB database collections between instances

This library is currently in production and can regularly experience breaking changes

Installation

[dependencies]
tuxedo = { version = "0.1.0" }

Usage

use tuxedo::{
  Mask, MongoModel, ProcessorConfigBuilder, ReplicationManagerBuilder, ReplicationStrategy, TuxedoResult,
};

#[derive(Clone, Debug, Serialize, Deserialize, MongoModel)]
#[mongo_model(collection = "users")]
pub struct User {
    #[serde(rename = "_id")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<ObjectId>,
    pub first_name: String,
    pub last_name: String,
}

impl Mask for User {
    fn mask(&mut self) {
        self.first_name = Self::fake_first_name();
        self.last_name = Self::fake_last_name();
    }
}

#[tokio::main]
async fn main() -> TuxedoResult<()> {
    let replication_manager = ReplicationManagerBuilder::new()
        .source_uri("mongodb://localhost:27017")
        .target_uri("mongodb://localhost:27016")
        .source_db("source_db_name")
        .target_db("target_db_name")
        .batch_size(2500 as usize)
        .strategy(ReplicationStrategy::Mask)
        .add_processor::<User>()
        .build()
        .await?;

    replication_manager.run().await?;

    Ok(())
}

Processors

Processors are used for collections that need to be masked.

They can be configured individually using a ProcessorConfigBuilder alongside the add_processor_with_config function. This is required for things like discriminators/polymorphic models, and can be done by overriding the query as needed to ensure no duplicate entries are created.

Replicators

Replicators are used for collections that need to be replicated, but do not need to be masked. They have the benefit of not requiring a struct to replicate the data, but are also significantly slower as they as (de)serialized using a bson::Document, which is much less ideal then a defined struct. It is recommended for larger collections to use a struct and define the Mask trait with a NOP to avoid the masking portion, but allow for much faster replication speeds.

About

A masking library for MongoDB written in Rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages