Crate encrypt_config
source ·Expand description
encrypt-config
A rust crate to manage, persist and encrypt your configurations.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
About The Project
A rust crate to manage, persist, encrypt configurations.
Built With
- Rust
- Keyring
Usage
use encrypt_config::{Config, SecretSource};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Foo(String);
struct SecretSourceImpl;
// impl `SecectSource` trait for `SecretSourceImpl`
impl SecretSource for SecretSourceImpl {
type Value = Foo;
// Where the encypted file is. Don't need if turning on `default_config_dir` feature.
fn path(&self) -> std::path::PathBuf {
std::path::PathBuf::from("tests").join("secret.conf")
}
}
let mut config = Config::new("test"); // `test` is the name of rsa private key in OS' secret manager
config.add_secret_source(SecretSourceImpl).unwrap(); // This will read and decrypt the config from local storage. However, it is empty now.
let new_value = Foo("value".to_owned());
let patch = SecretSourceImpl.upgrade("key", &new_value); // `upgrade` will return a `Patch`
patch.apply(&mut config).unwrap(); // No change will happen until the `Patch` is applied
let v: Foo = config.get("key").unwrap();
assert_eq!(v, Foo("value".to_owned()));For more examples, please refer to the Example or 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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - 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
Structs
- A struct that can be used to store configuration values.
- A patch that can be used to modify the config. You can get a
ConfigPatchby callingPersistSource::upgrade, and apply it by callingConfigPatch::applyto a config. No change will happen until you callConfigPatch::apply. - A patch that can be used to modify the config. You can get a
SecretConfigPatchby callingSecretSource::upgrade, and apply it by callingSecretConfigPatch::applyto a config. No change will happen until you callSecretConfigPatch::apply.
Enums
Traits
- A trait for persisted but not encrypted config source.
- A trait for persisted and encrypted config source.
- A trait for normal config source that is neither encrypted or persisted.