Skip to content

Commit

Permalink
Check for SSH key errors. Closes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Dec 12, 2024
1 parent 891b355 commit ccfd21c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion rs/crates/rq-core/src/github.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{ensure, Context, Result};
use anyhow::{bail, ensure, Context, Result};
use futures_util::future::try_join_all;
use http::StatusCode;
use octocrab::{
Expand Down Expand Up @@ -84,6 +84,19 @@ pub async fn load_user() -> Result<String> {
Ok(user.login)
}

pub fn check_ssh() -> Result<()> {
let output = command("ssh -T [email protected]", Path::new("/")).output()?;
if !output.status.success() {
let stderr = String::from_utf8(output.stderr)?;
if stderr.trim() == "[email protected]: Permission denied (publickey)." {
bail!("Your machine is not setup for a secure connection to Github. Please follow the instructions here: https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey");
} else {
bail!("Failed to establish a secure connection to Github with error:\n{stderr}")
}
}
Ok(())
}

pub enum GitProtocol {
Ssh,
Https,
Expand Down
4 changes: 3 additions & 1 deletion rs/crates/rq-core/src/quest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{borrow::Cow, collections::HashMap, path::PathBuf, time::Duration};

use crate::{
git::{GitRepo, UPSTREAM},
github::{load_user, GithubRepo, PullSelector},
github::{self, load_user, GithubRepo, PullSelector},
package::QuestPackage,
stage::{Stage, StagePart, StagePartStatus},
template::{InstanceOutputs, PackageTemplate, QuestTemplate, RepoTemplate},
Expand Down Expand Up @@ -135,6 +135,8 @@ impl Quest {
source: CreateSource,
state_event: Box<dyn StateEmitter>,
) -> Result<Self> {
github::check_ssh()?;

let template: Box<dyn QuestTemplate> = match source {
CreateSource::Remote { user, repo } => {
let upstream = GithubRepo::load(&user, &repo).await?;
Expand Down

0 comments on commit ccfd21c

Please sign in to comment.