| 79 | } |
| 80 | |
| 81 | fn apply_credentials( |
| 82 | options: &mut ServiceOptions, |
| 83 | existing_credentials: Option<&ServiceCredentials>, |
| 84 | policy: CredentialPolicy, |
| 85 | ) { |
| 86 | if options.access_token.is_none() { |
| 87 | options.access_token = (policy == CredentialPolicy::Preserve) |
| 88 | .then(|| existing_credentials.and_then(|credentials| credentials.access_token.clone())) |
| 89 | .flatten() |
| 90 | .or_else(|| Some(auth::generate_access_token())); |
| 91 | } |
| 92 | if options.pairing_code.is_none() { |
| 93 | options.pairing_code = (policy == CredentialPolicy::Preserve) |
| 94 | .then(|| existing_credentials.and_then(|credentials| credentials.pairing_code.clone())) |
| 95 | .flatten() |
| 96 | .or_else(|| Some(auth::generate_pairing_code())); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | pub fn installed_port() -> anyhow::Result<Option<u16>> { |
| 101 | if !launch_agent_supported() { |