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: config editor #193

Merged
merged 8 commits into from
Nov 27, 2024
Merged

feat: config editor #193

merged 8 commits into from
Nov 27, 2024

Conversation

MasterKenth
Copy link
Contributor

@MasterKenth MasterKenth commented Nov 19, 2024

Added ability to edit (some) settings in frontend; very cool 😎.
image

Not all settings are migrated from .env to db yet - only FIXED_PIN, OPENAI_API_KEY, BREVO_API_URL and BREVO_API_KEY right now. Migration requires changing a lot of code since settings fetching is now async/db-dependent.

BREAKING CHANGES

  • FIXED_PIN can no longer be None - instead a blank value '' means "disabled".
  • MAIL_CLIENT no longer does anything - instead Brevo is always used as long as BREVO_API_KEY is not blank ('').

@MasterKenth MasterKenth changed the title 🚧 Wip(config): edit config (env vars) in ui feat: config editor Nov 19, 2024
@MasterKenth MasterKenth marked this pull request as ready for review November 22, 2024 13:16
Comment on lines +34 to +35
console.log('Try setup settings')
await setup_settings()
Copy link
Member

Choose a reason for hiding this comment

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

Getting an error where setup_settings is called before project is created.

The error occurs when code is tested with clean DB (empty MongoDB).

Shuffling the order fixes the problem for me:

@asynccontextmanager
async def lifespan(_app: FastAPI):
    console.log('Try setup db')
    await setup_db()
    console.log('Try setup initial project')
    await setup_project()
    console.log('Try setup settings')
    await setup_settings()
    console.log('Try setup Sentry')
    await setup_sentry()
    console.log('Try setup file parser environment')
    await setup_file_parser()
    yield
    console.log('😴 Unmounting app ...')
    console.log('Shutting down Sentry')
    client = Hub.current.client
    if client is not None:
        client.close(timeout=2.0)

payload = BrevoPayload.model_validate(payload.model_dump())
settings_service = SettingsServiceFactory().get_service()
url = await settings_service.get_value(SettingKey.BREVO_API_URL)
key = await settings_service.get_value(SettingKey.BREVO_API_KEY)
Copy link
Member

Choose a reason for hiding this comment

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

send_mail raises requests.exceptions.InvalidHeader: Header part (SecretStr('**********')) from ('api-key', SecretStr('**********')) must be of type str or bytes, not <class 'pydantic.types.SecretStr'>

Might be cause by my test environment. There is a value set for FIXED_PIN in my .env.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Remove BREVO_API_KEY from .env file (temp fix until settings and .env are completely separated, wip).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This probably also applies to OPENAI_API_KEY and any other SecretStr env var.

@MasterKenth MasterKenth merged commit d4e6fb4 into master Nov 27, 2024
2 checks passed
@MasterKenth MasterKenth deleted the feat/config-editor branch November 27, 2024 14:11
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.

3 participants