Skip to content

feat(cpp): add functions related to user management, and initial high-level client - #3733

Open
slbotbm wants to merge 11 commits into
apache:masterfrom
slbotbm:cpp-more-3-functions
Open

feat(cpp): add functions related to user management, and initial high-level client#3733
slbotbm wants to merge 11 commits into
apache:masterfrom
slbotbm:cpp-more-3-functions

Conversation

@slbotbm

@slbotbm slbotbm commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR address?

Closes #
Relates to #2100

Rationale

Works towards completion of cpp client.

What changed?

Adds the following:

  • create_user
  • get_user
  • get_users
  • update_user
  • delete_user
    and their tests.

Adds high level client that will function as primary API with documentation. The diff looks big since a lot of the public api was changed and aligned to PascalCase. I have not rewritten the tests using the high level client since I would like to do that at once instead of a gradual approach.

Local Execution

  • Passed
  • Pre-commit hooks ran

AI Usage

If AI tools were used, please answer:

  1. Which tools? codex
  2. Scope of usage? code generation
  3. How did you verify the generated code works correctly? read through it
  4. Can you explain every line of the code if asked? yes

@slbotbm
slbotbm marked this pull request as draft July 22, 2026 20:01
@github-actions github-actions Bot added S-waiting-on-review PR is waiting on a reviewer and removed S-waiting-on-review PR is waiting on a reviewer labels Jul 22, 2026
@slbotbm
slbotbm marked this pull request as ready for review August 1, 2026 15:21
@github-actions github-actions Bot added the S-waiting-on-review PR is waiting on a reviewer label Aug 1, 2026

@ethanlin01x ethanlin01x left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions

Comment thread foreign/cpp/src/client.rs
})
}

pub fn update_user(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust SDK allows updating username and status independently (Option params), but this forces both. Consider has_username / has_status flags like the existing has_permissions pattern

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread foreign/cpp/include/iggy.hpp Outdated
* @return Information about the authenticated session.
* @throws IggyException if authentication fails.
*/
LoginInfo Login(std::string username, std::string password) const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Login() returning ffi::LoginInfo leaks the FFI's has_access_token bool-flag workaround into the high-level API. Since this is meant to be the primary API, a dedicated type with std::optional for the token would be cleaner, and avoids a breaking change later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh this is currently a workaround for cxx's limitations. I eventually plan to convert all structs defined in rust to cpp structs/enums and call them from rust. That'll give the users a better experience as compared to now. I'll remember this, and implement this when I make that change.

Comment thread foreign/cpp/include/iggy.hpp Outdated
* @throws IggyException if the connection or automatic authentication
* fails.
*/
void Connect() const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: These methods are const but clearly mutate connection state (it only compiles because the state lives behind client_). Marking them non-const would better communicate the semantics, since const usually implies no observable state change and often thread-safety.

Applies to:

  • Connect()
  • Disconnect()
  • Shutdown()
  • Login()
  • Logout()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@slbotbm
slbotbm requested a review from ethanlin01x August 3, 2026 20:12
Comment thread foreign/cpp/src/client.rs
Comment on lines 62 to 69
/// Creates a new client connection and returns a raw pointer to the underlying [`Client`].
///
/// # Ownership
///
/// The returned `*mut Client` is owned by the caller (the C++ side). The caller is responsible
/// for calling [`delete_connection`] exactly once to release the resources. Failing to do so
/// leaks the underlying tokio runtime resources and the open network connection.
///

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and iggy.hpp:389-395 says destroying the client releases the connection. IggyClient::connect spawns a heartbeat holding its own Arc to the transport, exiting only on ClientShutdown, so the socket, the server session and the ping loop all survive. Same reason :488 ("no effect when already connected") is false and the :501-505 reuse cycle leaks a task per cycle. Worth filing upstream: store the JoinHandle discarded at clients/client.rs:250 and abort it in a Drop for IggyClient.

Comment on lines +490 to +493
* @note HTTP is stateless; connecting initializes heartbeat processing but
* does not open a persistent transport connection.
* @throws IggyException if the connection or automatic authentication
* fails.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This promises Connect() throws on failure. With the documented default (unlimited retries) tcp_client.rs:424-442 retries forever and block_on parks the caller indefinitely. It can only throw if WithReconnectionMaxRetries(n) was called.

Comment thread foreign/cpp/src/client.rs
Comment on lines +113 to +126
if config.has_tls_enabled {
builder = builder.with_tls_enabled(config.tls_enabled);
if config.tls_enabled {
if !config.tls_domain.is_empty() {
builder = builder.with_tls_domain(config.tls_domain);
}
if !config.tls_ca_file.is_empty() {
builder = builder.with_tls_ca_file(config.tls_ca_file);
}
if config.has_tls_validate_certificate {
builder = builder.with_tls_validate_certificate(config.tls_validate_certificate);
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_tls_enabled: Builder().WithTlsDomain(d).WithTlsCaFile(p).Build() without WithTlsEnabled(true) silently drops all three TLS settings and connects in plaintext. The gate carries no information either, since TcpClientConfig::default() is already tls_enabled: false. Suggest deleting the field, calling with_tls_enabled unconditionally, and erroring when TLS material is set with TLS off. - set_reconnection_max_retries (src/lib.rs:348): dead. "Never set" and WithoutReconnectionLimit() are indistinguishable, and {set_=false, has_=true, value=n} is representable and silently ignored. has_reconnection_max_retries alone expresses Option<u32>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review PR is waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants