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

Bugfix/ticket 26 #28

Merged
merged 2 commits into from
Oct 1, 2024
Merged

Conversation

brettchaldecott
Copy link
Contributor

@brettchaldecott brettchaldecott commented Oct 1, 2024

Explain your changes

  • This fix resolves issues with the .env files. The original implementation required that the .env files where always in place, even if blank. This has been changed so that the .env files do not have to be present.
    Bug: KindeClient ignores environment variables #26
  • Further fix required following environment loading changes have been made as caused pipeline issue, this fix is to handle the setting of the grant type to a KINDE_GRANT_TYPE=authorization_code. Originally this could only be KINDE_GRANT_TYPE=CODE. Now both are support. This enables more transparency between the Spring Boot libraries and Kinde.

Checklist

🛟 If you need help, consider asking for advice over in the Kinde community.

Brett Chaldecott added 2 commits October 1, 2024 07:26
…de-oss#26 Local testing works ok, will need further clean environmental testing to confirm all is in order
Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The changes involve modifications to the KindeClientBuilder and AuthorizationType classes. In the KindeClientBuilder, the constructor's error handling for loading environment variables has been simplified. The AuthorizationType enum has been updated to include a new constructor that accommodates a list of string values, enhancing the matching capabilities for authorization types.

Changes

Files Change Summary
kinde-core/src/main/java/com/kinde/KindeClientBuilder.java The constructor now uses Dotenv.configure().ignoreIfMissing().systemProperties().load() for loading environment variables, simplifying error handling by removing the try-catch block.
kinde-core/src/main/java/com/kinde/authorization/AuthorizationType.java The AuthorizationType enum has a new constructor accepting a list of string values. The CODE constant initializes this list with "authorization_code", and the fromValue method has been enhanced for flexible matching.

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 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.

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.

Project coverage is 42.63%. Comparing base (cc95861) to head (9d5a129).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...ava/com/kinde/authorization/AuthorizationType.java 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main      #28      +/-   ##
============================================
+ Coverage     42.44%   42.63%   +0.19%     
- Complexity      175      176       +1     
============================================
  Files            53       53              
  Lines           959      964       +5     
  Branches         77       77              
============================================
+ Hits            407      411       +4     
  Misses          515      515              
- Partials         37       38       +1     
Files with missing lines Coverage Δ
...re/src/main/java/com/kinde/KindeClientBuilder.java 76.66% <100.00%> (+0.57%) ⬆️
...ava/com/kinde/authorization/AuthorizationType.java 80.95% <77.77%> (-4.77%) ⬇️

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

🧹 Outside diff range and nitpick comments (2)
kinde-core/src/main/java/com/kinde/KindeClientBuilder.java (2)

Line range hint 193-199: Suggest improvements to setParameterFromEnvironmental method

While the method works as intended, consider the following improvements:

  1. Enhance logging:

    • Include the actual value being set (if not sensitive) in the info log.
    • Use string formatting instead of concatenation for better performance.
  2. Simplify the method:

    • Consider using Optional to handle null checks more elegantly.

Here's a suggested refactor:

private void setParameterFromEnvironmental(KindeParameters parameter, Dotenv dotenv) {
    Optional.ofNullable(dotenv.get(parameter.getValue()))
        .ifPresent(value -> {
            Object mappedValue = parameter.getMapper().apply(value);
            this.parameters.put(parameter.getValue(), mappedValue);
            log.info("Set parameter: {} = {}", parameter.getValue(), 
                     parameter.getValue().toLowerCase().contains("secret") ? "****" : mappedValue);
        });
}

This refactored version:

  • Uses Optional to handle null checks.
  • Improves logging by including the set value (masking if it's a secret).
  • Uses string formatting in logging for better performance.

Line range hint 176-186: Approve overall changes with a minor suggestion

The changes to the constructor don't negatively impact the rest of the class, which is good. The build() method still properly checks for required parameters.

As a minor improvement, consider refactoring the build() method to use Java 8+ features for a more concise check of required parameters:

public KindeClient build() {
    Set<String> requiredParams = Set.of(
        KindeParameters.CLIENT_ID.getValue(),
        KindeParameters.CLIENT_SECRET.getValue(),
        KindeParameters.DOMAIN.getValue()
    );
    
    if (!this.parameters.keySet().containsAll(requiredParams)) {
        throw new InvalidParameterException("The required parameters were not set");
    }
    
    return injector.getInstance(KindeClient.class);
}

This refactored version:

  • Uses a Set literal for required parameters, improving readability.
  • Simplifies the containsAll check.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cc95861 and 9d5a129.

📒 Files selected for processing (2)
  • kinde-core/src/main/java/com/kinde/KindeClientBuilder.java (1 hunks)
  • kinde-core/src/main/java/com/kinde/authorization/AuthorizationType.java (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
kinde-core/src/main/java/com/kinde/authorization/AuthorizationType.java

[warning] 44-44: kinde-core/src/main/java/com/kinde/authorization/AuthorizationType.java#L44
Added line #L44 was not covered by tests

🔇 Additional comments (7)
kinde-core/src/main/java/com/kinde/authorization/AuthorizationType.java (5)

5-7: LGTM: Import statements are appropriate.

The added imports for ArrayList and List are necessary for the new implementation of the values list in the enum. These changes align well with the modifications made to the AuthorizationType enum.


11-11: LGTM: Enum constant initialization updated correctly.

The CODE enum constant now includes "authorization_code" as an additional value, which aligns with the PR objectives. This change enhances the flexibility of the SDK by supporting both KINDE_GRANT_TYPE=authorization_code and KINDE_GRANT_TYPE=CODE.


17-17: LGTM: New field declaration is appropriate.

The new values field of type List<String> is correctly declared as final and initialized with an ArrayList. This implementation allows for efficient storage and retrieval of multiple string values for each enum constant.


24-28: LGTM: New constructor implementation is correct.

The new constructor correctly initializes both the value field and the values list. The use of addAll() ensures that all provided values are added to the list, allowing for multiple string representations of each enum constant.


43-45: 🛠️ Refactor suggestion

Optimize new logic and add test coverage.

The new logic correctly implements the requirement to match against additional values in the values list. However, there are a few points to consider:

  1. The stream operation can be simplified for better readability:

    if (constant.values.contains(value)) {
        return constant;
    }
  2. This new logic is not covered by tests according to the static analysis hint. It's crucial to add test cases that cover this new functionality to ensure its correctness and prevent future regressions.

Could you please add test cases to cover this new logic? Here's a script to verify the current test coverage:

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 44-44: kinde-core/src/main/java/com/kinde/authorization/AuthorizationType.java#L44
Added line #L44 was not covered by tests

kinde-core/src/main/java/com/kinde/KindeClientBuilder.java (2)

Line range hint 1-199: Summary: Changes align well with PR objectives

The modifications to KindeClientBuilder.java successfully address the PR objectives:

  1. The new Dotenv configuration (ignoreIfMissing()) allows for the absence of .env files without causing issues, as required.
  2. The overall functionality of the class is maintained, ensuring that it still works as expected.
  3. The code has been simplified, potentially improving its robustness and maintainability.

While the changes don't directly address the grant type configuration mentioned in the PR objectives, they lay the groundwork for more flexible environment variable handling, which could facilitate such changes in the future.

To fully meet the PR objectives, ensure that the AuthorizationType enum (not shown in this file) has been updated to support both KINDE_GRANT_TYPE=authorization_code and KINDE_GRANT_TYPE=CODE.


24-40: Approve changes with a request for verification

The simplification of the environment variable loading process is a good improvement. The use of ignoreIfMissing() aligns well with the PR objective of allowing the absence of .env files without causing issues.

However, to ensure the changes meet the PR objectives fully:

  1. Please verify that the application behaves correctly when the .env file is missing.
  2. Consider adding a log statement to inform when the .env file is missing, for debugging purposes.

To verify the behavior when .env file is missing, you can run the following script:

This script will temporarily rename the .env file, run the application, and check for any errors in the output.

@DanielRivers DanielRivers merged commit 03f82ff into kinde-oss:main Oct 1, 2024
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 2, 2024
2 tasks
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.

2 participants