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)
|
||||
}
|
||||
|
||||
func TestDeleteSecret(t *testing.T) {
|
||||
_, err := client.Secrets.KvV2Delete(ctx, "foo") // currently disregarding modifier options
|
||||
if err != nil {
|
||||
log.Fatal("kv2: Failed to delete secret:\n\t", err)
|
||||
}
|
||||
}
|
||||
// func TestDeleteSecret(t *testing.T) {
|
||||
// _, err := client.Secrets.KvV2Delete(ctx, "foo") // currently disregarding modifier options
|
||||
// if err != nil {
|
||||
// log.Fatal("kv2: Failed to delete secret:\n\t", err)
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestReadSecret(t *testing.T) {
|
||||
_, err := client.Secrets.KvV2Read(ctx, "bar")
|
||||
|
|
|
|||
|
|
@ -116,18 +116,32 @@ async fn post_data(
|
|||
payload.options,
|
||||
path
|
||||
);
|
||||
let existing_secrets = sqlx::query("SELECT * FROM secret_versions WHERE secret_path = $1")
|
||||
.bind(&path)
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut version: i64 = existing_secrets.len().try_into().unwrap();
|
||||
version += 1;
|
||||
|
||||
let mut highest_num = 0;
|
||||
match sqlx::query("SELECT version_number FROM secret_versions WHERE secret_path = $1").bind (&path).fetch_all(&pool).await{
|
||||
Ok(v)=> {
|
||||
|
||||
for curr_ver in v {
|
||||
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();
|
||||
log::debug!("Received data: {:?}", data);
|
||||
let created_time = Utc::now();
|
||||
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)")
|
||||
.bind(&data)
|
||||
.bind(created_time_string)
|
||||
|
|
@ -150,14 +164,13 @@ async fn post_data(
|
|||
// }
|
||||
// }
|
||||
let return_struct = KvSecretResData {
|
||||
created_time : created_time,
|
||||
custom_metadata : None,
|
||||
deletion_time : None,
|
||||
destroyed : false,
|
||||
version : version
|
||||
created_time: created_time,
|
||||
custom_metadata: None,
|
||||
deletion_time: None,
|
||||
destroyed: false,
|
||||
version: version,
|
||||
};
|
||||
return Ok((StatusCode::OK, Json(return_struct)).into_response());
|
||||
|
||||
}
|
||||
Err(e) => {
|
||||
error!("{:?}", e);
|
||||
|
|
|
|||
Loading…
Reference in a new issue