+ add mock secret struct with serialization
+ add basic secret update sled interaction
This commit is contained in:
parent
8c6bafbb5c
commit
922d1e2c20
7 changed files with 81 additions and 18 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -5,3 +5,5 @@
|
|||
|
||||
*.pdf
|
||||
target/
|
||||
go_client/openapi.json
|
||||
crates/storage-sled/sled_db
|
||||
34
Cargo.lock
generated
34
Cargo.lock
generated
|
|
@ -82,7 +82,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.59",
|
||||
"syn 2.0.60",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -175,6 +175,10 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "base"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
|
|
@ -404,9 +408,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
|||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "1.3.0"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f24ce812868d86d19daa79bf3bf9175bc44ea323391147a5e3abde2a283871b"
|
||||
checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
|
|
@ -619,7 +623,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.59",
|
||||
"syn 2.0.60",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -660,9 +664,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.80"
|
||||
version = "1.0.81"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e"
|
||||
checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
|
@ -749,22 +753,22 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.197"
|
||||
version = "1.0.198"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
|
||||
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.197"
|
||||
version = "1.0.198"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
||||
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.59",
|
||||
"syn 2.0.60",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -873,9 +877,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.59"
|
||||
version = "2.0.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a"
|
||||
checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -921,7 +925,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.59",
|
||||
"syn 2.0.60",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1006,7 +1010,7 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"syn 2.0.59",
|
||||
"syn 2.0.60",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
|
|
@ -7,3 +7,5 @@ edition = "2021"
|
|||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.198", features = ["derive"] }
|
||||
serde_json = "1.0.116"
|
||||
|
|
|
|||
|
|
@ -12,3 +12,22 @@ mod tests {
|
|||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
|
||||
use serde_json::Result;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct TempSecret {
|
||||
pub content: String,
|
||||
pub version: i64
|
||||
}
|
||||
|
||||
/// serialize secret to JSON byte vector
|
||||
pub fn serialize_secret_json(secret: &TempSecret) -> Result<Vec<u8>> {
|
||||
serde_json::to_vec(&secret)
|
||||
}
|
||||
|
||||
// /// deserialize JSON byte vector to secret
|
||||
// pub fn deserialize_secret_struct(raw: &String) -> Result<TempSecret> {
|
||||
// serde_json::from_str(raw)
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -8,5 +8,4 @@ workspace = true
|
|||
|
||||
[dependencies]
|
||||
base = { path = "../base" }
|
||||
|
||||
sled = "0.34.7"
|
||||
|
|
|
|||
|
|
@ -11,4 +11,39 @@ mod tests {
|
|||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
#[test]
|
||||
fn test_sled() {
|
||||
let db: sled::Db = sled::open("sled_db").unwrap();
|
||||
update_secret(db, "foo", TempSecret{version: 1, content: "foo".to_string()});
|
||||
}
|
||||
}
|
||||
|
||||
use sled::Db;
|
||||
use base::{serialize_secret_json, TempSecret};
|
||||
|
||||
/// [TODO] Currently no proper versioning
|
||||
/// inserts a secret. If there was already a secret in the given path, the version is incremented
|
||||
fn update_secret(db: Db, path: &str, mut secret: TempSecret) {
|
||||
if let Ok(Some(_)) = db.get(path) { // Idiomatic way. Ok(Some(_)) is true when something was found
|
||||
secret.version += 1;
|
||||
print!("something was found \n")
|
||||
}
|
||||
// if let secret_json = serialize_secret_json(&secret) {
|
||||
// let _res = db.insert(path, secret_json); // maybe this can be handled cleaner
|
||||
match serialize_secret_json(&secret) {
|
||||
Ok(secret_json) => {
|
||||
match db.insert(path, secret_json) {
|
||||
Ok(_) => println!("Secret inserted"),
|
||||
Err(e) => eprintln!("Failed to insert secret: {}", e),
|
||||
}
|
||||
}
|
||||
Err(e) => eprintln!("Failed to serialize secret: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
// /// read and return a secret from the DB
|
||||
// /// if there is no secret, return None
|
||||
// fn get_secret(db: Db, path: &str) -> Option<TempSecret>{
|
||||
// let raw_secret = db.get(path);
|
||||
// return None
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
var client *vault.Client
|
||||
var ctx context.Context
|
||||
var mountpath = ""
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
ctx = context.Background()
|
||||
|
|
@ -36,6 +37,7 @@ func TestMain(m *testing.M) {
|
|||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
// https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#create-update-secret
|
||||
// @Philip der Path steht in der KvV2Write Methode
|
||||
func TestWriteSecret(t *testing.T) {
|
||||
// Path foo
|
||||
|
|
@ -44,7 +46,7 @@ func TestWriteSecret(t *testing.T) {
|
|||
"password1": "abc123",
|
||||
"password2": "correct horse battery staple",
|
||||
}},
|
||||
vault.WithMountPath("kw_mount_path"),
|
||||
vault.WithMountPath(mountpath),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal("kv2: Failed to write secret:\n\t", err)
|
||||
|
|
@ -57,7 +59,7 @@ func TestWriteSecret(t *testing.T) {
|
|||
"password1": "secure123",
|
||||
"password2": "second password",
|
||||
}},
|
||||
vault.WithMountPath("kw_mount_path"),
|
||||
vault.WithMountPath(mountpath),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal("kv2: Failed to write secret:\n\t", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue