Skip to content

Commit

Permalink
Use aHash, improve permissioner (#1159)
Browse files Browse the repository at this point in the history
  • Loading branch information
spetz authored Aug 18, 2024
1 parent ecc0d94 commit c540014
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 76 deletions.
27 changes: 23 additions & 4 deletions Cargo.lock

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

5 changes: 3 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.11"
version = "0.5.12"
edition = "2021"
authors = ["bartosz.ciesla@gmail.com"]
repository = "https://github.com/iggy-rs/iggy"
Expand All @@ -10,11 +10,12 @@ license = "MIT"
keywords = ["iggy", "cli", "messaging", "streaming"]

[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.10" }
iggy = { path = "../sdk", features = ["iggy-cli"], version = "0.6.12" }
keyring = "2.3.3"
passterm = "2.0.1"
thiserror = "1.0.61"
Expand Down
8 changes: 4 additions & 4 deletions cli/src/args/permissions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use self::{global::GlobalPermissionsArg, stream::StreamPermissionsArg};
use ahash::AHashMap;
use clap::ValueEnum;
use iggy::models::{
permissions::{Permissions, StreamPermissions},
user_status::UserStatus,
};
use std::collections::HashMap;

pub(crate) mod constants;
pub(crate) mod global;
Expand Down Expand Up @@ -34,7 +34,7 @@ impl From<PermissionsArgs> for Option<Permissions> {
.stream
.into_iter()
.map(|s| (s.stream_id, s.into()))
.collect::<HashMap<u32, StreamPermissions>>();
.collect::<AHashMap<u32, StreamPermissions>>();

match (value.global, stream_permissions.is_empty()) {
(Some(global), true) => Some(Permissions {
Expand Down Expand Up @@ -104,7 +104,7 @@ mod tests {
Option::from(PermissionsArgs::new(None, Some(vec![stream])));

let permissions = Permissions {
streams: Some(HashMap::from([(1, StreamPermissions::default())])),
streams: Some(AHashMap::from([(1, StreamPermissions::default())])),
..Default::default()
};
assert_eq!(permissions_args, Some(permissions));
Expand All @@ -118,7 +118,7 @@ mod tests {
Option::from(PermissionsArgs::new(Some(global), Some(vec![stream])));

let mut permissions = Permissions {
streams: Some(HashMap::from([(1, StreamPermissions::default())])),
streams: Some(AHashMap::from([(1, StreamPermissions::default())])),
..Default::default()
};
permissions.global.manage_topics = true;
Expand Down
11 changes: 6 additions & 5 deletions cli/src/args/permissions/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use super::constants::{
READ_TOPICS_SHORT, SEND_MESSAGES_LONG, SEND_MESSAGES_SHORT,
};
use crate::args::permissions::topic::TopicPermissionsArg;
use ahash::AHashMap;
use iggy::models::permissions::StreamPermissions;
use std::{collections::HashMap, str::FromStr};
use std::str::FromStr;

#[derive(Debug, PartialEq)]
pub(super) enum StreamPermission {
Expand Down Expand Up @@ -65,7 +66,7 @@ impl StreamPermissionsArg {
}

if !topic_permissions.is_empty() {
let mut permissions = HashMap::new();
let mut permissions = AHashMap::new();
for permission in topic_permissions {
permissions.insert(permission.topic_id, permission.permissions);
}
Expand Down Expand Up @@ -363,7 +364,7 @@ mod tests {
read_topics: false,
poll_messages: false,
send_messages: false,
topics: Some(HashMap::from([
topics: Some(AHashMap::from([
(
2,
TopicPermissions {
Expand Down Expand Up @@ -398,7 +399,7 @@ mod tests {
read_topics: false,
poll_messages: false,
send_messages: false,
topics: Some(HashMap::from([
topics: Some(AHashMap::from([
(
2,
TopicPermissions {
Expand Down Expand Up @@ -496,7 +497,7 @@ mod tests {
read_topics: false,
poll_messages: false,
send_messages: false,
topics: Some(HashMap::from([
topics: Some(AHashMap::from([
(
2,
TopicPermissions {
Expand Down
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ name = "new-sdk-producer"
path = "src/new-sdk/producer/main.rs"

[dependencies]
ahash = { version = "0.8.11", features = ["serde"] }
anyhow = "1.0.86"
bytes = "1.6.0"
clap = { version = "4.5.4", features = ["derive"] }
Expand Down
5 changes: 3 additions & 2 deletions examples/src/multi-tenant/consumer/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ahash::AHashMap;
use clap::Parser;
use futures_util::future::join_all;
use futures_util::StreamExt;
Expand Down Expand Up @@ -174,7 +175,7 @@ async fn create_user(
.get_stream(&stream_name.try_into()?)
.await?
.expect("Stream does not exist");
let mut topic_permissions = HashMap::new();
let mut topic_permissions = AHashMap::new();
for topic in topics {
let topic_id = Identifier::named(topic)?;
let topic = client
Expand All @@ -192,7 +193,7 @@ async fn create_user(
);
}

let mut streams_permissions = HashMap::new();
let mut streams_permissions = AHashMap::new();
streams_permissions.insert(
stream.id,
StreamPermissions {
Expand Down
3 changes: 2 additions & 1 deletion examples/src/multi-tenant/producer/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ahash::AHashMap;
use clap::Parser;
use futures_util::future::join_all;
use iggy::client::{Client, StreamClient, UserClient};
Expand Down Expand Up @@ -310,7 +311,7 @@ async fn create_stream_and_user(
) -> Result<(), IggyError> {
let stream = client.create_stream(stream_name, None).await?;
info!("Created stream: {stream_name} with ID: {}", stream.id);
let mut streams_permissions = HashMap::new();
let mut streams_permissions = AHashMap::new();
streams_permissions.insert(
stream.id,
StreamPermissions {
Expand Down
1 change: 1 addition & 0 deletions integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.1"
edition = "2021"

[dependencies]
ahash = { version = "0.8.11", features = ["serde"] }
assert_cmd = "2.0.14"
async-trait = "0.1.80"
bytes = "1.6.0"
Expand Down
12 changes: 6 additions & 6 deletions integration/tests/cli/user/test_user_create_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use crate::cli::common::{
IggyCmdCommand, IggyCmdTest, IggyCmdTestCase, TestHelpCmd, CLAP_INDENT, USAGE_PREFIX,
};
use crate::cli::user::common::PermissionsTestArgs;
use ahash::AHashMap;
use assert_cmd::assert::Assert;
use async_trait::async_trait;
use iggy::client::Client;
use iggy::models::permissions::{GlobalPermissions, StreamPermissions, TopicPermissions};
use iggy::models::{permissions::Permissions, user_status::UserStatus};
use predicates::str::diff;
use serial_test::parallel;
use std::collections::HashMap;

#[derive(Debug, Clone)]
enum UserStatusTest {
Expand Down Expand Up @@ -175,7 +175,7 @@ pub async fn should_be_successful() {
vec![String::from("3")],
Some(Permissions {
global: GlobalPermissions::default(),
streams: Some(HashMap::from([(3u32, StreamPermissions::default())])),
streams: Some(AHashMap::from([(3u32, StreamPermissions::default())])),
}),
),
))
Expand All @@ -190,10 +190,10 @@ pub async fn should_be_successful() {
vec![String::from("1#1:m_top,r_top,p_msg,s_msg")],
Some(Permissions {
global: GlobalPermissions::default(),
streams: Some(HashMap::from([(
streams: Some(AHashMap::from([(
1u32,
StreamPermissions {
topics: Some(HashMap::from([(
topics: Some(AHashMap::from([(
1,
TopicPermissions {
manage_topic: true,
Expand Down Expand Up @@ -230,10 +230,10 @@ pub async fn should_be_successful() {
poll_messages: false,
send_messages: false,
},
streams: Some(HashMap::from([(
streams: Some(AHashMap::from([(
2u32,
StreamPermissions {
topics: Some(HashMap::from([(
topics: Some(AHashMap::from([(
1,
TopicPermissions {
manage_topic: false,
Expand Down
7 changes: 3 additions & 4 deletions integration/tests/cli/user/test_user_get_command.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::collections::HashMap;

use crate::cli::common::{
IggyCmdCommand, IggyCmdTest, IggyCmdTestCase, TestHelpCmd, TestUserId, CLAP_INDENT,
USAGE_PREFIX,
};
use ahash::AHashMap;
use assert_cmd::assert::Assert;
use async_trait::async_trait;
use iggy::client::Client;
Expand Down Expand Up @@ -75,10 +74,10 @@ impl TestUserGetCmd {

if let Some(topic_id) = self.check_topic_perms {
stream_perms.topics =
Some(HashMap::from([(topic_id, TopicPermissions::default())]));
Some(AHashMap::from([(topic_id, TopicPermissions::default())]));
};

permissions.streams = Some(HashMap::from([(stream_id, stream_perms)]));
permissions.streams = Some(AHashMap::from([(stream_id, stream_perms)]));
}

Some(permissions)
Expand Down
12 changes: 6 additions & 6 deletions integration/tests/cli/user/test_user_permissions_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::cli::common::{
USAGE_PREFIX,
};
use crate::cli::user::common::PermissionsTestArgs;
use ahash::AHashMap;
use assert_cmd::assert::Assert;
use async_trait::async_trait;
use iggy::client::Client;
Expand All @@ -12,7 +13,6 @@ use iggy::models::user_info::UserId;
use iggy::models::user_status::UserStatus;
use predicates::str::diff;
use serial_test::parallel;
use std::collections::HashMap;

struct TestUserPermissionsCmd {
username: String,
Expand Down Expand Up @@ -140,7 +140,7 @@ pub async fn should_be_successful() {
vec![String::from("3")],
Some(Permissions {
global: GlobalPermissions::default(),
streams: Some(HashMap::from([(3u32, StreamPermissions::default())])),
streams: Some(AHashMap::from([(3u32, StreamPermissions::default())])),
}),
),
TestUserId::Numeric,
Expand All @@ -154,10 +154,10 @@ pub async fn should_be_successful() {
vec![String::from("1#2:m_top,r_top,p_msg,s_msg")],
Some(Permissions {
global: GlobalPermissions::default(),
streams: Some(HashMap::from([(
streams: Some(AHashMap::from([(
1u32,
StreamPermissions {
topics: Some(HashMap::from([(
topics: Some(AHashMap::from([(
2,
TopicPermissions {
manage_topic: true,
Expand Down Expand Up @@ -193,10 +193,10 @@ pub async fn should_be_successful() {
poll_messages: false,
send_messages: false,
},
streams: Some(HashMap::from([(
streams: Some(AHashMap::from([(
2u32,
StreamPermissions {
topics: Some(HashMap::from([(
topics: Some(AHashMap::from([(
2u32,
TopicPermissions {
manage_topic: false,
Expand Down
3 changes: 2 additions & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iggy"
version = "0.6.11"
version = "0.6.12"
description = "Iggy is the persistent message streaming platform written in Rust, supporting QUIC, TCP and HTTP transport protocols, capable of processing millions of messages per second."
edition = "2021"
license = "MIT"
Expand All @@ -13,6 +13,7 @@ readme = "../README.md"

[dependencies]
aes-gcm = "0.10.3"
ahash = { version = "0.8.11", features = ["serde"] }
anyhow = "1.0.86"
async-broadcast = { version = "0.7.1" }
async-dropper = { version = "0.3.1", features = ["tokio", "simple"] }
Expand Down
Loading

0 comments on commit c540014

Please sign in to comment.