From b1a5f9f11af61bf339cbe6ed91f5a4c068381c79 Mon Sep 17 00:00:00 2001 From: Joseph Montanaro Date: Wed, 18 Sep 2024 09:14:28 -0400 Subject: [PATCH] start working on docker helper --- src-tauri/creddy_cli/src/cli.rs | 23 +++++++++++++++++++++++ src-tauri/creddy_cli/src/cli/docker.rs | 0 src-tauri/creddy_cli/src/lib.rs | 1 + src-tauri/creddy_cli/src/main.rs | 1 + src-tauri/creddy_cli/src/proto.rs | 16 ++++++++++++++++ src-tauri/src/main.rs | 1 + 6 files changed, 42 insertions(+) create mode 100644 src-tauri/creddy_cli/src/cli/docker.rs diff --git a/src-tauri/creddy_cli/src/cli.rs b/src-tauri/creddy_cli/src/cli.rs index fefc47e..60bd449 100644 --- a/src-tauri/creddy_cli/src/cli.rs +++ b/src-tauri/creddy_cli/src/cli.rs @@ -70,6 +70,9 @@ pub enum Action { Exec(ExecArgs), /// Invoke an action normally triggered by hotkey (e.g. launch terminal) Shortcut(InvokeArgs), + /// Interact with Docker credentials via the docker-credential-helper protocol + #[command(subcommand)] + Docker(DockerCmd), } @@ -101,6 +104,17 @@ pub struct InvokeArgs { } +#[derive(Debug, Subcommand)] +pub enum DockerCmd { + /// Get a stored Docker credential + Get, + /// Store a new Docker credential + Store, + /// Remove a stored Docker credential + Erase, +} + + pub fn get(args: GetArgs, global: GlobalArgs) -> anyhow::Result<()> { let req = CliRequest::GetCredential { name: args.name, @@ -185,6 +199,15 @@ pub fn invoke_shortcut(args: InvokeArgs, global: GlobalArgs) -> anyhow::Result<( } +pub fn docker_credential_helper(cmd: DockerCmd) -> anyhow::Result<()> { + let req = match cmd { + DockerCmd::Get => todo!(), + DockerCmd::Store => todo!(), + DockerCmd::Erase => todo!(), + }; +} + + // Explanation for double-result: the server will return a (serialized) Result // to indicate when the operation succeeded or failed, which we deserialize. // However, the operation may fail to even communicate with the server, in diff --git a/src-tauri/creddy_cli/src/cli/docker.rs b/src-tauri/creddy_cli/src/cli/docker.rs new file mode 100644 index 0000000..e69de29 diff --git a/src-tauri/creddy_cli/src/lib.rs b/src-tauri/creddy_cli/src/lib.rs index dd93db6..8488828 100644 --- a/src-tauri/creddy_cli/src/lib.rs +++ b/src-tauri/creddy_cli/src/lib.rs @@ -5,6 +5,7 @@ pub use cli::{ exec, get, invoke_shortcut, + docker_credential_helper, }; pub(crate) use platform::connect; diff --git a/src-tauri/creddy_cli/src/main.rs b/src-tauri/creddy_cli/src/main.rs index f41513f..683c431 100644 --- a/src-tauri/creddy_cli/src/main.rs +++ b/src-tauri/creddy_cli/src/main.rs @@ -11,6 +11,7 @@ fn main() { Some(Action::Get(args)) => creddy_cli::get(args, cli.global_args), Some(Action::Exec(args)) => creddy_cli::exec(args, cli.global_args), Some(Action::Shortcut(args)) => creddy_cli::invoke_shortcut(args, cli.global_args), + Some(Action::Docker(cmd)) => creddy_cli::docker_credential_helper(cmd), }; if let Err(e) = res { diff --git a/src-tauri/creddy_cli/src/proto.rs b/src-tauri/creddy_cli/src/proto.rs index e40defc..dd7a508 100644 --- a/src-tauri/creddy_cli/src/proto.rs +++ b/src-tauri/creddy_cli/src/proto.rs @@ -14,6 +14,11 @@ pub enum CliRequest { name: Option, base: bool, }, + SaveCredential { + name: String, + is_default: bool, + credential: CliCredential, + }, InvokeShortcut(ShortcutAction), } @@ -46,6 +51,7 @@ impl Display for CliResponse { pub enum CliCredential { AwsBase(AwsBaseCredential), AwsSession(AwsSessionCredential), + Docker(DockerCredential), } @@ -75,6 +81,16 @@ pub struct AwsSessionCredential { fn default_aws_version() -> usize { 1 } +#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct DockerCredential { + #[serde(rename = "PascalCase")] + pub server_url: String, + pub username: String, + pub secret: String, +} + + #[derive(Debug, Serialize, Deserialize)] pub struct ServerError { code: String, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 91f703b..c0b5187 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -21,6 +21,7 @@ fn main() { Some(Action::Get(args)) => creddy_cli::get(args, cli.global_args), Some(Action::Exec(args)) => creddy_cli::exec(args, cli.global_args), Some(Action::Shortcut(args)) => creddy_cli::invoke_shortcut(args, cli.global_args), + Some(Action::Docker(cmd)) => creddy_cli::docker_credential_helper(cmd), }; if let Err(e) = res {