Skip to content

Commit

Permalink
stop converting to string
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Sep 15, 2023
1 parent b4b3846 commit 7c4abbd
Showing 1 changed file with 18 additions and 39 deletions.
57 changes: 18 additions & 39 deletions tooling/bundler/src/bundle/macos/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ pub fn notarize(
Err(anyhow::anyhow!("{log_message}").into())
}
} else {
return Err(
anyhow::anyhow!("failed to parse notarytool output as JSON: `{output_str}`").into(),
);
Err(anyhow::anyhow!("failed to parse notarytool output as JSON: `{output_str}`").into())
}
}

Expand All @@ -327,14 +325,14 @@ fn staple_app(mut app_bundle_path: PathBuf) -> crate::Result<()> {

pub enum NotarizeAuth {
AppleId {
apple_id: String,
password: String,
team_id: Option<String>,
apple_id: OsString,
password: OsString,
team_id: Option<OsString>,
},
ApiKey {
key: String,
key: OsString,
key_path: PathBuf,
issuer: String,
issuer: OsString,
},
}

Expand Down Expand Up @@ -381,39 +379,20 @@ pub fn notarize_auth() -> crate::Result<NotarizeAuth> {
var_os("APPLE_PASSWORD"),
var_os("APPLE_TEAM_ID"),
) {
(Some(apple_id), Some(apple_password), team_id) => {
let apple_id = apple_id
.to_str()
.expect("failed to convert APPLE_ID to string")
.to_string();
let password = apple_password
.to_str()
.expect("failed to convert APPLE_PASSWORD to string")
.to_string();
let team_id = team_id.map(|team_id| {
team_id
.to_str()
.expect("failed to convert APPLE_TEAM_ID to string")
.to_string()
});
Ok(NotarizeAuth::AppleId {
apple_id,
password,
team_id,
})
}
(Some(apple_id), Some(password), team_id) => Ok(NotarizeAuth::AppleId {
apple_id,
password,
team_id,
}),
_ => {
match (var_os("APPLE_API_KEY"), var_os("APPLE_API_ISSUER"), var("APPLE_API_KEY_PATH")) {
(Some(api_key), Some(api_issuer), Ok(key_path)) => {
let key = api_key.to_str().expect("failed to convert APPLE_API_KEY to string").to_string();
let issuer = api_issuer.to_str().expect("failed to convert APPLE_API_ISSUER to string").to_string();
(Some(key), Some(issuer), Ok(key_path)) => {
Ok(NotarizeAuth::ApiKey { key, key_path: key_path.into(), issuer })
},
(Some(api_key), Some(api_issuer), Err(_)) => {
let key = api_key.to_str().expect("failed to convert APPLE_API_KEY to string").to_string();
let issuer = api_issuer.to_str().expect("failed to convert APPLE_API_ISSUER to string").to_string();

let api_key_file_name = format!("AuthKey_{key}.p8");
(Some(key), Some(issuer), Err(_)) => {
let mut api_key_file_name = OsString::from("AuthKey_");
api_key_file_name.push(&key);
api_key_file_name.push(".p8");
let mut key_path = None;

let mut search_paths = vec!["./private_keys".into()];
Expand All @@ -433,7 +412,7 @@ pub fn notarize_auth() -> crate::Result<NotarizeAuth> {
if let Some(key_path) = key_path {
Ok(NotarizeAuth::ApiKey { key, key_path, issuer })
} else {
Err(anyhow::anyhow!("could not find API key file. Please set the APPLE_API_KEY_PATH environment variables to the path to the {api_key_file_name} file").into())
Err(anyhow::anyhow!("could not find API key file. Please set the APPLE_API_KEY_PATH environment variables to the path to the {api_key_file_name:?} file").into())
}
}
_ => Err(anyhow::anyhow!("no APPLE_ID & APPLE_PASSWORD or APPLE_API_KEY & APPLE_API_ISSUER & APPLE_API_KEY_PATH environment variables found").into())
Expand All @@ -442,7 +421,7 @@ pub fn notarize_auth() -> crate::Result<NotarizeAuth> {
}
}

fn find_api_key(folder: PathBuf, file_name: &str) -> Option<PathBuf> {
fn find_api_key(folder: PathBuf, file_name: &OsString) -> Option<PathBuf> {
let path = folder.join(file_name);
if path.exists() {
Some(path)
Expand Down

0 comments on commit 7c4abbd

Please sign in to comment.