Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add certificate expiry date to certificate list #35

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions taxy-webui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ url = "2.4.0"
base64 = "0.21.2"
time = { version = "0.3.23", features = ["formatting"] }
gloo-events = "0.1.2"
web-time = "1.0.0"
fancy-duration = "0.9.1"
23 changes: 23 additions & 0 deletions taxy-webui/src/format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use fancy_duration::FancyDuration;
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
use wasm_bindgen::UnwrapThrowExt;
use web_time::{Duration, SystemTime, UNIX_EPOCH};

pub fn format_expiry(unix_time: i64) -> String {
let time = OffsetDateTime::from_unix_timestamp(unix_time).unwrap_throw();
let timestamp = time.format(&Rfc3339).unwrap_throw();
let date = timestamp.split('T').next().unwrap_throw().to_string();

let time = UNIX_EPOCH
.checked_add(Duration::from_secs(unix_time as u64))
.unwrap_throw();

let duration = if let Ok(duration) = time.duration_since(SystemTime::now()) {
let duration = FancyDuration::new(duration).to_string();
duration.split(' ').next().unwrap_throw().to_string()
} else {
"Expired".to_string()
};

format!("{} ({})", date, duration)
}
1 change: 1 addition & 0 deletions taxy-webui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use yew_router::prelude::*;
mod auth;
mod components;
mod event;
mod format;
mod pages;
mod store;

Expand Down
13 changes: 13 additions & 0 deletions taxy-webui/src/pages/cert_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::auth::use_ensure_auth;
use crate::format::format_expiry;
use crate::pages::Route;
use crate::store::{AcmeStore, CertStore};
use crate::API_ENDPOINT;
Expand Down Expand Up @@ -164,6 +165,9 @@ pub fn cert_list() -> Html {
<th scope="col" class="px-4 py-3">
{"Digest"}
</th>
<th scope="col" class="px-4 py-3">
{"Expires on"}
</th>
<th scope="col" class="px-4 py-3">
<span class="sr-only">{"Edit"}</span>
</th>
Expand Down Expand Up @@ -206,6 +210,9 @@ pub fn cert_list() -> Html {
<td class="px-4 py-4">
{entry.id.to_string()}
</td>
<td class="px-4 py-4">
{format_expiry(entry.not_after)}
</td>
<td class="px-4 py-4 w-0 whitespace-nowrap" align="right">
<a class="cursor-pointer font-medium text-blue-600 hover:underline mr-5" onclick={download_onclick}>{"Download"}</a>
<a class="cursor-pointer font-medium text-red-600 hover:underline" onclick={delete_onclick}>{"Delete"}</a>
Expand Down Expand Up @@ -239,6 +246,9 @@ pub fn cert_list() -> Html {
<th scope="col" class="px-4 py-3">
{"Private Key"}
</th>
<th scope="col" class="px-4 py-3">
{"Expires on"}
</th>
<th scope="col" class="px-4 py-3" align="right">
<span class="sr-only">{"Edit"}</span>
</th>
Expand Down Expand Up @@ -279,6 +289,9 @@ pub fn cert_list() -> Html {
{"Yes"}
}
</td>
<td class="px-4 py-4">
{format_expiry(entry.not_after)}
</td>
<td class="px-4 py-4 w-0 whitespace-nowrap" align="right">
<a class="cursor-pointer font-medium text-blue-600 hover:underline mr-5" onclick={download_onclick}>{"Download"}</a>
<a class="cursor-pointer font-medium text-red-600 hover:underline" onclick={delete_onclick}>{"Delete"}</a>
Expand Down
Loading