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

feat(resend): added env variablers #673

Merged
merged 2 commits into from
Jul 17, 2023
Merged

feat(resend): added env variablers #673

merged 2 commits into from
Jul 17, 2023

Conversation

StanGirard
Copy link
Collaborator

Added resend as Brain settings and updated emails so we can change it

@StanGirard StanGirard requested a review from gozineb July 17, 2023 09:41
@vercel
Copy link

vercel bot commented Jul 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2023 11:57am
quivrapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2023 11:57am

@github-actions
Copy link
Contributor

github-actions bot commented Jul 17, 2023

/home/runner/work/quivr/quivr/backend/core/models/brains_subscription_invitations.py: LOGAF Level 3

The code is generally good, but there are a few areas for potential improvement:

  1. Error Handling: In the resend_invitation_email method, you are catching a general exception. It would be better to catch specific exceptions that you expect might occur. This way, you can provide more specific error messages and handle different types of exceptions in different ways.

  2. Logging: You are using print statements to log the response from the resend API. It would be better to use a logger for this, as you have done elsewhere in your code. This will allow you to control the level of logging and where the logs are sent.

  3. Code Duplication: The create_subscription_invitation and update_subscription_invitation methods have similar code for interacting with the database. You could consider refactoring this to reduce code duplication.

Here's an example of how you might refactor the resend_invitation_email method:

def resend_invitation_email(self):
    brains_settings = BrainSettings()  # pyright: ignore reportPrivateUsage=none
    resend.api_key = brains_settings.resend_api_key

    brain_url = self.get_brain_url()

    html_body = f"""
    <p>This brain has been shared with you by {self.inviter_email}.</p>
    <p><a href='{brain_url}'>Click here</a> to access your brain.</p>
    """

    try:
        r = resend.Emails.send(
            {
                "from": brains_settings.resend_email_address,
                "to": self.email,
                "subject": "Quivr - Brain Shared With You",
                "html": html_body,
            }
        )
        logger.info("Resend response: %s", r)
    except resend.ResendAPIError as e:
        logger.error(f"Error sending email: {e}")
        return

    return r

/home/runner/work/quivr/quivr/backend/core/models/settings.py: LOGAF Level 2

The code functions, but there are significant issues that need attention:

  1. API Keys: The BrainSettings class includes API keys as class attributes. This is a security risk, as it exposes sensitive information. You should store API keys in environment variables or a secure configuration file, and access them using a secure method.

  2. Hardcoded Values: The resend_api_key and resend_email_address attributes have hardcoded default values. It would be better to set these values in a configuration file or environment variables, so they can be changed without modifying the code.

Here's an example of how you might refactor the BrainSettings class:

from pydantic import BaseSettings, Field

class BrainSettings(BaseSettings):
    openai_api_key: str = Field(..., env="OPENAI_API_KEY")
    anthropic_api_key: str = Field(..., env="ANTHROPIC_API_KEY")
    supabase_url: str = Field(..., env="SUPABASE_URL")
    supabase_service_key: str = Field(..., env="SUPABASE_SERVICE_KEY")
    resend_api_key: str = Field(..., env="RESEND_API_KEY")
    resend_email_address: str = Field(..., env="RESEND_EMAIL_ADDRESS")

In this example, the Field function is used to specify that the value for each attribute should be taken from an environment variable with the same name. The ... argument means that the environment variable is required. If it is not set, an error will be raised.


🔒🔁🔍


Powered by Code Review GPT

@gozineb gozineb merged commit f631363 into main Jul 17, 2023
3 checks passed
StanGirard added a commit that referenced this pull request Sep 12, 2023
* feat(resend): added env variablers

* fix(resend): made optional
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