use std::path::{Path, PathBuf};
use crate::runner::RunnerError;
pub const SLOT_KEY_ID: &str = "APPLE_API_KEY_ID";
pub const SLOT_ISSUER: &str = "APPLE_API_ISSUER";
pub const SLOT_KEY_P8: &str = "APPLE_API_KEY_P8";
pub fn write_p8_key(work_dir: &Path, key_id: &str, contents: &str) -> Result<PathBuf, RunnerError> {
let path = work_dir.join(format!("AuthKey_{key_id}.p8"));
std::fs::write(&path, contents)
.map_err(|e| RunnerError::Outcome(format!("apple: writing API key file: {e}")))?;
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600))
.map_err(|e| RunnerError::Outcome(format!("apple: chmod 600 API key file: {e}")))?;
}
Ok(path)
}