Skip to content

Commit

Permalink
Add login-session feature to iggy CLI (#1178)
Browse files Browse the repository at this point in the history
Add login-session feature to default features for iggy CLI and disable
it for official docker release due to missing keyring storage inside
docker. Updating release workflow to build server and cli separately.
  • Loading branch information
BartoszCiesla authored Aug 25, 2024
1 parent d3428b9 commit 4946804
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 16 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,22 @@ jobs:
run: sudo apt-get update --yes && sudo apt-get install --yes musl-tools
if: contains(matrix.platform.name, 'musl')

- name: Build release binary
- name: Build iggy-server release binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: "build"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--verbose --release"
args: "--verbose --release --bin iggy-server"
if: ${{ matrix.toolchain }} == 'stable'

- name: Build iggy-cli release binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: "build"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--verbose --release --no-default-features --bin iggy"
if: ${{ matrix.toolchain }} == 'stable'

- name: Prepare artifacts
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iggy-cli"
version = "0.5.12"
version = "0.5.13"
edition = "2021"
authors = ["bartosz.ciesla@gmail.com"]
repository = "https://github.com/iggy-rs/iggy"
Expand All @@ -9,14 +9,18 @@ description = "Iggy is the persistent message streaming platform written in Rust
license = "MIT"
keywords = ["iggy", "cli", "messaging", "streaming"]

[features]
default = ["login-session"]
login-session = ["dep:keyring"]

[dependencies]
ahash = { version = "0.8.11", features = ["serde"] }
anyhow = "1.0.86"
clap = { version = "4.5.4", features = ["derive"] }
clap_complete = "4.5.16"
figlet-rs = "0.1.5"
iggy = { path = "../sdk", features = ["iggy-cli"], version = "0.6.12" }
keyring = { version = "3.2.0", features = ["sync-secret-service", "vendored"] }
keyring = { version = "3.2.0", features = ["sync-secret-service", "vendored"], optional = true }
passterm = "2.0.1"
thiserror = "1.0.61"
tokio = { version = "1.38.0", features = ["full"] }
Expand Down
9 changes: 8 additions & 1 deletion cli/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ use crate::args::{
partition::PartitionAction,
personal_access_token::PersonalAccessTokenAction,
stream::StreamAction,
system::{LoginArgs, PingArgs, StatsArgs},
system::{PingArgs, StatsArgs},
topic::TopicAction,
};

#[cfg(feature = "login-session")]
use crate::args::system::LoginArgs;

use self::user::UserAction;

pub(crate) mod client;
Expand Down Expand Up @@ -80,6 +83,7 @@ pub(crate) struct CliOptions {
#[clap(short, long, group = "credentials")]
pub(crate) token: Option<String>,

#[cfg(feature = "login-session")]
/// Iggy server personal access token name
///
/// When personal access token is created using command line tool and stored
Expand Down Expand Up @@ -154,13 +158,15 @@ pub(crate) enum Command {
/// context operations
#[command(subcommand, visible_alias = "ctx")]
Context(ContextAction),
#[cfg(feature = "login-session")]
/// login to Iggy server
///
/// Command logs in to Iggy server using provided credentials and stores session token
/// in platform-specific secure storage. Session token is used for authentication in
/// subsequent commands until logout command is executed.
#[clap(verbatim_doc_comment, visible_alias = "li")]
Login(LoginArgs),
#[cfg(feature = "login-session")]
/// logout from Iggy server
///
/// Command logs out from Iggy server and removes session token from platform-specific
Expand Down Expand Up @@ -218,6 +224,7 @@ impl IggyMergedConsoleArgs {
username: args.cli.username.or(context.username),
password: args.cli.password.or(context.password),
token: args.cli.token.or(context.token),
#[cfg(feature = "login-session")]
token_name: args.cli.token_name.or(context.token_name),
generator: args.cli.generator,
};
Expand Down
22 changes: 16 additions & 6 deletions cli/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ use crate::error::{CmdToolError, IggyCmdError};
use anyhow::{bail, Context};
use iggy::args::Args;
use iggy::cli::system::session::ServerSession;
use iggy::cli_command::PRINT_TARGET;
use iggy::client::{PersonalAccessTokenClient, UserClient};
use iggy::clients::client::IggyClient;
use iggy::error::IggyError;
use keyring::Entry;
use passterm::{isatty, prompt_password_stdin, prompt_password_tty, Stream};
use std::env::var;
use tracing::{event, Level};

#[cfg(feature = "login-session")]
mod credentials_login_session {
pub(crate) use iggy::cli_command::PRINT_TARGET;
pub(crate) use keyring::Entry;
pub(crate) use tracing::{event, Level};
}

#[cfg(feature = "login-session")]
use credentials_login_session::*;

static ENV_IGGY_USERNAME: &str = "IGGY_USERNAME";
static ENV_IGGY_PASSWORD: &str = "IGGY_PASSWORD";
Expand Down Expand Up @@ -57,8 +64,9 @@ impl<'a> IggyCredentials<'a> {
}
}

#[cfg(feature = "login-session")]
if let Some(token_name) = &cli_options.token_name {
match iggy_args.get_server_address() {
return match iggy_args.get_server_address() {
Some(server_address) => {
let server_address = format!("iggy:{}", server_address);
event!(target: PRINT_TARGET, Level::DEBUG,"Checking token presence under service: {} and name: {}",
Expand All @@ -73,8 +81,10 @@ impl<'a> IggyCredentials<'a> {
})
}
None => Err(IggyCmdError::CmdToolError(CmdToolError::MissingServerAddress).into()),
}
} else if let Some(token) = &cli_options.token {
};
}

if let Some(token) = &cli_options.token {
Ok(Self {
credentials: Some(Credentials::PersonalAccessToken(token.clone())),
iggy_client: None,
Expand Down
2 changes: 2 additions & 0 deletions cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use thiserror::Error;
#[derive(Error, Debug)]
pub(crate) enum CmdToolError {
MissingCredentials,
#[cfg(feature = "login-session")]
MissingServerAddress,
}

Expand All @@ -13,6 +14,7 @@ impl Display for CmdToolError {
Self::MissingCredentials => {
write!(f, "Missing iggy server credentials")
}
#[cfg(feature = "login-session")]
Self::MissingServerAddress => {
write!(f, "Missing iggy server address")
}
Expand Down
14 changes: 12 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use clap::Parser;
use iggy::args::Args;
use iggy::cli::context::common::ContextManager;
use iggy::cli::context::use_context::UseContextCmd;
use iggy::cli::utils::login_session_expiry::LoginSessionExpiry;
use iggy::cli::{
client::{get_client::GetClientCmd, get_clients::GetClientsCmd},
consumer_group::{
Expand All @@ -44,7 +43,7 @@ use iggy::cli::{
create_stream::CreateStreamCmd, delete_stream::DeleteStreamCmd, get_stream::GetStreamCmd,
get_streams::GetStreamsCmd, purge_stream::PurgeStreamCmd, update_stream::UpdateStreamCmd,
},
system::{login::LoginCmd, logout::LogoutCmd, me::GetMeCmd, ping::PingCmd, stats::GetStatsCmd},
system::{me::GetMeCmd, ping::PingCmd, stats::GetStatsCmd},
topics::{
create_topic::CreateTopicCmd, delete_topic::DeleteTopicCmd, get_topic::GetTopicCmd,
get_topics::GetTopicsCmd, purge_topic::PurgeTopicCmd, update_topic::UpdateTopicCmd,
Expand All @@ -67,6 +66,15 @@ use iggy::utils::personal_access_token_expiry::PersonalAccessTokenExpiry;
use std::sync::Arc;
use tracing::{event, Level};

#[cfg(feature = "login-session")]
mod main_login_session {
pub(crate) use iggy::cli::system::{login::LoginCmd, logout::LogoutCmd};
pub(crate) use iggy::cli::utils::login_session_expiry::LoginSessionExpiry;
}

#[cfg(feature = "login-session")]
use main_login_session::*;

fn get_command(
command: Command,
cli_options: &CliOptions,
Expand Down Expand Up @@ -272,10 +280,12 @@ fn get_command(
Box::new(UseContextCmd::new(use_args.context_name.clone()))
}
},
#[cfg(feature = "login-session")]
Command::Login(login_args) => Box::new(LoginCmd::new(
iggy_args.get_server_address().unwrap(),
LoginSessionExpiry::new(login_args.expiry.clone()),
)),
#[cfg(feature = "login-session")]
Command::Logout => Box::new(LogoutCmd::new(iggy_args.get_server_address().unwrap())),
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "server"
version = "0.4.14"
version = "0.4.20"
edition = "2021"
build = "src/build.rs"

Expand Down

0 comments on commit 4946804

Please sign in to comment.