Skip to content

Conversation

@Subhra264
Copy link
Contributor

@Subhra264 Subhra264 commented Sep 5, 2024

  • Enrichment tables are not listed correctly with RBAC.
  • Create ofga ownership for metadata streams

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced handling of stream types for improved flexibility and functionality.
    • Introduced enterprise-level ownership management features for metadata handling in the context of the enterprise feature.
  • Bug Fixes

    • Streamlined logic for retrieving model keys associated with stream types, ensuring more accurate results.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Walkthrough

The pull request introduces modifications to the handling of stream types within the list function and related components. Key changes include a streamlined approach to retrieving model keys for different stream types, the addition of ownership management functionality gated by the enterprise feature flag, and adjustments to the get_streams function to conditionally format stream type strings. These changes affect the functionality and control flow of several modules, enhancing their adaptability to enterprise configurations.

Changes

Files Change Summary
src/handler/http/request/stream/mod.rs, src/service/metadata/distinct_values.rs, src/service/metadata/trace_list_index.rs Introduced new conditional blocks within the Metadata trait implementations, gated by the enterprise feature flag, to call set_ownership_if_not_exists if openfga is enabled.
src/service/stream.rs Modified the get_streams function to include a match statement that conditionally formats the s_type parameter for StreamType::EnrichmentTables.

Suggested labels

🧹 Updates

Tip

New features

Walkthrough comment now includes:

  • Possibly related PRs: A list of potentially related PRs to help you recall past context.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs. You can also provide custom labeling instructions in the UI or configuration file.

Notes:

  • Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Sep 5, 2024
@Subhra264 Subhra264 marked this pull request as ready for review September 9, 2024 07:09
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
src/service/stream.rs (1)

Line range hint 1-300: Improve error handling by avoiding unwraps.

The use of unwrap in several places (e.g., database schema retrievals) could lead to panics in production. Consider using more robust error handling to ensure the application remains stable and provides meaningful error messages to the users.

Replace unwrap with error handling, for example:

let schema = infra::schema::get(org_id, stream_name, stream_type)
    .await
    .map_err(|e| Error::new(ErrorKind::Other, e))?;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5562edb and 509034f.

Files selected for processing (4)
  • src/handler/http/request/stream/mod.rs (1 hunks)
  • src/service/metadata/distinct_values.rs (1 hunks)
  • src/service/metadata/trace_list_index.rs (1 hunks)
  • src/service/stream.rs (1 hunks)
Additional context used
Path-based instructions (4)
src/service/metadata/trace_list_index.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/service/metadata/distinct_values.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/handler/http/request/stream/mod.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/service/stream.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (3)
src/service/metadata/trace_list_index.rs (1)

129-143: Conditional feature flag usage is correct.

The use of the enterprise feature flag to conditionally compile the new ownership management functionality is correctly implemented. The async call to set_ownership_if_not_exists is properly awaited, ensuring that the operation completes before proceeding.

Ensure that the enterprise and openfga features are correctly configured in your environment to test this functionality effectively.

src/service/metadata/distinct_values.rs (1)

183-197: Conditional feature flag usage is correct.

The use of the enterprise feature flag to conditionally compile the new ownership management functionality is correctly implemented. The async call to set_ownership_if_not_exists is properly awaited, ensuring that the operation completes before proceeding.

Ensure that the enterprise and openfga features are correctly configured in your environment to test this functionality effectively.

src/handler/http/request/stream/mod.rs (1)

342-363: Stream type handling is improved.

The modifications to the list function to use OFGA_MODELS for dynamically fetching model keys based on stream_type enhance flexibility and maintainability. The use of map_or to provide a default value if the model key is not found is correctly implemented.

Consider adding unit tests to verify that the list function correctly handles various stream_type values and correctly interacts with OFGA_MODELS.

