Can set location of temporary directory
This commit is contained in:
		@@ -4,4 +4,5 @@ pub mod minio;
 | 
				
			|||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
pub mod minio_test_server;
 | 
					pub mod minio_test_server;
 | 
				
			||||||
pub mod secrets;
 | 
					pub mod secrets;
 | 
				
			||||||
 | 
					pub mod temp;
 | 
				
			||||||
pub mod utils;
 | 
					pub mod utils;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ use serde::Deserialize;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use crate::constants::{MC_EXE, SECRET_MINIO_BUCKET_ACCESS_LEN, SECRET_MINIO_BUCKET_SECRET_LEN};
 | 
					use crate::constants::{MC_EXE, SECRET_MINIO_BUCKET_ACCESS_LEN, SECRET_MINIO_BUCKET_SECRET_LEN};
 | 
				
			||||||
use crate::crd::{BucketRetention, MinioBucketSpec, RetentionType};
 | 
					use crate::crd::{BucketRetention, MinioBucketSpec, RetentionType};
 | 
				
			||||||
 | 
					use crate::temp;
 | 
				
			||||||
use crate::utils::rand_str;
 | 
					use crate::utils::rand_str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const MC_ALIAS_NAME: &str = "managedminioinst";
 | 
					const MC_ALIAS_NAME: &str = "managedminioinst";
 | 
				
			||||||
@@ -173,7 +174,7 @@ impl MinioService {
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        log::debug!("exec_mc_cmd with args {:?}", args);
 | 
					        log::debug!("exec_mc_cmd with args {:?}", args);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let conf_dir = mktemp::Temp::new_dir()?;
 | 
					        let conf_dir = temp::create_temp_dir()?;
 | 
				
			||||||
        let global_flags = ["--config-dir", conf_dir.to_str().unwrap(), "--json"];
 | 
					        let global_flags = ["--config-dir", conf_dir.to_str().unwrap(), "--json"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // First, set our alias to mc in a temporary directory
 | 
					        // First, set our alias to mc in a temporary directory
 | 
				
			||||||
@@ -458,7 +459,7 @@ impl MinioService {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /// Apply a bucket policy
 | 
					    /// Apply a bucket policy
 | 
				
			||||||
    pub async fn policy_apply(&self, name: &str, content: &str) -> anyhow::Result<()> {
 | 
					    pub async fn policy_apply(&self, name: &str, content: &str) -> anyhow::Result<()> {
 | 
				
			||||||
        let tmp_file = mktemp::Temp::new_file()?;
 | 
					        let tmp_file = temp::create_temp_file()?;
 | 
				
			||||||
        std::fs::write(&tmp_file, content)?;
 | 
					        std::fs::write(&tmp_file, content)?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let res = self
 | 
					        let res = self
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
//! Used for testing only
 | 
					//! Used for testing only
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::minio::MinioService;
 | 
					use crate::minio::MinioService;
 | 
				
			||||||
 | 
					use crate::temp;
 | 
				
			||||||
use crate::utils::rand_str;
 | 
					use crate::utils::rand_str;
 | 
				
			||||||
use rand::RngCore;
 | 
					use rand::RngCore;
 | 
				
			||||||
use std::io::ErrorKind;
 | 
					use std::io::ErrorKind;
 | 
				
			||||||
@@ -20,7 +21,7 @@ pub struct MinioTestServer {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl MinioTestServer {
 | 
					impl MinioTestServer {
 | 
				
			||||||
    pub async fn start() -> anyhow::Result<Self> {
 | 
					    pub async fn start() -> anyhow::Result<Self> {
 | 
				
			||||||
        let storage_dir = mktemp::Temp::new_dir()?;
 | 
					        let storage_dir = temp::create_temp_dir()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let root_user = rand_str(30);
 | 
					        let root_user = rand_str(30);
 | 
				
			||||||
        let root_password = rand_str(30);
 | 
					        let root_password = rand_str(30);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								src/temp.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/temp.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					use std::path::{Path, PathBuf};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Get the directory where temp files should be created
 | 
				
			||||||
 | 
					fn temp_path() -> Option<PathBuf> {
 | 
				
			||||||
 | 
					    std::env::var("TEMP_DIR")
 | 
				
			||||||
 | 
					        .as_deref()
 | 
				
			||||||
 | 
					        .ok()
 | 
				
			||||||
 | 
					        .map(Path::new)
 | 
				
			||||||
 | 
					        .map(|p| p.to_path_buf())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Create a temporary directory
 | 
				
			||||||
 | 
					pub fn create_temp_dir() -> std::io::Result<mktemp::Temp> {
 | 
				
			||||||
 | 
					    match temp_path() {
 | 
				
			||||||
 | 
					        None => mktemp::Temp::new_dir(),
 | 
				
			||||||
 | 
					        Some(p) => mktemp::Temp::new_dir_in(p),
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Create a temporary file
 | 
				
			||||||
 | 
					pub fn create_temp_file() -> std::io::Result<mktemp::Temp> {
 | 
				
			||||||
 | 
					    match temp_path() {
 | 
				
			||||||
 | 
					        None => mktemp::Temp::new_file(),
 | 
				
			||||||
 | 
					        Some(p) => mktemp::Temp::new_file_in(p),
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user