Skip to content

Commit

Permalink
alpha1 (#10)
Browse files Browse the repository at this point in the history
* Update issue templates (#1)

* Create test.yml (#2)

* Create release.yml (#3)

* Update test.yml (#4)

* test

* error handling (#6)

* 7 action cache (#8)

* action (#9)

* test

* test

* test

* test

* test

* test

* test

* test

* modified: README.md description
  • Loading branch information
kingwingfly authored Dec 18, 2023
1 parent 54720f0 commit 4042523
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 76 deletions.
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: "[Bug]"
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior, or a Minimal Reproducible Code Snippet.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Information (please complete the following information):**
OS: [e.g. macOS]
Output of `rustc -V`

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[New Feature]"
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Rust

on:
pull_request:
branches: [release]
types: [closed]

env:
CARGO_TERM_COLOR: always

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Extract version
id: extract-version
run: echo "version=$(grep -oP '^version = "\K[^"]+' Cargo.toml | awk '{$1=$1;print}')" >> $GITHUB_OUTPUT

- name: Cache restore
uses: actions/cache/restore@v3
id: cache-cargo-restore
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.extract-version.outputs.version }}

- name: Run clippy
run: cargo clippy --all-features --all-targets -- -D warnings
- name: Build
run: cargo build
- name: Run tests
run: cargo test

- name: publish crates
uses: katyo/publish-crates@v2
with:
# crates.io registry token
registry-token: ${{ secrets.crates_io }}
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Rust

on:
pull_request:
branches: [dev]
types: [opened]

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Extract version
id: extract-version
run: echo "version=$(grep -oP '^version = "\K[^"]+' Cargo.toml | awk '{$1=$1;print}')" >> $GITHUB_OUTPUT

- name: Cache restore
uses: actions/cache/restore@v3
id: cache-cargo-restore
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ steps.extract-version.outputs.version }}

- name: Run clippy
run: cargo clippy --all-features --all-targets -- -D warnings
- name: Build
run: cargo build
- name: Run tests
run: cargo test

- name: Cache save
if: steps.cache-cargo-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
id: cache-cargo-save
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ steps.cache-cargo-restore.outputs.cache-primary-key }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "encrypt_config"
version = "0.0.1-alpha1"
authors = ["Louis <[email protected]>"]
description = "A config manager, supporting encryption."
description = "A rust crate to manage, persist and encrypt your configurations."
license = "MIT"
edition = "2021"
repository = "https://github.com/kingwingfly/encrypt-config"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ A rust crate to manage, persist, encrypt configurations.
<!-- GETTING STARTED -->
## Getting Started

Details here: [Example](tests/tests.rs)
Details here: [Example](example/eamples.rs)

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- USAGE EXAMPLES -->
## Usage
```rust
use encrypt_config::{Config, ConfigKey, ConfigResult, SecretSource};
```rust no_run
use encrypt_config::{Config, ConfigResult, SecretSource};

#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
struct Bar(String);
Expand All @@ -108,7 +108,7 @@ impl SecretSource for SecretSourceImpl {
type Value = Bar;

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

Expand All @@ -132,7 +132,7 @@ 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())).unwrap();
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();
Expand Down
23 changes: 12 additions & 11 deletions tests/tests.rs → examples/example.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use encrypt_config::{Config, ConfigKey, ConfigResult, PersistSource, SecretSource, Source};
use encrypt_config::{Config, PersistSource, SecretSource, Source};

struct NormalSource;
impl Source for NormalSource {
type Value = String;
type Map = Vec<(String, Self::Value)>;

fn collect(&self) -> ConfigResult<Self::Map> {
fn collect(&self) -> Result<Self::Map, Box<dyn std::error::Error>> {
Ok(vec![("key".to_owned(), "value".to_owned())])
}
}
Expand All @@ -17,7 +17,7 @@ struct PersistSourceImpl;
impl PersistSource for PersistSourceImpl {
type Value = Foo;

fn source_name(&self) -> ConfigKey {
fn source_name(&self) -> String {
"test".to_owned()
}

Expand All @@ -37,7 +37,7 @@ struct SecretSourceImpl;
impl SecretSource for SecretSourceImpl {
type Value = Bar;

fn source_name(&self) -> ConfigKey {
fn source_name(&self) -> String {
"secret_test".to_owned()
}

Expand All @@ -50,8 +50,7 @@ impl SecretSource for SecretSourceImpl {
}
}

#[test]
fn source_test() {
fn config_tests() {
let mut config = Config::new("test");
config.add_source(NormalSource).unwrap();
config.add_persist_source(PersistSourceImpl).unwrap();
Expand All @@ -62,20 +61,22 @@ fn source_test() {
assert_eq!(v, Foo("hello".to_owned()));
let v: Bar = config.get("secret_test").unwrap();
assert_eq!(v, Bar("world".to_owned()));
let patch = NormalSource
.upgrade("key", &"new_value".to_owned())
.unwrap();
let patch = NormalSource.upgrade("key", &"new_value".to_owned());
patch.apply(&mut config).unwrap();
let v: String = config.get("key").unwrap();
assert_eq!(v, "new_value");
let patch = PersistSourceImpl.upgrade(&Foo("hi".to_owned())).unwrap();
let patch = PersistSourceImpl.upgrade(&Foo("hi".to_owned()));
patch.apply(&mut config).unwrap();
let v: Foo = config.get("test").unwrap();
assert_eq!(v, Foo("hi".to_owned()));
let patch = SecretSourceImpl.upgrade(&Bar("Louis".to_owned())).unwrap();
let patch = SecretSourceImpl.upgrade(&Bar("Louis".to_owned()));
patch.apply(&mut config).unwrap();
let v: Bar = config.get("secret_test").unwrap();
assert_eq!(v, Bar("Louis".to_owned()));
std::fs::remove_file("tests/secret_test").unwrap();
std::fs::remove_file("tests/test").unwrap();
}

fn main() {
config_tests();
}
Loading

0 comments on commit 4042523

Please sign in to comment.