Comment on lines +80 to +83
let s_type = match s_type {
StreamType::EnrichmentTables => "enrichment_table".to_string(),
_ => s_type.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.

Refactor suggestion for stream type handling.

The handling of stream_type using a match statement is clear and functional. However, consider using a method on the StreamType enum to encapsulate this logic, which would improve maintainability and reduce the complexity within the get_streams function.

Here's a proposed refactor:

impl StreamType {
    fn as_permitted_string(&self) -> String {
        match self {
            StreamType::EnrichmentTables => "enrichment_table".to_string(),
            _ => self.to_string(),
        }
    }
}

Then, replace the match statement in get_streams with:

- let s_type = match s_type {
-     StreamType::EnrichmentTables => "enrichment_table".to_string(),
-     _ => s_type.to_string(),
- };
+ let s_type = s_type.as_permitted_string();

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 509034f and ff0f61e.

Files selected for processing (4)
  • src/handler/http/request/stream/mod.rs (1 hunks)
  • src/service/metadata/distinct_values.rs (1 hunks)
  • src/service/metadata/trace_list_index.rs (1 hunks)
  • src/service/stream.rs (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/service/metadata/distinct_values.rs
  • src/service/metadata/trace_list_index.rs
  • src/service/stream.rs
Additional context used
Path-based instructions (1)
src/handler/http/request/stream/mod.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (1)
src/handler/http/request/stream/mod.rs (1)

342-342: Approved import statement for OFGA_MODELS.

The addition of OFGA_MODELS is essential for the new functionality to dynamically fetch model keys based on stream types, aligning with the PR's objectives to enhance RBAC handling.

Comment on lines +342 to +363
use o2_enterprise::enterprise::openfga::meta::mapping::OFGA_MODELS;

let user_id = req.headers().get("user_id").unwrap();
if let Some(s_type) = &stream_type {
if !s_type.eq(&StreamType::EnrichmentTables) && !s_type.eq(&StreamType::Metadata) {
match crate::handler::http::auth::validator::list_objects_for_user(
&org_id,
user_id.to_str().unwrap(),
"GET",
&s_type.to_string(),
)
.await
{
Ok(stream_list) => {
_stream_list_from_rbac = stream_list;
}
Err(e) => {
return Ok(crate::common::meta::http::HttpResponse::forbidden(
e.to_string(),
));
}
let stream_type_str = s_type.to_string();
match crate::handler::http::auth::validator::list_objects_for_user(
&org_id,
user_id.to_str().unwrap(),
"GET",
OFGA_MODELS
.get(stream_type_str.as_str())
.map_or(stream_type_str.as_str(), |model| model.key),
)
.await
{
Ok(stream_list) => {
_stream_list_from_rbac = stream_list;
}
Err(e) => {
return Ok(crate::common::meta::http::HttpResponse::forbidden(
e.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.

Approved changes with a suggestion for error handling.

The modifications in the list function to use OFGA_MODELS for fetching model keys based on stream types are well-aligned with the PR's objectives. This approach enhances flexibility and maintainability.

However, consider adding more robust error handling for cases where user_id might not be present in the headers, as currently, the code unwraps it directly which could lead to a panic if it's absent.

Consider adding a check before unwrapping user_id:

let user_id = match req.headers().get("user_id") {
    Some(uid) => uid,
    None => return Ok(crate::common::meta::http::HttpResponse::forbidden("User ID is required".to_string())),
};

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ff0f61e and 2c5fcd3.

Files selected for processing (4)
  • src/handler/http/request/stream/mod.rs (1 hunks)
  • src/service/metadata/distinct_values.rs (1 hunks)
  • src/service/metadata/trace_list_index.rs (1 hunks)
  • src/service/stream.rs (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/service/metadata/distinct_values.rs
  • src/service/metadata/trace_list_index.rs
  • src/service/stream.rs
Additional context used
Path-based instructions (1)
src/handler/http/request/stream/mod.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (1)
src/handler/http/request/stream/mod.rs (1)

342-363: Approved changes with a suggestion for error handling.

The modifications in the list function to use OFGA_MODELS for fetching model keys based on stream types are well-aligned with the PR's objectives. This approach enhances flexibility and maintainability.

However, consider adding more robust error handling for cases where user_id might not be present in the headers, as currently, the code unwraps it directly which could lead to a panic if it's absent.

Consider adding a check before unwrapping user_id:

let user_id = match req.headers().get("user_id") {
    Some(uid) => uid,
    None => return Ok(crate::common::meta::http::HttpResponse::forbidden("User ID is required".to_string())),
};

@Subhra264 Subhra264 merged commit 22ecc96 into main Sep 9, 2024
@Subhra264 Subhra264 deleted the enrich_list_rbac branch September 9, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants