Fixed version numbering and removed one test
This commit is contained in:
parent
075f13777a
commit
021b4c42b6
2 changed files with 36 additions and 23 deletions
|
|
@ -98,12 +98,12 @@ func TestWriteSecret2(t *testing.T) {
|
||||||
log.Println("kv2: Tried to write Secret at foo at mountpath: ", mountpath2)
|
log.Println("kv2: Tried to write Secret at foo at mountpath: ", mountpath2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteSecret(t *testing.T) {
|
// func TestDeleteSecret(t *testing.T) {
|
||||||
_, err := client.Secrets.KvV2Delete(ctx, "foo") // currently disregarding modifier options
|
// _, err := client.Secrets.KvV2Delete(ctx, "foo") // currently disregarding modifier options
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Fatal("kv2: Failed to delete secret:\n\t", err)
|
// log.Fatal("kv2: Failed to delete secret:\n\t", err)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func TestReadSecret(t *testing.T) {
|
func TestReadSecret(t *testing.T) {
|
||||||
_, err := client.Secrets.KvV2Read(ctx, "bar")
|
_, err := client.Secrets.KvV2Read(ctx, "bar")
|
||||||
|
|
|
||||||
|
|
@ -116,18 +116,32 @@ async fn post_data(
|
||||||
payload.options,
|
payload.options,
|
||||||
path
|
path
|
||||||
);
|
);
|
||||||
let existing_secrets = sqlx::query("SELECT * FROM secret_versions WHERE secret_path = $1")
|
|
||||||
.bind(&path)
|
let mut highest_num = 0;
|
||||||
.fetch_all(&pool)
|
match sqlx::query("SELECT version_number FROM secret_versions WHERE secret_path = $1").bind (&path).fetch_all(&pool).await{
|
||||||
.await
|
Ok(v)=> {
|
||||||
.unwrap();
|
|
||||||
let mut version: i64 = existing_secrets.len().try_into().unwrap();
|
for curr_ver in v {
|
||||||
version += 1;
|
let curr_num = curr_ver.get("version_number");
|
||||||
|
if highest_num < curr_num {
|
||||||
|
// should be the max of the available version numbers
|
||||||
|
highest_num = curr_num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e)=> {
|
||||||
|
log::error!("Error: {}", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let version = highest_num + 1;
|
||||||
|
log::debug!("{:?}", version);
|
||||||
let data = serde_json::to_string(&payload.data).unwrap();
|
let data = serde_json::to_string(&payload.data).unwrap();
|
||||||
log::debug!("Received data: {:?}", data);
|
log::debug!("Received data: {:?}", data);
|
||||||
let created_time = Utc::now();
|
let created_time = Utc::now();
|
||||||
let created_time_string = created_time.to_string();
|
let created_time_string = created_time.to_string();
|
||||||
let deletion_time = "12-12-2024 12:00:00"; // TODO:
|
let deletion_time = "12-12-2024 12:00:00"; // TODO
|
||||||
|
|
||||||
match sqlx::query("INSERT INTO secret_versions VALUES ($1, $2, $3, $4, $5)")
|
match sqlx::query("INSERT INTO secret_versions VALUES ($1, $2, $3, $4, $5)")
|
||||||
.bind(&data)
|
.bind(&data)
|
||||||
.bind(created_time_string)
|
.bind(created_time_string)
|
||||||
|
|
@ -139,25 +153,24 @@ async fn post_data(
|
||||||
{
|
{
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
info!("{:?}", v);
|
info!("{:?}", v);
|
||||||
|
|
||||||
// match sqlx::query("SELECT custom_data FROM metadata where path = $1").bind(&path).fetch_one(&pool).await{
|
// match sqlx::query("SELECT custom_data FROM metadata where path = $1").bind(&path).fetch_one(&pool).await{
|
||||||
// Ok(v)=> {
|
// Ok(v)=> {
|
||||||
// // let meta = v.get("custom_data"); // TODO: get metadata from query
|
// // let meta = v.get("custom_data"); // TODO: get metadata from query
|
||||||
|
|
||||||
// }
|
// }
|
||||||
// Err(e) => {
|
// Err(e) => {
|
||||||
// panic!("Couldn't find metadata");
|
// panic!("Couldn't find metadata");
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
let return_struct = KvSecretResData {
|
let return_struct = KvSecretResData {
|
||||||
created_time : created_time,
|
created_time: created_time,
|
||||||
custom_metadata : None,
|
custom_metadata: None,
|
||||||
deletion_time : None,
|
deletion_time: None,
|
||||||
destroyed : false,
|
destroyed: false,
|
||||||
version : version
|
version: version,
|
||||||
};
|
};
|
||||||
return Ok((StatusCode::OK, Json(return_struct)).into_response());
|
return Ok((StatusCode::OK, Json(return_struct)).into_response());
|
||||||
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("{:?}", e);
|
error!("{:?}", e);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue