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

Add user param to on_init command section #68

Merged
merged 1 commit into from
Jan 10, 2024

Conversation

Kaspiman
Copy link
Contributor

@Kaspiman Kaspiman commented Jan 10, 2024

Reason for This PR

closes: roadrunner-server/roadrunner#1585

Description of Changes

Added abillity to configure user for on_init command section.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • New Features

    • Introduced a new user configuration option for initialization settings.
  • Refactor

    • Streamlined command initialization by incorporating a unified configuration structure.
    • Simplified the command setup process in plugins with consolidated configuration parameters.

Signed-off-by: Plakhotnikov Vladimir <v.plahotnikov@yclients.tech>
Copy link

coderabbitai bot commented Jan 10, 2024

Walkthrough

The update involves restructuring how configuration is managed in a Go application. A new User field has been added to the InitConfig struct, and the handling of command initialization has been refactored. Instead of passing multiple configuration fields separately, the entire InitConfig object is now passed around, streamlining the codebase and reducing complexity in function signatures and method implementations.

Changes

Files Change Summaries
config.go Added User field to InitConfig struct.
init.go Refactored command struct and newCommand function to use InitConfig.
plugin.go Simplified command initialization in Serve method to use InitConfig.

Poem

In the land of code, where the rabbits hop,
A new field in InitConfig did pop.
With a hop, skip, and a refactor leap,
Simplified the code, oh so neat! 🐇💻

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 20c91b0 and 8cd68e7.
Files selected for processing (3)
  • config.go (1 hunks)
  • init.go (1 hunks)
  • plugin.go (1 hunks)
Additional comments: 5
config.go (1)
  • 38-39: Adding the User field to the InitConfig struct is consistent with the PR's objective to allow specifying a user for the on_init command. Ensure that the new field is properly documented and that its usage is clear to the users of the library.
init.go (3)
  • 16-17: The refactoring to include an InitConfig object in the command struct is a good approach to simplify parameter passing and improve maintainability.

  • 33-37: The check for a non-empty User field and the subsequent call to utils.ExecuteFromUser is a critical addition. Ensure that the ExecuteFromUser function is robust and handles potential errors when switching users.

  • 40-40: The use of a timer to enforce the ExecTimeout is appropriate. Ensure that the timer is stopped in all code paths to avoid resource leaks.

plugin.go (1)
  • 162-162: The simplification in the Serve method to pass the entire OnInit struct is a good practice as it reduces the complexity of the function signature and makes future changes easier.

config.go Show resolved Hide resolved
plugin.go Show resolved Hide resolved
@Kaspiman Kaspiman changed the title Add user param to on_init command Add user param to on_init command section Jan 10, 2024
@rustatian rustatian self-requested a review January 10, 2024 15:46
@rustatian rustatian added the enhancement New feature or request label Jan 10, 2024
}

func newCommand(log *zap.Logger, env map[string]string, cmd []string, execTimeout time.Duration) *command {
func newCommand(log *zap.Logger, cfg *InitConfig) *command {
Copy link
Member

Choose a reason for hiding this comment

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

Good catch with *InitConfig 👍

Copy link
Member

@rustatian rustatian left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @Kaspiman 👍

@rustatian
Copy link
Member

Hey @Kaspiman 👋
It would be nice if you also update documentation here: link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[💡 FEATURE REQUEST]: Add the ability to configure the user and group for on_init and after_init phases
2 participants