Skip to content

Commit

Permalink
Merge pull request #48 from Dstack-TEE/abspath
Browse files Browse the repository at this point in the history
teepod: Use path-absolutize instead of canonicalize
  • Loading branch information
kvinwang authored Dec 11, 2024
2 parents 8ef7bac + ef72287 commit b81df93
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ chrono = "0.4.38"
clap = { version = "4.5.22", features = ["derive", "string"] }
dashmap = "6.1.0"
fs-err = "3.0.0"
path-absolutize = "3.1.1"
futures = "0.3.31"
git-version = "0.3.9"
libc = "0.2.167"
Expand Down
1 change: 1 addition & 0 deletions certbot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum_dispatch = { workspace = true }
fs-err = { workspace = true }
hickory-resolver = { workspace = true }
instant-acme = { workspace = true }
path-absolutize.workspace = true
rcgen = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
Expand Down
4 changes: 3 additions & 1 deletion certbot/src/acme_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ impl AcmeClient {
key_pem: &str,
backup_dir: impl AsRef<Path>,
) -> Result<()> {
use path_absolutize::Absolutize;

// Put the new cert in {backup_dir}/%Y%m%d_%H%M%S/cert.pem
let cert_dir = self.new_cert_dir(backup_dir.as_ref())?;
let backup_path = fs::canonicalize(&cert_dir)?;
let backup_path = cert_dir.absolutize()?;
let cert_path = backup_path.join("cert.pem");
let key_path = backup_path.join("key.pem");
fs::write(&cert_path, cert_pem)?;
Expand Down
1 change: 1 addition & 0 deletions teepod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ supervisor-client = { workspace = true }
ra-rpc = { workspace = true, features = ["client", "rocket"] }
teepod-rpc = { workspace = true }
kms-rpc = { workspace = true }
path-absolutize = { workspace = true }
3 changes: 2 additions & 1 deletion teepod/src/app/image.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fs_err as fs;
use path_absolutize::Absolutize;
use std::path::{Path, PathBuf};

use anyhow::{bail, Context, Result};
Expand Down Expand Up @@ -36,7 +37,7 @@ pub struct Image {

impl Image {
pub fn load(base_path: impl AsRef<Path>) -> Result<Self> {
let base_path = fs::canonicalize(base_path.as_ref())?;
let base_path = base_path.as_ref().absolutize()?;
let info = ImageInfo::load(base_path.join("metadata.json"))?;
let initrd = base_path.join(&info.initrd);
let kernel = base_path.join(&info.kernel);
Expand Down
6 changes: 3 additions & 3 deletions teepod/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{net::IpAddr, path::PathBuf, str::FromStr};

use anyhow::{bail, Context, Result};
use fs_err as fs;
use path_absolutize::Absolutize;
use rocket::figment::{
providers::{Format, Toml},
Figment,
Expand Down Expand Up @@ -153,8 +153,8 @@ pub struct Config {
impl Config {
pub fn abs_path(self) -> Result<Self> {
Ok(Self {
image_path: fs::canonicalize(&self.image_path)?,
run_path: fs::canonicalize(&self.run_path)?,
image_path: self.image_path.absolutize()?.to_path_buf(),
run_path: self.run_path.absolutize()?.to_path_buf(),
..self
})
}
Expand Down
5 changes: 4 additions & 1 deletion teepod/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::path::Path;

use anyhow::{anyhow, Context, Result};
use clap::Parser;
use config::Config;
use path_absolutize::Absolutize;
use rocket::fairing::AdHoc;
use rocket_apitoken::ApiToken;
use supervisor_client::SupervisorClient;
Expand Down Expand Up @@ -42,7 +45,7 @@ async fn main() -> Result<()> {
let api_auth = ApiToken::new(config.auth.tokens.clone(), config.auth.enabled);
let supervisor = {
let cfg = &config.supervisor;
let abs_exe = fs_err::canonicalize(cfg.exe.as_str())?;
let abs_exe = Path::new(&cfg.exe).absolutize()?;
SupervisorClient::start_and_connect_uds(&abs_exe, &cfg.sock, &cfg.pid_file, &cfg.log_file)
.await
.context("Failed to start supervisor")?
Expand Down

0 comments on commit b81df93

Please sign in to comment.