Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): cerbos new REEARTH_ACCOUNTS_DEV [FLOW-BE-52] #42

Merged
merged 3 commits into from
Mar 3, 2025

Conversation

akiyatomohiro
Copy link
Contributor

@akiyatomohiro akiyatomohiro commented Mar 3, 2025

Overview

What I've done

ref: https://www.notion.so/eukarya/Testing-check-permission-after-migration-1ab16e0fb16580e08d50d15c41362f78?pvs=4#1ab16e0fb1658041a689cc03fe0e3c8a

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features
    • Introduced a new configuration option to enable development mode.
    • Improved backend initialization to adjust behavior dynamically when in development mode.

Copy link

coderabbitai bot commented Mar 3, 2025

Walkthrough

The pull request introduces a new environment variable REEARTH_ACCOUNTS_DEV=false in the environment example file. In the server startup code, the Cerbos client initialization is updated to conditionally add the plaintext option based on the value of REEARTH_ACCOUNTS_DEV. This change ensures that the client configuration can be adjusted dynamically based on the environment setting.

Changes

File Path Change Summary
server/.env.example Added new environment variable REEARTH_ACCOUNTS_DEV=false.
server/internal/app/server.go Modified Cerbos client initialization by conditionally appending cerbos.WithPlaintext() based on whether REEARTH_ACCOUNTS_DEV is set to "true".

Sequence Diagram(s)

sequenceDiagram
    participant S as Server Start
    participant E as Environment
    participant C as Cerbos Client

    S->>E: Read REEARTH_ACCOUNTS_DEV value
    alt Value equals "true"
        S->>C: Initialize client with plaintext option
    else Value not "true"
        S->>C: Initialize client without plaintext option
    end
Loading

Suggested Reviewers

  • pyshx
  • KeisukeYamashita

Poem

I hop through code in fields so bright,
With new settings glowing in the night.
A conditional leap, a careful dance,
Rabbit-style checks enhance our chance.
Happy hops as servers run—code done!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this 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.

@akiyatomohiro akiyatomohiro marked this pull request as ready for review March 3, 2025 10:40
Copy link

@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

🧹 Nitpick comments (2)
server/internal/app/server.go (2)

44-47: Consider adding a log message when using plaintext mode

When running with the plaintext option, it would be helpful to add a log message indicating that the insecure connection mode is being used. This provides additional visibility and helps prevent accidental use in production.

if os.Getenv("REEARTH_ACCOUNTS_DEV") == "true" {
+    log.Info("Using plaintext (insecure) connection for Cerbos as REEARTH_ACCOUNTS_DEV=true")
    opts = append(opts, cerbos.WithPlaintext())
}

46-46: Consider a more robust environment variable check

The current check for the environment variable uses a direct string comparison. A more robust approach would be to use a dedicated function for parsing boolean environment variables that handles different formats ("true", "True", "1", etc.).

- if os.Getenv("REEARTH_ACCOUNTS_DEV") == "true" {
+ // ParseBool handles "1", "t", "T", "TRUE", "true", "True", 
+ // "0", "f", "F", "FALSE", "false", "False"
+ if devMode, _ := strconv.ParseBool(os.Getenv("REEARTH_ACCOUNTS_DEV")); devMode {

Don't forget to add the import:

import (
    // ...existing imports
+   "strconv"
)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3fc967d and a42925a.

📒 Files selected for processing (2)
  • server/.env.example (1 hunks)
  • server/internal/app/server.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • server/.env.example
🔇 Additional comments (2)
server/internal/app/server.go (2)

44-50: Improve security by making plaintext connection conditional based on environment - Good change!

This change enhances security by making the plaintext connection option for Cerbos conditional rather than hardcoded. Now the plaintext option will only be used in development environments where REEARTH_ACCOUNTS_DEV=true, while production environments can use secure connections by default.


44-47:

✅ Verification successful

Verify the environment variable usage across the codebase

Let's verify that the REEARTH_ACCOUNTS_DEV environment variable is consistently used and documented throughout the codebase.


🏁 Script executed:

#!/bin/bash
# Search for other occurrences of REEARTH_ACCOUNTS_DEV
echo "Searching for REEARTH_ACCOUNTS_DEV usage in the codebase..."
rg "REEARTH_ACCOUNTS_DEV" --type go --type-add env:.env

# Check if the variable is documented in README or other documentation
echo "Checking for documentation of REEARTH_ACCOUNTS_DEV..."
rg "REEARTH_ACCOUNTS_DEV" --type md
rg "REEARTH_ACCOUNTS_DEV" -g "*.env*"

# Check the .env.example file
echo "Content of .env.example for REEARTH_ACCOUNTS_DEV:"
if [ -f ".env.example" ]; then
  grep "REEARTH_ACCOUNTS_DEV" .env.example
elif [ -f "server/.env.example" ]; then
  grep "REEARTH_ACCOUNTS_DEV" server/.env.example
fi

Length of output: 745


Environment Variable Usage Verified: Consistent Across the Codebase

The verification confirms that:

  • The REEARTH_ACCOUNTS_DEV variable is used only in server/internal/app/server.go,
  • Its default value (false) is set in server/.env.example,
  • No other occurrences were found in markdown documentation.

No additional modifications are needed.

@akiyatomohiro akiyatomohiro requested a review from pyshx March 3, 2025 10:47
@pyshx pyshx changed the title chore: fix cerbos new [FLOW-BE-52] fix(server): cerbos new REEARTH_ACCOUNTS_DEV [FLOW-BE-52] Mar 3, 2025
@akiyatomohiro akiyatomohiro merged commit f65066b into main Mar 3, 2025
12 checks passed
@akiyatomohiro akiyatomohiro deleted the chore/fix-cerbos-new branch March 3, 2025 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants