From 4c18de8b7a48100be564265bf7f759aa95d44e51 Mon Sep 17 00:00:00 2001 From: Joseph Montanaro Date: Sat, 28 Dec 2024 06:59:01 -0500 Subject: [PATCH] fix docker credential helper when credentials are not found --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/creddy_cli/src/cli/docker.rs | 15 ++++++++++++--- src-tauri/creddy_cli/src/lib.rs | 3 +-- src-tauri/creddy_cli/src/proto.rs | 4 ++-- src-tauri/tauri.conf.json | 2 +- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 69b659c..1971987 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "creddy", - "version": "0.6.1", + "version": "0.6.2", "scripts": { "dev": "vite", "build": "vite build", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index de170e2..90fc83d 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1217,7 +1217,7 @@ dependencies = [ [[package]] name = "creddy" -version = "0.6.1" +version = "0.6.2" dependencies = [ "argon2", "auto-launch", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7714fda..1537c58 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "creddy" -version = "0.6.1" +version = "0.6.2" description = "A friendly AWS credentials manager" authors = ["Joseph Montanaro"] license = "" diff --git a/src-tauri/creddy_cli/src/cli/docker.rs b/src-tauri/creddy_cli/src/cli/docker.rs index c42b578..6ff2ca8 100644 --- a/src-tauri/creddy_cli/src/cli/docker.rs +++ b/src-tauri/creddy_cli/src/cli/docker.rs @@ -29,11 +29,20 @@ pub fn docker_get(global_args: GlobalArgs) -> anyhow::Result<()> { server_url: server_url.trim().to_owned() }; - match super::make_request(global_args.server_addr, &req)?? { - CliResponse::Credential(CliCredential::Docker(d)) => { + let server_resp = super::make_request(global_args.server_addr, &req)?; + match server_resp { + Ok(CliResponse::Credential(CliCredential::Docker(d))) => { println!("{}", serde_json::to_string(&d)?); }, - r => bail!("Unexpected response from server: {r}"), + Err(e) if e.code == "NoCredentials" => { + // To indicate credentials are not found, a credential helper *must* print + // this message to stdout, then exit 1. Any other message/status will cause + // some builds to fail. This is, of course, not documented anywhere. + println!("credentials not found in native keychain"); + std::process::exit(1); + }, + Err(e) => Err(e)?, + Ok(r) => bail!("Unexpected response from server: {r}"), } Ok(()) } diff --git a/src-tauri/creddy_cli/src/lib.rs b/src-tauri/creddy_cli/src/lib.rs index a02db2c..9eaec77 100644 --- a/src-tauri/creddy_cli/src/lib.rs +++ b/src-tauri/creddy_cli/src/lib.rs @@ -27,8 +27,7 @@ mod platform { use tokio::net::UnixStream; pub async fn connect(addr: Option) -> Result { - let default = if cfg!(debug_assertions) { "creddy-server-dev" } else { "creddy-server" }; - let path = addr.unwrap_or_else(|| server_addr(default)); + let path = addr.unwrap_or_else(|| server_addr("creddy-server")); UnixStream::connect(&path).await } diff --git a/src-tauri/creddy_cli/src/proto.rs b/src-tauri/creddy_cli/src/proto.rs index e861111..fdb5662 100644 --- a/src-tauri/creddy_cli/src/proto.rs +++ b/src-tauri/creddy_cli/src/proto.rs @@ -99,8 +99,8 @@ pub struct DockerCredential { #[derive(Debug, Serialize, Deserialize)] pub struct ServerError { - code: String, - msg: String, + pub code: String, + pub msg: String, } impl Display for ServerError { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 15b33cc..eacef81 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -50,7 +50,7 @@ } }, "productName": "creddy", - "version": "0.6.1", + "version": "0.6.2", "identifier": "creddy", "plugins": {}, "app": {