encrypt_config 0.0.1-alpha1

A rust crate to manage, persist and encrypt your configurations.
Documentation

Contributors Forks Stargazers Issues MIT License LinkedIn

About The Project

Product Name Screen Shot

A rust crate to manage, persist, encrypt configurations.

Built With

  • Rust
  • Keyring

Getting Started

Details here: Example

Usage

use encrypt_config::{Config, ConfigResult, SecretSource};

#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
struct Bar(String);

struct SecretSourceImpl;

// impl `SecectSource` trait for `SecretSourceImpl`
impl SecretSource for SecretSourceImpl {
    type Value = Bar;

    // The key to query from `Config`
    fn source_name(&self) -> String {
        "secret_test".to_owned()
    }

    // The default value if the persist file has not been created
    fn default(&self) -> Self::Value {
        Bar("world".to_owned())
    }

    // Where the encypted file is in. Don't need if turning on `default_config_dir` feature.
    fn path(&self) -> std::path::PathBuf {
        std::path::PathBuf::from("tests").join(self.source_name())
    }
}

// `test` is the name of rsa private key in OS' secret manager
let mut config = Config::new("test");
config.add_secret_source(SecretSourceImpl).unwrap();

// `get` will do a deserialization
let v: Bar = config.get("secret_test").unwrap();
assert_eq!(v, Bar("world".to_owned()));

// `upgrade` will return a `Patch`
let patch = SecretSourceImpl.upgrade(&Bar("Louis".to_owned()));
// No change will happen until the `Patch` is applied
patch.apply(&mut config).unwrap();
let v: Bar = config.get("secret_test").unwrap();
assert_eq!(v, Bar("Louis".to_owned()));

For more examples, please refer to the Documentation

Roadmap

  • Enable protobuf instead of json for better performance

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Louis - 836250617@qq.com

Project Link: https://github.com/kingwingfly/encrypt-config

Acknowledgments

  • None