Skip to content

Conversation

@Eden-D-Zhang
Copy link
Contributor

Description

This PR sets the foundation of the clp-credential-manager service.

Added:

  • New component: clp-credential-manager Rust Crate.
  • Dependencies, including those needed in the future (AWS, JWT, SQLx, etc.)
  • Service configuration structs
  • Error enumeration considering planned functionality
  • Basic health route for service API
  • Barebones service initialization

Next up:

  • Implement credential DB CRUD operations
  • Add DB operation auditing

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Cargo fmt, check, clippy

@Eden-D-Zhang Eden-D-Zhang requested a review from a team as a code owner November 26, 2025 02:54
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hoophalab hoophalab self-requested a review December 1, 2025 15:49
Copy link
Contributor

@hoophalab hoophalab left a comment

Choose a reason for hiding this comment

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

LGTM in general. There are some comments

Comment on lines 60 to 68
fn init_tracing() {
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));

let _ = tracing_subscriber::fmt()
.with_env_filter(env_filter)
.with_target(false)
.json()
.try_init();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. The tracing_subscriber::fmt()...try_init() call returns a Result which is being dropped, meaning any initialization failure will be ignored, leading to silent bugs.

Possible implementations: we could use anyhow::Result<()>, or define a crate-wide Error type and use Result<(), Error>

Suggested change
fn init_tracing() {
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
let _ = tracing_subscriber::fmt()
.with_env_filter(env_filter)
.with_target(false)
.json()
.try_init();
}
fn init_tracing() -> Result<(), Error>{
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
tracing_subscriber::fmt()
.with_env_filter(env_filter)
.with_target(false)
.json()
.try_init()?;
}
  1. Zhihao will probably suggest you implementing log file rotation in code.
    https://github.com/y-scope/clp/blob/main/components/api-server/src/bin/api_server.rs#L45C1-L66C2

hoophalab
hoophalab previously approved these changes Dec 1, 2025
Copy link
Contributor

@hoophalab hoophalab left a comment

Choose a reason for hiding this comment

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

A few comments to make the code more rusty, otherwise all good. @LinZhihao-723 you can start having another review.

Comment on lines 68 to 69
.try_init()
.map_err(|err| anyhow::Error::msg(err.to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.try_init()
.map_err(|err| anyhow::Error::msg(err.to_string()))
.try_init()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change isn't working for me:

"? couldn't convert the error: dyn StdError + Send + Sync: Sized is not satisfied"

Eden-D-Zhang and others added 2 commits December 1, 2025 18:44
Co-authored-by: hoophalab <200652805+hoophalab@users.noreply.github.com>
Copy link
Member

@LinZhihao-723 LinZhihao-723 left a comment

Choose a reason for hiding this comment

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

In general a great job, but still some things to fix. @hoophalab please also check my comments so that you can help catch more later.
I think there are two lessons learned in this PR:

  • As your first PR to Rust this is still too large. Personally, I would say this PR can be split into three PRs: one to set up the error handling system, one to set up the server skeleton like #1715, and last one for the rest. In that way, you get more chance to learn step by step and save more time on the later review process.
  • When contributing to sth you're not familiar with, you can check what other components are doing. We had similar set up for the API server and clp-rust-utils a month ago, which can be references to you to pick up.

Comment on lines 16 to 20
pub fn build_router() -> Router<AppState> {
Router::new()
.route("/health", get(health::health_check))
.layer(TraceLayer::new_for_http())
}
Copy link
Member

Choose a reason for hiding this comment

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

Can u pass the state into this method to be consistent with the API server?

.with_state(client)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had trouble getting the above suggestion to work, plus it seems the current implementation is actually recommended.

https://docs.rs/axum/0.8.7/axum/routing/struct.Router.html#returning-routers-with-states-from-functions

Copy link
Member

Choose a reason for hiding this comment

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

kk thx for referring to the doc. Let me check.

Comment on lines 83 to 91
/// Supplies the default `MySQL` server port (`3306`).
const fn default_mysql_port() -> u16 {
3306
}

/// Supplies the default maximum connection count for the `MySQL` pool.
const fn default_max_connections() -> u32 {
DEFAULT_MAX_CONNECTIONS
}
Copy link
Member

Choose a reason for hiding this comment

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

We should group all "default" wrappers together.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure but I guess Eden might don't want to provide default value for every field? So he cannot use impl Default for ...

Copy link
Member

Choose a reason for hiding this comment

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

Let's wait for @junhaoliao to check whether we should share the DB credential config schema with CLP DB config. If they're shareable then we can get rid of this entirely.


/// Connection options for the `MySQL` backend that stores credentials.
#[derive(Debug, Clone, Deserialize)]
pub struct DatabaseConfig {
Copy link
Member

Choose a reason for hiding this comment

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

pub should comes before private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be irrelevant pending the option of using the clp_rust_utils config instead, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. But it's a heads up for the proper ordering.


init_tracing()?;

let config = AppConfig::from_file(&args.config)?;
Copy link
Member

Choose a reason for hiding this comment

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

Back to the previous comment: if you want to make the errors traceable, you should log the error before return. Otherwise when you start this thing inside docker compose I'm not sure how that error will be reflected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand what you mean here; can you explain what I need to add here?

Eden-D-Zhang and others added 2 commits December 4, 2025 11:57
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants